Skip to content

Commit f975241

Browse files
committed
Auto merge of #66924 - Centril:rollup-r7pljxh, r=Centril
Rollup of 7 pull requests Successful merges: - #66346 (Replace .unwrap() with ? in std::os::unix::net) - #66789 (rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.) - #66822 (libunwind_panic: adjust miri panic hack) - #66827 (handle diverging functions forwarding their return place) - #66828 (Less minification) - #66850 (rustc: hide HirId's fmt::Debug output from -Z span_free_formats.) - #66907 (rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl.) Failed merges: - #66874 (Miri engine: proper support for `Assert` MIR terminators) r? @ghost
2 parents 4007d4e + 1569dab commit f975241

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+483
-484
lines changed

src/libcore/intrinsics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,11 @@ extern "rust-intrinsic" {
13481348
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
13491349

13501350
/// Internal hook used by Miri to implement unwinding.
1351+
/// Compiles to a NOP during non-Miri codegen.
1352+
///
13511353
/// Perma-unstable: do not use
13521354
#[cfg(not(bootstrap))]
1353-
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> !;
1355+
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
13541356
}
13551357

13561358
// Some functions are defined here because they accidentally got made

src/libpanic_unwind/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use core::raw;
3636
use core::panic::BoxMeUp;
3737

3838
cfg_if::cfg_if! {
39-
if #[cfg(miri)] {
40-
#[path = "miri.rs"]
41-
mod imp;
42-
} else if #[cfg(target_os = "emscripten")] {
39+
if #[cfg(target_os = "emscripten")] {
4340
#[path = "emcc.rs"]
4441
mod imp;
4542
} else if #[cfg(target_arch = "wasm32")] {
@@ -94,5 +91,14 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
9491
#[unwind(allowed)]
9592
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
9693
let payload = payload as *mut &mut dyn BoxMeUp;
97-
imp::panic(Box::from_raw((*payload).take_box()))
94+
let payload = (*payload).take_box();
95+
96+
// Miri panic support: cfg'd out of normal builds just to be sure.
97+
// When going through normal codegen, `miri_start_panic` is a NOP, so the
98+
// Miri-enabled sysroot still supports normal unwinding. But when executed in
99+
// Miri, this line initiates unwinding.
100+
#[cfg(miri)]
101+
core::intrinsics::miri_start_panic(payload);
102+
103+
imp::panic(Box::from_raw(payload))
98104
}

src/libpanic_unwind/miri.rs

-42
This file was deleted.

src/librustc/mir/mod.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ pub struct Body<'tcx> {
104104
/// and used for debuginfo. Indexed by a `SourceScope`.
105105
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,
106106

107-
/// Crate-local information for each source scope, that can't (and
108-
/// needn't) be tracked across crates.
109-
pub source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
110-
111107
/// The yield type of the function, if it is a generator.
112108
pub yield_ty: Option<Ty<'tcx>>,
113109

