From 8c942c1511cc99fbc8f3e6ed56e5e3cfd8c0ff4a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 8 Feb 2020 20:24:42 +0200 Subject: [PATCH 01/18] rustc_mir: rename `location: SourceInfo` to `source_info`. --- compiler/rustc_mir/src/transform/inline.rs | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 796ad6c9c2978..5163e025cbaab 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -33,7 +33,7 @@ struct CallSite<'tcx> { callee: DefId, substs: SubstsRef<'tcx>, bb: BasicBlock, - location: SourceInfo, + source_info: SourceInfo, } impl<'tcx> MirPass<'tcx> for Inline { @@ -217,7 +217,7 @@ impl Inliner<'tcx> { callee: instance.def_id(), substs: instance.substs, bb, - location: terminator.source_info, + source_info: terminator.source_info, }); } } @@ -440,7 +440,7 @@ impl Inliner<'tcx> { for mut scope in callee_body.source_scopes.iter().cloned() { if scope.parent_scope.is_none() { - scope.parent_scope = Some(callsite.location.scope); + scope.parent_scope = Some(callsite.source_info.scope); // FIXME(eddyb) is this really needed? // (also note that it's always overwritten below) scope.span = callee_body.span; @@ -449,7 +449,7 @@ impl Inliner<'tcx> { // FIXME(eddyb) this doesn't seem right at all. // The inlined source scopes should probably be annotated as // such, but also contain all of the original information. - scope.span = callsite.location.span; + scope.span = callsite.source_info.span; let idx = caller_body.source_scopes.push(scope); scope_map.push(idx); @@ -459,7 +459,7 @@ impl Inliner<'tcx> { let mut local = callee_body.local_decls[loc].clone(); local.source_info.scope = scope_map[local.source_info.scope]; - local.source_info.span = callsite.location.span; + local.source_info.span = callsite.source_info.span; let idx = caller_body.local_decls.push(local); local_map.push(idx); @@ -491,13 +491,13 @@ impl Inliner<'tcx> { let ty = dest.ty(caller_body, self.tcx); - let temp = LocalDecl::new(ty, callsite.location.span); + let temp = LocalDecl::new(ty, callsite.source_info.span); let tmp = caller_body.local_decls.push(temp); let tmp = Place::from(tmp); let stmt = Statement { - source_info: callsite.location, + source_info: callsite.source_info, kind: StatementKind::Assign(box (tmp, dest)), }; caller_body[callsite.bb].statements.push(stmt); @@ -535,7 +535,7 @@ impl Inliner<'tcx> { } let terminator = Terminator { - source_info: callsite.location, + source_info: callsite.source_info, kind: TerminatorKind::Goto { target: BasicBlock::new(bb_len) }, }; @@ -654,20 +654,23 @@ impl Inliner<'tcx> { let ty = arg.ty(caller_body, self.tcx); - let arg_tmp = LocalDecl::new(ty, callsite.location.span); + let arg_tmp = LocalDecl::new(ty, callsite.source_info.span); let arg_tmp = caller_body.local_decls.push(arg_tmp); caller_body[callsite.bb].statements.push(Statement { - source_info: callsite.location, + source_info: callsite.source_info, kind: StatementKind::StorageLive(arg_tmp), }); caller_body[callsite.bb].statements.push(Statement { - source_info: callsite.location, + source_info: callsite.source_info, kind: StatementKind::Assign(box (Place::from(arg_tmp), arg)), }); caller_body[return_block].statements.insert( 0, - Statement { source_info: callsite.location, kind: StatementKind::StorageDead(arg_tmp) }, + Statement { + source_info: callsite.source_info, + kind: StatementKind::StorageDead(arg_tmp), + }, ); arg_tmp From 708fc0b692b4ec7894986369214dc1f13ca33882 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 8 Feb 2020 21:28:19 +0200 Subject: [PATCH 02/18] rustc_mir: use Instance more in the inliner. --- compiler/rustc_mir/src/transform/inline.rs | 53 ++++++++++++---------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 5163e025cbaab..1b8cf2c7121c5 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -1,13 +1,12 @@ //! Inlining pass for MIR functions use rustc_attr as attr; -use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::subst::{Subst, SubstsRef}; +use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt}; use rustc_target::spec::abi::Abi; @@ -30,8 +29,7 @@ pub struct Inline; #[derive(Copy, Clone, Debug)] struct CallSite<'tcx> { - callee: DefId, - substs: SubstsRef<'tcx>, + callee: Instance<'tcx>, bb: BasicBlock, source_info: SourceInfo, } @@ -101,12 +99,18 @@ impl Inliner<'tcx> { local_change = false; while let Some(callsite) = callsites.pop_front() { debug!("checking whether to inline callsite {:?}", callsite); - if !self.tcx.is_mir_available(callsite.callee) { - debug!("checking whether to inline callsite {:?} - MIR unavailable", callsite); - continue; + + if let InstanceDef::Item(_) = callsite.callee.def { + if !self.tcx.is_mir_available(callsite.callee.def_id()) { + debug!( + "checking whether to inline callsite {:?} - MIR unavailable", + callsite, + ); + continue; + } } - let callee_body = if let Some(callee_def_id) = callsite.callee.as_local() { + let callee_body = if let Some(callee_def_id) = callsite.callee.def_id().as_local() { let callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id); // Avoid a cycle here by only using `optimized_mir` only if we have // a lower `HirId` than the callee. This ensures that the callee will @@ -119,19 +123,21 @@ impl Inliner<'tcx> { && self_hir_id < callee_hir_id && caller_body.generator_kind.is_none() { - self.tcx.optimized_mir(callsite.callee) + self.tcx.instance_mir(callsite.callee.def) } else { continue; } } else { // This cannot result in a cycle since the callee MIR is from another crate // and is already optimized. - self.tcx.optimized_mir(callsite.callee) + self.tcx.instance_mir(callsite.callee.def) }; + let callee_body: &Body<'tcx> = &*callee_body; + let callee_body = if self.consider_optimizing(callsite, callee_body) { self.tcx.subst_and_normalize_erasing_regions( - &callsite.substs, + &callsite.callee.substs, self.param_env, callee_body, ) @@ -204,21 +210,16 @@ impl Inliner<'tcx> { // To resolve an instance its substs have to be fully normalized, so // we do this here. let normalized_substs = self.tcx.normalize_erasing_regions(self.param_env, substs); - let instance = + let callee = Instance::resolve(self.tcx, self.param_env, callee_def_id, normalized_substs) .ok() .flatten()?; - if let InstanceDef::Virtual(..) = instance.def { + if let InstanceDef::Virtual(..) | InstanceDef::Intrinsic(_) = callee.def { return None; } - return Some(CallSite { - callee: instance.def_id(), - substs: instance.substs, - bb, - source_info: terminator.source_info, - }); + return Some(CallSite { callee, bb, source_info: terminator.source_info }); } } @@ -243,7 +244,7 @@ impl Inliner<'tcx> { return false; } - let codegen_fn_attrs = tcx.codegen_fn_attrs(callsite.callee); + let codegen_fn_attrs = tcx.codegen_fn_attrs(callsite.callee.def_id()); if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::TRACK_CALLER) { debug!("`#[track_caller]` present - not inlining"); @@ -282,8 +283,8 @@ impl Inliner<'tcx> { // Only inline local functions if they would be eligible for cross-crate // inlining. This is to ensure that the final crate doesn't have MIR that // reference unexported symbols - if callsite.callee.is_local() { - if callsite.substs.non_erasable_generics().count() == 0 && !hinted { + if callsite.callee.def_id().is_local() { + if callsite.callee.substs.non_erasable_generics().count() == 0 && !hinted { debug!(" callee is an exported function - not inlining"); return false; } @@ -336,7 +337,7 @@ impl Inliner<'tcx> { work_list.push(target); // If the place doesn't actually need dropping, treat it like // a regular goto. - let ty = place.ty(callee_body, tcx).subst(tcx, callsite.substs).ty; + let ty = place.ty(callee_body, tcx).subst(tcx, callsite.callee.substs).ty; if ty.needs_drop(tcx, self.param_env) { cost += CALL_PENALTY; if let Some(unwind) = unwind { @@ -399,7 +400,7 @@ impl Inliner<'tcx> { for v in callee_body.vars_and_temps_iter() { let v = &callee_body.local_decls[v]; - let ty = v.ty.subst(tcx, callsite.substs); + let ty = v.ty.subst(tcx, callsite.callee.substs); // Cost of the var is the size in machine-words, if we know // it. if let Some(size) = type_size_of(tcx, self.param_env, ty) { @@ -583,7 +584,9 @@ impl Inliner<'tcx> { // tmp2 = tuple_tmp.2 // // and the vector is `[closure_ref, tmp0, tmp1, tmp2]`. - if tcx.is_closure(callsite.callee) { + // FIXME(eddyb) make this check for `"rust-call"` ABI combined with + // `callee_body.spread_arg == None`, instead of special-casing closures. + if tcx.is_closure(callsite.callee.def_id()) { let mut args = args.into_iter(); let self_ = self.create_temp_if_necessary( args.next().unwrap(), From 6bc5eafbce7dd3630a26b9f2e94938a4dfc61c06 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 8 Feb 2020 21:31:09 +0200 Subject: [PATCH 03/18] rustc_mir: track inlined callees in SourceScopeData. --- compiler/rustc_middle/src/mir/mod.rs | 13 +++++--- .../rustc_middle/src/mir/type_foldable.rs | 1 - compiler/rustc_middle/src/mir/visit.rs | 33 +++++++++++++++++-- compiler/rustc_mir/src/shim.rs | 7 +++- .../rustc_mir/src/transform/const_prop.rs | 2 +- compiler/rustc_mir/src/transform/inline.rs | 14 +++----- compiler/rustc_mir/src/util/pretty.rs | 19 +++++++++-- compiler/rustc_mir_build/src/build/mod.rs | 2 +- compiler/rustc_mir_build/src/build/scope.rs | 1 + .../cycle.main.DestinationPropagation.diff | 2 +- .../union.main.DestinationPropagation.diff | 2 +- ...anup.main-{closure#0}.generator_drop.0.mir | 4 +-- .../inline_any_operand.bar.Inline.after.mir | 2 +- .../inline_closure.foo.Inline.after.mir | 2 +- ...e_closure_borrows_arg.foo.Inline.after.mir | 2 +- ...line_closure_captures.foo.Inline.after.mir | 2 +- ...patibility.inlined_no_sanitize.Inline.diff | 2 +- ...ibility.inlined_target_feature.Inline.diff | 2 +- ...line_into_box_place.main.Inline.32bit.diff | 2 +- ...line_into_box_place.main.Inline.64bit.diff | 2 +- .../inline/inline_retag.bar.Inline.after.mir | 2 +- .../inline_specialization.main.Inline.diff | 2 +- ...line_trait_method_2.test2.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.a.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.b.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.c.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.d.Inline.after.mir | 2 +- .../issue_73223.main.PreCodegen.32bit.diff | 6 ++-- .../issue_73223.main.PreCodegen.64bit.diff | 6 ++-- ..._73223.main.SimplifyArmIdentity.32bit.diff | 6 ++-- ..._73223.main.SimplifyArmIdentity.64bit.diff | 6 ++-- ...annot_opt_generic.RemoveUnneededDrops.diff | 2 +- ...ed_drops.dont_opt.RemoveUnneededDrops.diff | 2 +- ...nneeded_drops.opt.RemoveUnneededDrops.diff | 2 +- ....opt_generic_copy.RemoveUnneededDrops.diff | 2 +- ...mplify_arm.id_try.SimplifyArmIdentity.diff | 6 ++-- ...implify_arm.id_try.SimplifyBranchSame.diff | 6 ++-- ...y.try_identity.DestinationPropagation.diff | 6 ++-- ..._try.try_identity.SimplifyArmIdentity.diff | 6 ++-- ....try_identity.SimplifyBranchSame.after.mir | 6 ++-- ..._try.try_identity.SimplifyLocals.after.mir | 6 ++-- 41 files changed, 124 insertions(+), 74 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index b38efedbf607e..09bcf4b1d3e11 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -161,7 +161,7 @@ pub struct Body<'tcx> { /// A list of source scopes; these are referenced by statements /// and used for debuginfo. Indexed by a `SourceScope`. - pub source_scopes: IndexVec, + pub source_scopes: IndexVec>, /// The yield type of the function, if it is a generator. pub yield_ty: Option>, @@ -244,7 +244,7 @@ impl<'tcx> Body<'tcx> { pub fn new( source: MirSource<'tcx>, basic_blocks: IndexVec>, - source_scopes: IndexVec, + source_scopes: IndexVec>, local_decls: LocalDecls<'tcx>, user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, arg_count: usize, @@ -1868,11 +1868,16 @@ rustc_index::newtype_index! { } } -#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] -pub struct SourceScopeData { +#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)] +pub struct SourceScopeData<'tcx> { pub span: Span, pub parent_scope: Option, + /// Whether this scope is the root of a scope tree of another body, + /// inlined into this body by the MIR inliner. + /// `ty::Instance` is the callee, and the `Span` is the call site. + pub inlined: Option<(ty::Instance<'tcx>, Span)>, + /// Crate-local information for this source scope, that can't (and /// needn't) be tracked across crates. pub local_data: ClearCrossCrate, diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 9297aed66a459..6aab54b92748d 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -10,7 +10,6 @@ CloneTypeFoldableAndLiftImpls! { FakeReadCause, RetagKind, SourceScope, - SourceScopeData, SourceScopeLocalData, UserTypeAnnotationIndex, } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 58dd0bc00d204..a9049ef02a694 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -85,7 +85,7 @@ macro_rules! make_mir_visitor { } fn visit_source_scope_data(&mut self, - scope_data: & $($mutability)? SourceScopeData) { + scope_data: & $($mutability)? SourceScopeData<'tcx>) { self.super_source_scope_data(scope_data); } @@ -317,10 +317,14 @@ macro_rules! make_mir_visitor { } } - fn super_source_scope_data(&mut self, scope_data: & $($mutability)? SourceScopeData) { + fn super_source_scope_data( + &mut self, + scope_data: & $($mutability)? SourceScopeData<'tcx>, + ) { let SourceScopeData { span, parent_scope, + inlined, local_data: _, } = scope_data; @@ -328,6 +332,31 @@ macro_rules! make_mir_visitor { if let Some(parent_scope) = parent_scope { self.visit_source_scope(parent_scope); } + if let Some((callee, callsite_span)) = inlined { + let location = START_BLOCK.start_location(); + + self.visit_span(callsite_span); + + let ty::Instance { def: callee_def, substs: callee_substs } = callee; + match callee_def { + ty::InstanceDef::Item(_def_id) => {} + + ty::InstanceDef::Intrinsic(_def_id) | + ty::InstanceDef::VtableShim(_def_id) | + ty::InstanceDef::ReifyShim(_def_id) | + ty::InstanceDef::Virtual(_def_id, _) | + ty::InstanceDef::ClosureOnceShim { call_once: _def_id } | + ty::InstanceDef::DropGlue(_def_id, None) => {} + + ty::InstanceDef::FnPtrShim(_def_id, ty) | + ty::InstanceDef::DropGlue(_def_id, Some(ty)) | + ty::InstanceDef::CloneShim(_def_id, ty) => { + // FIXME(eddyb) use a better `TyContext` here. + self.visit_ty(ty, TyContext::Location(location)); + } + } + self.visit_substs(callee_substs, location); + } } fn super_statement(&mut self, diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir/src/shim.rs index 5431d22e70320..877ee30bcedfd 100644 --- a/compiler/rustc_mir/src/shim.rs +++ b/compiler/rustc_mir/src/shim.rs @@ -212,7 +212,12 @@ fn new_body<'tcx>( source, basic_blocks, IndexVec::from_elem_n( - SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear }, + SourceScopeData { + span, + parent_scope: None, + inlined: None, + local_data: ClearCrossCrate::Clear, + }, 1, ), local_decls, diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 14b310cda939e..c743104f6ba19 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -313,7 +313,7 @@ struct ConstPropagator<'mir, 'tcx> { param_env: ParamEnv<'tcx>, // FIXME(eddyb) avoid cloning these two fields more than once, // by accessing them through `ecx` instead. - source_scopes: IndexVec, + source_scopes: IndexVec>, local_decls: IndexVec>, // Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store // the last known `SourceInfo` here and just keep revisiting it. diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 1b8cf2c7121c5..b6d8ca8e5a6ed 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -112,7 +112,7 @@ impl Inliner<'tcx> { let callee_body = if let Some(callee_def_id) = callsite.callee.def_id().as_local() { let callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id); - // Avoid a cycle here by only using `optimized_mir` only if we have + // Avoid a cycle here by only using `instance_mir` only if we have // a lower `HirId` than the callee. This ensures that the callee will // not inline us. This trick only works without incremental compilation. // So don't do it if that is enabled. Also avoid inlining into generators, @@ -442,15 +442,11 @@ impl Inliner<'tcx> { for mut scope in callee_body.source_scopes.iter().cloned() { if scope.parent_scope.is_none() { scope.parent_scope = Some(callsite.source_info.scope); - // FIXME(eddyb) is this really needed? - // (also note that it's always overwritten below) - scope.span = callee_body.span; - } - // FIXME(eddyb) this doesn't seem right at all. - // The inlined source scopes should probably be annotated as - // such, but also contain all of the original information. - scope.span = callsite.source_info.span; + // Mark the outermost callee scope as an inlined one. + assert_eq!(scope.inlined, None); + scope.inlined = Some((callsite.callee, callsite.source_info.span)); + } let idx = caller_body.source_scopes.push(scope); scope_map.push(idx); diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index bd7c25bf25043..a8db273e7c7ee 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -548,8 +548,23 @@ fn write_scope_tree( }; for &child in children { - assert_eq!(body.source_scopes[child].parent_scope, Some(parent)); - writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?; + let child_data = &body.source_scopes[child]; + assert_eq!(child_data.parent_scope, Some(parent)); + + if let Some((callee, callsite_span)) = child_data.inlined { + let indented_header = + format!("{0:1$}scope {2} (inlined {3}) {{", "", indent, child.index(), callee); + writeln!( + w, + "{0:1$} // at {2}", + indented_header, + ALIGN, + tcx.sess.source_map().span_to_string(callsite_span), + )?; + } else { + writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?; + } + write_scope_tree(tcx, body, scope_tree, w, child, depth + 1)?; writeln!(w, "{0:1$}}}", "", depth * INDENT.len())?; } diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 899fc647493a0..f9995f43f5a8d 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -334,7 +334,7 @@ struct Builder<'a, 'tcx> { /// The vector of all scopes that we have created thus far; /// we track this for debuginfo later. - source_scopes: IndexVec, + source_scopes: IndexVec>, source_scope: SourceScope, /// The guard-context: each time we build the guard expression for diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index ad6386ca12d52..2b1affbd6aa68 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -705,6 +705,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.source_scopes.push(SourceScopeData { span, parent_scope: Some(parent), + inlined: None, local_data: ClearCrossCrate::Set(scope_local_data), }) } diff --git a/src/test/mir-opt/dest-prop/cycle.main.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/cycle.main.DestinationPropagation.diff index 881c296cee77a..bba10f09c3fbb 100644 --- a/src/test/mir-opt/dest-prop/cycle.main.DestinationPropagation.diff +++ b/src/test/mir-opt/dest-prop/cycle.main.DestinationPropagation.diff @@ -18,7 +18,7 @@ scope 3 { - debug z => _3; // in scope 3 at $DIR/cycle.rs:11:9: 11:10 + debug z => _4; // in scope 3 at $DIR/cycle.rs:11:9: 11:10 - scope 4 { + scope 4 (inlined std::mem::drop::) { // at $DIR/cycle.rs:14:5: 14:12 debug _x => _6; // in scope 4 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } } diff --git a/src/test/mir-opt/dest-prop/union.main.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/union.main.DestinationPropagation.diff index f15e7bcb2fba6..0028e280516da 100644 --- a/src/test/mir-opt/dest-prop/union.main.DestinationPropagation.diff +++ b/src/test/mir-opt/dest-prop/union.main.DestinationPropagation.diff @@ -11,7 +11,7 @@ debug un => _1; // in scope 1 at $DIR/union.rs:13:9: 13:11 scope 2 { } - scope 3 { + scope 3 (inlined std::mem::drop::) { // at $DIR/union.rs:15:5: 15:27 debug _x => _4; // in scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } } diff --git a/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir b/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir index 8e8ab08823578..27b86d66ded2d 100644 --- a/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir +++ b/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir @@ -26,9 +26,9 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1 scope 1 { debug _s => (((*_1) as variant#3).0: std::string::String); // in scope 1 at $DIR/generator-drop-cleanup.rs:11:13: 11:15 } - scope 2 { + scope 2 (inlined String::new) { // at $DIR/generator-drop-cleanup.rs:11:18: 11:31 let mut _6: std::vec::Vec; // in scope 2 at $DIR/generator-drop-cleanup.rs:11:18: 11:31 - scope 3 { + scope 3 (inlined Vec::::new) { // at $SRC_DIR/alloc/src/string.rs:LL:COL } } diff --git a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir index 4d623297f8d68..1ced3fe5d1570 100644 --- a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir @@ -8,7 +8,7 @@ fn bar() -> bool { let mut _6: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13 scope 1 { debug f => _1; // in scope 1 at $DIR/inline-any-operand.rs:11:9: 11:10 - scope 2 { + scope 2 (inlined foo) { // at $DIR/inline-any-operand.rs:12:5: 12:13 debug x => _5; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9 debug y => _6; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17 let mut _3: i32; // in scope 2 at $DIR/inline-any-operand.rs:12:5: 12:13 diff --git a/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir index c970b1bfac490..93a63c8478391 100644 --- a/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir @@ -13,7 +13,7 @@ fn foo(_1: T, _2: i32) -> i32 { let mut _9: i32; // in scope 0 at $DIR/inline-closure.rs:12:5: 12:12 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure.rs:11:9: 11:10 - scope 2 { + scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure.rs:12:5: 12:12 debug _t => _8; // in scope 2 at $DIR/inline-closure.rs:11:14: 11:16 debug _q => _9; // in scope 2 at $DIR/inline-closure.rs:11:18: 11:20 } diff --git a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir index 2f2db51ec8627..390b2320ef613 100644 --- a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir @@ -13,7 +13,7 @@ fn foo(_1: T, _2: &i32) -> i32 { let mut _10: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure-borrows-arg.rs:12:9: 12:10 - scope 2 { + scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 debug r => _9; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:14: 12:15 debug _s => _10; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:23: 12:25 let _8: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 diff --git a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir index 5138b50c9f005..c6d1e8147a331 100644 --- a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir @@ -13,7 +13,7 @@ fn foo(_1: T, _2: i32) -> (i32, T) { let mut _10: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure-captures.rs:11:9: 11:10 - scope 2 { + scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure-captures.rs:12:5: 12:9 debug _q => _10; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:10:23: 10:24 debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:10:17: 10:18 diff --git a/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff b/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff index 7b0ecaffdd7cb..2fc908b51f39a 100644 --- a/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff +++ b/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff @@ -4,7 +4,7 @@ fn inlined_no_sanitize() -> () { let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:24:37: 24:37 let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:25:5: 25:18 -+ scope 1 { ++ scope 1 (inlined no_sanitize) { // at $DIR/inline-compatibility.rs:25:5: 25:18 + } bb0: { diff --git a/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff b/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff index f55eae6c50a5f..c92594d08de2b 100644 --- a/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff +++ b/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff @@ -4,7 +4,7 @@ fn inlined_target_feature() -> () { let mut _0: (); // return place in scope 0 at $DIR/inline-compatibility.rs:13:40: 13:40 let _1: (); // in scope 0 at $DIR/inline-compatibility.rs:14:5: 14:21 -+ scope 1 { ++ scope 1 (inlined target_feature) { // at $DIR/inline-compatibility.rs:14:5: 14:21 + } bb0: { diff --git a/src/test/mir-opt/inline/inline_into_box_place.main.Inline.32bit.diff b/src/test/mir-opt/inline/inline_into_box_place.main.Inline.32bit.diff index fac2f6bd1ec15..f5c8ee134dbab 100644 --- a/src/test/mir-opt/inline/inline_into_box_place.main.Inline.32bit.diff +++ b/src/test/mir-opt/inline/inline_into_box_place.main.Inline.32bit.diff @@ -10,7 +10,7 @@ scope 1 { debug _x => _1; // in scope 1 at $DIR/inline-into-box-place.rs:8:9: 8:11 } -+ scope 2 { ++ scope 2 (inlined Vec::::new) { // at $DIR/inline-into-box-place.rs:8:33: 8:43 + } bb0: { diff --git a/src/test/mir-opt/inline/inline_into_box_place.main.Inline.64bit.diff b/src/test/mir-opt/inline/inline_into_box_place.main.Inline.64bit.diff index 4535cf290a1da..5aeffa9c2a542 100644 --- a/src/test/mir-opt/inline/inline_into_box_place.main.Inline.64bit.diff +++ b/src/test/mir-opt/inline/inline_into_box_place.main.Inline.64bit.diff @@ -10,7 +10,7 @@ scope 1 { debug _x => _1; // in scope 1 at $DIR/inline-into-box-place.rs:8:9: 8:11 } -+ scope 2 { ++ scope 2 (inlined Vec::::new) { // at $DIR/inline-into-box-place.rs:8:33: 8:43 + } bb0: { diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir index 5258f67ebde6f..cdcfeec98f990 100644 --- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -14,7 +14,7 @@ fn bar() -> bool { debug f => _1; // in scope 1 at $DIR/inline-retag.rs:11:9: 11:10 let mut _9: &i32; // in scope 1 at $DIR/inline-retag.rs:12:11: 12:14 let mut _10: &i32; // in scope 1 at $DIR/inline-retag.rs:12:7: 12:9 - scope 2 { + scope 2 (inlined foo) { // at $DIR/inline-retag.rs:12:5: 12:15 debug x => _3; // in scope 2 at $DIR/inline-retag.rs:16:8: 16:9 debug y => _6; // in scope 2 at $DIR/inline-retag.rs:16:17: 16:18 let mut _11: i32; // in scope 2 at $DIR/inline-retag.rs:12:5: 12:15 diff --git a/src/test/mir-opt/inline/inline_specialization.main.Inline.diff b/src/test/mir-opt/inline/inline_specialization.main.Inline.diff index 2ffc02523596e..96442842bd598 100644 --- a/src/test/mir-opt/inline/inline_specialization.main.Inline.diff +++ b/src/test/mir-opt/inline/inline_specialization.main.Inline.diff @@ -7,7 +7,7 @@ scope 1 { debug x => _1; // in scope 1 at $DIR/inline-specialization.rs:5:9: 5:10 } -+ scope 2 { ++ scope 2 (inlined as Foo>::bar) { // at $DIR/inline-specialization.rs:5:13: 5:38 + } bb0: { diff --git a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir index 09546205962a4..8c7eb753cc037 100644 --- a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir @@ -5,7 +5,7 @@ fn test2(_1: &dyn X) -> bool { let mut _0: bool; // return place in scope 0 at $DIR/inline-trait-method_2.rs:4:24: 4:28 let mut _2: &dyn X; // in scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11 let mut _3: &dyn X; // in scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11 - scope 1 { + scope 1 (inlined test) { // at $DIR/inline-trait-method_2.rs:5:5: 5:12 debug x => _2; // in scope 1 at $DIR/inline-trait-method_2.rs:9:9: 9:10 let mut _4: &dyn X; // in scope 1 at $DIR/inline-trait-method_2.rs:5:5: 5:12 } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir index 501e3e9cf968b..e91b79b8db5f0 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir @@ -6,7 +6,7 @@ fn a(_1: &mut [T]) -> &mut [T] { let mut _2: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 let mut _3: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 let mut _4: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6 - scope 1 { + scope 1 (inlined <[T] as AsMut<[T]>>::as_mut) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 debug self => _4; // in scope 1 at $SRC_DIR/core/src/convert/mod.rs:LL:COL let mut _5: &mut [T]; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir index c9a6aed3d4ab3..9378489fabab1 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir @@ -6,7 +6,7 @@ fn b(_1: &mut Box) -> &mut T { let mut _2: &mut T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 let mut _3: &mut T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 let mut _4: &mut std::boxed::Box; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6 - scope 1 { + scope 1 (inlined as AsMut>::as_mut) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 debug self => _4; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL let mut _5: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 let mut _6: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir index 77492c8937978..670f055dc054b 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir @@ -5,7 +5,7 @@ fn c(_1: &[T]) -> &[T] { let mut _0: &[T]; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:25: 12:29 let _2: &[T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15 let mut _3: &[T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:6 - scope 1 { + scope 1 (inlined <[T] as AsRef<[T]>>::as_ref) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:13:5: 13:15 debug self => _3; // in scope 1 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir index 89f8aae73cd31..c33e859eb6b0c 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir @@ -5,7 +5,7 @@ fn d(_1: &Box) -> &T { let mut _0: &T; // return place in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:28: 17:30 let _2: &T; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15 let mut _3: &std::boxed::Box; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:6 - scope 1 { + scope 1 (inlined as AsRef>::as_ref) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:18:5: 18:15 debug self => _3; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL } diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff index ef7c73068faf6..ac08a4512d0e3 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff @@ -35,14 +35,14 @@ scope 5 { debug arg0 => _25; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL debug arg1 => _28; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - scope 6 { + scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _25; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _24; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL } - scope 8 { + scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _27; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -50,7 +50,7 @@ let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL } } - scope 10 { + scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _29; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _31; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _29: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff index ef7c73068faf6..ac08a4512d0e3 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff @@ -35,14 +35,14 @@ scope 5 { debug arg0 => _25; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL debug arg1 => _28; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - scope 6 { + scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _25; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _24; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL } - scope 8 { + scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _27; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -50,7 +50,7 @@ let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL } } - scope 10 { + scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _29; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _31; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _29: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index 9039735f6ba38..b302114fa1787 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -58,7 +58,7 @@ scope 5 { debug arg0 => _36; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL debug arg1 => _37; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - scope 6 { + scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _39; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _40; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -66,7 +66,7 @@ let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL } - scope 8 { + scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _43; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -75,7 +75,7 @@ let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL } } - scope 10 { + scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _23; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _27; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _54: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index 9039735f6ba38..b302114fa1787 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -58,7 +58,7 @@ scope 5 { debug arg0 => _36; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL debug arg1 => _37; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - scope 6 { + scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _39; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _40; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -66,7 +66,7 @@ let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL } - scope 8 { + scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _43; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL @@ -75,7 +75,7 @@ let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL } } - scope 10 { + scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _23; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _27; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL let mut _54: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL diff --git a/src/test/mir-opt/remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff index 787cf6f97c1f2..d84012295e4d3 100644 --- a/src/test/mir-opt/remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff @@ -6,7 +6,7 @@ let mut _0: (); // return place in scope 0 at $DIR/remove_unneeded_drops.rs:20:32: 20:32 let _2: (); // in scope 0 at $DIR/remove_unneeded_drops.rs:21:5: 21:12 let mut _3: T; // in scope 0 at $DIR/remove_unneeded_drops.rs:21:10: 21:11 - scope 1 { + scope 1 (inlined std::mem::drop::) { // at $DIR/remove_unneeded_drops.rs:21:5: 21:12 debug _x => _3; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } diff --git a/src/test/mir-opt/remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff index 52e182eeb4a8a..b0b1e80e864c4 100644 --- a/src/test/mir-opt/remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff @@ -6,7 +6,7 @@ let mut _0: (); // return place in scope 0 at $DIR/remove_unneeded_drops.rs:8:27: 8:27 let _2: (); // in scope 0 at $DIR/remove_unneeded_drops.rs:9:5: 9:12 let mut _3: std::vec::Vec; // in scope 0 at $DIR/remove_unneeded_drops.rs:9:10: 9:11 - scope 1 { + scope 1 (inlined std::mem::drop::>) { // at $DIR/remove_unneeded_drops.rs:9:5: 9:12 debug _x => _3; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } diff --git a/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff index bc9e1344f3176..0984829435b66 100644 --- a/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff @@ -6,7 +6,7 @@ let mut _0: (); // return place in scope 0 at $DIR/remove_unneeded_drops.rs:3:17: 3:17 let _2: (); // in scope 0 at $DIR/remove_unneeded_drops.rs:4:5: 4:12 let mut _3: bool; // in scope 0 at $DIR/remove_unneeded_drops.rs:4:10: 4:11 - scope 1 { + scope 1 (inlined std::mem::drop::) { // at $DIR/remove_unneeded_drops.rs:4:5: 4:12 debug _x => _3; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } diff --git a/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff index 5c8b1d1372115..0b0ce968af076 100644 --- a/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff @@ -6,7 +6,7 @@ let mut _0: (); // return place in scope 0 at $DIR/remove_unneeded_drops.rs:13:36: 13:36 let _2: (); // in scope 0 at $DIR/remove_unneeded_drops.rs:14:5: 14:12 let mut _3: T; // in scope 0 at $DIR/remove_unneeded_drops.rs:14:10: 14:11 - scope 1 { + scope 1 (inlined std::mem::drop::) { // at $DIR/remove_unneeded_drops.rs:14:5: 14:12 debug _x => _3; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index a811a2c178f17..56ae6cae8071c 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -22,11 +22,11 @@ - debug err => _6; // in scope 2 at $DIR/simplify-arm.rs:24:14: 24:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:24:14: 24:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify-arm.rs:24:14: 24:15 - debug t => _9; // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify-arm.rs:24:13: 24:15 - debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15 @@ -39,7 +39,7 @@ scope 5 { } } - scope 6 { + scope 6 (inlined as Try>::into_result) { // at $DIR/simplify-arm.rs:24:13: 24:15 debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index b0cc3e88f35ac..9cfa3d2231ae0 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -20,10 +20,10 @@ scope 2 { debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify-arm.rs:24:14: 24:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify-arm.rs:24:14: 24:15 debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify-arm.rs:24:13: 24:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15 } @@ -34,7 +34,7 @@ scope 5 { } } - scope 6 { + scope 6 (inlined as Try>::into_result) { // at $DIR/simplify-arm.rs:24:13: 24:15 debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff index 12a6617cc5a27..d36ab58f43027 100644 --- a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff +++ b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff @@ -20,10 +20,10 @@ scope 2 { debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify_try.rs:8:14: 8:15 debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 } @@ -34,7 +34,7 @@ scope 5 { } } - scope 6 { + scope 6 (inlined as Try>::into_result) { // at $DIR/simplify_try.rs:8:13: 8:15 - debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL + debug self => _0; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff index 534836eff7b2d..ab99f122c3bcd 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff @@ -22,11 +22,11 @@ - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify_try.rs:8:14: 8:15 - debug t => _9; // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 - debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 @@ -39,7 +39,7 @@ scope 5 { } } - scope 6 { + scope 6 (inlined as Try>::into_result) { // at $DIR/simplify_try.rs:8:13: 8:15 debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir index d2e37bf4e12eb..a084542321dd8 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir @@ -19,10 +19,10 @@ fn try_identity(_1: std::result::Result) -> std::result::Result ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify_try.rs:8:14: 8:15 debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 } @@ -33,7 +33,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result as Try>::into_result) { // at $DIR/simplify_try.rs:8:13: 8:15 debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try.try_identity.SimplifyLocals.after.mir index 508f2705d0701..51029c3021a8b 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyLocals.after.mir @@ -9,10 +9,10 @@ fn try_identity(_1: std::result::Result) -> std::result::Result ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:8:14: 8:15 scope 3 { - scope 7 { + scope 7 (inlined >::from) { // at $DIR/simplify_try.rs:8:14: 8:15 debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } - scope 8 { + scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } @@ -22,7 +22,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result as Try>::into_result) { // at $DIR/simplify_try.rs:8:13: 8:15 debug self => _0; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL } From fb36440b7a0d2444dd079876d4fde6b0ee9d5670 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 8 Feb 2020 23:46:57 +0200 Subject: [PATCH 04/18] test: ensure #[track_caller] tests also test MIR inlining. --- .../rfc-2091-track-caller/caller-location-intrinsic.rs | 6 ++++-- .../ui/rfc-2091-track-caller/const-caller-location.rs | 10 ++++++---- src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs | 6 ++++-- src/test/ui/rfc-2091-track-caller/pass.rs | 3 +++ .../ui/rfc-2091-track-caller/std-panic-locations.rs | 2 ++ .../ui/rfc-2091-track-caller/track-caller-attribute.rs | 10 ++++++---- .../rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs | 2 ++ src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs | 2 ++ 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs b/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs index f244b74e391ff..b2ed8a0d7da68 100644 --- a/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs +++ b/src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 #[inline(never)] #[track_caller] @@ -13,13 +15,13 @@ macro_rules! caller_location_from_macro { fn main() { let loc = codegen_caller_loc(); assert_eq!(loc.file(), file!()); - assert_eq!(loc.line(), 14); + assert_eq!(loc.line(), 16); assert_eq!(loc.column(), 15); // `Location::caller()` in a macro should behave similarly to `file!` and `line!`, // i.e. point to where the macro was invoked, instead of the macro itself. let loc2 = caller_location_from_macro!(); assert_eq!(loc2.file(), file!()); - assert_eq!(loc2.line(), 21); + assert_eq!(loc2.line(), 23); assert_eq!(loc2.column(), 16); } diff --git a/src/test/ui/rfc-2091-track-caller/const-caller-location.rs b/src/test/ui/rfc-2091-track-caller/const-caller-location.rs index 8030a4d967a67..89a42acafba78 100644 --- a/src/test/ui/rfc-2091-track-caller/const-caller-location.rs +++ b/src/test/ui/rfc-2091-track-caller/const-caller-location.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 #![feature(const_caller_location, const_fn)] @@ -24,18 +26,18 @@ const fn contained() -> &'static Location<'static> { fn main() { assert_eq!(LOCATION.file(), file!()); - assert_eq!(LOCATION.line(), 7); + assert_eq!(LOCATION.line(), 9); assert_eq!(LOCATION.column(), 29); assert_eq!(TRACKED.file(), file!()); - assert_eq!(TRACKED.line(), 9); + assert_eq!(TRACKED.line(), 11); assert_eq!(TRACKED.column(), 28); assert_eq!(NESTED.file(), file!()); - assert_eq!(NESTED.line(), 17); + assert_eq!(NESTED.line(), 19); assert_eq!(NESTED.column(), 5); assert_eq!(CONTAINED.file(), file!()); - assert_eq!(CONTAINED.line(), 22); + assert_eq!(CONTAINED.line(), 24); assert_eq!(CONTAINED.column(), 5); } diff --git a/src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs b/src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs index 74217f47084a3..d072fb76f10d8 100644 --- a/src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs +++ b/src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 macro_rules! caller_location_from_macro { () => (core::panic::Location::caller()); @@ -7,13 +9,13 @@ macro_rules! caller_location_from_macro { fn main() { let loc = core::panic::Location::caller(); assert_eq!(loc.file(), file!()); - assert_eq!(loc.line(), 8); + assert_eq!(loc.line(), 10); assert_eq!(loc.column(), 15); // `Location::caller()` in a macro should behave similarly to `file!` and `line!`, // i.e. point to where the macro was invoked, instead of the macro itself. let loc2 = caller_location_from_macro!(); assert_eq!(loc2.file(), file!()); - assert_eq!(loc2.line(), 15); + assert_eq!(loc2.line(), 17); assert_eq!(loc2.column(), 16); } diff --git a/src/test/ui/rfc-2091-track-caller/pass.rs b/src/test/ui/rfc-2091-track-caller/pass.rs index ada150b25cf2c..4d548d4f0aa39 100644 --- a/src/test/ui/rfc-2091-track-caller/pass.rs +++ b/src/test/ui/rfc-2091-track-caller/pass.rs @@ -1,4 +1,7 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 + #[track_caller] fn f() {} diff --git a/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs b/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs index d6a3a760b3ee2..0d7a5c42532f1 100644 --- a/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs +++ b/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs @@ -1,5 +1,7 @@ // run-pass // ignore-wasm32-bare compiled with panic=abort by default +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 #![feature(option_expect_none, option_unwrap_none)] #![allow(unconditional_panic)] diff --git a/src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs b/src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs index efcc1f6942de1..43135ebbf65df 100644 --- a/src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs +++ b/src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 use std::panic::Location; @@ -18,21 +20,21 @@ fn nested_tracked() -> &'static Location<'static> { fn main() { let location = Location::caller(); assert_eq!(location.file(), file!()); - assert_eq!(location.line(), 19); + assert_eq!(location.line(), 21); assert_eq!(location.column(), 20); let tracked = tracked(); assert_eq!(tracked.file(), file!()); - assert_eq!(tracked.line(), 24); + assert_eq!(tracked.line(), 26); assert_eq!(tracked.column(), 19); let nested = nested_intrinsic(); assert_eq!(nested.file(), file!()); - assert_eq!(nested.line(), 11); + assert_eq!(nested.line(), 13); assert_eq!(nested.column(), 5); let contained = nested_tracked(); assert_eq!(contained.file(), file!()); - assert_eq!(contained.line(), 15); + assert_eq!(contained.line(), 17); assert_eq!(contained.column(), 5); } diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs index 5fcfea96d547a..2122a4ca21925 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 fn pass_to_ptr_call(f: fn(T), x: T) { f(x); diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs index 4415d850c241c..922d2d7b7021a 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs @@ -1,4 +1,6 @@ // run-pass +// revisions: default mir-opt +//[mir-opt] compile-flags: -Zmir-opt-level=3 fn ptr_call(f: fn()) { f(); From 6451b39a25fbad9e991c6ea014a86217c52d3fd6 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 21 Sep 2020 06:52:37 +0300 Subject: [PATCH 05/18] rustc_mir: support MIR-inlining #[track_caller] functions. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 65 +++++++++++---- compiler/rustc_middle/src/mir/mod.rs | 5 ++ compiler/rustc_middle/src/mir/visit.rs | 4 + .../interpret/intrinsics/caller_location.rs | 79 ++++++++++++------- compiler/rustc_mir/src/shim.rs | 1 + compiler/rustc_mir/src/transform/inline.rs | 18 +++-- compiler/rustc_mir/src/util/pretty.rs | 23 ++++-- compiler/rustc_mir_build/src/build/scope.rs | 1 + 8 files changed, 144 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index bec0a84cac0a1..da4637b1afcfb 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -405,7 +405,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.set_debug_loc(&mut bx, terminator.source_info); // Get the location information. - let location = self.get_caller_location(&mut bx, span).immediate(); + let location = self.get_caller_location(&mut bx, terminator.source_info).immediate(); // Put together the arguments to the panic entry point. let (lang_item, args) = match msg { @@ -442,7 +442,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx: &mut Bx, intrinsic: Option, instance: Option>, - span: Span, + source_info: mir::SourceInfo, destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>, cleanup: Option, ) -> bool { @@ -484,11 +484,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } }); let msg = bx.const_str(Symbol::intern(&msg_str)); - let location = self.get_caller_location(bx, span).immediate(); + let location = self.get_caller_location(bx, source_info).immediate(); // Obtain the panic entry point. // FIXME: dedup this with `codegen_assert_terminator` above. - let def_id = common::langcall(bx.tcx(), Some(span), "", LangItem::Panic); + let def_id = + common::langcall(bx.tcx(), Some(source_info.span), "", LangItem::Panic); let instance = ty::Instance::mono(bx.tcx(), def_id); let fn_abi = FnAbi::of_instance(bx, instance, &[]); let llfn = bx.get_fn_addr(instance); @@ -529,7 +530,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { cleanup: Option, fn_span: Span, ) { - let span = terminator.source_info.span; + let source_info = terminator.source_info; + let span = source_info.span; + // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar. let callee = self.codegen_operand(&mut bx, func); @@ -606,7 +609,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut bx, intrinsic, instance, - span, + source_info, destination, cleanup, ) { @@ -627,7 +630,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if intrinsic == Some(sym::caller_location) { if let Some((_, target)) = destination.as_ref() { - let location = self.get_caller_location(&mut bx, fn_span); + let location = self + .get_caller_location(&mut bx, mir::SourceInfo { span: fn_span, ..source_info }); if let ReturnDest::IndirectOperand(tmp, _) = ret_dest { location.val.store(&mut bx, tmp); @@ -686,7 +690,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &fn_abi, &args, dest, - terminator.source_info.span, + span, ); if let ReturnDest::IndirectOperand(dst, _) = ret_dest { @@ -793,7 +797,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { args.len() + 1, "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR", ); - let location = self.get_caller_location(&mut bx, fn_span); + let location = + self.get_caller_location(&mut bx, mir::SourceInfo { span: fn_span, ..source_info }); debug!( "codegen_call_terminator({:?}): location={:?} (fn_span {:?})", terminator, location, fn_span @@ -1179,17 +1184,49 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } - fn get_caller_location(&mut self, bx: &mut Bx, span: Span) -> OperandRef<'tcx, Bx::Value> { - self.caller_location.unwrap_or_else(|| { + fn get_caller_location( + &mut self, + bx: &mut Bx, + mut source_info: mir::SourceInfo, + ) -> OperandRef<'tcx, Bx::Value> { + let tcx = bx.tcx(); + + let mut span_to_caller_location = |span: Span| { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); - let caller = bx.tcx().sess.source_map().lookup_char_pos(topmost.lo()); - let const_loc = bx.tcx().const_caller_location(( + let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo()); + let const_loc = tcx.const_caller_location(( Symbol::intern(&caller.file.name.to_string()), caller.line as u32, caller.col_display as u32 + 1, )); OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty()) - }) + }; + + // Walk up the `SourceScope`s, in case some of them are from MIR inlining. + // If so, the starting `source_info.span` is in the innermost inlined + // function, and will be replaced with outer callsite spans as long + // as the inlined functions were `#[track_caller]`. + loop { + let scope_data = &self.mir.source_scopes[source_info.scope]; + + if let Some((callee, callsite_span)) = scope_data.inlined { + // Stop inside the most nested non-`#[track_caller]` function, + // before ever reaching its caller (which is irrelevant). + if !callee.def.requires_caller_location(tcx) { + return span_to_caller_location(source_info.span); + } + source_info.span = callsite_span; + } + + // Skip past all of the parents with `inlined: None`. + match scope_data.inlined_parent_scope { + Some(parent) => source_info.scope = parent, + None => break, + } + } + + // No inlined `SourceScope`s, or all of them were `#[track_caller]`. + self.caller_location.unwrap_or_else(|| span_to_caller_location(source_info.span)) } fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 09bcf4b1d3e11..fb7fb4957e56a 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1878,6 +1878,11 @@ pub struct SourceScopeData<'tcx> { /// `ty::Instance` is the callee, and the `Span` is the call site. pub inlined: Option<(ty::Instance<'tcx>, Span)>, + /// Nearest (transitive) parent scope (if any) which is inlined. + /// This is an optimization over walking up `parent_scope` + /// until a scope with `inlined: Some(...)` is found. + pub inlined_parent_scope: Option, + /// Crate-local information for this source scope, that can't (and /// needn't) be tracked across crates. pub local_data: ClearCrossCrate, diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index a9049ef02a694..d8d639ab73451 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -325,6 +325,7 @@ macro_rules! make_mir_visitor { span, parent_scope, inlined, + inlined_parent_scope, local_data: _, } = scope_data; @@ -357,6 +358,9 @@ macro_rules! make_mir_visitor { } self.visit_substs(callee_substs, location); } + if let Some(inlined_parent_scope) = inlined_parent_scope { + self.visit_source_scope(inlined_parent_scope); + } } fn super_statement(&mut self, diff --git a/compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs b/compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs index d9be28cf9dbb6..5c917f00d157b 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs @@ -15,38 +15,61 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a /// frame which is not `#[track_caller]`. crate fn find_closest_untracked_caller_location(&self) -> Span { - let frame = self - .stack() - .iter() - .rev() - // Find first non-`#[track_caller]` frame. - .find(|frame| { + for frame in self.stack().iter().rev() { + debug!("find_closest_untracked_caller_location: checking frame {:?}", frame.instance); + + // Assert that the frame we look at is actually executing code currently + // (`loc` is `Err` when we are unwinding and the frame does not require cleanup). + let loc = frame.loc.unwrap(); + + // This could be a non-`Call` terminator (such as `Drop`), or not a terminator at all + // (such as `box`). Use the normal span by default. + let mut source_info = *frame.body.source_info(loc); + + // If this is a `Call` terminator, use the `fn_span` instead. + let block = &frame.body.basic_blocks()[loc.block]; + if loc.statement_index == block.statements.len() { debug!( - "find_closest_untracked_caller_location: checking frame {:?}", - frame.instance + "find_closest_untracked_caller_location: got terminator {:?} ({:?})", + block.terminator(), + block.terminator().kind ); - !frame.instance.def.requires_caller_location(*self.tcx) - }) - // Assert that there is always such a frame. - .unwrap(); - // Assert that the frame we look at is actually executing code currently - // (`loc` is `Err` when we are unwinding and the frame does not require cleanup). - let loc = frame.loc.unwrap(); - // If this is a `Call` terminator, use the `fn_span` instead. - let block = &frame.body.basic_blocks()[loc.block]; - if loc.statement_index == block.statements.len() { - debug!( - "find_closest_untracked_caller_location:: got terminator {:?} ({:?})", - block.terminator(), - block.terminator().kind - ); - if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind { - return fn_span; + if let TerminatorKind::Call { fn_span, .. } = block.terminator().kind { + source_info.span = fn_span; + } + } + + // Walk up the `SourceScope`s, in case some of them are from MIR inlining. + // If so, the starting `source_info.span` is in the innermost inlined + // function, and will be replaced with outer callsite spans as long + // as the inlined functions were `#[track_caller]`. + loop { + let scope_data = &frame.body.source_scopes[source_info.scope]; + + if let Some((callee, callsite_span)) = scope_data.inlined { + // Stop inside the most nested non-`#[track_caller]` function, + // before ever reaching its caller (which is irrelevant). + if !callee.def.requires_caller_location(*self.tcx) { + return source_info.span; + } + source_info.span = callsite_span; + } + + // Skip past all of the parents with `inlined: None`. + match scope_data.inlined_parent_scope { + Some(parent) => source_info.scope = parent, + None => break, + } + } + + // Stop inside the most nested non-`#[track_caller]` function, + // before ever reaching its caller (which is irrelevant). + if !frame.instance.def.requires_caller_location(*self.tcx) { + return source_info.span; } } - // This is a different terminator (such as `Drop`) or not a terminator at all - // (such as `box`). Use the normal span. - frame.body.source_info(loc).span + + bug!("no non-`#[track_caller]` frame found") } /// Allocate a `const core::panic::Location` with the provided filename and line/column numbers. diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir/src/shim.rs index 877ee30bcedfd..b2fa4b11f3658 100644 --- a/compiler/rustc_mir/src/shim.rs +++ b/compiler/rustc_mir/src/shim.rs @@ -216,6 +216,7 @@ fn new_body<'tcx>( span, parent_scope: None, inlined: None, + inlined_parent_scope: None, local_data: ClearCrossCrate::Clear, }, 1, diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index b6d8ca8e5a6ed..96df6023c7195 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -246,11 +246,6 @@ impl Inliner<'tcx> { let codegen_fn_attrs = tcx.codegen_fn_attrs(callsite.callee.def_id()); - if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::TRACK_CALLER) { - debug!("`#[track_caller]` present - not inlining"); - return false; - } - let self_features = &self.codegen_fn_attrs.target_features; let callee_features = &codegen_fn_attrs.target_features; if callee_features.iter().any(|feature| !self_features.contains(feature)) { @@ -441,11 +436,24 @@ impl Inliner<'tcx> { for mut scope in callee_body.source_scopes.iter().cloned() { if scope.parent_scope.is_none() { + let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope]; + + // Attach the outermost callee scope as a child of the callsite + // scope, via the `parent_scope` and `inlined_parent_scope` chains. scope.parent_scope = Some(callsite.source_info.scope); + assert_eq!(scope.inlined_parent_scope, None); + scope.inlined_parent_scope = if callsite_scope.inlined.is_some() { + Some(callsite.source_info.scope) + } else { + callsite_scope.inlined_parent_scope + }; // Mark the outermost callee scope as an inlined one. assert_eq!(scope.inlined, None); scope.inlined = Some((callsite.callee, callsite.source_info.span)); + } else if scope.inlined_parent_scope.is_none() { + // Make it easy to find the scope with `inlined` set above. + scope.inlined_parent_scope = Some(scope_map[OUTERMOST_SOURCE_SCOPE]); } let idx = caller_body.source_scopes.push(scope); diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index a8db273e7c7ee..ac4d6563d6c24 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -551,18 +551,31 @@ fn write_scope_tree( let child_data = &body.source_scopes[child]; assert_eq!(child_data.parent_scope, Some(parent)); - if let Some((callee, callsite_span)) = child_data.inlined { - let indented_header = - format!("{0:1$}scope {2} (inlined {3}) {{", "", indent, child.index(), callee); + let (special, span) = if let Some((callee, callsite_span)) = child_data.inlined { + ( + format!( + " (inlined {}{})", + if callee.def.requires_caller_location(tcx) { "#[track_caller] " } else { "" }, + callee + ), + Some(callsite_span), + ) + } else { + (String::new(), None) + }; + + let indented_header = format!("{0:1$}scope {2}{3} {{", "", indent, child.index(), special); + + if let Some(span) = span { writeln!( w, "{0:1$} // at {2}", indented_header, ALIGN, - tcx.sess.source_map().span_to_string(callsite_span), + tcx.sess.source_map().span_to_string(span), )?; } else { - writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?; + writeln!(w, "{}", indented_header)?; } write_scope_tree(tcx, body, scope_tree, w, child, depth + 1)?; diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 2b1affbd6aa68..b6321c3bf6702 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -706,6 +706,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { span, parent_scope: Some(parent), inlined: None, + inlined_parent_scope: None, local_data: ClearCrossCrate::Set(scope_local_data), }) } From 387e31c9a7e6f7df3da513e2241a03e0b738ea4d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 21 Sep 2020 07:13:34 +0300 Subject: [PATCH 06/18] rustc_mir: properly map scope parent chains into the caller when inlining. --- compiler/rustc_mir/src/transform/inline.rs | 5 +++ ...e_closure_borrows_arg.foo.Inline.after.mir | 6 +-- .../issue-76997-inline-scopes-parenting.rs | 7 ++++ ...ine_scopes_parenting.main.Inline.after.mir | 41 +++++++++++++++++++ .../issue_73223.main.PreCodegen.32bit.diff | 8 ++-- .../issue_73223.main.PreCodegen.64bit.diff | 8 ++-- ..._73223.main.SimplifyArmIdentity.32bit.diff | 8 ++-- ..._73223.main.SimplifyArmIdentity.64bit.diff | 8 ++-- 8 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 src/test/mir-opt/inline/issue-76997-inline-scopes-parenting.rs create mode 100644 src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 96df6023c7195..947466c87fa99 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -435,6 +435,11 @@ impl Inliner<'tcx> { let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len()); for mut scope in callee_body.source_scopes.iter().cloned() { + // Map the callee scopes into the caller. + // FIXME(eddyb) this may ICE if the scopes are out of order. + scope.parent_scope = scope.parent_scope.map(|s| scope_map[s]); + scope.inlined_parent_scope = scope.inlined_parent_scope.map(|s| scope_map[s]); + if scope.parent_scope.is_none() { let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope]; diff --git a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir index 390b2320ef613..cb2cd785b4871 100644 --- a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir @@ -17,11 +17,11 @@ fn foo(_1: T, _2: &i32) -> i32 { debug r => _9; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:14: 12:15 debug _s => _10; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:23: 12:25 let _8: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + scope 3 { + debug variable => _8; // in scope 3 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 + } } } - scope 3 { - debug variable => _8; // in scope 3 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 - } bb0: { StorageLive(_3); // scope 0 at $DIR/inline-closure-borrows-arg.rs:12:9: 12:10 diff --git a/src/test/mir-opt/inline/issue-76997-inline-scopes-parenting.rs b/src/test/mir-opt/inline/issue-76997-inline-scopes-parenting.rs new file mode 100644 index 0000000000000..76d806acc6349 --- /dev/null +++ b/src/test/mir-opt/inline/issue-76997-inline-scopes-parenting.rs @@ -0,0 +1,7 @@ +// Tests that MIR inliner can handle `SourceScopeData` parenting correctly. (#76997) + +// EMIT_MIR issue_76997_inline_scopes_parenting.main.Inline.after.mir +fn main() { + let f = |x| { let y = x; y }; + f(()) +} diff --git a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir new file mode 100644 index 0000000000000..9d1e8aca40822 --- /dev/null +++ b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir @@ -0,0 +1,41 @@ +// MIR for `main` after Inline + +fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:4:11: 4:11 + let _1: [closure@$DIR/issue-76997-inline-scopes-parenting.rs:5:13: 5:33]; // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:5:9: 5:10 + let mut _2: &[closure@$DIR/issue-76997-inline-scopes-parenting.rs:5:13: 5:33]; // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:6 + let mut _3: ((),); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + let mut _4: (); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:7: 6:9 + let mut _6: (); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + scope 1 { + debug f => _1; // in scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:5:9: 5:10 + scope 2 (inlined main::{closure#0}) { // at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + debug x => _6; // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:14: 5:15 + let _5: (); // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + scope 3 { + debug y => _5; // in scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 + } + } + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:5:9: 5:10 + StorageLive(_2); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:6 + _2 = &_1; // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:6 + StorageLive(_3); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageLive(_4); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:7: 6:9 + (_3.0: ()) = move _4; // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageLive(_6); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + _6 = move (_3.0: ()); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageLive(_5); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 + _5 = const (); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:27: 5:28 + _0 = const (); // scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:30: 5:31 + StorageDead(_5); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:32: 5:33 + StorageDead(_6); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageDead(_4); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 + StorageDead(_3); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 + StorageDead(_2); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 + StorageDead(_1); // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:7:1: 7:2 + return; // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:7:2: 7:2 + } +} diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff index ac08a4512d0e3..82d17488782ec 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff @@ -41,6 +41,8 @@ let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 7 { + } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL @@ -48,6 +50,8 @@ let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 9 { + } } } scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL @@ -63,10 +67,6 @@ scope 2 { debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } - scope 7 { - } - scope 9 { - } bb0: { StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff index ac08a4512d0e3..82d17488782ec 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff @@ -41,6 +41,8 @@ let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 7 { + } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL @@ -48,6 +50,8 @@ let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 9 { + } } } scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL @@ -63,10 +67,6 @@ scope 2 { debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } - scope 7 { - } - scope 9 { - } bb0: { StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index b302114fa1787..f4295b278e63e 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -65,6 +65,8 @@ let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 7 { + } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL @@ -73,6 +75,8 @@ let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 9 { + } } } scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL @@ -88,10 +92,6 @@ scope 2 { debug v => _4; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } - scope 7 { - } - scope 9 { - } bb0: { StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index b302114fa1787..f4295b278e63e 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -65,6 +65,8 @@ let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 7 { + } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL @@ -73,6 +75,8 @@ let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + scope 9 { + } } } scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL @@ -88,10 +92,6 @@ scope 2 { debug v => _4; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } - scope 7 { - } - scope 9 { - } bb0: { StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 From 2bfb462b58db63aaa0a43bacde39687928fe901e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 9 Feb 2020 03:38:22 +0200 Subject: [PATCH 07/18] rustc_mir: don't throw away inlined locals' spans. --- compiler/rustc_mir/src/transform/inline.rs | 1 - ...anup.main-{closure#0}.generator_drop.0.mir | 2 +- .../inline_any_operand.bar.Inline.after.mir | 4 ++-- ...e_closure_borrows_arg.foo.Inline.after.mir | 2 +- ...line_closure_captures.foo.Inline.after.mir | 2 +- .../inline/inline_retag.bar.Inline.after.mir | 4 ++-- ...line_trait_method_2.test2.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.a.Inline.after.mir | 2 +- ...67_inline_as_ref_as_mut.b.Inline.after.mir | 4 ++-- ...ine_scopes_parenting.main.Inline.after.mir | 2 +- .../issue_73223.main.PreCodegen.32bit.diff | 18 +++++++-------- .../issue_73223.main.PreCodegen.64bit.diff | 18 +++++++-------- ..._73223.main.SimplifyArmIdentity.32bit.diff | 22 +++++++++---------- ..._73223.main.SimplifyArmIdentity.64bit.diff | 22 +++++++++---------- ...mplify_arm.id_try.SimplifyArmIdentity.diff | 2 +- ...implify_arm.id_try.SimplifyBranchSame.diff | 2 +- ...y.try_identity.DestinationPropagation.diff | 2 +- ..._try.try_identity.SimplifyArmIdentity.diff | 2 +- ....try_identity.SimplifyBranchSame.after.mir | 2 +- 19 files changed, 57 insertions(+), 58 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 947466c87fa99..5a8c10ae9155c 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -469,7 +469,6 @@ impl Inliner<'tcx> { let mut local = callee_body.local_decls[loc].clone(); local.source_info.scope = scope_map[local.source_info.scope]; - local.source_info.span = callsite.source_info.span; let idx = caller_body.local_decls.push(local); local_map.push(idx); diff --git a/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir b/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir index 27b86d66ded2d..164e769e93b02 100644 --- a/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir +++ b/src/test/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir @@ -27,7 +27,7 @@ fn main::{closure#0}(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 1 debug _s => (((*_1) as variant#3).0: std::string::String); // in scope 1 at $DIR/generator-drop-cleanup.rs:11:13: 11:15 } scope 2 (inlined String::new) { // at $DIR/generator-drop-cleanup.rs:11:18: 11:31 - let mut _6: std::vec::Vec; // in scope 2 at $DIR/generator-drop-cleanup.rs:11:18: 11:31 + let mut _6: std::vec::Vec; // in scope 2 at $SRC_DIR/alloc/src/string.rs:LL:COL scope 3 (inlined Vec::::new) { // at $SRC_DIR/alloc/src/string.rs:LL:COL } } diff --git a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir index 1ced3fe5d1570..2d97f4e6d6f71 100644 --- a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir @@ -11,8 +11,8 @@ fn bar() -> bool { scope 2 (inlined foo) { // at $DIR/inline-any-operand.rs:12:5: 12:13 debug x => _5; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9 debug y => _6; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17 - let mut _3: i32; // in scope 2 at $DIR/inline-any-operand.rs:12:5: 12:13 - let mut _4: i32; // in scope 2 at $DIR/inline-any-operand.rs:12:5: 12:13 + let mut _3: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 + let mut _4: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 } } diff --git a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir index cb2cd785b4871..92399ebaf9d1d 100644 --- a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir @@ -16,7 +16,7 @@ fn foo(_1: T, _2: &i32) -> i32 { scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 debug r => _9; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:14: 12:15 debug _s => _10; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:23: 12:25 - let _8: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + let _8: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 scope 3 { debug variable => _8; // in scope 3 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 } diff --git a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir index c6d1e8147a331..ffdc7f3ffe6e4 100644 --- a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir @@ -17,7 +17,7 @@ fn foo(_1: T, _2: i32) -> (i32, T) { debug _q => _10; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:10:23: 10:24 debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:10:17: 10:18 - let mut _9: T; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9 + let mut _9: T; // in scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 } } diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir index cdcfeec98f990..0cace4e32c405 100644 --- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -17,8 +17,8 @@ fn bar() -> bool { scope 2 (inlined foo) { // at $DIR/inline-retag.rs:12:5: 12:15 debug x => _3; // in scope 2 at $DIR/inline-retag.rs:16:8: 16:9 debug y => _6; // in scope 2 at $DIR/inline-retag.rs:16:17: 16:18 - let mut _11: i32; // in scope 2 at $DIR/inline-retag.rs:12:5: 12:15 - let mut _12: i32; // in scope 2 at $DIR/inline-retag.rs:12:5: 12:15 + let mut _11: i32; // in scope 2 at $DIR/inline-retag.rs:17:5: 17:7 + let mut _12: i32; // in scope 2 at $DIR/inline-retag.rs:17:11: 17:13 } } diff --git a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir index 8c7eb753cc037..907a56d6a0e42 100644 --- a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir @@ -7,7 +7,7 @@ fn test2(_1: &dyn X) -> bool { let mut _3: &dyn X; // in scope 0 at $DIR/inline-trait-method_2.rs:5:10: 5:11 scope 1 (inlined test) { // at $DIR/inline-trait-method_2.rs:5:5: 5:12 debug x => _2; // in scope 1 at $DIR/inline-trait-method_2.rs:9:9: 9:10 - let mut _4: &dyn X; // in scope 1 at $DIR/inline-trait-method_2.rs:5:5: 5:12 + let mut _4: &dyn X; // in scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:6 } bb0: { diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir index e91b79b8db5f0..08f0dac2e9d05 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir @@ -8,7 +8,7 @@ fn a(_1: &mut [T]) -> &mut [T] { let mut _4: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6 scope 1 (inlined <[T] as AsMut<[T]>>::as_mut) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 debug self => _4; // in scope 1 at $SRC_DIR/core/src/convert/mod.rs:LL:COL - let mut _5: &mut [T]; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 + let mut _5: &mut [T]; // in scope 1 at $SRC_DIR/core/src/convert/mod.rs:LL:COL } bb0: { diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir index 9378489fabab1..af97434f62929 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir @@ -8,8 +8,8 @@ fn b(_1: &mut Box) -> &mut T { let mut _4: &mut std::boxed::Box; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6 scope 1 (inlined as AsMut>::as_mut) { // at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 debug self => _4; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL - let mut _5: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 - let mut _6: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 + let mut _5: &mut T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL + let mut _6: &mut T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL } bb0: { diff --git a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir index 9d1e8aca40822..cdd27ff1036b2 100644 --- a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir @@ -11,7 +11,7 @@ fn main() -> () { debug f => _1; // in scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:5:9: 5:10 scope 2 (inlined main::{closure#0}) { // at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 debug x => _6; // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:14: 5:15 - let _5: (); // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + let _5: (); // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 scope 3 { debug y => _5; // in scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 } diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff index 82d17488782ec..23aefe07892fd 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff @@ -38,18 +38,18 @@ scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _25; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _24; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _25: &&i32; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 7 { } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _27; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _28: &&i32; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 9 { } } @@ -57,9 +57,9 @@ scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _29; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _31; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _29: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _30: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _31: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _29: &[&str]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _30: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _31: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL } } } diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff index 82d17488782ec..23aefe07892fd 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff @@ -38,18 +38,18 @@ scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _25; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _24; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _25: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _23: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _24: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _25: &&i32; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 7 { } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _28; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _27; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _28: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _26: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _28: &&i32; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 9 { } } @@ -57,9 +57,9 @@ scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _29; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _31; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _29: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _30: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _31: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _29: &[&str]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _30: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _31: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL } } } diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index f4295b278e63e..b9cb58e14c45d 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -61,20 +61,20 @@ scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _39; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _40; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _49: &&i32; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 7 { } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _43; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _53: &&i32; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 9 { } } @@ -82,9 +82,9 @@ scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _23; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _27; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _54: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _55: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _56: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _54: &[&str]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _55: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _56: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL } } } diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index f4295b278e63e..b9cb58e14c45d 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -61,20 +61,20 @@ scope 6 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _39; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _40; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _49: &&i32; // in scope 6 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _46: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _47: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _48: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _49: &&i32; // in scope 6 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 7 { } } scope 8 (inlined ArgumentV1::new::<&i32>) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug x => _42; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug f => _43; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _53: &&i32; // in scope 8 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _50: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _51: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _52: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _53: &&i32; // in scope 8 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL scope 9 { } } @@ -82,9 +82,9 @@ scope 10 (inlined Arguments::new_v1) { // at $SRC_DIR/std/src/macros.rs:LL:COL debug pieces => _23; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL debug args => _27; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL - let mut _54: &[&str]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _55: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL - let mut _56: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/std/src/macros.rs:LL:COL + let mut _54: &[&str]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _55: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL + let mut _56: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/core/src/fmt/mod.rs:LL:COL } } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index 56ae6cae8071c..9a9395c3c8891 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -29,7 +29,7 @@ scope 8 (inlined as Try>::from_error) { // at $DIR/simplify-arm.rs:24:13: 24:15 - debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15 + let mut _12: i32; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index 9cfa3d2231ae0..ed96a22f8e3d0 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -25,7 +25,7 @@ } scope 8 (inlined as Try>::from_error) { // at $DIR/simplify-arm.rs:24:13: 24:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15 + let mut _12: i32; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } } diff --git a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff index d36ab58f43027..38da3a8a9e8d3 100644 --- a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff +++ b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff @@ -25,7 +25,7 @@ } scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 + let mut _12: i32; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } } diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff index ab99f122c3bcd..29b338b339b26 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff @@ -29,7 +29,7 @@ scope 8 (inlined as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 - debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 + let mut _12: i32; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } } diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir index a084542321dd8..e3527b99576fd 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir @@ -24,7 +24,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result as Try>::from_error) { // at $DIR/simplify_try.rs:8:13: 8:15 debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL - let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15 + let mut _12: i32; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL } } } From 9d57c417fc1bac25b0274a34ae581c2e18a9d44e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 10 Feb 2020 03:03:24 +0200 Subject: [PATCH 08/18] rustc_codegen_llvm: create `DIFile`s from just `SourceFile`s. --- .../src/debuginfo/create_scope_map.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/doc.rs | 2 +- .../src/debuginfo/metadata.rs | 21 +++++-------- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 16 ++++------ .../rustc_codegen_ssa/src/mir/debuginfo.rs | 31 +++---------------- .../rustc_codegen_ssa/src/traits/debuginfo.rs | 3 -- 6 files changed, 21 insertions(+), 54 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 7f47b61de3f92..4c352c7ae0c3d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -76,7 +76,7 @@ fn make_mir_scope( } let loc = cx.lookup_debug_loc(scope_data.span.lo()); - let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate); + let file_metadata = file_metadata(cx, &loc.file); let scope_metadata = unsafe { Some(llvm::LLVMRustDIBuilderCreateLexicalBlock( diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/doc.rs b/compiler/rustc_codegen_llvm/src/debuginfo/doc.rs index b3a8fa2988785..10dd590652949 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/doc.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/doc.rs @@ -28,7 +28,7 @@ //! utilizing a cache. The way to get a shared metadata node when needed is //! thus to just call the corresponding function in this module: //! -//! let file_metadata = file_metadata(crate_context, path); +//! let file_metadata = file_metadata(cx, file); //! //! The function will take care of probing the cache for an existing node for //! that exact file path. diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 5587e6ead1dbb..73c1f73ec7fe9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -26,7 +26,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_fs_util::path_to_c_string; use rustc_hir::def::CtorKind; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::ich::NodeIdHashingMode; use rustc_middle::mir::interpret::truncate; @@ -760,16 +760,12 @@ fn hex_encode(data: &[u8]) -> String { hex_string } -pub fn file_metadata( - cx: &CodegenCx<'ll, '_>, - source_file: &SourceFile, - defining_crate: CrateNum, -) -> &'ll DIFile { - debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate); +pub fn file_metadata(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile { + debug!("file_metadata: file_name: {}", source_file.name); let hash = Some(&source_file.src_hash); let file_name = Some(source_file.name.to_string()); - let directory = if defining_crate == LOCAL_CRATE { + let directory = if source_file.is_real_file() && !source_file.is_imported() { Some(cx.sess().working_dir.0.to_string_lossy().to_string()) } else { // If the path comes from an upstream crate we assume it has been made @@ -1835,7 +1831,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> { if !span.is_dummy() { let loc = cx.lookup_debug_loc(span.lo()); return Some(SourceInfo { - file: file_metadata(cx, &loc.file, def_id.krate), + file: file_metadata(cx, &loc.file), line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), }); } @@ -2474,7 +2470,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global let (file_metadata, line_number) = if !span.is_dummy() { let loc = cx.lookup_debug_loc(span.lo()); - (file_metadata(cx, &loc.file, LOCAL_CRATE), loc.line) + (file_metadata(cx, &loc.file), loc.line) } else { (unknown_file_metadata(cx), None) }; @@ -2576,9 +2572,8 @@ pub fn create_vtable_metadata(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, vtable: & pub fn extend_scope_to_file( cx: &CodegenCx<'ll, '_>, scope_metadata: &'ll DIScope, - file: &rustc_span::SourceFile, - defining_crate: CrateNum, + file: &SourceFile, ) -> &'ll DILexicalBlock { - let file_metadata = file_metadata(cx, &file, defining_crate); + let file_metadata = file_metadata(cx, file); unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) } } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 80e0e7bf2e06c..32752fa61bae4 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -21,7 +21,7 @@ use rustc_codegen_ssa::debuginfo::type_names; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_codegen_ssa::traits::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE}; use rustc_index::vec::IndexVec; use rustc_middle::mir; use rustc_middle::ty::layout::HasTyCtxt; @@ -246,7 +246,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let def_id = instance.def_id(); let containing_scope = get_containing_scope(self, instance); let loc = self.lookup_debug_loc(span.lo()); - let file_metadata = file_metadata(self, &loc.file, def_id.krate); + let file_metadata = file_metadata(self, &loc.file); let function_type_metadata = unsafe { let fn_signature = get_function_signature(self, fn_abi); @@ -318,10 +318,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { file_start_pos: BytePos(0), file_end_pos: BytePos(0), }; - let mut fn_debug_context = FunctionDebugContext { - scopes: IndexVec::from_elem(null_scope, &mir.source_scopes), - defining_crate: def_id.krate, - }; + let mut fn_debug_context = + FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) }; // Fill in all the scopes, with the information from the MIR body. compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context); @@ -509,9 +507,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { &self, scope_metadata: &'ll DIScope, file: &rustc_span::SourceFile, - defining_crate: CrateNum, ) -> &'ll DILexicalBlock { - metadata::extend_scope_to_file(&self, scope_metadata, file, defining_crate) + metadata::extend_scope_to_file(&self, scope_metadata, file) } fn debuginfo_finalize(&self) { @@ -522,7 +519,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). fn create_dbg_var( &self, - dbg_context: &FunctionDebugContext<&'ll DIScope>, variable_name: Symbol, variable_type: Ty<'tcx>, scope_metadata: &'ll DIScope, @@ -530,7 +526,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { span: Span, ) -> &'ll DIVariable { let loc = self.lookup_debug_loc(span.lo()); - let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate); + let file_metadata = file_metadata(self, &loc.file); let type_metadata = type_metadata(self, variable_type, span); diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 26a646b029367..09b6ba9a2ef60 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -1,5 +1,4 @@ use crate::traits::*; -use rustc_hir::def_id::CrateNum; use rustc_index::vec::IndexVec; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir; @@ -15,7 +14,6 @@ use super::{FunctionCx, LocalRef}; pub struct FunctionDebugContext { pub scopes: IndexVec>, - pub defining_crate: CrateNum, } #[derive(Copy, Clone)] @@ -95,19 +93,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pos: BytePos, ) -> Option { let debug_context = self.debug_context.as_ref()?; - let scope_metadata = debug_context.scopes[scope_id].scope_metadata; + let scope_metadata = debug_context.scopes[scope_id].scope_metadata?; if pos < debug_context.scopes[scope_id].file_start_pos || pos >= debug_context.scopes[scope_id].file_end_pos { let sm = self.cx.sess().source_map(); - let defining_crate = debug_context.defining_crate; - Some(self.cx.extend_scope_to_file( - scope_metadata.unwrap(), - &sm.lookup_char_pos(pos).file, - defining_crate, - )) + Some(self.cx.extend_scope_to_file(scope_metadata, &sm.lookup_char_pos(pos).file)) } else { - scope_metadata + Some(scope_metadata) } } @@ -158,14 +151,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // FIXME(eddyb) is this `+ 1` needed at all? let kind = VariableKind::ArgumentVariable(arg_index + 1); - self.cx.create_dbg_var( - self.debug_context.as_ref().unwrap(), - name, - self.monomorphize(&decl.ty), - scope, - kind, - span, - ) + self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span) }); Some(PerLocalVarDebugInfo { @@ -340,14 +326,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } else { VariableKind::LocalVariable }; - self.cx.create_dbg_var( - self.debug_context.as_ref().unwrap(), - var.name, - var_ty, - scope, - var_kind, - span, - ) + self.cx.create_dbg_var(var.name, var_ty, scope, var_kind, span) }); per_local[var.place.local].push(PerLocalVarDebugInfo { diff --git a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs index 1ee0f489ffc10..79654dc3633d4 100644 --- a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs @@ -1,6 +1,5 @@ use super::BackendTypes; use crate::mir::debuginfo::{FunctionDebugContext, VariableKind}; -use rustc_hir::def_id::CrateNum; use rustc_middle::mir; use rustc_middle::ty::{Instance, Ty}; use rustc_span::{SourceFile, Span, Symbol}; @@ -26,7 +25,6 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { &self, scope_metadata: Self::DIScope, file: &SourceFile, - defining_crate: CrateNum, ) -> Self::DIScope; fn debuginfo_finalize(&self); @@ -34,7 +32,6 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). fn create_dbg_var( &self, - dbg_context: &FunctionDebugContext, variable_name: Symbol, variable_type: Ty<'tcx>, scope_metadata: Self::DIScope, From fa2b381ec83556111a99750bcc7688521d7e8b0d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 10 Feb 2020 22:30:51 +0200 Subject: [PATCH 09/18] rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method. --- compiler/rustc_codegen_llvm/src/common.rs | 1 + .../src/debuginfo/create_scope_map.rs | 14 ++--- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 57 ++++++++++--------- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 +- .../rustc_codegen_ssa/src/traits/debuginfo.rs | 9 +++ .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 5 +- 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index 0992410a728bd..2cd745ec420f8 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -80,6 +80,7 @@ impl Funclet<'ll> { impl BackendTypes for CodegenCx<'ll, 'tcx> { type Value = &'ll Value; + // FIXME(eddyb) replace this with a `Function` "subclass" of `Value`. type Function = &'ll Value; type BasicBlock = &'ll BasicBlock; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 4c352c7ae0c3d..11855675ccfdd 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -5,7 +5,7 @@ use rustc_codegen_ssa::traits::*; use crate::common::CodegenCx; use crate::llvm; -use crate::llvm::debuginfo::{DIScope, DISubprogram}; +use crate::llvm::debuginfo::DIScope; use rustc_middle::mir::{Body, SourceScope}; use rustc_session::config::DebugInfo; @@ -16,7 +16,7 @@ use rustc_index::vec::Idx; pub fn compute_mir_scopes( cx: &CodegenCx<'ll, '_>, mir: &Body<'_>, - fn_metadata: &'ll DISubprogram, + fn_dbg_scope: &'ll DIScope, debug_context: &mut FunctionDebugContext<&'ll DIScope>, ) { // Find all the scopes with variables defined in them. @@ -37,16 +37,16 @@ pub fn compute_mir_scopes( // Instantiate all scopes. for idx in 0..mir.source_scopes.len() { let scope = SourceScope::new(idx); - make_mir_scope(cx, &mir, fn_metadata, &has_variables, debug_context, scope); + make_mir_scope(cx, &mir, fn_dbg_scope, &has_variables, debug_context, scope); } } fn make_mir_scope( cx: &CodegenCx<'ll, '_>, mir: &Body<'_>, - fn_metadata: &'ll DISubprogram, + fn_dbg_scope: &'ll DIScope, has_variables: &BitSet, - debug_context: &mut FunctionDebugContext<&'ll DISubprogram>, + debug_context: &mut FunctionDebugContext<&'ll DIScope>, scope: SourceScope, ) { if debug_context.scopes[scope].is_valid() { @@ -55,13 +55,13 @@ fn make_mir_scope( let scope_data = &mir.source_scopes[scope]; let parent_scope = if let Some(parent) = scope_data.parent_scope { - make_mir_scope(cx, mir, fn_metadata, has_variables, debug_context, parent); + make_mir_scope(cx, mir, fn_dbg_scope, has_variables, debug_context, parent); debug_context.scopes[parent] } else { // The root is the function itself. let loc = cx.lookup_debug_loc(mir.span.lo()); debug_context.scopes[scope] = DebugScope { - scope_metadata: Some(fn_metadata), + scope_metadata: Some(fn_dbg_scope), file_start_pos: loc.file.start_pos, file_end_pos: loc.file.end_pos, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 32752fa61bae4..3f47c62ccaec1 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -235,16 +235,36 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { return None; } - let span = mir.span; + // Initialize fn debug context (including scopes). + // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`. + let empty_scope = DebugScope { + scope_metadata: None, + file_start_pos: BytePos(0), + file_end_pos: BytePos(0), + }; + let mut fn_debug_context = + FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) }; - // This can be the case for functions inlined from another crate - if span.is_dummy() { - // FIXME(simulacrum): Probably can't happen; remove. - return None; - } + // Fill in all the scopes, with the information from the MIR body. + compute_mir_scopes( + self, + mir, + self.dbg_scope_fn(instance, fn_abi, Some(llfn)), + &mut fn_debug_context, + ); + + Some(fn_debug_context) + } + fn dbg_scope_fn( + &self, + instance: Instance<'tcx>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + maybe_definition_llfn: Option<&'ll Value>, + ) -> &'ll DIScope { let def_id = instance.def_id(); let containing_scope = get_containing_scope(self, instance); + let span = self.tcx.def_span(def_id); let loc = self.lookup_debug_loc(span.lo()); let file_metadata = file_metadata(self, &loc.file); @@ -291,8 +311,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } - let fn_metadata = unsafe { - llvm::LLVMRustDIBuilderCreateFunction( + unsafe { + return llvm::LLVMRustDIBuilderCreateFunction( DIB(self), containing_scope, name.as_ptr().cast(), @@ -305,26 +325,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { scope_line.unwrap_or(UNKNOWN_LINE_NUMBER), flags, spflags, - llfn, + maybe_definition_llfn, template_parameters, None, - ) - }; - - // Initialize fn debug context (including scopes). - // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`. - let null_scope = DebugScope { - scope_metadata: None, - file_start_pos: BytePos(0), - file_end_pos: BytePos(0), - }; - let mut fn_debug_context = - FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) }; - - // Fill in all the scopes, with the information from the MIR body. - compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context); - - return Some(fn_debug_context); + ); + } fn get_function_signature<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4c1fee0106a94..8305f654e03a8 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1854,7 +1854,7 @@ extern "C" { ScopeLine: c_uint, Flags: DIFlags, SPFlags: DISPFlags, - Fn: &'a Value, + MaybeFn: Option<&'a Value>, TParam: &'a DIArray, Decl: Option<&'a DIDescriptor>, ) -> &'a DISubprogram; diff --git a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs index 79654dc3633d4..3d2e0ac7be2fc 100644 --- a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs @@ -21,6 +21,15 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { mir: &mir::Body<'_>, ) -> Option>; + // FIXME(eddyb) find a common convention for all of the debuginfo-related + // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). + fn dbg_scope_fn( + &self, + instance: Instance<'tcx>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + maybe_definition_llfn: Option, + ) -> Self::DIScope; + fn extend_scope_to_file( &self, scope_metadata: Self::DIScope, diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 9f8ea7f43d84b..dbd02a0ca3dba 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -733,7 +733,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction( const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, unsigned ScopeLine, LLVMRustDIFlags Flags, - LLVMRustDISPFlags SPFlags, LLVMValueRef Fn, LLVMMetadataRef TParam, + LLVMRustDISPFlags SPFlags, LLVMValueRef MaybeFn, LLVMMetadataRef TParam, LLVMMetadataRef Decl) { DITemplateParameterArray TParams = DITemplateParameterArray(unwrap(TParam)); @@ -750,7 +750,8 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction( unwrapDI(File), LineNo, unwrapDI(Ty), ScopeLine, llvmFlags, llvmSPFlags, TParams, unwrapDIPtr(Decl)); - unwrap(Fn)->setSubprogram(Sub); + if (MaybeFn) + unwrap(MaybeFn)->setSubprogram(Sub); return wrap(Sub); } From 88d874de6395a5422caad1f61783dadd395d49d0 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 10 Feb 2020 22:52:20 +0200 Subject: [PATCH 10/18] rustc_codegen_llvm: avoid converting between DILocation and Value. --- compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 3 ++- .../rustc_codegen_llvm/src/debuginfo/source_loc.rs | 6 +++--- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 12 +++++++----- compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 3f47c62ccaec1..c940656b2561e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -192,7 +192,8 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { let dbg_loc = self.cx().create_debug_loc(scope, span); unsafe { - llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc); + let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc); + llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval); } } fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs b/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs index 517246cd0b24b..f1d9b8653bcb7 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs @@ -2,8 +2,8 @@ use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; use super::utils::debug_context; use crate::common::CodegenCx; -use crate::llvm::debuginfo::DIScope; -use crate::llvm::{self, Value}; +use crate::llvm; +use crate::llvm::debuginfo::{DILocation, DIScope}; use rustc_codegen_ssa::traits::*; use rustc_data_structures::sync::Lrc; @@ -45,7 +45,7 @@ impl CodegenCx<'ll, '_> { } } - pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value { + pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation { let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo()); unsafe { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 8305f654e03a8..daceda20097da 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -5,8 +5,9 @@ use rustc_codegen_ssa::coverageinfo::map as coverage_map; use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, - DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DINameSpace, DISPFlags, DIScope, - DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, + DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace, + DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, + DebugEmissionKind, }; use libc::{c_char, c_int, c_uint, size_t}; @@ -794,6 +795,7 @@ pub mod debuginfo { pub struct DIBuilder<'a>(InvariantOpaque<'a>); pub type DIDescriptor = Metadata; + pub type DILocation = Metadata; pub type DIScope = DIDescriptor; pub type DIFile = DIScope; pub type DILexicalBlock = DIScope; @@ -2005,7 +2007,7 @@ extern "C" { VarInfo: &'a DIVariable, AddrOps: *const i64, AddrOpsCount: c_uint, - DL: &'a Value, + DL: &'a DILocation, InsertAtEnd: &'a BasicBlock, ) -> &'a Value; @@ -2093,8 +2095,8 @@ extern "C" { Line: c_uint, Column: c_uint, Scope: &'a DIScope, - InlinedAt: Option<&'a Metadata>, - ) -> &'a Value; + InlinedAt: Option<&'a DILocation>, + ) -> &'a DILocation; pub fn LLVMRustDIBuilderCreateOpDeref() -> i64; pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64; diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index dbd02a0ca3dba..3beb328339e7a 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -931,12 +931,12 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder, extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo, - int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL, + int64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL, LLVMBasicBlockRef InsertAtEnd) { return wrap(Builder->insertDeclare( unwrap(V), unwrap(VarInfo), Builder->createExpression(llvm::ArrayRef(AddrOps, AddrOpsCount)), - DebugLoc(cast(unwrap(DL)->getMetadata())), + DebugLoc(cast(DL)), unwrap(InsertAtEnd))); } @@ -1003,7 +1003,7 @@ LLVMRustDICompositeTypeReplaceArrays(LLVMRustDIBuilderRef Builder, DINodeArray(unwrap(Params))); } -extern "C" LLVMValueRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) { @@ -1012,7 +1012,7 @@ LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line, DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr(Scope), unwrapDIPtr(InlinedAt)); - return wrap(MetadataAsValue::get(Context, debug_loc.getAsMDNode())); + return wrap(debug_loc.getAsMDNode()); } extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() { From 737499593db6d7702de3bf9d0070ec3f8e65d71e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 10 Feb 2020 22:52:30 +0200 Subject: [PATCH 11/18] rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa. --- compiler/rustc_codegen_llvm/src/builder.rs | 1 + compiler/rustc_codegen_llvm/src/common.rs | 1 + .../src/debuginfo/create_scope_map.rs | 10 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 94 ++++++++++---- .../src/debuginfo/source_loc.rs | 61 --------- .../rustc_codegen_ssa/src/mir/debuginfo.rs | 118 ++++++++---------- .../rustc_codegen_ssa/src/traits/backend.rs | 1 + .../rustc_codegen_ssa/src/traits/debuginfo.rs | 7 +- compiler/rustc_codegen_ssa/src/traits/mod.rs | 1 + 9 files changed, 132 insertions(+), 162 deletions(-) delete mode 100644 compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 491191d058cf0..978ad37c0f390 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -56,6 +56,7 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> { type Funclet = as BackendTypes>::Funclet; type DIScope = as BackendTypes>::DIScope; + type DILocation = as BackendTypes>::DILocation; type DIVariable = as BackendTypes>::DIVariable; } diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index 2cd745ec420f8..7633dd0600d5f 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -88,6 +88,7 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> { type Funclet = Funclet<'ll>; type DIScope = &'ll llvm::debuginfo::DIScope; + type DILocation = &'ll llvm::debuginfo::DILocation; type DIVariable = &'ll llvm::debuginfo::DIVariable; } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 11855675ccfdd..f6b7f257f2f37 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -49,7 +49,7 @@ fn make_mir_scope( debug_context: &mut FunctionDebugContext<&'ll DIScope>, scope: SourceScope, ) { - if debug_context.scopes[scope].is_valid() { + if debug_context.scopes[scope].dbg_scope.is_some() { return; } @@ -61,7 +61,7 @@ fn make_mir_scope( // The root is the function itself. let loc = cx.lookup_debug_loc(mir.span.lo()); debug_context.scopes[scope] = DebugScope { - scope_metadata: Some(fn_dbg_scope), + dbg_scope: Some(fn_dbg_scope), file_start_pos: loc.file.start_pos, file_end_pos: loc.file.end_pos, }; @@ -78,17 +78,17 @@ fn make_mir_scope( let loc = cx.lookup_debug_loc(scope_data.span.lo()); let file_metadata = file_metadata(cx, &loc.file); - let scope_metadata = unsafe { + let dbg_scope = unsafe { Some(llvm::LLVMRustDIBuilderCreateLexicalBlock( DIB(cx), - parent_scope.scope_metadata.unwrap(), + parent_scope.dbg_scope.unwrap(), file_metadata, loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER), )) }; debug_context.scopes[scope] = DebugScope { - scope_metadata, + dbg_scope, file_start_pos: loc.file.start_pos, file_end_pos: loc.file.end_pos, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index c940656b2561e..7b416f1f6adba 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -3,7 +3,8 @@ mod doc; use rustc_codegen_ssa::mir::debuginfo::VariableKind::*; -use self::metadata::{file_metadata, type_metadata, TypeMap, UNKNOWN_LINE_NUMBER}; +use self::metadata::{file_metadata, type_metadata, TypeMap}; +use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; use self::namespace::mangled_name_of_instance; use self::type_names::compute_debuginfo_type_name; use self::utils::{create_DIArray, is_node_local_to_unit, DIB}; @@ -13,7 +14,8 @@ use crate::builder::Builder; use crate::common::CodegenCx; use crate::llvm; use crate::llvm::debuginfo::{ - DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable, + DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DIType, + DIVariable, }; use crate::value::Value; @@ -21,6 +23,7 @@ use rustc_codegen_ssa::debuginfo::type_names; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_codegen_ssa::traits::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE}; use rustc_index::vec::IndexVec; use rustc_middle::mir; @@ -29,7 +32,7 @@ use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TypeFoldable}; use rustc_session::config::{self, DebugInfo}; use rustc_span::symbol::Symbol; -use rustc_span::{self, BytePos, Span}; +use rustc_span::{self, BytePos, Pos, SourceFile, SourceFileAndLine, Span}; use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; @@ -41,7 +44,6 @@ mod create_scope_map; pub mod gdb; pub mod metadata; mod namespace; -mod source_loc; mod utils; pub use self::create_scope_map::compute_mir_scopes; @@ -141,14 +143,11 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { fn dbg_var_addr( &mut self, dbg_var: &'ll DIVariable, - scope_metadata: &'ll DIScope, + dbg_loc: &'ll DILocation, variable_alloca: Self::Value, direct_offset: Size, indirect_offsets: &[Size], - span: Span, ) { - let cx = self.cx(); - // Convert the direct and indirect offsets to address ops. // FIXME(eddyb) use `const`s instead of getting the values via FFI, // the values should match the ones in the DWARF standard anyway. @@ -168,14 +167,10 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { } } - // FIXME(eddyb) maybe this information could be extracted from `dbg_var`, - // to avoid having to pass it down in both places? - // NB: `var` doesn't seem to know about the column, so that's a limitation. - let dbg_loc = cx.create_debug_loc(scope_metadata, span); unsafe { // FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`. llvm::LLVMRustDIBuilderInsertDeclareAtEnd( - DIB(cx), + DIB(self.cx()), variable_alloca, dbg_var, addr_ops.as_ptr(), @@ -186,16 +181,13 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { } } - fn set_source_location(&mut self, scope: &'ll DIScope, span: Span) { - debug!("set_source_location: {}", self.sess().source_map().span_to_string(span)); - - let dbg_loc = self.cx().create_debug_loc(scope, span); - + fn set_dbg_loc(&mut self, dbg_loc: &'ll DILocation) { unsafe { let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc); llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval); } } + fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) { gdb::insert_reference_to_gdb_debug_scripts_section_global(self) } @@ -224,6 +216,49 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { } } +/// A source code location used to generate debug information. +// FIXME(eddyb) rename this to better indicate it's a duplicate of +// `rustc_span::Loc` rather than `DILocation`, perhaps by making +// `lookup_char_pos` return the right information instead. +pub struct DebugLoc { + /// Information about the original source file. + pub file: Lrc, + /// The (1-based) line number. + pub line: Option, + /// The (1-based) column number. + pub col: Option, +} + +impl CodegenCx<'ll, '_> { + /// Looks up debug source information about a `BytePos`. + // FIXME(eddyb) rename this to better indicate it's a duplicate of + // `lookup_char_pos` rather than `dbg_loc`, perhaps by making + // `lookup_char_pos` return the right information instead. + pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc { + let (file, line, col) = match self.sess().source_map().lookup_line(pos) { + Ok(SourceFileAndLine { sf: file, line }) => { + let line_pos = file.line_begin_pos(pos); + + // Use 1-based indexing. + let line = (line + 1) as u32; + let col = (pos - line_pos).to_u32() + 1; + + (file, Some(line), Some(col)) + } + Err(file) => (file, None, None), + }; + + // For MSVC, omit the column number. + // Otherwise, emit it. This mimics clang behaviour. + // See discussion in https://github.com/rust-lang/rust/issues/42921 + if self.sess().target.options.is_like_msvc { + DebugLoc { file, line, col: None } + } else { + DebugLoc { file, line, col } + } + } +} + impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn create_function_debug_context( &self, @@ -237,12 +272,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { } // Initialize fn debug context (including scopes). - // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`. - let empty_scope = DebugScope { - scope_metadata: None, - file_start_pos: BytePos(0), - file_end_pos: BytePos(0), - }; + // FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`. + let empty_scope = + DebugScope { dbg_scope: None, file_start_pos: BytePos(0), file_end_pos: BytePos(0) }; let mut fn_debug_context = FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) }; @@ -505,6 +537,20 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } + fn dbg_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation { + let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo()); + + unsafe { + llvm::LLVMRustDIBuilderCreateDebugLocation( + utils::debug_context(self).llcontext, + line.unwrap_or(UNKNOWN_LINE_NUMBER), + col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + scope, + None, + ) + } + } + fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value) { metadata::create_vtable_metadata(self, ty, vtable) } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs b/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs deleted file mode 100644 index f1d9b8653bcb7..0000000000000 --- a/compiler/rustc_codegen_llvm/src/debuginfo/source_loc.rs +++ /dev/null @@ -1,61 +0,0 @@ -use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; -use super::utils::debug_context; - -use crate::common::CodegenCx; -use crate::llvm; -use crate::llvm::debuginfo::{DILocation, DIScope}; -use rustc_codegen_ssa::traits::*; - -use rustc_data_structures::sync::Lrc; -use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span}; - -/// A source code location used to generate debug information. -pub struct DebugLoc { - /// Information about the original source file. - pub file: Lrc, - /// The (1-based) line number. - pub line: Option, - /// The (1-based) column number. - pub col: Option, -} - -impl CodegenCx<'ll, '_> { - /// Looks up debug source information about a `BytePos`. - pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc { - let (file, line, col) = match self.sess().source_map().lookup_line(pos) { - Ok(SourceFileAndLine { sf: file, line }) => { - let line_pos = file.line_begin_pos(pos); - - // Use 1-based indexing. - let line = (line + 1) as u32; - let col = (pos - line_pos).to_u32() + 1; - - (file, Some(line), Some(col)) - } - Err(file) => (file, None, None), - }; - - // For MSVC, omit the column number. - // Otherwise, emit it. This mimics clang behaviour. - // See discussion in https://github.com/rust-lang/rust/issues/42921 - if self.sess().target.options.is_like_msvc { - DebugLoc { file, line, col: None } - } else { - DebugLoc { file, line, col } - } - } - - pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation { - let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo()); - - unsafe { - llvm::LLVMRustDIBuilderCreateDebugLocation( - debug_context(self).llcontext, - line.unwrap_or(UNKNOWN_LINE_NUMBER), - col.unwrap_or(UNKNOWN_COLUMN_NUMBER), - scope, - None, - ) - } - } -} diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 09b6ba9a2ef60..ddb9372cf8f73 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -37,71 +37,58 @@ pub struct PerLocalVarDebugInfo<'tcx, D> { #[derive(Clone, Copy, Debug)] pub struct DebugScope { - pub scope_metadata: Option, + // FIXME(eddyb) this should never be `None`, after initialization. + pub dbg_scope: Option, // Start and end offsets of the file to which this DIScope belongs. // These are used to quickly determine whether some span refers to the same file. pub file_start_pos: BytePos, pub file_end_pos: BytePos, } -impl DebugScope { - pub fn is_valid(&self) -> bool { - self.scope_metadata.is_some() - } -} - impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn set_debug_loc(&self, bx: &mut Bx, source_info: mir::SourceInfo) { - let (scope, span) = self.debug_loc(source_info); - bx.set_span(span); - if let Some(scope) = scope { - bx.set_source_location(scope, span); + bx.set_span(source_info.span); + if let Some(dbg_loc) = self.dbg_loc(source_info) { + bx.set_dbg_loc(dbg_loc); } } - pub fn debug_loc(&self, source_info: mir::SourceInfo) -> (Option, Span) { + fn dbg_loc(&self, source_info: mir::SourceInfo) -> Option { + let (scope, span) = self.dbg_scope_and_span(source_info)?; + Some(self.cx.dbg_loc(scope, span)) + } + + fn dbg_scope_and_span(&self, source_info: mir::SourceInfo) -> Option<(Bx::DIScope, Span)> { // Bail out if debug info emission is not enabled. - match self.debug_context { - None => return (None, source_info.span), - Some(_) => {} - } + let debug_context = self.debug_context.as_ref()?; + let scope = &debug_context.scopes[source_info.scope]; // In order to have a good line stepping behavior in debugger, we overwrite debug // locations of macro expansions with that of the outermost expansion site // (unless the crate is being compiled with `-Z debug-macros`). - if !source_info.span.from_expansion() || self.cx.sess().opts.debugging_opts.debug_macros { - let scope = self.scope_metadata_for_loc(source_info.scope, source_info.span.lo()); - (scope, source_info.span) - } else { + let mut span = source_info.span; + if span.from_expansion() && !self.cx.sess().opts.debugging_opts.debug_macros { // Walk up the macro expansion chain until we reach a non-expanded span. // We also stop at the function body level because no line stepping can occur // at the level above that. - let span = rustc_span::hygiene::walk_chain(source_info.span, self.mir.span.ctxt()); - let scope = self.scope_metadata_for_loc(source_info.scope, span.lo()); // Use span of the outermost expansion site, while keeping the original lexical scope. - (scope, span) + span = rustc_span::hygiene::walk_chain(span, self.mir.span.ctxt()); } - } - // DILocations inherit source file name from the parent DIScope. Due to macro expansions - // it may so happen that the current span belongs to a different file than the DIScope - // corresponding to span's containing source scope. If so, we need to create a DIScope - // "extension" into that file. - fn scope_metadata_for_loc( - &self, - scope_id: mir::SourceScope, - pos: BytePos, - ) -> Option { - let debug_context = self.debug_context.as_ref()?; - let scope_metadata = debug_context.scopes[scope_id].scope_metadata?; - if pos < debug_context.scopes[scope_id].file_start_pos - || pos >= debug_context.scopes[scope_id].file_end_pos - { + // FIXME(eddyb) this should never be `None`. + let mut dbg_scope = scope.dbg_scope?; + + // DILocations inherit source file name from the parent DIScope. Due to macro expansions + // it may so happen that the current span belongs to a different file than the DIScope + // corresponding to span's containing source scope. If so, we need to create a DIScope + // "extension" into that file. + let pos = span.lo(); + if pos < scope.file_start_pos || pos >= scope.file_end_pos { let sm = self.cx.sess().source_map(); - Some(self.cx.extend_scope_to_file(scope_metadata, &sm.lookup_char_pos(pos).file)) - } else { - Some(scope_metadata) + dbg_scope = self.cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file); } + + Some((dbg_scope, span)) } /// Apply debuginfo and/or name, after creating the `alloca` for a local, @@ -142,17 +129,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } else { let name = kw::Invalid; let decl = &self.mir.local_decls[local]; - let (scope, span) = if full_debug_info { - self.debug_loc(decl.source_info) + let dbg_var = if full_debug_info { + self.dbg_scope_and_span(decl.source_info).map(|(scope, span)| { + // FIXME(eddyb) is this `+ 1` needed at all? + let kind = VariableKind::ArgumentVariable(arg_index + 1); + + self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span) + }) } else { - (None, decl.source_info.span) + None }; - let dbg_var = scope.map(|scope| { - // FIXME(eddyb) is this `+ 1` needed at all? - let kind = VariableKind::ArgumentVariable(arg_index + 1); - - self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span) - }); Some(PerLocalVarDebugInfo { name, @@ -233,6 +219,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let vars = vars.iter().copied().chain(fallback_var); for var in vars { + let dbg_var = match var.dbg_var { + Some(dbg_var) => dbg_var, + None => continue, + }; + let dbg_loc = match self.dbg_loc(var.source_info) { + Some(dbg_loc) => dbg_loc, + None => continue, + }; + let mut layout = base.layout; let mut direct_offset = Size::ZERO; // FIXME(eddyb) use smallvec here. @@ -269,19 +264,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } - let (scope, span) = self.debug_loc(var.source_info); - if let Some(scope) = scope { - if let Some(dbg_var) = var.dbg_var { - bx.dbg_var_addr( - dbg_var, - scope, - base.llval, - direct_offset, - &indirect_offsets, - span, - ); - } - } + bx.dbg_var_addr(dbg_var, dbg_loc, base.llval, direct_offset, &indirect_offsets); } } @@ -305,12 +288,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls); for var in &self.mir.var_debug_info { - let (scope, span) = if full_debug_info { - self.debug_loc(var.source_info) - } else { - (None, var.source_info.span) - }; - let dbg_var = scope.map(|scope| { + let scope_and_span = + if full_debug_info { self.dbg_scope_and_span(var.source_info) } else { None }; + let dbg_var = scope_and_span.map(|(scope, span)| { let place = var.place; let var_ty = self.monomorphized_place_ty(place.as_ref()); let var_kind = if self.mir.local_kind(place.local) == mir::LocalKind::Arg diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index 3fb189e19844d..b9c555c2eb069 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -34,6 +34,7 @@ pub trait BackendTypes { // FIXME(eddyb) find a common convention for all of the debuginfo-related // names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.). type DIScope: Copy; + type DILocation: Copy; type DIVariable: Copy; } diff --git a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs index 3d2e0ac7be2fc..a7588eb4d14cf 100644 --- a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs @@ -30,6 +30,8 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { maybe_definition_llfn: Option, ) -> Self::DIScope; + fn dbg_loc(&self, scope: Self::DIScope, span: Span) -> Self::DILocation; + fn extend_scope_to_file( &self, scope_metadata: Self::DIScope, @@ -55,14 +57,13 @@ pub trait DebugInfoBuilderMethods: BackendTypes { fn dbg_var_addr( &mut self, dbg_var: Self::DIVariable, - scope_metadata: Self::DIScope, + dbg_loc: Self::DILocation, variable_alloca: Self::Value, direct_offset: Size, // NB: each offset implies a deref (i.e. they're steps in a pointer chain). indirect_offsets: &[Size], - span: Span, ); - fn set_source_location(&mut self, scope: Self::DIScope, span: Span); + fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation); fn insert_reference_to_gdb_debug_scripts_section_global(&mut self); fn set_var_name(&mut self, value: Self::Value, name: &str); } diff --git a/compiler/rustc_codegen_ssa/src/traits/mod.rs b/compiler/rustc_codegen_ssa/src/traits/mod.rs index 82518b7f0c388..8ada6c10479da 100644 --- a/compiler/rustc_codegen_ssa/src/traits/mod.rs +++ b/compiler/rustc_codegen_ssa/src/traits/mod.rs @@ -95,6 +95,7 @@ pub trait HasCodegen<'tcx>: Type = Self::Type, Funclet = Self::Funclet, DIScope = Self::DIScope, + DILocation = Self::DILocation, DIVariable = Self::DIVariable, >; } From 0ce4452fce0a1aa6d8a2a7f08da105c225463f4d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 11 Feb 2020 01:27:33 +0200 Subject: [PATCH 12/18] rustc_codegen_llvm: add support for inlined function debuginfo. --- .../src/debuginfo/create_scope_map.rs | 71 ++++++++++---- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 22 +++-- .../rustc_codegen_ssa/src/mir/debuginfo.rs | 95 ++++++++++++------- compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 +- .../rustc_codegen_ssa/src/traits/debuginfo.rs | 11 ++- 5 files changed, 137 insertions(+), 64 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index f6b7f257f2f37..6737872f203ad 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -3,21 +3,26 @@ use super::utils::DIB; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext}; use rustc_codegen_ssa::traits::*; +use crate::abi::FnAbi; use crate::common::CodegenCx; use crate::llvm; -use crate::llvm::debuginfo::DIScope; +use crate::llvm::debuginfo::{DILocation, DIScope}; use rustc_middle::mir::{Body, SourceScope}; +use rustc_middle::ty::layout::FnAbiExt; +use rustc_middle::ty::{self, Instance}; use rustc_session::config::DebugInfo; use rustc_index::bit_set::BitSet; use rustc_index::vec::Idx; /// Produces DIScope DIEs for each MIR Scope which has variables defined in it. +// FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`. pub fn compute_mir_scopes( - cx: &CodegenCx<'ll, '_>, - mir: &Body<'_>, + cx: &CodegenCx<'ll, 'tcx>, + instance: Instance<'tcx>, + mir: &Body<'tcx>, fn_dbg_scope: &'ll DIScope, - debug_context: &mut FunctionDebugContext<&'ll DIScope>, + debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>, ) { // Find all the scopes with variables defined in them. let mut has_variables = BitSet::new_empty(mir.source_scopes.len()); @@ -37,16 +42,17 @@ pub fn compute_mir_scopes( // Instantiate all scopes. for idx in 0..mir.source_scopes.len() { let scope = SourceScope::new(idx); - make_mir_scope(cx, &mir, fn_dbg_scope, &has_variables, debug_context, scope); + make_mir_scope(cx, instance, &mir, fn_dbg_scope, &has_variables, debug_context, scope); } } fn make_mir_scope( - cx: &CodegenCx<'ll, '_>, - mir: &Body<'_>, + cx: &CodegenCx<'ll, 'tcx>, + instance: Instance<'tcx>, + mir: &Body<'tcx>, fn_dbg_scope: &'ll DIScope, has_variables: &BitSet, - debug_context: &mut FunctionDebugContext<&'ll DIScope>, + debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>, scope: SourceScope, ) { if debug_context.scopes[scope].dbg_scope.is_some() { @@ -55,22 +61,23 @@ fn make_mir_scope( let scope_data = &mir.source_scopes[scope]; let parent_scope = if let Some(parent) = scope_data.parent_scope { - make_mir_scope(cx, mir, fn_dbg_scope, has_variables, debug_context, parent); + make_mir_scope(cx, instance, mir, fn_dbg_scope, has_variables, debug_context, parent); debug_context.scopes[parent] } else { // The root is the function itself. let loc = cx.lookup_debug_loc(mir.span.lo()); debug_context.scopes[scope] = DebugScope { dbg_scope: Some(fn_dbg_scope), + inlined_at: None, file_start_pos: loc.file.start_pos, file_end_pos: loc.file.end_pos, }; return; }; - if !has_variables.contains(scope) { - // Do not create a DIScope if there are no variables - // defined in this MIR Scope, to avoid debuginfo bloat. + if !has_variables.contains(scope) && scope_data.inlined.is_none() { + // Do not create a DIScope if there are no variables defined in this + // MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat. debug_context.scopes[scope] = parent_scope; return; } @@ -78,17 +85,39 @@ fn make_mir_scope( let loc = cx.lookup_debug_loc(scope_data.span.lo()); let file_metadata = file_metadata(cx, &loc.file); - let dbg_scope = unsafe { - Some(llvm::LLVMRustDIBuilderCreateLexicalBlock( - DIB(cx), - parent_scope.dbg_scope.unwrap(), - file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), - loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER), - )) + let dbg_scope = match scope_data.inlined { + Some((callee, _)) => { + // FIXME(eddyb) this would be `self.monomorphize(&callee)` + // if this is moved to `rustc_codegen_ssa::mir::debuginfo`. + let callee = cx.tcx.subst_and_normalize_erasing_regions( + instance.substs, + ty::ParamEnv::reveal_all(), + &callee, + ); + let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]); + cx.dbg_scope_fn(callee, &callee_fn_abi, None) + } + None => unsafe { + llvm::LLVMRustDIBuilderCreateLexicalBlock( + DIB(cx), + parent_scope.dbg_scope.unwrap(), + file_metadata, + loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + ) + }, }; + + let inlined_at = scope_data.inlined.map(|(_, callsite_span)| { + // FIXME(eddyb) this doesn't account for the macro-related + // `Span` fixups that `rustc_codegen_ssa::mir::debuginfo` does. + let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span); + cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span) + }); + debug_context.scopes[scope] = DebugScope { - dbg_scope, + dbg_scope: Some(dbg_scope), + inlined_at: inlined_at.or(parent_scope.inlined_at), file_start_pos: loc.file.start_pos, file_end_pos: loc.file.end_pos, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 7b416f1f6adba..beaea49874e6e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -265,22 +265,27 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, llfn: &'ll Value, - mir: &mir::Body<'_>, - ) -> Option> { + mir: &mir::Body<'tcx>, + ) -> Option> { if self.sess().opts.debuginfo == DebugInfo::None { return None; } // Initialize fn debug context (including scopes). // FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`. - let empty_scope = - DebugScope { dbg_scope: None, file_start_pos: BytePos(0), file_end_pos: BytePos(0) }; + let empty_scope = DebugScope { + dbg_scope: None, + inlined_at: None, + file_start_pos: BytePos(0), + file_end_pos: BytePos(0), + }; let mut fn_debug_context = FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) }; // Fill in all the scopes, with the information from the MIR body. compute_mir_scopes( self, + instance, mir, self.dbg_scope_fn(instance, fn_abi, Some(llfn)), &mut fn_debug_context, @@ -537,7 +542,12 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } - fn dbg_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation { + fn dbg_loc( + &self, + scope: &'ll DIScope, + inlined_at: Option<&'ll DILocation>, + span: Span, + ) -> &'ll DILocation { let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo()); unsafe { @@ -546,7 +556,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { line.unwrap_or(UNKNOWN_LINE_NUMBER), col.unwrap_or(UNKNOWN_COLUMN_NUMBER), scope, - None, + inlined_at, ) } } diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index ddb9372cf8f73..e93830397c95e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -12,8 +12,8 @@ use super::operand::OperandValue; use super::place::PlaceRef; use super::{FunctionCx, LocalRef}; -pub struct FunctionDebugContext { - pub scopes: IndexVec>, +pub struct FunctionDebugContext { + pub scopes: IndexVec>, } #[derive(Copy, Clone)] @@ -36,15 +36,42 @@ pub struct PerLocalVarDebugInfo<'tcx, D> { } #[derive(Clone, Copy, Debug)] -pub struct DebugScope { +pub struct DebugScope { // FIXME(eddyb) this should never be `None`, after initialization. - pub dbg_scope: Option, + pub dbg_scope: Option, + + /// Call site location, if this scope was inlined from another function. + pub inlined_at: Option, + // Start and end offsets of the file to which this DIScope belongs. // These are used to quickly determine whether some span refers to the same file. pub file_start_pos: BytePos, pub file_end_pos: BytePos, } +impl<'tcx, S: Copy, L: Copy> DebugScope { + /// DILocations inherit source file name from the parent DIScope. Due to macro expansions + /// it may so happen that the current span belongs to a different file than the DIScope + /// corresponding to span's containing source scope. If so, we need to create a DIScope + /// "extension" into that file. + pub fn adjust_dbg_scope_for_span>( + &self, + cx: &Cx, + span: Span, + ) -> S { + // FIXME(eddyb) this should never be `None`. + let dbg_scope = self.dbg_scope.unwrap(); + + let pos = span.lo(); + if pos < self.file_start_pos || pos >= self.file_end_pos { + let sm = cx.sess().source_map(); + cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file) + } else { + dbg_scope + } + } +} + impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn set_debug_loc(&self, bx: &mut Bx, source_info: mir::SourceInfo) { bx.set_span(source_info.span); @@ -54,19 +81,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } fn dbg_loc(&self, source_info: mir::SourceInfo) -> Option { - let (scope, span) = self.dbg_scope_and_span(source_info)?; - Some(self.cx.dbg_loc(scope, span)) + let span = self.adjust_span_for_debugging(source_info.span); + let scope = &self.debug_context.as_ref()?.scopes[source_info.scope]; + let dbg_scope = scope.adjust_dbg_scope_for_span(self.cx, span); + Some(self.cx.dbg_loc(dbg_scope, scope.inlined_at, span)) } - fn dbg_scope_and_span(&self, source_info: mir::SourceInfo) -> Option<(Bx::DIScope, Span)> { + /// In order to have a good line stepping behavior in debugger, we overwrite debug + /// locations of macro expansions with that of the outermost expansion site + /// (unless the crate is being compiled with `-Z debug-macros`). + fn adjust_span_for_debugging(&self, mut span: Span) -> Span { // Bail out if debug info emission is not enabled. - let debug_context = self.debug_context.as_ref()?; - let scope = &debug_context.scopes[source_info.scope]; + if self.debug_context.is_none() { + return span; + } - // In order to have a good line stepping behavior in debugger, we overwrite debug - // locations of macro expansions with that of the outermost expansion site - // (unless the crate is being compiled with `-Z debug-macros`). - let mut span = source_info.span; if span.from_expansion() && !self.cx.sess().opts.debugging_opts.debug_macros { // Walk up the macro expansion chain until we reach a non-expanded span. // We also stop at the function body level because no line stepping can occur @@ -75,20 +104,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { span = rustc_span::hygiene::walk_chain(span, self.mir.span.ctxt()); } - // FIXME(eddyb) this should never be `None`. - let mut dbg_scope = scope.dbg_scope?; - - // DILocations inherit source file name from the parent DIScope. Due to macro expansions - // it may so happen that the current span belongs to a different file than the DIScope - // corresponding to span's containing source scope. If so, we need to create a DIScope - // "extension" into that file. - let pos = span.lo(); - if pos < scope.file_start_pos || pos >= scope.file_end_pos { - let sm = self.cx.sess().source_map(); - dbg_scope = self.cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file); - } - - Some((dbg_scope, span)) + span } /// Apply debuginfo and/or name, after creating the `alloca` for a local, @@ -130,11 +146,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let name = kw::Invalid; let decl = &self.mir.local_decls[local]; let dbg_var = if full_debug_info { - self.dbg_scope_and_span(decl.source_info).map(|(scope, span)| { + self.debug_context.as_ref().map(|debug_context| { // FIXME(eddyb) is this `+ 1` needed at all? let kind = VariableKind::ArgumentVariable(arg_index + 1); - self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span) + let arg_ty = self.monomorphize(&decl.ty); + + let span = self.adjust_span_for_debugging(decl.source_info.span); + let scope = &debug_context.scopes[decl.source_info.scope]; + let dbg_scope = scope.adjust_dbg_scope_for_span(self.cx, span); + + self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span) }) } else { None @@ -288,9 +310,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls); for var in &self.mir.var_debug_info { - let scope_and_span = - if full_debug_info { self.dbg_scope_and_span(var.source_info) } else { None }; - let dbg_var = scope_and_span.map(|(scope, span)| { + let dbg_scope_and_span = if full_debug_info { + self.debug_context.as_ref().map(|debug_context| { + let span = self.adjust_span_for_debugging(var.source_info.span); + let scope = &debug_context.scopes[var.source_info.scope]; + (scope.adjust_dbg_scope_for_span(self.cx, span), span) + }) + } else { + None + }; + let dbg_var = dbg_scope_and_span.map(|(dbg_scope, span)| { let place = var.place; let var_ty = self.monomorphized_place_ty(place.as_ref()); let var_kind = if self.mir.local_kind(place.local) == mir::LocalKind::Arg @@ -306,7 +335,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } else { VariableKind::LocalVariable }; - self.cx.create_dbg_var(var.name, var_ty, scope, var_kind, span) + self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span) }); per_local[var.place.local].push(PerLocalVarDebugInfo { diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index bff263567bf6b..84e82e88e8eea 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -26,7 +26,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { mir: &'tcx mir::Body<'tcx>, - debug_context: Option>, + debug_context: Option>, llfn: Bx::Function, diff --git a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs index a7588eb4d14cf..3e66d711d2ef5 100644 --- a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs @@ -18,8 +18,8 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, llfn: Self::Function, - mir: &mir::Body<'_>, - ) -> Option>; + mir: &mir::Body<'tcx>, + ) -> Option>; // FIXME(eddyb) find a common convention for all of the debuginfo-related // names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.). @@ -30,7 +30,12 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { maybe_definition_llfn: Option, ) -> Self::DIScope; - fn dbg_loc(&self, scope: Self::DIScope, span: Span) -> Self::DILocation; + fn dbg_loc( + &self, + scope: Self::DIScope, + inlined_at: Option, + span: Span, + ) -> Self::DILocation; fn extend_scope_to_file( &self, From 9b21c50335887fe9ecbd44d5a3efa105feae0a6d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 22 Sep 2020 00:33:34 +0300 Subject: [PATCH 13/18] rustc_mir: create the Integrator as soon as possible in MIR inlining. --- compiler/rustc_mir/src/transform/inline.rs | 89 +++++++++---------- .../inline_any_operand.bar.Inline.after.mir | 38 ++++---- ...e_closure_borrows_arg.foo.Inline.after.mir | 26 +++--- ...line_closure_captures.foo.Inline.after.mir | 20 ++--- ...ine_scopes_parenting.main.Inline.after.mir | 20 ++--- 5 files changed, 96 insertions(+), 97 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 5a8c10ae9155c..df5faa9ad07e0 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -431,49 +431,6 @@ impl Inliner<'tcx> { TerminatorKind::Call { args, destination: Some(destination), cleanup, .. } => { debug!("inlined {:?} into {:?}", callsite.callee, caller_body.source); - let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len()); - let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len()); - - for mut scope in callee_body.source_scopes.iter().cloned() { - // Map the callee scopes into the caller. - // FIXME(eddyb) this may ICE if the scopes are out of order. - scope.parent_scope = scope.parent_scope.map(|s| scope_map[s]); - scope.inlined_parent_scope = scope.inlined_parent_scope.map(|s| scope_map[s]); - - if scope.parent_scope.is_none() { - let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope]; - - // Attach the outermost callee scope as a child of the callsite - // scope, via the `parent_scope` and `inlined_parent_scope` chains. - scope.parent_scope = Some(callsite.source_info.scope); - assert_eq!(scope.inlined_parent_scope, None); - scope.inlined_parent_scope = if callsite_scope.inlined.is_some() { - Some(callsite.source_info.scope) - } else { - callsite_scope.inlined_parent_scope - }; - - // Mark the outermost callee scope as an inlined one. - assert_eq!(scope.inlined, None); - scope.inlined = Some((callsite.callee, callsite.source_info.span)); - } else if scope.inlined_parent_scope.is_none() { - // Make it easy to find the scope with `inlined` set above. - scope.inlined_parent_scope = Some(scope_map[OUTERMOST_SOURCE_SCOPE]); - } - - let idx = caller_body.source_scopes.push(scope); - scope_map.push(idx); - } - - for loc in callee_body.vars_and_temps_iter() { - let mut local = callee_body.local_decls[loc].clone(); - - local.source_info.scope = scope_map[local.source_info.scope]; - - let idx = caller_body.local_decls.push(local); - local_map.push(idx); - } - // If the call is something like `a[*i] = f(i)`, where // `i : &mut usize`, then just duplicating the `a[*i]` // Place could result in two different locations if `f` @@ -524,8 +481,8 @@ impl Inliner<'tcx> { let mut integrator = Integrator { block_idx: bb_len, args: &args, - local_map, - scope_map, + local_map: IndexVec::with_capacity(callee_body.local_decls.len()), + scope_map: IndexVec::with_capacity(callee_body.source_scopes.len()), destination: dest, return_block, cleanup_block: cleanup, @@ -533,6 +490,48 @@ impl Inliner<'tcx> { tcx: self.tcx, }; + for mut scope in callee_body.source_scopes.iter().cloned() { + // Map the callee scopes into the caller. + // FIXME(eddyb) this may ICE if the scopes are out of order. + scope.parent_scope = scope.parent_scope.map(|s| integrator.scope_map[s]); + scope.inlined_parent_scope = + scope.inlined_parent_scope.map(|s| integrator.scope_map[s]); + + if scope.parent_scope.is_none() { + let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope]; + + // Attach the outermost callee scope as a child of the callsite + // scope, via the `parent_scope` and `inlined_parent_scope` chains. + scope.parent_scope = Some(callsite.source_info.scope); + assert_eq!(scope.inlined_parent_scope, None); + scope.inlined_parent_scope = if callsite_scope.inlined.is_some() { + Some(callsite.source_info.scope) + } else { + callsite_scope.inlined_parent_scope + }; + + // Mark the outermost callee scope as an inlined one. + assert_eq!(scope.inlined, None); + scope.inlined = Some((callsite.callee, callsite.source_info.span)); + } else if scope.inlined_parent_scope.is_none() { + // Make it easy to find the scope with `inlined` set above. + scope.inlined_parent_scope = + Some(integrator.scope_map[OUTERMOST_SOURCE_SCOPE]); + } + + let idx = caller_body.source_scopes.push(scope); + integrator.scope_map.push(idx); + } + + for loc in callee_body.vars_and_temps_iter() { + let mut local = callee_body.local_decls[loc].clone(); + + local.source_info.scope = integrator.scope_map[local.source_info.scope]; + + let idx = caller_body.local_decls.push(local); + integrator.local_map.push(idx); + } + for mut var_debug_info in callee_body.var_debug_info.drain(..) { integrator.visit_var_debug_info(&mut var_debug_info); caller_body.var_debug_info.push(var_debug_info); diff --git a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir index 2d97f4e6d6f71..b2745a17e9717 100644 --- a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir @@ -4,15 +4,15 @@ fn bar() -> bool { let mut _0: bool; // return place in scope 0 at $DIR/inline-any-operand.rs:10:13: 10:17 let _1: fn(i32, i32) -> bool {foo}; // in scope 0 at $DIR/inline-any-operand.rs:11:9: 11:10 let mut _2: fn(i32, i32) -> bool {foo}; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:6 - let mut _5: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13 - let mut _6: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13 + let mut _3: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13 + let mut _4: i32; // in scope 0 at $DIR/inline-any-operand.rs:12:5: 12:13 scope 1 { debug f => _1; // in scope 1 at $DIR/inline-any-operand.rs:11:9: 11:10 scope 2 (inlined foo) { // at $DIR/inline-any-operand.rs:12:5: 12:13 - debug x => _5; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9 - debug y => _6; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17 - let mut _3: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 - let mut _4: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 + debug x => _3; // in scope 2 at $DIR/inline-any-operand.rs:16:8: 16:9 + debug y => _4; // in scope 2 at $DIR/inline-any-operand.rs:16:16: 16:17 + let mut _5: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 + let mut _6: i32; // in scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 } } @@ -24,19 +24,19 @@ fn bar() -> bool { // + literal: Const { ty: fn(i32, i32) -> bool {foo}, val: Value(Scalar()) } StorageLive(_2); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6 _2 = _1; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6 - StorageLive(_5); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 - _5 = const 1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 - StorageLive(_6); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 - _6 = const -1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 - StorageLive(_3); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 - _3 = _5; // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 - StorageLive(_4); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 - _4 = _6; // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 - _0 = Eq(move _3, move _4); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:11 - StorageDead(_4); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 - StorageDead(_3); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 - StorageDead(_6); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 - StorageDead(_5); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + StorageLive(_3); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + _3 = const 1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + StorageLive(_4); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + _4 = const -1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + StorageLive(_5); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 + _5 = _3; // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:6 + StorageLive(_6); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 + _6 = _4; // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 + _0 = Eq(move _5, move _6); // scope 2 at $DIR/inline-any-operand.rs:17:5: 17:11 + StorageDead(_6); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 + StorageDead(_5); // scope 2 at $DIR/inline-any-operand.rs:17:10: 17:11 + StorageDead(_4); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + StorageDead(_3); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 StorageDead(_2); // scope 1 at $DIR/inline-any-operand.rs:12:12: 12:13 StorageDead(_1); // scope 0 at $DIR/inline-any-operand.rs:13:1: 13:2 return; // scope 0 at $DIR/inline-any-operand.rs:13:2: 13:2 diff --git a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir index 92399ebaf9d1d..c6893022be60a 100644 --- a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir @@ -9,16 +9,16 @@ fn foo(_1: T, _2: &i32) -> i32 { let mut _5: (&i32, &i32); // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 let mut _6: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:7: 16:8 let mut _7: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:10: 16:11 + let mut _8: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 let mut _9: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - let mut _10: &i32; // in scope 0 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure-borrows-arg.rs:12:9: 12:10 scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - debug r => _9; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:14: 12:15 - debug _s => _10; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:23: 12:25 - let _8: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 + debug r => _8; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:14: 12:15 + debug _s => _9; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:12:23: 12:25 + let _10: &i32; // in scope 2 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 scope 3 { - debug variable => _8; // in scope 3 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 + debug variable => _10; // in scope 3 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 } } } @@ -34,16 +34,16 @@ fn foo(_1: T, _2: &i32) -> i32 { _7 = &(*_2); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:10: 16:11 (_5.0: &i32) = move _6; // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 (_5.1: &i32) = move _7; // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + StorageLive(_8); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + _8 = move (_5.0: &i32); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 StorageLive(_9); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - _9 = move (_5.0: &i32); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - StorageLive(_10); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - _10 = move (_5.1: &i32); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 - StorageLive(_8); // scope 2 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 - _8 = _9; // scope 2 at $DIR/inline-closure-borrows-arg.rs:13:24: 13:27 - _0 = (*_9); // scope 3 at $DIR/inline-closure-borrows-arg.rs:14:9: 14:18 - StorageDead(_8); // scope 2 at $DIR/inline-closure-borrows-arg.rs:15:5: 15:6 - StorageDead(_10); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + _9 = move (_5.1: &i32); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + StorageLive(_10); // scope 2 at $DIR/inline-closure-borrows-arg.rs:13:13: 13:21 + _10 = _8; // scope 2 at $DIR/inline-closure-borrows-arg.rs:13:24: 13:27 + _0 = (*_8); // scope 3 at $DIR/inline-closure-borrows-arg.rs:14:9: 14:18 + StorageDead(_10); // scope 2 at $DIR/inline-closure-borrows-arg.rs:15:5: 15:6 StorageDead(_9); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 + StorageDead(_8); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:5: 16:12 StorageDead(_7); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:11: 16:12 StorageDead(_6); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:11: 16:12 StorageDead(_5); // scope 1 at $DIR/inline-closure-borrows-arg.rs:16:11: 16:12 diff --git a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir index ffdc7f3ffe6e4..2950af63d3c60 100644 --- a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir @@ -10,14 +10,14 @@ fn foo(_1: T, _2: i32) -> (i32, T) { let mut _6: &[closure@foo::{closure#0}]; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:6 let mut _7: (i32,); // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 let mut _8: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:7: 12:8 - let mut _10: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 + let mut _9: i32; // in scope 0 at $DIR/inline-closure-captures.rs:12:5: 12:9 scope 1 { debug x => _3; // in scope 1 at $DIR/inline-closure-captures.rs:11:9: 11:10 scope 2 (inlined foo::::{closure#0}) { // at $DIR/inline-closure-captures.rs:12:5: 12:9 - debug _q => _10; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 + debug _q => _9; // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16 debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:10:23: 10:24 debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:10:17: 10:18 - let mut _9: T; // in scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 + let mut _10: T; // in scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 } } @@ -37,14 +37,14 @@ fn foo(_1: T, _2: i32) -> (i32, T) { StorageLive(_8); // scope 1 at $DIR/inline-closure-captures.rs:12:7: 12:8 _8 = _2; // scope 1 at $DIR/inline-closure-captures.rs:12:7: 12:8 (_7.0: i32) = move _8; // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 - StorageLive(_10); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 - _10 = move (_7.0: i32); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 + StorageLive(_9); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 + _9 = move (_7.0: i32); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 (_0.0: i32) = (*((*_6).0: &i32)); // scope 2 at $DIR/inline-closure-captures.rs:11:19: 11:20 - StorageLive(_9); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 - _9 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 - (_0.1: T) = move _9; // scope 2 at $DIR/inline-closure-captures.rs:11:18: 11:24 - StorageDead(_9); // scope 2 at $DIR/inline-closure-captures.rs:11:23: 11:24 - StorageDead(_10); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 + StorageLive(_10); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 + _10 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:11:22: 11:23 + (_0.1: T) = move _10; // scope 2 at $DIR/inline-closure-captures.rs:11:18: 11:24 + StorageDead(_10); // scope 2 at $DIR/inline-closure-captures.rs:11:23: 11:24 + StorageDead(_9); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9 StorageDead(_8); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9 StorageDead(_7); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9 StorageDead(_6); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9 diff --git a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir index cdd27ff1036b2..df5355e905eb0 100644 --- a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir @@ -6,14 +6,14 @@ fn main() -> () { let mut _2: &[closure@$DIR/issue-76997-inline-scopes-parenting.rs:5:13: 5:33]; // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:6 let mut _3: ((),); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 let mut _4: (); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:7: 6:9 - let mut _6: (); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + let mut _5: (); // in scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 scope 1 { debug f => _1; // in scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:5:9: 5:10 scope 2 (inlined main::{closure#0}) { // at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 - debug x => _6; // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:14: 5:15 - let _5: (); // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 + debug x => _5; // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:14: 5:15 + let _6: (); // in scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 scope 3 { - debug y => _5; // in scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 + debug y => _6; // in scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 } } } @@ -25,13 +25,13 @@ fn main() -> () { StorageLive(_3); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 StorageLive(_4); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:7: 6:9 (_3.0: ()) = move _4; // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 - StorageLive(_6); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 - _6 = move (_3.0: ()); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 - StorageLive(_5); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 - _5 = const (); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:27: 5:28 + StorageLive(_5); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + _5 = move (_3.0: ()); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageLive(_6); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:23: 5:24 + _6 = const (); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:27: 5:28 _0 = const (); // scope 3 at $DIR/issue-76997-inline-scopes-parenting.rs:5:30: 5:31 - StorageDead(_5); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:32: 5:33 - StorageDead(_6); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 + StorageDead(_6); // scope 2 at $DIR/issue-76997-inline-scopes-parenting.rs:5:32: 5:33 + StorageDead(_5); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:5: 6:10 StorageDead(_4); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 StorageDead(_3); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 StorageDead(_2); // scope 1 at $DIR/issue-76997-inline-scopes-parenting.rs:6:9: 6:10 From aff4d3e659872ec1fbf469e91575a9a711ce4705 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 22 Sep 2020 02:21:26 +0300 Subject: [PATCH 14/18] rustc_mir: run the MIR inlining Integrator on the whole callee body at once. --- compiler/rustc_mir/src/transform/inline.rs | 135 ++++++++++----------- 1 file changed, 65 insertions(+), 70 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index df5faa9ad07e0..944f41c61a2b5 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -2,7 +2,7 @@ use rustc_attr as attr; use rustc_index::bit_set::BitSet; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::Idx; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; @@ -14,6 +14,7 @@ use super::simplify::{remove_dead_blocks, CfgSimplifier}; use crate::transform::MirPass; use std::collections::VecDeque; use std::iter; +use std::ops::RangeFrom; const DEFAULT_THRESHOLD: usize = 50; const HINT_THRESHOLD: usize = 100; @@ -477,12 +478,11 @@ impl Inliner<'tcx> { // Copy the arguments if needed. let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, return_block); - let bb_len = caller_body.basic_blocks().len(); let mut integrator = Integrator { - block_idx: bb_len, args: &args, - local_map: IndexVec::with_capacity(callee_body.local_decls.len()), - scope_map: IndexVec::with_capacity(callee_body.source_scopes.len()), + new_locals: Local::new(caller_body.local_decls.len()).., + new_scopes: SourceScope::new(caller_body.source_scopes.len()).., + new_blocks: BasicBlock::new(caller_body.basic_blocks().len()).., destination: dest, return_block, cleanup_block: cleanup, @@ -490,13 +490,12 @@ impl Inliner<'tcx> { tcx: self.tcx, }; - for mut scope in callee_body.source_scopes.iter().cloned() { - // Map the callee scopes into the caller. - // FIXME(eddyb) this may ICE if the scopes are out of order. - scope.parent_scope = scope.parent_scope.map(|s| integrator.scope_map[s]); - scope.inlined_parent_scope = - scope.inlined_parent_scope.map(|s| integrator.scope_map[s]); + // Map all `Local`s, `SourceScope`s and `BasicBlock`s to new ones + // (or existing ones, in a few special cases) in the caller. + integrator.visit_body(&mut callee_body); + for scope in &mut callee_body.source_scopes { + // FIXME(eddyb) move this into a `fn visit_scope_data` in `Integrator`. if scope.parent_scope.is_none() { let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope]; @@ -516,38 +515,26 @@ impl Inliner<'tcx> { } else if scope.inlined_parent_scope.is_none() { // Make it easy to find the scope with `inlined` set above. scope.inlined_parent_scope = - Some(integrator.scope_map[OUTERMOST_SOURCE_SCOPE]); + Some(integrator.map_scope(OUTERMOST_SOURCE_SCOPE)); } - - let idx = caller_body.source_scopes.push(scope); - integrator.scope_map.push(idx); - } - - for loc in callee_body.vars_and_temps_iter() { - let mut local = callee_body.local_decls[loc].clone(); - - local.source_info.scope = integrator.scope_map[local.source_info.scope]; - - let idx = caller_body.local_decls.push(local); - integrator.local_map.push(idx); - } - - for mut var_debug_info in callee_body.var_debug_info.drain(..) { - integrator.visit_var_debug_info(&mut var_debug_info); - caller_body.var_debug_info.push(var_debug_info); } - for (bb, mut block) in callee_body.basic_blocks_mut().drain_enumerated(..) { - integrator.visit_basic_block_data(bb, &mut block); - caller_body.basic_blocks_mut().push(block); - } + // Insert all of the (mapped) parts of the callee body into the caller. + caller_body.local_decls.extend( + // FIXME(eddyb) make `Range` iterable so that we can use + // `callee_body.local_decls.drain(callee_body.vars_and_temps())` + callee_body + .vars_and_temps_iter() + .map(|local| callee_body.local_decls[local].clone()), + ); + caller_body.source_scopes.extend(callee_body.source_scopes.drain(..)); + caller_body.var_debug_info.extend(callee_body.var_debug_info.drain(..)); + caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..)); - let terminator = Terminator { + caller_body[callsite.bb].terminator = Some(Terminator { source_info: callsite.source_info, - kind: TerminatorKind::Goto { target: BasicBlock::new(bb_len) }, - }; - - caller_body[callsite.bb].terminator = Some(terminator); + kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) }, + }); true } @@ -703,10 +690,10 @@ fn type_size_of<'tcx>( * stuff. */ struct Integrator<'a, 'tcx> { - block_idx: usize, args: &'a [Local], - local_map: IndexVec, - scope_map: IndexVec, + new_locals: RangeFrom, + new_scopes: RangeFrom, + new_blocks: RangeFrom, destination: Place<'tcx>, return_block: BasicBlock, cleanup_block: Option, @@ -715,23 +702,31 @@ struct Integrator<'a, 'tcx> { } impl<'a, 'tcx> Integrator<'a, 'tcx> { - fn update_target(&self, tgt: BasicBlock) -> BasicBlock { - let new = BasicBlock::new(tgt.index() + self.block_idx); - debug!("updating target `{:?}`, new: `{:?}`", tgt, new); + fn map_local(&self, local: Local) -> Local { + let new = if local == RETURN_PLACE { + self.destination.local + } else { + let idx = local.index() - 1; + if idx < self.args.len() { + self.args[idx] + } else { + Local::new(self.new_locals.start.index() + (idx - self.args.len())) + } + }; + debug!("mapping local `{:?}` to `{:?}`", local, new); new } - fn make_integrate_local(&self, local: Local) -> Local { - if local == RETURN_PLACE { - return self.destination.local; - } - - let idx = local.index() - 1; - if idx < self.args.len() { - return self.args[idx]; - } + fn map_scope(&self, scope: SourceScope) -> SourceScope { + let new = SourceScope::new(self.new_scopes.start.index() + scope.index()); + debug!("mapping scope `{:?}` to `{:?}`", scope, new); + new + } - self.local_map[Local::new(idx - self.args.len())] + fn map_block(&self, block: BasicBlock) -> BasicBlock { + let new = BasicBlock::new(self.new_blocks.start.index() + block.index()); + debug!("mapping block `{:?}` to `{:?}`", block, new); + new } } @@ -741,7 +736,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { } fn visit_local(&mut self, local: &mut Local, _ctxt: PlaceContext, _location: Location) { - *local = self.make_integrate_local(*local); + *local = self.map_local(*local); + } + + fn visit_source_scope(&mut self, scope: &mut SourceScope) { + *scope = self.map_scope(*scope); } fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) { @@ -785,18 +784,18 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { match terminator.kind { TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => bug!(), TerminatorKind::Goto { ref mut target } => { - *target = self.update_target(*target); + *target = self.map_block(*target); } TerminatorKind::SwitchInt { ref mut targets, .. } => { for tgt in targets.all_targets_mut() { - *tgt = self.update_target(*tgt); + *tgt = self.map_block(*tgt); } } TerminatorKind::Drop { ref mut target, ref mut unwind, .. } | TerminatorKind::DropAndReplace { ref mut target, ref mut unwind, .. } => { - *target = self.update_target(*target); + *target = self.map_block(*target); if let Some(tgt) = *unwind { - *unwind = Some(self.update_target(tgt)); + *unwind = Some(self.map_block(tgt)); } else if !self.in_cleanup_block { // Unless this drop is in a cleanup block, add an unwind edge to // the original call's cleanup block @@ -805,10 +804,10 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { } TerminatorKind::Call { ref mut destination, ref mut cleanup, .. } => { if let Some((_, ref mut tgt)) = *destination { - *tgt = self.update_target(*tgt); + *tgt = self.map_block(*tgt); } if let Some(tgt) = *cleanup { - *cleanup = Some(self.update_target(tgt)); + *cleanup = Some(self.map_block(tgt)); } else if !self.in_cleanup_block { // Unless this call is in a cleanup block, add an unwind edge to // the original call's cleanup block @@ -816,9 +815,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { } } TerminatorKind::Assert { ref mut target, ref mut cleanup, .. } => { - *target = self.update_target(*target); + *target = self.map_block(*target); if let Some(tgt) = *cleanup { - *cleanup = Some(self.update_target(tgt)); + *cleanup = Some(self.map_block(tgt)); } else if !self.in_cleanup_block { // Unless this assert is in a cleanup block, add an unwind edge to // the original call's cleanup block @@ -836,8 +835,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { TerminatorKind::Abort => {} TerminatorKind::Unreachable => {} TerminatorKind::FalseEdge { ref mut real_target, ref mut imaginary_target } => { - *real_target = self.update_target(*real_target); - *imaginary_target = self.update_target(*imaginary_target); + *real_target = self.map_block(*real_target); + *imaginary_target = self.map_block(*imaginary_target); } TerminatorKind::FalseUnwind { real_target: _, unwind: _ } => // see the ordering of passes in the optimized_mir query. @@ -846,13 +845,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { } TerminatorKind::InlineAsm { ref mut destination, .. } => { if let Some(ref mut tgt) = *destination { - *tgt = self.update_target(*tgt); + *tgt = self.map_block(*tgt); } } } } - - fn visit_source_scope(&mut self, scope: &mut SourceScope) { - *scope = self.scope_map[*scope]; - } } From f8aae504692295095454fa221c2ca1a7a46fb3c5 Mon Sep 17 00:00:00 2001 From: oli Date: Mon, 26 Oct 2020 12:49:49 +0000 Subject: [PATCH 15/18] Prefer `bug!` over `unwrap()` --- compiler/rustc_codegen_ssa/src/mir/debuginfo.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index e93830397c95e..f45b52115bc4c 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -60,7 +60,9 @@ impl<'tcx, S: Copy, L: Copy> DebugScope { span: Span, ) -> S { // FIXME(eddyb) this should never be `None`. - let dbg_scope = self.dbg_scope.unwrap(); + let dbg_scope = self + .dbg_scope + .unwrap_or_else(|| bug!("`dbg_scope` is only `None` during initialization")); let pos = span.lo(); if pos < self.file_start_pos || pos >= self.file_end_pos { From 7101ce9127d805e602ea3fa75d5bbea4bf1e5dce Mon Sep 17 00:00:00 2001 From: oli Date: Mon, 26 Oct 2020 13:04:52 +0000 Subject: [PATCH 16/18] Deduplicate span and dbg_scope adjustment --- .../rustc_codegen_ssa/src/mir/debuginfo.rs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index f45b52115bc4c..4e0396a15a646 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -83,10 +83,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } fn dbg_loc(&self, source_info: mir::SourceInfo) -> Option { + let (dbg_scope, inlined_at, span) = self.adjusted_span_and_dbg_scope(source_info)?; + Some(self.cx.dbg_loc(dbg_scope, inlined_at, span)) + } + + fn adjusted_span_and_dbg_scope( + &self, + source_info: mir::SourceInfo, + ) -> Option<(Bx::DIScope, Option, Span)> { let span = self.adjust_span_for_debugging(source_info.span); let scope = &self.debug_context.as_ref()?.scopes[source_info.scope]; - let dbg_scope = scope.adjust_dbg_scope_for_span(self.cx, span); - Some(self.cx.dbg_loc(dbg_scope, scope.inlined_at, span)) + Some((scope.adjust_dbg_scope_for_span(self.cx, span), scope.inlined_at, span)) } /// In order to have a good line stepping behavior in debugger, we overwrite debug @@ -148,18 +155,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let name = kw::Invalid; let decl = &self.mir.local_decls[local]; let dbg_var = if full_debug_info { - self.debug_context.as_ref().map(|debug_context| { - // FIXME(eddyb) is this `+ 1` needed at all? - let kind = VariableKind::ArgumentVariable(arg_index + 1); + self.adjusted_span_and_dbg_scope(decl.source_info).map( + |(dbg_scope, _, span)| { + // FIXME(eddyb) is this `+ 1` needed at all? + let kind = VariableKind::ArgumentVariable(arg_index + 1); - let arg_ty = self.monomorphize(&decl.ty); + let arg_ty = self.monomorphize(&decl.ty); - let span = self.adjust_span_for_debugging(decl.source_info.span); - let scope = &debug_context.scopes[decl.source_info.scope]; - let dbg_scope = scope.adjust_dbg_scope_for_span(self.cx, span); - - self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span) - }) + self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span) + }, + ) } else { None }; @@ -313,15 +318,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls); for var in &self.mir.var_debug_info { let dbg_scope_and_span = if full_debug_info { - self.debug_context.as_ref().map(|debug_context| { - let span = self.adjust_span_for_debugging(var.source_info.span); - let scope = &debug_context.scopes[var.source_info.scope]; - (scope.adjust_dbg_scope_for_span(self.cx, span), span) - }) + self.adjusted_span_and_dbg_scope(var.source_info) } else { None }; - let dbg_var = dbg_scope_and_span.map(|(dbg_scope, span)| { + let dbg_var = dbg_scope_and_span.map(|(dbg_scope, _, span)| { let place = var.place; let var_ty = self.monomorphized_place_ty(place.as_ref()); let var_kind = if self.mir.local_kind(place.local) == mir::LocalKind::Arg From 7ae8bc3957fa78dbe99ec70ddbdc27a9be42e52d Mon Sep 17 00:00:00 2001 From: oli Date: Mon, 26 Oct 2020 13:18:12 +0000 Subject: [PATCH 17/18] Add an inlining debuginfo test --- src/test/codegen/inline-debuginfo.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/codegen/inline-debuginfo.rs diff --git a/src/test/codegen/inline-debuginfo.rs b/src/test/codegen/inline-debuginfo.rs new file mode 100644 index 0000000000000..219347ad7d879 --- /dev/null +++ b/src/test/codegen/inline-debuginfo.rs @@ -0,0 +1,16 @@ +#![crate_type="rlib"] +// compile-flags: -Copt-level=3 -g + +#[no_mangle] +#[inline(always)] +pub extern "C" fn callee(x: u32) -> u32 { + x + 4 +} + +// CHECK-LABEL: caller +// CHECK: call void @llvm.dbg.value(metadata i32 %y, metadata !{{.*}}, metadata !DIExpression(DW_OP_constu, 3, DW_OP_minus, DW_OP_stack_value)), !dbg [[A:!.*]] +// CHECK: [[A]] = !DILocation(line: {{.*}}, scope: {{.*}}, inlinedAt: {{.*}}) +#[no_mangle] +pub extern "C" fn caller(y: u32) -> u32 { + callee(y - 3) +} From 2b3f00928c3b0db93c87d462a53c9f0df98f3e27 Mon Sep 17 00:00:00 2001 From: oli Date: Mon, 26 Oct 2020 14:09:27 +0000 Subject: [PATCH 18/18] Ignore long lines in test --- src/test/codegen/inline-debuginfo.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/codegen/inline-debuginfo.rs b/src/test/codegen/inline-debuginfo.rs index 219347ad7d879..1546dfa10a313 100644 --- a/src/test/codegen/inline-debuginfo.rs +++ b/src/test/codegen/inline-debuginfo.rs @@ -1,5 +1,6 @@ #![crate_type="rlib"] // compile-flags: -Copt-level=3 -g +// ignore-tidy-linelength #[no_mangle] #[inline(always)]