Skip to content

Commit 7ebd87a

Browse files
committed
Auto merge of #72021 - Dylan-DPC:rollup-1w61ihk, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #71581 (Unify lints handling in rustdoc) - #71710 (Test for zero-sized function items not ICEing) - #71970 (Improve bitcode generation for Apple platforms) - #71975 (Reduce `TypedArena` creations in `check_match`.) - #72003 (allow wasm target for rustc-ap-rustc_span) - #72017 (Work around ICEs during cross-compilation for target, ast, & attr) Failed merges: r? @ghost
2 parents 7b80539 + 827ec49 commit 7ebd87a

File tree

17 files changed

+253
-186
lines changed

17 files changed

+253
-186
lines changed

src/librustc_ast/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#![feature(unicode_internals)]
2020
#![recursion_limit = "256"]
2121

22+
// FIXME(#56935): Work around ICEs during cross-compilation.
23+
#[allow(unused)]
24+
extern crate rustc_macros;
25+
2226
#[macro_export]
2327
macro_rules! unwrap_or {
2428
($opt:expr, $default:expr) => {

src/librustc_attr/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
77
#![feature(or_patterns)]
88

9+
// FIXME(#56935): Work around ICEs during cross-compilation.
10+
#[allow(unused)]
11+
extern crate rustc_macros;
12+
913
mod builtin;
1014

1115
pub use builtin::*;

src/librustc_codegen_llvm/back/write.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,8 @@ pub(crate) unsafe fn codegen(
651651
"LLVM_module_codegen_embed_bitcode",
652652
&module.name[..],
653653
);
654-
embed_bitcode(cgcx, llcx, llmod, Some(data));
654+
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
655655
}
656-
} else if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Marker) {
657-
embed_bitcode(cgcx, llcx, llmod, None);
658656
}
659657

660658
if config.emit_ir {
@@ -777,8 +775,8 @@ pub(crate) unsafe fn codegen(
777775
/// * __LLVM,__cmdline
778776
///
779777
/// It appears *both* of these sections are necessary to get the linker to
780-
/// recognize what's going on. For us though we just always throw in an empty
781-
/// cmdline section.
778+
/// recognize what's going on. A suitable cmdline value is taken from the
779+
/// target spec.
782780
///
783781
/// Furthermore debug/O1 builds don't actually embed bitcode but rather just
784782
/// embed an empty section.
@@ -789,9 +787,10 @@ unsafe fn embed_bitcode(
789787
cgcx: &CodegenContext<LlvmCodegenBackend>,
790788
llcx: &llvm::Context,
791789
llmod: &llvm::Module,
792-
bitcode: Option<&[u8]>,
790+
cmdline: &str,
791+
bitcode: &[u8],
793792
) {
794-
let llconst = common::bytes_in_context(llcx, bitcode.unwrap_or(&[]));
793+
let llconst = common::bytes_in_context(llcx, bitcode);
795794
let llglobal = llvm::LLVMAddGlobal(
796795
llmod,
797796
common::val_ty(llconst),
@@ -800,14 +799,15 @@ unsafe fn embed_bitcode(
800799
llvm::LLVMSetInitializer(llglobal, llconst);
801800

802801
let is_apple = cgcx.opts.target_triple.triple().contains("-ios")
803-
|| cgcx.opts.target_triple.triple().contains("-darwin");
802+
|| cgcx.opts.target_triple.triple().contains("-darwin")
803+
|| cgcx.opts.target_triple.triple().contains("-tvos");
804804

805805
let section = if is_apple { "__LLVM,__bitcode\0" } else { ".llvmbc\0" };
806806
llvm::LLVMSetSection(llglobal, section.as_ptr().cast());
807807
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
808808
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
809809

810-
let llconst = common::bytes_in_context(llcx, &[]);
810+
let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
811811
let llglobal = llvm::LLVMAddGlobal(
812812
llmod,
813813
common::val_ty(llconst),

src/librustc_codegen_ssa/back/write.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ pub enum BitcodeSection {
6868
// No bitcode section.
6969
None,
7070

71-
// An empty bitcode section (to placate tools such as the iOS linker that
72-
// require this section even if they don't use it).
73-
Marker,
74-
7571
// A full, uncompressed bitcode section.
7672
Full,
7773
}
@@ -101,6 +97,7 @@ pub struct ModuleConfig {
10197
pub emit_ir: bool,
10298
pub emit_asm: bool,
10399
pub emit_obj: EmitObj,
100+
pub bc_cmdline: String,
104101

105102
// Miscellaneous flags. These are mostly copied from command-line
106103
// options.
@@ -147,14 +144,8 @@ impl ModuleConfig {
147144
|| sess.opts.cg.linker_plugin_lto.enabled()
148145
{
149146
EmitObj::Bitcode
150-
} else if need_crate_bitcode_for_rlib(sess) {
151-
let force_full = need_crate_bitcode_for_rlib(sess);
152-
match sess.opts.optimize {
153-
config::OptLevel::No | config::OptLevel::Less if !force_full => {
154-
EmitObj::ObjectCode(BitcodeSection::Marker)
155-
}
156-
_ => EmitObj::ObjectCode(BitcodeSection::Full),
157-
}
147+
} else if need_bitcode_in_object(sess) {
148+
EmitObj::ObjectCode(BitcodeSection::Full)
158149
} else {
159150
EmitObj::ObjectCode(BitcodeSection::None)
160151
};
@@ -211,6 +202,7 @@ impl ModuleConfig {
211202
false
212203
),
213204
emit_obj,
205+
bc_cmdline: sess.target.target.options.bitcode_llvm_cmdline.clone(),
214206

215207
verify_llvm_ir: sess.verify_llvm_ir(),
216208
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
@@ -372,10 +364,12 @@ pub struct CompiledModules {
372364
pub allocator_module: Option<CompiledModule>,
373365
}
374366

375-
fn need_crate_bitcode_for_rlib(sess: &Session) -> bool {
376-
sess.opts.cg.embed_bitcode
367+
fn need_bitcode_in_object(sess: &Session) -> bool {
368+
let requested_for_rlib = sess.opts.cg.embed_bitcode
377369
&& sess.crate_types.borrow().contains(&CrateType::Rlib)
378-
&& sess.opts.output_types.contains_key(&OutputType::Exe)
370+
&& sess.opts.output_types.contains_key(&OutputType::Exe);
371+
let forced_by_target = sess.target.target.options.forces_embed_bitcode;
372+
requested_for_rlib || forced_by_target
379373
}
380374

381375
fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool {

src/librustc_mir_build/hair/pattern/_match.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,11 @@ crate struct MatchCheckCtxt<'a, 'tcx> {
580580
/// outside it's module and should not be matchable with an empty match
581581
/// statement.
582582
crate module: DefId,
583-
param_env: ty::ParamEnv<'tcx>,
583+
crate param_env: ty::ParamEnv<'tcx>,
584584
crate pattern_arena: &'a TypedArena<Pat<'tcx>>,
585585
}
586586

587587
impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
588-
crate fn create_and_enter<R>(
589-
tcx: TyCtxt<'tcx>,
590-
param_env: ty::ParamEnv<'tcx>,
591-
module: DefId,
592-
f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>) -> R,
593-
) -> R {
594-
let pattern_arena = TypedArena::default();
595-
596-
f(MatchCheckCtxt { tcx, param_env, module, pattern_arena: &pattern_arena })
597-
}
598-
599588
fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
600589
if self.tcx.features().exhaustive_patterns {
601590
self.tcx.is_ty_uninhabited_from(self.module, ty, self.param_env)

src/librustc_mir_build/hair/pattern/check_match.rs

+86-81
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::_match::Usefulness::*;
22
use super::_match::WitnessPreference::*;
33
use super::_match::{expand_pattern, is_useful, MatchCheckCtxt, Matrix, PatStack};
4-
54
use super::{PatCtxt, PatKind, PatternError};
65

6+
use arena::TypedArena;
77
use rustc_ast::ast::Mutability;
88
use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder};
99
use rustc_hir as hir;
@@ -17,7 +17,6 @@ use rustc_session::lint::builtin::{IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERN
1717
use rustc_session::parse::feature_err;
1818
use rustc_session::Session;
1919
use rustc_span::{sym, Span};
20-
2120
use std::slice;
2221

2322
crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
@@ -26,8 +25,12 @@ crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) {
2625
Some(id) => tcx.hir().body_owned_by(tcx.hir().as_local_hir_id(id)),
2726
};
2827

29-
let mut visitor =
30-
MatchVisitor { tcx, tables: tcx.body_tables(body_id), param_env: tcx.param_env(def_id) };
28+
let mut visitor = MatchVisitor {
29+
tcx,
30+
tables: tcx.body_tables(body_id),
31+
param_env: tcx.param_env(def_id),
32+
pattern_arena: TypedArena::default(),
33+
};
3134
visitor.visit_body(tcx.hir().body(body_id));
3235
}
3336

@@ -39,6 +42,7 @@ struct MatchVisitor<'a, 'tcx> {
3942
tcx: TyCtxt<'tcx>,
4043
tables: &'a ty::TypeckTables<'tcx>,
4144
param_env: ty::ParamEnv<'tcx>,
45+
pattern_arena: TypedArena<super::Pat<'tcx>>,
4246
}
4347

4448
impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
@@ -143,9 +147,13 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
143147
(pattern, pattern_ty)
144148
}
145149

146-
fn check_in_cx(&self, hir_id: HirId, f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>)) {
147-
let module = self.tcx.parent_module(hir_id);
148-
MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module.to_def_id(), |cx| f(cx));
150+
fn new_cx(&self, hir_id: HirId) -> MatchCheckCtxt<'_, 'tcx> {
151+
MatchCheckCtxt {
152+
tcx: self.tcx,
153+
param_env: self.param_env,
154+
module: self.tcx.parent_module(hir_id).to_def_id(),
155+
pattern_arena: &self.pattern_arena,
156+
}
149157
}
150158

151159
fn check_match(
@@ -159,91 +167,88 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
159167
self.check_patterns(arm.guard.is_some(), &arm.pat);
160168
}
161169

162-
self.check_in_cx(scrut.hir_id, |ref mut cx| {
163-
let mut have_errors = false;
170+
let mut cx = self.new_cx(scrut.hir_id);
164171

165-
let inlined_arms: Vec<_> = arms
166-
.iter()
167-
.map(|hir::Arm { pat, guard, .. }| {
168-
(self.lower_pattern(cx, pat, &mut have_errors).0, pat.hir_id, guard.is_some())
169-
})
170-
.collect();
172+
let mut have_errors = false;
171173

172-
// Bail out early if inlining failed.
173-
if have_errors {
174-
return;
175-
}
174+
let inlined_arms: Vec<_> = arms
175+
.iter()
176+
.map(|hir::Arm { pat, guard, .. }| {
177+
(self.lower_pattern(&mut cx, pat, &mut have_errors).0, pat.hir_id, guard.is_some())
178+
})
179+
.collect();
180+
181+
// Bail out early if inlining failed.
182+
if have_errors {
183+
return;
184+
}
176185

177-
// Fourth, check for unreachable arms.
178-
let matrix = check_arms(cx, &inlined_arms, source);
186+
// Fourth, check for unreachable arms.
187+
let matrix = check_arms(&mut cx, &inlined_arms, source);
179188

180-
// Fifth, check if the match is exhaustive.
181-
let scrut_ty = self.tables.node_type(scrut.hir_id);
182-
// Note: An empty match isn't the same as an empty matrix for diagnostics purposes,
183-
// since an empty matrix can occur when there are arms, if those arms all have guards.
184-
let is_empty_match = inlined_arms.is_empty();
185-
check_exhaustive(cx, scrut_ty, scrut.span, &matrix, scrut.hir_id, is_empty_match);
186-
})
189+
// Fifth, check if the match is exhaustive.
190+
let scrut_ty = self.tables.node_type(scrut.hir_id);
191+
// Note: An empty match isn't the same as an empty matrix for diagnostics purposes,
192+
// since an empty matrix can occur when there are arms, if those arms all have guards.
193+
let is_empty_match = inlined_arms.is_empty();
194+
check_exhaustive(&mut cx, scrut_ty, scrut.span, &matrix, scrut.hir_id, is_empty_match);
187195
}
188196

189197
fn check_irrefutable(&self, pat: &'tcx Pat<'tcx>, origin: &str, sp: Option<Span>) {
190-
self.check_in_cx(pat.hir_id, |ref mut cx| {
191-
let (pattern, pattern_ty) = self.lower_pattern(cx, pat, &mut false);
192-
let pats: Matrix<'_, '_> = vec![PatStack::from_pattern(pattern)].into_iter().collect();
193-
194-
let witnesses = match check_not_useful(cx, pattern_ty, &pats, pat.hir_id) {
195-
Ok(_) => return,
196-
Err(err) => err,
197-
};
198-
199-
let joined_patterns = joined_uncovered_patterns(&witnesses);
200-
let mut err = struct_span_err!(
201-
self.tcx.sess,
202-
pat.span,
203-
E0005,
204-
"refutable pattern in {}: {} not covered",
205-
origin,
206-
joined_patterns
207-
);
208-
let suggest_if_let = match &pat.kind {
209-
hir::PatKind::Path(hir::QPath::Resolved(None, path))
210-
if path.segments.len() == 1 && path.segments[0].args.is_none() =>
211-
{
212-
const_not_var(&mut err, cx.tcx, pat, path);
213-
false
214-
}
215-
_ => {
216-
err.span_label(
217-
pat.span,
218-
pattern_not_covered_label(&witnesses, &joined_patterns),
219-
);
220-
true
221-
}
222-
};
198+
let mut cx = self.new_cx(pat.hir_id);
223199

224-
if let (Some(span), true) = (sp, suggest_if_let) {
225-
err.note(
226-
"`let` bindings require an \"irrefutable pattern\", like a `struct` or \
227-
an `enum` with only one variant",
228-
);
229-
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
230-
err.span_suggestion(
231-
span,
232-
"you might want to use `if let` to ignore the variant that isn't matched",
233-
format!("if {} {{ /* */ }}", &snippet[..snippet.len() - 1]),
234-
Applicability::HasPlaceholders,
235-
);
236-
}
237-
err.note(
238-
"for more information, visit \
239-
https://doc.rust-lang.org/book/ch18-02-refutability.html",
200+
let (pattern, pattern_ty) = self.lower_pattern(&mut cx, pat, &mut false);
201+
let pats: Matrix<'_, '_> = vec![PatStack::from_pattern(pattern)].into_iter().collect();
202+
203+
let witnesses = match check_not_useful(&mut cx, pattern_ty, &pats, pat.hir_id) {
204+
Ok(_) => return,
205+
Err(err) => err,
206+
};
207+
208+
let joined_patterns = joined_uncovered_patterns(&witnesses);
209+
let mut err = struct_span_err!(
210+
self.tcx.sess,
211+
pat.span,
212+
E0005,
213+
"refutable pattern in {}: {} not covered",
214+
origin,
215+
joined_patterns
216+
);
217+
let suggest_if_let = match &pat.kind {
218+
hir::PatKind::Path(hir::QPath::Resolved(None, path))
219+
if path.segments.len() == 1 && path.segments[0].args.is_none() =>
220+
{
221+
const_not_var(&mut err, cx.tcx, pat, path);
222+
false
223+
}
224+
_ => {
225+
err.span_label(pat.span, pattern_not_covered_label(&witnesses, &joined_patterns));
226+
true
227+
}
228+
};
229+
230+
if let (Some(span), true) = (sp, suggest_if_let) {
231+
err.note(
232+
"`let` bindings require an \"irrefutable pattern\", like a `struct` or \
233+
an `enum` with only one variant",
234+
);
235+
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
236+
err.span_suggestion(
237+
span,
238+
"you might want to use `if let` to ignore the variant that isn't matched",
239+
format!("if {} {{ /* */ }}", &snippet[..snippet.len() - 1]),
240+
Applicability::HasPlaceholders,
240241
);
241242
}
243+
err.note(
244+
"for more information, visit \
245+
https://doc.rust-lang.org/book/ch18-02-refutability.html",
246+
);
247+
}
242248

243-
adt_defined_here(cx, &mut err, pattern_ty, &witnesses);
244-
err.note(&format!("the matched value is of type `{}`", pattern_ty));
245-
err.emit();
246-
});
249+
adt_defined_here(&mut cx, &mut err, pattern_ty, &witnesses);
250+
err.note(&format!("the matched value is of type `{}`", pattern_ty));
251+
err.emit();
247252
}
248253
}
249254

src/librustc_span/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#![feature(optin_builtin_traits)]
1515
#![feature(specialization)]
1616

17+
// FIXME(#56935): Work around ICEs during cross-compilation.
18+
#[allow(unused)]
19+
extern crate rustc_macros;
20+
1721
use rustc_data_structures::AtomicRef;
1822
use rustc_macros::HashStable_Generic;
1923
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};

0 commit comments

Comments
 (0)