rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo.
This commit is contained in:
parent
ca1ac6b6fb
commit
b10c157bd8
11 changed files with 53 additions and 33 deletions
|
@ -26,8 +26,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
|
||||||
ty,
|
ty,
|
||||||
name,
|
name,
|
||||||
source_info,
|
source_info,
|
||||||
|
syntactic_source_info,
|
||||||
internal,
|
internal,
|
||||||
syntactic_scope,
|
|
||||||
is_user_variable
|
is_user_variable
|
||||||
});
|
});
|
||||||
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability });
|
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability });
|
||||||
|
|
|
@ -506,7 +506,7 @@ pub struct LocalDecl<'tcx> {
|
||||||
pub name: Option<Name>,
|
pub name: Option<Name>,
|
||||||
|
|
||||||
/// Source info of the local. The `SourceScope` is the *visibility* one,
|
/// 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,
|
pub source_info: SourceInfo,
|
||||||
|
|
||||||
/// The *syntactic* (i.e. not visibility) source scope the local is defined
|
/// 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`.
|
/// `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
|
/// 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
|
/// "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).
|
/// scope (where the "rest" of a block is under all prior let-statements).
|
||||||
///
|
///
|
||||||
/// The end result looks like this:
|
/// The end result looks like this:
|
||||||
|
@ -574,10 +574,10 @@ pub struct LocalDecl<'tcx> {
|
||||||
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
|
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
|
||||||
/// │ │ // in practice because I'm lazy.
|
/// │ │ // in practice because I'm lazy.
|
||||||
/// │ │
|
/// │ │
|
||||||
/// │ │← x.syntactic_scope
|
/// │ │← x.syntactic_source_info.scope
|
||||||
/// │ │← `x.parse().unwrap()`
|
/// │ │← `x.parse().unwrap()`
|
||||||
/// │ │
|
/// │ │
|
||||||
/// │ │ │← y.syntactic_scope
|
/// │ │ │← y.syntactic_source_info.scope
|
||||||
/// │ │
|
/// │ │
|
||||||
/// │ │ │{ let y: u32 }
|
/// │ │ │{ let y: u32 }
|
||||||
/// │ │ │
|
/// │ │ │
|
||||||
|
@ -588,7 +588,7 @@ pub struct LocalDecl<'tcx> {
|
||||||
/// │ │← x.source_info.scope
|
/// │ │← x.source_info.scope
|
||||||
/// │ │← `drop(x)` // this accesses `x: u32`
|
/// │ │← `drop(x)` // this accesses `x: u32`
|
||||||
/// ```
|
/// ```
|
||||||
pub syntactic_scope: SourceScope,
|
pub syntactic_source_info: SourceInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LocalDecl<'tcx> {
|
impl<'tcx> LocalDecl<'tcx> {
|
||||||
|
@ -603,7 +603,10 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
span,
|
span,
|
||||||
scope: OUTERMOST_SOURCE_SCOPE
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
},
|
},
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: SourceInfo {
|
||||||
|
span,
|
||||||
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
|
},
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: false
|
is_user_variable: false
|
||||||
}
|
}
|
||||||
|
@ -620,7 +623,10 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
span,
|
span,
|
||||||
scope: OUTERMOST_SOURCE_SCOPE
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
},
|
},
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: SourceInfo {
|
||||||
|
span,
|
||||||
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
|
},
|
||||||
internal: true,
|
internal: true,
|
||||||
is_user_variable: false
|
is_user_variable: false
|
||||||
}
|
}
|
||||||
|
@ -638,7 +644,10 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
span,
|
span,
|
||||||
scope: OUTERMOST_SOURCE_SCOPE
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
},
|
},
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: SourceInfo {
|
||||||
|
span,
|
||||||
|
scope: OUTERMOST_SOURCE_SCOPE
|
||||||
|
},
|
||||||
internal: false,
|
internal: false,
|
||||||
name: None, // FIXME maybe we do want some name here?
|
name: None, // FIXME maybe we do want some name here?
|
||||||
is_user_variable: false
|
is_user_variable: false
|
||||||
|
@ -2192,7 +2201,7 @@ BraceStructTypeFoldableImpl! {
|
||||||
ty,
|
ty,
|
||||||
name,
|
name,
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope,
|
syntactic_source_info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,7 +716,7 @@ macro_rules! make_mir_visitor {
|
||||||
name: _,
|
name: _,
|
||||||
ref $($mutability)* source_info,
|
ref $($mutability)* source_info,
|
||||||
internal: _,
|
internal: _,
|
||||||
ref $($mutability)* syntactic_scope,
|
ref $($mutability)* syntactic_source_info,
|
||||||
is_user_variable: _,
|
is_user_variable: _,
|
||||||
} = *local_decl;
|
} = *local_decl;
|
||||||
|
|
||||||
|
@ -724,8 +724,8 @@ macro_rules! make_mir_visitor {
|
||||||
local,
|
local,
|
||||||
source_info: *source_info,
|
source_info: *source_info,
|
||||||
});
|
});
|
||||||
|
self.visit_source_info(syntactic_source_info);
|
||||||
self.visit_source_info(source_info);
|
self.visit_source_info(source_info);
|
||||||
self.visit_source_scope(syntactic_scope);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_source_scope(&mut self,
|
fn super_source_scope(&mut self,
|
||||||
|
|
|
@ -311,7 +311,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
|
||||||
|
|
||||||
tcx.struct_span_lint_node(
|
tcx.struct_span_lint_node(
|
||||||
UNUSED_MUT,
|
UNUSED_MUT,
|
||||||
vsi[local_decl.syntactic_scope].lint_root,
|
vsi[local_decl.syntactic_source_info.scope].lint_root,
|
||||||
source_info.span,
|
source_info.span,
|
||||||
"variable does not need to be mutable"
|
"variable does not need to be mutable"
|
||||||
)
|
)
|
||||||
|
|
|
@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
ty: ptr_ty,
|
ty: ptr_ty,
|
||||||
name: None,
|
name: None,
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope: source_info.scope,
|
syntactic_source_info: source_info,
|
||||||
internal: true,
|
internal: true,
|
||||||
is_user_variable: false
|
is_user_variable: false
|
||||||
});
|
});
|
||||||
|
|
|
@ -314,7 +314,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
None));
|
None));
|
||||||
// If we have lints, create a new source scope
|
// If we have lints, create a new source scope
|
||||||
// that marks the lints for the locals. See the comment
|
// 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() {
|
if lint_level.is_explicit() {
|
||||||
syntactic_scope =
|
syntactic_scope =
|
||||||
this.new_source_scope(scope_span, lint_level, None);
|
this.new_source_scope(scope_span, lint_level, None);
|
||||||
|
@ -324,7 +324,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
span,
|
span,
|
||||||
scope: var_scope.unwrap()
|
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);
|
ty, has_guard);
|
||||||
});
|
});
|
||||||
var_scope
|
var_scope
|
||||||
|
@ -1114,7 +1118,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
/// in the arm body, which will have type `T`.
|
/// in the arm body, which will have type `T`.
|
||||||
fn declare_binding(&mut self,
|
fn declare_binding(&mut self,
|
||||||
source_info: SourceInfo,
|
source_info: SourceInfo,
|
||||||
syntactic_scope: SourceScope,
|
syntactic_source_info: SourceInfo,
|
||||||
mutability: Mutability,
|
mutability: Mutability,
|
||||||
name: Name,
|
name: Name,
|
||||||
var_id: NodeId,
|
var_id: NodeId,
|
||||||
|
@ -1122,8 +1126,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
has_guard: ArmHasGuard)
|
has_guard: ArmHasGuard)
|
||||||
{
|
{
|
||||||
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \
|
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, source_info={:?}, \
|
||||||
syntactic_scope={:?})",
|
syntactic_source_info={:?})",
|
||||||
var_id, name, var_ty, source_info, syntactic_scope);
|
var_id, name, var_ty, source_info, syntactic_source_info);
|
||||||
|
|
||||||
let tcx = self.hir.tcx();
|
let tcx = self.hir.tcx();
|
||||||
let local = LocalDecl::<'tcx> {
|
let local = LocalDecl::<'tcx> {
|
||||||
|
@ -1131,7 +1135,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
ty: var_ty.clone(),
|
ty: var_ty.clone(),
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope,
|
syntactic_source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: true,
|
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),
|
ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty),
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope,
|
syntactic_source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: true,
|
is_user_variable: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 {
|
self.local_decls.push(LocalDecl {
|
||||||
mutability: Mutability::Mut,
|
mutability: Mutability::Mut,
|
||||||
ty,
|
ty,
|
||||||
source_info: SourceInfo {
|
source_info,
|
||||||
scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: source_info,
|
||||||
span: pattern.map_or(self.fn_span, |pat| pat.span)
|
|
||||||
},
|
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
|
||||||
name,
|
name,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: false,
|
is_user_variable: false,
|
||||||
|
|
|
@ -138,10 +138,11 @@ enum CallKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
|
fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
|
||||||
|
let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span };
|
||||||
LocalDecl {
|
LocalDecl {
|
||||||
mutability, ty, name: None,
|
mutability, ty, name: None,
|
||||||
source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span },
|
source_info,
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: 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>,
|
fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>,
|
||||||
mir: &mut Mir<'tcx>) -> Local {
|
mir: &mut Mir<'tcx>) -> Local {
|
||||||
|
let source_info = source_info(mir);
|
||||||
let new_ret = LocalDecl {
|
let new_ret = LocalDecl {
|
||||||
mutability: Mutability::Mut,
|
mutability: Mutability::Mut,
|
||||||
ty: ret_ty,
|
ty: ret_ty,
|
||||||
name: None,
|
name: None,
|
||||||
source_info: source_info(mir),
|
source_info,
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: false,
|
is_user_variable: false,
|
||||||
};
|
};
|
||||||
|
@ -641,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
|
||||||
ty: tcx.mk_nil(),
|
ty: tcx.mk_nil(),
|
||||||
name: None,
|
name: None,
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: false,
|
is_user_variable: false,
|
||||||
};
|
};
|
||||||
|
@ -657,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
|
||||||
}),
|
}),
|
||||||
name: None,
|
name: None,
|
||||||
source_info,
|
source_info,
|
||||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
syntactic_source_info: source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_user_variable: false,
|
is_user_variable: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -400,6 +400,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
|
||||||
|
|
||||||
local.source_info.scope = scope_map[local.source_info.scope];
|
local.source_info.scope = scope_map[local.source_info.scope];
|
||||||
local.source_info.span = callsite.location.span;
|
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);
|
let idx = caller_mir.local_decls.push(local);
|
||||||
local_map.push(idx);
|
local_map.push(idx);
|
||||||
|
|
|
@ -335,6 +335,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||||
// otherwise we would use the `promoted` directly.
|
// otherwise we would use the `promoted` directly.
|
||||||
let mut promoted_ref = LocalDecl::new_temp(ref_ty, span);
|
let mut promoted_ref = LocalDecl::new_temp(ref_ty, span);
|
||||||
promoted_ref.source_info = statement.source_info;
|
promoted_ref.source_info = statement.source_info;
|
||||||
|
promoted_ref.syntactic_source_info = statement.source_info;
|
||||||
let promoted_ref = local_decls.push(promoted_ref);
|
let promoted_ref = local_decls.push(promoted_ref);
|
||||||
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
|
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
|
||||||
self.extra_statements.push((loc, Statement {
|
self.extra_statements.push((loc, Statement {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue