提交 b10c157b 编写于 作者: E Eduard-Mihai Burtescu

rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo.

上级 ca1ac6b6
......@@ -26,8 +26,8 @@
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 });
......
......@@ -506,7 +506,7 @@ pub struct LocalDecl<'tcx> {
pub name: Option<Name>,
/// 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 @@ pub fn new_temp(ty: Ty<'tcx>, span: Span) -> Self {
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 @@ pub fn new_internal(ty: Ty<'tcx>, span: Span) -> Self {
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 @@ pub fn new_return_place(return_ty: Ty, span: Span) -> LocalDecl {
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 @@ impl<'tcx> TypeFoldable<'tcx> for LocalDecl<'tcx> {
ty,
name,
source_info,
syntactic_scope,
syntactic_source_info,
}
}
......
......@@ -716,7 +716,7 @@ fn super_local_decl(&mut self,
name: _,
ref $($mutability)* source_info,
internal: _,
ref $($mutability)* syntactic_scope,
ref $($mutability)* syntactic_source_info,
is_user_variable: _,
} = *local_decl;
......@@ -724,8 +724,8 @@ fn super_local_decl(&mut self,
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,
......
......@@ -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"
)
......
......@@ -247,7 +247,7 @@ pub fn into_expr(&mut self,
ty: ptr_ty,
name: None,
source_info,
syntactic_scope: source_info.scope,
syntactic_source_info: source_info,
internal: true,
is_user_variable: false
});
......
......@@ -314,7 +314,7 @@ pub fn declare_bindings(&mut self,
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 @@ pub fn declare_bindings(&mut self,
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 @@ fn bind_matched_candidate_for_arm_body(&mut self,
/// 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 @@ fn declare_binding(&mut self,
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 @@ fn declare_binding(&mut self,
ty: var_ty.clone(),
name: Some(name),
source_info,
syntactic_scope,
syntactic_source_info,
internal: false,
is_user_variable: true,
};
......@@ -1143,7 +1147,7 @@ fn declare_binding(&mut self,
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,
});
......
......@@ -657,14 +657,15 @@ fn args_and_body(&mut self,
}
}
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,
......
......@@ -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
}
......
......@@ -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,
};
......
......@@ -400,6 +400,9 @@ fn inline_call(&self,
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);
......
......@@ -335,6 +335,7 @@ fn interior_base<'a, 'tcx>(place: &'a mut Place<'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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册