From b10c157bd860c7d6baad56aeee550a84927e1e29 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 29 May 2018 12:24:53 +0300 Subject: [PATCH] rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo. --- src/librustc/ich/impls_mir.rs | 2 +- src/librustc/mir/mod.rs | 29 +++++++++++++------- src/librustc/mir/visit.rs | 4 +-- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 18 +++++++----- src/librustc_mir/build/mod.rs | 11 ++++---- src/librustc_mir/shim.rs | 5 ++-- src/librustc_mir/transform/generator.rs | 9 +++--- src/librustc_mir/transform/inline.rs | 3 ++ src/librustc_mir/transform/promote_consts.rs | 1 + 11 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 59d5ce278c6..a3acb6c1b24 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -26,8 +26,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { ty, name, source_info, + syntactic_source_info, internal, - syntactic_scope, is_user_variable }); impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index b60be21773b..2faacfb598f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -506,7 +506,7 @@ pub struct LocalDecl<'tcx> { pub name: Option, /// Source info of the local. The `SourceScope` is the *visibility* one, - /// not the the *syntactic* one (see `syntactic_scope` for more details). + /// not the the *syntactic* one (see `syntactic_source_info` for more details). pub source_info: SourceInfo, /// The *syntactic* (i.e. not visibility) source scope the local is defined @@ -560,9 +560,9 @@ pub struct LocalDecl<'tcx> { /// `drop(x)`, we want it to refer to `x: u32`. /// /// To allow both uses to work, we need to have more than a single scope - /// for a local. We have the `syntactic_scope` represent the + /// for a local. We have the `syntactic_source_info.scope` represent the /// "syntactic" lint scope (with a variable being under its let - /// block) while the source-info scope represents the "local variable" + /// block) while the `source_info.scope` represents the "local variable" /// scope (where the "rest" of a block is under all prior let-statements). /// /// The end result looks like this: @@ -574,10 +574,10 @@ pub struct LocalDecl<'tcx> { /// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes /// │ │ // in practice because I'm lazy. /// │ │ - /// │ │← x.syntactic_scope + /// │ │← x.syntactic_source_info.scope /// │ │← `x.parse().unwrap()` /// │ │ - /// │ │ │← y.syntactic_scope + /// │ │ │← y.syntactic_source_info.scope /// │ │ /// │ │ │{ let y: u32 } /// │ │ │ @@ -588,7 +588,7 @@ pub struct LocalDecl<'tcx> { /// │ │← x.source_info.scope /// │ │← `drop(x)` // this accesses `x: u32` /// ``` - pub syntactic_scope: SourceScope, + pub syntactic_source_info: SourceInfo, } impl<'tcx> LocalDecl<'tcx> { @@ -603,7 +603,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: false, is_user_variable: false } @@ -620,7 +623,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: true, is_user_variable: false } @@ -638,7 +644,10 @@ impl<'tcx> LocalDecl<'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: SourceInfo { + span, + scope: OUTERMOST_SOURCE_SCOPE + }, internal: false, name: None, // FIXME maybe we do want some name here? is_user_variable: false @@ -2192,7 +2201,7 @@ BraceStructTypeFoldableImpl! { ty, name, source_info, - syntactic_scope, + syntactic_source_info, } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 0b50d55b1af..72d7540b287 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -716,7 +716,7 @@ macro_rules! make_mir_visitor { name: _, ref $($mutability)* source_info, internal: _, - ref $($mutability)* syntactic_scope, + ref $($mutability)* syntactic_source_info, is_user_variable: _, } = *local_decl; @@ -724,8 +724,8 @@ macro_rules! make_mir_visitor { local, source_info: *source_info, }); + self.visit_source_info(syntactic_source_info); self.visit_source_info(source_info); - self.visit_source_scope(syntactic_scope); } fn super_source_scope(&mut self, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 0257af0c89f..0fab6634e0b 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -311,7 +311,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( tcx.struct_span_lint_node( UNUSED_MUT, - vsi[local_decl.syntactic_scope].lint_root, + vsi[local_decl.syntactic_source_info.scope].lint_root, source_info.span, "variable does not need to be mutable" ) diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 562f890b4c0..f8b57bed93e 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: ptr_ty, name: None, source_info, - syntactic_scope: source_info.scope, + syntactic_source_info: source_info, internal: true, is_user_variable: false }); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 6d731da0cfb..80739aa9d4f 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { None)); // If we have lints, create a new source scope // that marks the lints for the locals. See the comment - // on the `syntactic_scope` field for why this is needed. + // on the `syntactic_source_info` field for why this is needed. if lint_level.is_explicit() { syntactic_scope = this.new_source_scope(scope_span, lint_level, None); @@ -324,7 +324,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { span, scope: var_scope.unwrap() }; - this.declare_binding(source_info, syntactic_scope, mutability, name, var, + let syntactic_source_info = SourceInfo { + span, + scope: syntactic_scope, + }; + this.declare_binding(source_info, syntactic_source_info, mutability, name, var, ty, has_guard); }); var_scope @@ -1114,7 +1118,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// in the arm body, which will have type `T`. fn declare_binding(&mut self, source_info: SourceInfo, - syntactic_scope: SourceScope, + syntactic_source_info: SourceInfo, mutability: Mutability, name: Name, var_id: NodeId, @@ -1122,8 +1126,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { has_guard: ArmHasGuard) { debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \ - syntactic_scope={:?})", - var_id, name, var_ty, source_info, syntactic_scope); + syntactic_source_info={:?})", + var_id, name, var_ty, source_info, syntactic_source_info); let tcx = self.hir.tcx(); let local = LocalDecl::<'tcx> { @@ -1131,7 +1135,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: var_ty.clone(), name: Some(name), source_info, - syntactic_scope, + syntactic_source_info, internal: false, is_user_variable: true, }; @@ -1143,7 +1147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), name: Some(name), source_info, - syntactic_scope, + syntactic_source_info, internal: false, is_user_variable: true, }); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 23a266d47cf..06f43ad4621 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -657,14 +657,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } } + let source_info = SourceInfo { + scope: OUTERMOST_SOURCE_SCOPE, + span: pattern.map_or(self.fn_span, |pat| pat.span) + }; self.local_decls.push(LocalDecl { mutability: Mutability::Mut, ty, - source_info: SourceInfo { - scope: OUTERMOST_SOURCE_SCOPE, - span: pattern.map_or(self.fn_span, |pat| pat.span) - }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, name, internal: false, is_user_variable: false, diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 71f76f47afe..6692849bd0f 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -138,10 +138,11 @@ enum CallKind { } fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl { + let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }; LocalDecl { mutability, ty, name: None, - source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span }, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, internal: false, is_user_variable: false } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index f7ee6276aaa..1c833453c36 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -295,12 +295,13 @@ fn make_generator_state_argument_indirect<'a, 'tcx>( fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>, mir: &mut Mir<'tcx>) -> Local { + let source_info = source_info(mir); let new_ret = LocalDecl { mutability: Mutability::Mut, ty: ret_ty, name: None, - source_info: source_info(mir), - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + source_info, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; @@ -641,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>( ty: tcx.mk_nil(), name: None, source_info, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; @@ -657,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>( }), name: None, source_info, - syntactic_scope: OUTERMOST_SOURCE_SCOPE, + syntactic_source_info: source_info, internal: false, is_user_variable: false, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 9fa078f8dab..2434f303178 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -400,6 +400,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { local.source_info.scope = scope_map[local.source_info.scope]; local.source_info.span = callsite.location.span; + local.syntactic_source_info.scope = + scope_map[local.syntactic_source_info.scope]; + local.syntactic_source_info.span = callsite.location.span; let idx = caller_mir.local_decls.push(local); local_map.push(idx); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 19bc4fd03f4..61f43f23a23 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -335,6 +335,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { // otherwise we would use the `promoted` directly. let mut promoted_ref = LocalDecl::new_temp(ref_ty, span); promoted_ref.source_info = statement.source_info; + promoted_ref.syntactic_source_info = statement.source_info; let promoted_ref = local_decls.push(promoted_ref); assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref); self.extra_statements.push((loc, Statement {