@@ -167,7 +163,6 @@ impl<'tcx> Body<'tcx> {
167163
pub fn new(
168164
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
169165
source_scopes: IndexVec<SourceScope, SourceScopeData>,
170-
source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
171166
local_decls: LocalDecls<'tcx>,
172167
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
173168
arg_count: usize,
@@ -188,7 +183,6 @@ impl<'tcx> Body<'tcx> {
188183
phase: MirPhase::Build,
189184
basic_blocks,
190185
source_scopes,
191-
source_scope_local_data,
192186
yield_ty: None,
193187
generator_drop: None,
194188
generator_layout: None,
@@ -435,6 +429,13 @@ pub enum ClearCrossCrate<T> {
435429
}
436430

437431
impl<T> ClearCrossCrate<T> {
432+
pub fn as_ref(&'a self) -> ClearCrossCrate<&'a T> {
433+
match self {
434+
ClearCrossCrate::Clear => ClearCrossCrate::Clear,
435+
ClearCrossCrate::Set(v) => ClearCrossCrate::Set(v),
436+
}
437+
}
438+
438439
pub fn assert_crate_local(self) -> T {
439440
match self {
440441
ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"),
@@ -2027,6 +2028,10 @@ rustc_index::newtype_index! {
20272028
pub struct SourceScopeData {
20282029
pub span: Span,
20292030
pub parent_scope: Option<SourceScope>,
2031+
2032+
/// Crate-local information for this source scope, that can't (and
2033+
/// needn't) be tracked across crates.
2034+
pub local_data: ClearCrossCrate<SourceScopeLocalData>,
20302035
}
20312036

20322037
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
@@ -2308,10 +2313,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23082313
}
23092314
}
23102315

2311-
AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
2316+
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
23122317
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
23132318
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
2314-
format!("[closure@{:?}]", hir_id)
2319+
let substs = tcx.lift(&substs).unwrap();
2320+
format!(
2321+
"[closure@{}]",
2322+
tcx.def_path_str_with_substs(def_id, substs),
2323+
)
23152324
} else {
23162325
format!("[closure@{:?}]", tcx.hir().span(hir_id))
23172326
};

src/librustc/mir/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ macro_rules! make_mir_visitor {
317317
let SourceScopeData {
318318
span,
319319
parent_scope,
320+
local_data: _,
320321
} = scope_data;
321322

322323
self.visit_span(span);

src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pub trait PrettyPrinter<'tcx>:
682682
// FIXME(eddyb) should use `def_span`.
683683
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
684684
if self.tcx().sess.opts.debugging_opts.span_free_formats {
685-
p!(write("@{:?}", hir_id));
685+
p!(write("@"), print_def_path(did, substs));
686686
} else {
687687
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
688688
}

src/librustc/ty/structural_impls.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! hand, though we've recently added some macros and proc-macros to help with the tedium.
44
55
use crate::hir::def::Namespace;
6+
use crate::hir::def_id::CRATE_DEF_INDEX;
67
use crate::mir::ProjectionKind;
78
use crate::mir::interpret;
89
use crate::ty::{self, Lift, Ty, TyCtxt, InferConst};
@@ -95,8 +96,11 @@ impl fmt::Debug for ty::BoundRegion {
9596
match *self {
9697
ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
9798
ty::BrNamed(did, name) => {
98-
write!(f, "BrNamed({:?}:{:?}, {})",
99-
did.krate, did.index, name)
99+
if did.index == CRATE_DEF_INDEX {
100+
write!(f, "BrNamed({})", name)
101+
} else {
102+
write!(f, "BrNamed({:?}, {})", did, name)
103+
}
100104
}
101105
ty::BrEnv => write!(f, "BrEnv"),
102106
}

src/librustc_codegen_ssa/mir/block.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
528528
_ => FnAbi::new(&bx, sig, &extra_args)
529529
};
530530

531-
// This should never be reachable at runtime:
532-
// We should only emit a call to this intrinsic in #[cfg(miri)] mode,
533-
// which means that we will never actually use the generate object files
534-
// (we will just be interpreting the MIR)
535-
//
536-
// Note that we still need to be able to codegen *something* for this intrisnic:
537-
// Miri currently uses Xargo to build a special libstd. As a side effect,
538-
// we generate normal object files for libstd - while these are never used,
539-
// we still need to be able to build them.
531+
// For normal codegen, this Miri-specific intrinsic is just a NOP.
540532
if intrinsic == Some("miri_start_panic") {
541-
bx.abort();
542-
bx.unreachable();
533+
let target = destination.as_ref().unwrap().1;
534+
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
535+
helper.funclet_br(self, &mut bx, target);
543536
return;
544537
}
545538

src/librustc_mir/borrow_check/mod.rs

+34-33
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,10 @@ fn do_mir_borrowck<'a, 'tcx>(
300300
let mut initial_diag =
301301
mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow);
302302

303-
let lint_root = if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data {
304-
let scope = mbcx.body.source_info(location).scope;
305-
vsi[scope].lint_root
306-
} else {
307-
id
303+
let scope = mbcx.body.source_info(location).scope;
304+
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
305+
ClearCrossCrate::Set(data) => data.lint_root,
306+
_ => id,
308307
};
309308

310309
// Span and message don't matter; we overwrite them below anyway
@@ -338,38 +337,40 @@ fn do_mir_borrowck<'a, 'tcx>(
338337
debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
339338
let used_mut = mbcx.used_mut;
340339
for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
341-
if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data {
342-
let local_decl = &mbcx.body.local_decls[local];
343-
344-
// Skip over locals that begin with an underscore or have no name
345-
match mbcx.local_names[local] {
346-
Some(name) => if name.as_str().starts_with("_") {
347-
continue;
348-
},
349-
None => continue,
350-
}
340+
let local_decl = &mbcx.body.local_decls[local];
341+
let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data {
342+
ClearCrossCrate::Set(data) => data.lint_root,
343+
_ => continue,
344+
};
351345

352-
let span = local_decl.source_info.span;
353-
if span.desugaring_kind().is_some() {
354-
// If the `mut` arises as part of a desugaring, we should ignore it.
346+
// Skip over locals that begin with an underscore or have no name
347+
match mbcx.local_names[local] {
348+
Some(name) => if name.as_str().starts_with("_") {
355349
continue;
356-
}
350+
},
351+
None => continue,
352+
}
357353

358-
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
359-
tcx.struct_span_lint_hir(
360-
UNUSED_MUT,
361-
vsi[local_decl.source_info.scope].lint_root,
362-
span,
363-
"variable does not need to be mutable",
364-
)
365-
.span_suggestion_short(
366-
mut_span,
367-
"remove this `mut`",
368-
String::new(),
369-
Applicability::MachineApplicable,
370-
)
371-
.emit();
354+
let span = local_decl.source_info.span;
355+
if span.desugaring_kind().is_some() {
356+
// If the `mut` arises as part of a desugaring, we should ignore it.
357+
continue;
372358
}
359+
360+
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
361+
tcx.struct_span_lint_hir(
362+
UNUSED_MUT,
363+
lint_root,
364+
span,
365+
"variable does not need to be mutable",
366+
)
367+
.span_suggestion_short(
368+
mut_span,
369+
"remove this `mut`",
370+
String::new(),
371+
Applicability::MachineApplicable,
372+
)
373+
.emit();
373374
}
374375

375376
// Buffer any move errors that we collected and de-duplicated.

src/librustc_mir/build/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ struct Builder<'a, 'tcx> {
309309
/// The vector of all scopes that we have created thus far;
310310
/// we track this for debuginfo later.
311311
source_scopes: IndexVec<SourceScope, SourceScopeData>,
312-
source_scope_local_data: IndexVec<SourceScope, SourceScopeLocalData>,
313312
source_scope: SourceScope,
314313

315314
/// The guard-context: each time we build the guard expression for
@@ -704,7 +703,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
704703
block_context: BlockContext::new(),
705704
source_scopes: IndexVec::new(),
706705
source_scope: OUTERMOST_SOURCE_SCOPE,
707-
source_scope_local_data: IndexVec::new(),
708706
guard_context: vec![],
709707
push_unsafe_count: 0,
710708
unpushed_unsafe: safety,
@@ -741,7 +739,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
741739
Body::new(
742740
self.cfg.basic_blocks,
743741
self.source_scopes,
744-
ClearCrossCrate::Set(self.source_scope_local_data),
745742
self.local_decls,
746743
self.canonical_user_type_annotations,
747744
self.arg_count,
@@ -942,7 +939,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
942939
self.hir.root_lint_level
943940
);
944941
let parent_root = tcx.maybe_lint_level_root_bounded(
945-
self.source_scope_local_data[original_source_scope].lint_root,
942+
self.source_scopes[original_source_scope]
943+
.local_data
944+
.as_ref()
945+
.assert_crate_local()
946+
.lint_root,
946947
self.hir.root_lint_level,
947948
);
948949
if current_root != parent_root {

src/librustc_mir/build/scope.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
436436
// We estimate the true lint roots here to avoid creating a lot of source scopes.
437437

438438
let parent_root = tcx.maybe_lint_level_root_bounded(
439-
self.source_scope_local_data[source_scope].lint_root,
439+
self.source_scopes[source_scope]
440+
.local_data
441+
.as_ref()
442+
.assert_crate_local()
443+
.lint_root,
440444
self.hir.root_lint_level,
441445
);
442446
let current_root = tcx.maybe_lint_level_root_bounded(
@@ -654,23 +658,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
654658
let parent = self.source_scope;
655659
debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
656660
span, lint_level, safety,
657-
parent, self.source_scope_local_data.get(parent));
658-
let scope = self.source_scopes.push(SourceScopeData {
659-
span,
660-
parent_scope: Some(parent),
661-
});
661+
parent, self.source_scopes.get(parent));
662662
let scope_local_data = SourceScopeLocalData {
663663
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
664664
lint_root
665665
} else {
666-
self.source_scope_local_data[parent].lint_root
666+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root
667667
},
668668
safety: safety.unwrap_or_else(|| {
669-
self.source_scope_local_data[parent].safety
669+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().safety
670670
})
671671
};
672-
self.source_scope_local_data.push(scope_local_data);
673-
scope
672+
self.source_scopes.push(SourceScopeData {
673+
span,
674+
parent_scope: Some(parent),
675+
local_data: ClearCrossCrate::Set(scope_local_data),
676+
})
674677
}
675678

676679
/// Given a span and the current source scope, make a SourceInfo.

src/librustc_mir/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
849849
} else {
850850
block.terminator().source_info
851851
};
852-
match body.source_scope_local_data {
853-
mir::ClearCrossCrate::Set(ref ivs) => Some(ivs[source_info.scope].lint_root),
852+
match &body.source_scopes[source_info.scope].local_data {
853+
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
854854
mir::ClearCrossCrate::Clear => None,
855855
}
856856
});

0 commit comments

Comments
 (0)