1
Fork 0

Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk

rustc_mir: track inlined callees in SourceScopeData.

We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates.
This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default.

Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).`

Fixes #76997.

r? `@rust-lang/wg-mir-opt`
This commit is contained in:
bors 2020-10-26 18:50:22 +00:00
commit 0da6d42f29
68 changed files with 879 additions and 619 deletions

View file

@ -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<SourceScope, SourceScopeData>,
pub source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
/// The yield type of the function, if it is a generator.
pub yield_ty: Option<Ty<'tcx>>,
@ -244,7 +244,7 @@ impl<'tcx> Body<'tcx> {
pub fn new(
source: MirSource<'tcx>,
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
source_scopes: IndexVec<SourceScope, SourceScopeData>,
source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
local_decls: LocalDecls<'tcx>,
user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
arg_count: usize,
@ -1865,11 +1865,21 @@ 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<SourceScope>,
/// 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)>,
/// 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<SourceScope>,
/// Crate-local information for this source scope, that can't (and
/// needn't) be tracked across crates.
pub local_data: ClearCrossCrate<SourceScopeLocalData>,