rustc: rename mir::VisibilityScope to mir::SourceScope.
This commit is contained in:
parent
74d09399c1
commit
85d44c4276
20 changed files with 193 additions and 191 deletions
|
|
@ -127,7 +127,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::Field {
|
|||
}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>>
|
||||
for mir::VisibilityScope {
|
||||
for mir::SourceScope {
|
||||
#[inline]
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'a>,
|
||||
|
|
@ -363,8 +363,8 @@ for mir::ProjectionElem<'gcx, V, T>
|
|||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct mir::VisibilityScopeData { span, parent_scope });
|
||||
impl_stable_hash_for!(struct mir::VisibilityScopeInfo {
|
||||
impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope });
|
||||
impl_stable_hash_for!(struct mir::SourceScopeInfo {
|
||||
lint_root, safety
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -78,13 +78,13 @@ pub struct Mir<'tcx> {
|
|||
/// that indexes into this vector.
|
||||
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
|
||||
/// List of visibility (lexical) scopes; these are referenced by statements
|
||||
/// and used (eventually) for debuginfo. Indexed by a `VisibilityScope`.
|
||||
pub visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
|
||||
/// List of source scopes; these are referenced by statements
|
||||
/// and used for debuginfo. Indexed by a `SourceScope`.
|
||||
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,
|
||||
|
||||
/// Crate-local information for each visibility scope, that can't (and
|
||||
/// Crate-local information for each source scope, that can't (and
|
||||
/// needn't) be tracked across crates.
|
||||
pub visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope, VisibilityScopeInfo>>,
|
||||
pub source_scope_info: ClearCrossCrate<IndexVec<SourceScope, SourceScopeInfo>>,
|
||||
|
||||
/// Rvalues promoted from this function, such as borrows of constants.
|
||||
/// Each of them is the Mir of a constant with the fn's type parameters
|
||||
|
|
@ -137,9 +137,9 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
|
|||
|
||||
impl<'tcx> Mir<'tcx> {
|
||||
pub fn new(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||
visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
|
||||
visibility_scope_info: ClearCrossCrate<IndexVec<VisibilityScope,
|
||||
VisibilityScopeInfo>>,
|
||||
source_scopes: IndexVec<SourceScope, SourceScopeData>,
|
||||
source_scope_info: ClearCrossCrate<IndexVec<SourceScope,
|
||||
SourceScopeInfo>>,
|
||||
promoted: IndexVec<Promoted, Mir<'tcx>>,
|
||||
yield_ty: Option<Ty<'tcx>>,
|
||||
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
|
||||
|
|
@ -153,8 +153,8 @@ impl<'tcx> Mir<'tcx> {
|
|||
|
||||
Mir {
|
||||
basic_blocks,
|
||||
visibility_scopes,
|
||||
visibility_scope_info,
|
||||
source_scopes,
|
||||
source_scope_info,
|
||||
promoted,
|
||||
yield_ty,
|
||||
generator_drop: None,
|
||||
|
|
@ -309,7 +309,7 @@ impl<'tcx> Mir<'tcx> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct VisibilityScopeInfo {
|
||||
pub struct SourceScopeInfo {
|
||||
/// A NodeId with lint levels equivalent to this scope's lint levels.
|
||||
pub lint_root: ast::NodeId,
|
||||
/// The unsafe block that contains this node.
|
||||
|
|
@ -329,8 +329,8 @@ pub enum Safety {
|
|||
|
||||
impl_stable_hash_for!(struct Mir<'tcx> {
|
||||
basic_blocks,
|
||||
visibility_scopes,
|
||||
visibility_scope_info,
|
||||
source_scopes,
|
||||
source_scope_info,
|
||||
promoted,
|
||||
yield_ty,
|
||||
generator_drop,
|
||||
|
|
@ -376,8 +376,9 @@ pub struct SourceInfo {
|
|||
/// Source span for the AST pertaining to this MIR entity.
|
||||
pub span: Span,
|
||||
|
||||
/// The lexical visibility scope, i.e. which bindings can be seen.
|
||||
pub scope: VisibilityScope
|
||||
/// The source scope, keeping track of which bindings can be
|
||||
/// seen by debuginfo, active lint levels, `unsafe {...}`, etc.
|
||||
pub scope: SourceScope
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -512,16 +513,17 @@ pub struct LocalDecl<'tcx> {
|
|||
/// to generate better debuginfo.
|
||||
pub name: Option<Name>,
|
||||
|
||||
/// Source info of the local.
|
||||
/// Source info of the local. The `SourceScope` is the *visibility* one,
|
||||
/// not the the *syntactic* one (see `syntactic_scope` for more details).
|
||||
pub source_info: SourceInfo,
|
||||
|
||||
/// The *syntactic* visibility scope the local is defined
|
||||
/// The *syntactic* (i.e. not visibility) source scope the local is defined
|
||||
/// in. If the local was defined in a let-statement, this
|
||||
/// is *within* the let-statement, rather than outside
|
||||
/// of it.
|
||||
///
|
||||
/// This is needed because visibility scope of locals within a let-statement
|
||||
/// is weird.
|
||||
/// This is needed because the visibility source scope of locals within
|
||||
/// a let-statement is weird.
|
||||
///
|
||||
/// The reason is that we want the local to be *within* the let-statement
|
||||
/// for lint purposes, but we want the local to be *after* the let-statement
|
||||
|
|
@ -594,7 +596,7 @@ pub struct LocalDecl<'tcx> {
|
|||
/// │ │← x.source_info.scope
|
||||
/// │ │← `drop(x)` // this accesses `x: u32`
|
||||
/// ```
|
||||
pub syntactic_scope: VisibilityScope,
|
||||
pub syntactic_scope: SourceScope,
|
||||
}
|
||||
|
||||
impl<'tcx> LocalDecl<'tcx> {
|
||||
|
|
@ -607,9 +609,9 @@ impl<'tcx> LocalDecl<'tcx> {
|
|||
name: None,
|
||||
source_info: SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
is_user_variable: false
|
||||
}
|
||||
|
|
@ -624,9 +626,9 @@ impl<'tcx> LocalDecl<'tcx> {
|
|||
name: None,
|
||||
source_info: SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: true,
|
||||
is_user_variable: false
|
||||
}
|
||||
|
|
@ -642,9 +644,9 @@ impl<'tcx> LocalDecl<'tcx> {
|
|||
ty: return_ty,
|
||||
source_info: SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
name: None, // FIXME maybe we do want some name here?
|
||||
is_user_variable: false
|
||||
|
|
@ -1047,7 +1049,7 @@ impl<'tcx> BasicBlockData<'tcx> {
|
|||
self.statements.resize(gap.end, Statement {
|
||||
source_info: SourceInfo {
|
||||
span: DUMMY_SP,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
kind: StatementKind::Nop
|
||||
});
|
||||
|
|
@ -1501,16 +1503,16 @@ impl<'tcx> Debug for Place<'tcx> {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// Scopes
|
||||
|
||||
newtype_index!(VisibilityScope
|
||||
newtype_index!(SourceScope
|
||||
{
|
||||
DEBUG_FORMAT = "scope[{}]",
|
||||
const ARGUMENT_VISIBILITY_SCOPE = 0,
|
||||
const OUTERMOST_SOURCE_SCOPE = 0,
|
||||
});
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct VisibilityScopeData {
|
||||
pub struct SourceScopeData {
|
||||
pub span: Span,
|
||||
pub parent_scope: Option<VisibilityScope>,
|
||||
pub parent_scope: Option<SourceScope>,
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -2153,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! {
|
|||
SourceInfo,
|
||||
UpvarDecl,
|
||||
ValidationOp,
|
||||
VisibilityScopeData,
|
||||
VisibilityScope,
|
||||
VisibilityScopeInfo,
|
||||
SourceScopeData,
|
||||
SourceScope,
|
||||
SourceScopeInfo,
|
||||
}
|
||||
|
||||
BraceStructTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
|
||||
basic_blocks,
|
||||
visibility_scopes,
|
||||
visibility_scope_info,
|
||||
source_scopes,
|
||||
source_scope_info,
|
||||
promoted,
|
||||
yield_ty,
|
||||
generator_drop,
|
||||
|
|
|
|||
|
|
@ -92,9 +92,9 @@ macro_rules! make_mir_visitor {
|
|||
self.super_basic_block_data(block, data);
|
||||
}
|
||||
|
||||
fn visit_visibility_scope_data(&mut self,
|
||||
scope_data: & $($mutability)* VisibilityScopeData) {
|
||||
self.super_visibility_scope_data(scope_data);
|
||||
fn visit_source_scope_data(&mut self,
|
||||
scope_data: & $($mutability)* SourceScopeData) {
|
||||
self.super_source_scope_data(scope_data);
|
||||
}
|
||||
|
||||
fn visit_statement(&mut self,
|
||||
|
|
@ -261,9 +261,9 @@ macro_rules! make_mir_visitor {
|
|||
_location: Location) {
|
||||
}
|
||||
|
||||
fn visit_visibility_scope(&mut self,
|
||||
scope: & $($mutability)* VisibilityScope) {
|
||||
self.super_visibility_scope(scope);
|
||||
fn visit_source_scope(&mut self,
|
||||
scope: & $($mutability)* SourceScope) {
|
||||
self.super_source_scope(scope);
|
||||
}
|
||||
|
||||
// The `super_xxx` methods comprise the default behavior and are
|
||||
|
|
@ -274,7 +274,7 @@ macro_rules! make_mir_visitor {
|
|||
if let Some(yield_ty) = &$($mutability)* mir.yield_ty {
|
||||
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
|
||||
span: mir.span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -289,13 +289,13 @@ macro_rules! make_mir_visitor {
|
|||
self.visit_basic_block_data(bb, data);
|
||||
}
|
||||
|
||||
for scope in &$($mutability)* mir.visibility_scopes {
|
||||
self.visit_visibility_scope_data(scope);
|
||||
for scope in &$($mutability)* mir.source_scopes {
|
||||
self.visit_source_scope_data(scope);
|
||||
}
|
||||
|
||||
self.visit_ty(&$($mutability)* mir.return_ty(), TyContext::ReturnTy(SourceInfo {
|
||||
span: mir.span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
}));
|
||||
|
||||
for local in mir.local_decls.indices() {
|
||||
|
|
@ -327,16 +327,16 @@ macro_rules! make_mir_visitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn super_visibility_scope_data(&mut self,
|
||||
scope_data: & $($mutability)* VisibilityScopeData) {
|
||||
let VisibilityScopeData {
|
||||
fn super_source_scope_data(&mut self,
|
||||
scope_data: & $($mutability)* SourceScopeData) {
|
||||
let SourceScopeData {
|
||||
ref $($mutability)* span,
|
||||
ref $($mutability)* parent_scope,
|
||||
} = *scope_data;
|
||||
|
||||
self.visit_span(span);
|
||||
if let Some(ref $($mutability)* parent_scope) = *parent_scope {
|
||||
self.visit_visibility_scope(parent_scope);
|
||||
self.visit_source_scope(parent_scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -725,11 +725,11 @@ macro_rules! make_mir_visitor {
|
|||
source_info: *source_info,
|
||||
});
|
||||
self.visit_source_info(source_info);
|
||||
self.visit_visibility_scope(syntactic_scope);
|
||||
self.visit_source_scope(syntactic_scope);
|
||||
}
|
||||
|
||||
fn super_visibility_scope(&mut self,
|
||||
_scope: & $($mutability)* VisibilityScope) {
|
||||
fn super_source_scope(&mut self,
|
||||
_scope: & $($mutability)* SourceScope) {
|
||||
}
|
||||
|
||||
fn super_branch(&mut self,
|
||||
|
|
@ -775,7 +775,7 @@ macro_rules! make_mir_visitor {
|
|||
} = *source_info;
|
||||
|
||||
self.visit_span(span);
|
||||
self.visit_visibility_scope(scope);
|
||||
self.visit_source_scope(scope);
|
||||
}
|
||||
|
||||
fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use super::utils::{DIB, span_start};
|
|||
use llvm;
|
||||
use llvm::debuginfo::DIScope;
|
||||
use common::CodegenCx;
|
||||
use rustc::mir::{Mir, VisibilityScope};
|
||||
use rustc::mir::{Mir, SourceScope};
|
||||
|
||||
use libc::c_uint;
|
||||
use std::ptr;
|
||||
|
|
@ -45,13 +45,13 @@ impl MirDebugScope {
|
|||
/// Produce DIScope DIEs for each MIR Scope which has variables defined in it.
|
||||
/// If debuginfo is disabled, the returned vector is empty.
|
||||
pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
|
||||
-> IndexVec<VisibilityScope, MirDebugScope> {
|
||||
-> IndexVec<SourceScope, MirDebugScope> {
|
||||
let null_scope = MirDebugScope {
|
||||
scope_metadata: ptr::null_mut(),
|
||||
file_start_pos: BytePos(0),
|
||||
file_end_pos: BytePos(0)
|
||||
};
|
||||
let mut scopes = IndexVec::from_elem(null_scope, &mir.visibility_scopes);
|
||||
let mut scopes = IndexVec::from_elem(null_scope, &mir.source_scopes);
|
||||
|
||||
let debug_context = match *debug_context {
|
||||
FunctionDebugContext::RegularContext(ref data) => data,
|
||||
|
|
@ -62,15 +62,15 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
|
|||
};
|
||||
|
||||
// Find all the scopes with variables defined in them.
|
||||
let mut has_variables = BitVector::new(mir.visibility_scopes.len());
|
||||
let mut has_variables = BitVector::new(mir.source_scopes.len());
|
||||
for var in mir.vars_iter() {
|
||||
let decl = &mir.local_decls[var];
|
||||
has_variables.insert(decl.source_info.scope.index());
|
||||
}
|
||||
|
||||
// Instantiate all scopes.
|
||||
for idx in 0..mir.visibility_scopes.len() {
|
||||
let scope = VisibilityScope::new(idx);
|
||||
for idx in 0..mir.source_scopes.len() {
|
||||
let scope = SourceScope::new(idx);
|
||||
make_mir_scope(cx, &mir, &has_variables, debug_context, scope, &mut scopes);
|
||||
}
|
||||
|
||||
|
|
@ -81,13 +81,13 @@ fn make_mir_scope(cx: &CodegenCx,
|
|||
mir: &Mir,
|
||||
has_variables: &BitVector,
|
||||
debug_context: &FunctionDebugContextData,
|
||||
scope: VisibilityScope,
|
||||
scopes: &mut IndexVec<VisibilityScope, MirDebugScope>) {
|
||||
scope: SourceScope,
|
||||
scopes: &mut IndexVec<SourceScope, MirDebugScope>) {
|
||||
if scopes[scope].is_valid() {
|
||||
return;
|
||||
}
|
||||
|
||||
let scope_data = &mir.visibility_scopes[scope];
|
||||
let scope_data = &mir.source_scopes[scope];
|
||||
let parent_scope = if let Some(parent) = scope_data.parent_scope {
|
||||
make_mir_scope(cx, mir, has_variables, debug_context, parent, scopes);
|
||||
scopes[parent]
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ pub struct FunctionCx<'a, 'tcx:'a> {
|
|||
locals: IndexVec<mir::Local, LocalRef<'tcx>>,
|
||||
|
||||
/// Debug information for MIR scopes.
|
||||
scopes: IndexVec<mir::VisibilityScope, debuginfo::MirDebugScope>,
|
||||
scopes: IndexVec<mir::SourceScope, debuginfo::MirDebugScope>,
|
||||
|
||||
/// If this function is being monomorphized, this contains the type substitutions used.
|
||||
param_substs: &'tcx Substs<'tcx>,
|
||||
|
|
@ -158,9 +158,9 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
|
|||
|
||||
// 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 visibility scope. If so, we need to create a 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::VisibilityScope, pos: BytePos)
|
||||
fn scope_metadata_for_loc(&self, scope_id: mir::SourceScope, pos: BytePos)
|
||||
-> llvm::debuginfo::DIScope {
|
||||
let scope_metadata = self.scopes[scope_id].scope_metadata;
|
||||
if pos < self.scopes[scope_id].file_start_pos ||
|
||||
|
|
@ -411,7 +411,7 @@ fn create_funclets<'a, 'tcx>(
|
|||
/// indirect.
|
||||
fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
|
||||
fx: &FunctionCx<'a, 'tcx>,
|
||||
scopes: &IndexVec<mir::VisibilityScope, debuginfo::MirDebugScope>,
|
||||
scopes: &IndexVec<mir::SourceScope, debuginfo::MirDebugScope>,
|
||||
memory_locals: &BitVector)
|
||||
-> Vec<LocalRef<'tcx>> {
|
||||
let mir = fx.mir;
|
||||
|
|
@ -420,7 +420,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
|
|||
let mut llarg_idx = fx.fn_ty.ret.is_indirect() as usize;
|
||||
|
||||
// Get the argument scope, if it exists and if we need it.
|
||||
let arg_scope = scopes[mir::ARGUMENT_VISIBILITY_SCOPE];
|
||||
let arg_scope = scopes[mir::OUTERMOST_SOURCE_SCOPE];
|
||||
let arg_scope = if arg_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo {
|
||||
Some(arg_scope.scope_metadata)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
|
|||
debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
|
||||
|
||||
for local in mbcx.mir.mut_vars_and_args_iter().filter(|local| !mbcx.used_mut.contains(local)) {
|
||||
if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.visibility_scope_info {
|
||||
if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.source_scope_info {
|
||||
let local_decl = &mbcx.mir.local_decls[local];
|
||||
|
||||
// Skip implicit `self` argument for closures
|
||||
|
|
|
|||
|
|
@ -81,10 +81,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
//
|
||||
// First we build all the statements in the block.
|
||||
let mut let_scope_stack = Vec::with_capacity(8);
|
||||
let outer_visibility_scope = this.visibility_scope;
|
||||
let outer_source_scope = this.source_scope;
|
||||
let outer_push_unsafe_count = this.push_unsafe_count;
|
||||
let outer_unpushed_unsafe = this.unpushed_unsafe;
|
||||
this.update_visibility_scope_for_safety_mode(span, safety_mode);
|
||||
this.update_source_scope_for_safety_mode(span, safety_mode);
|
||||
|
||||
let source_info = this.source_info(span);
|
||||
for stmt in stmts {
|
||||
|
|
@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
this.push_scope((remainder_scope, source_info));
|
||||
let_scope_stack.push(remainder_scope);
|
||||
|
||||
// Declare the bindings, which may create a visibility scope.
|
||||
// Declare the bindings, which may create a source scope.
|
||||
let remainder_span = remainder_scope.span(this.hir.tcx(),
|
||||
&this.hir.region_scope_tree);
|
||||
let scope = this.declare_bindings(None, remainder_span, lint_level, &pattern,
|
||||
|
|
@ -143,9 +143,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
// Enter the visibility scope, after evaluating the initializer.
|
||||
if let Some(visibility_scope) = scope {
|
||||
this.visibility_scope = visibility_scope;
|
||||
// Enter the source scope, after evaluating the initializer.
|
||||
if let Some(source_scope) = scope {
|
||||
this.source_scope = source_scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -172,19 +172,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
for scope in let_scope_stack.into_iter().rev() {
|
||||
unpack!(block = this.pop_scope((scope, source_info), block));
|
||||
}
|
||||
// Restore the original visibility scope.
|
||||
this.visibility_scope = outer_visibility_scope;
|
||||
// Restore the original source scope.
|
||||
this.source_scope = outer_source_scope;
|
||||
this.push_unsafe_count = outer_push_unsafe_count;
|
||||
this.unpushed_unsafe = outer_unpushed_unsafe;
|
||||
block.unit()
|
||||
}
|
||||
|
||||
/// If we are changing the safety mode, create a new visibility scope
|
||||
fn update_visibility_scope_for_safety_mode(&mut self,
|
||||
/// If we are changing the safety mode, create a new source scope
|
||||
fn update_source_scope_for_safety_mode(&mut self,
|
||||
span: Span,
|
||||
safety_mode: BlockSafety)
|
||||
{
|
||||
debug!("update_visibility_scope_for({:?}, {:?})", span, safety_mode);
|
||||
debug!("update_source_scope_for({:?}, {:?})", span, safety_mode);
|
||||
let new_unsafety = match safety_mode {
|
||||
BlockSafety::Safe => None,
|
||||
BlockSafety::ExplicitUnsafe(node_id) => {
|
||||
|
|
@ -214,7 +214,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
|
||||
if let Some(unsafety) = new_unsafety {
|
||||
self.visibility_scope = self.new_visibility_scope(
|
||||
self.source_scope = self.new_source_scope(
|
||||
span, LintLevel::Inherited, Some(unsafety));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
LintLevel::Inherited,
|
||||
&arm.patterns[0],
|
||||
ArmHasGuard(arm.guard.is_some()));
|
||||
(body, scope.unwrap_or(self.visibility_scope))
|
||||
(body, scope.unwrap_or(self.source_scope))
|
||||
}).collect();
|
||||
|
||||
// create binding start block for link them by false edges
|
||||
|
|
@ -200,15 +200,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
let end_block = self.cfg.start_new_block();
|
||||
|
||||
let outer_source_info = self.source_info(span);
|
||||
for (arm_index, (body, visibility_scope)) in arm_bodies.into_iter().enumerate() {
|
||||
for (arm_index, (body, source_scope)) in arm_bodies.into_iter().enumerate() {
|
||||
let mut arm_block = arm_blocks.blocks[arm_index];
|
||||
// Re-enter the visibility scope we created the bindings in.
|
||||
self.visibility_scope = visibility_scope;
|
||||
// Re-enter the source scope we created the bindings in.
|
||||
self.source_scope = source_scope;
|
||||
unpack!(arm_block = self.into(destination, arm_block, body));
|
||||
self.cfg.terminate(arm_block, outer_source_info,
|
||||
TerminatorKind::Goto { target: end_block });
|
||||
}
|
||||
self.visibility_scope = outer_source_info.scope;
|
||||
self.source_scope = outer_source_info.scope;
|
||||
|
||||
end_block.unit()
|
||||
}
|
||||
|
|
@ -294,30 +294,30 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
block.unit()
|
||||
}
|
||||
|
||||
/// Declares the bindings of the given pattern and returns the visibility scope
|
||||
/// Declares the bindings of the given pattern and returns the source scope
|
||||
/// for the bindings in this patterns, if such a scope had to be created.
|
||||
/// NOTE: Declaring the bindings should always be done in their drop scope.
|
||||
pub fn declare_bindings(&mut self,
|
||||
mut var_scope: Option<VisibilityScope>,
|
||||
mut var_scope: Option<SourceScope>,
|
||||
scope_span: Span,
|
||||
lint_level: LintLevel,
|
||||
pattern: &Pattern<'tcx>,
|
||||
has_guard: ArmHasGuard)
|
||||
-> Option<VisibilityScope> {
|
||||
-> Option<SourceScope> {
|
||||
assert!(!(var_scope.is_some() && lint_level.is_explicit()),
|
||||
"can't have both a var and a lint scope at the same time");
|
||||
let mut syntactic_scope = self.visibility_scope;
|
||||
let mut syntactic_scope = self.source_scope;
|
||||
self.visit_bindings(pattern, &mut |this, mutability, name, var, span, ty| {
|
||||
if var_scope.is_none() {
|
||||
var_scope = Some(this.new_visibility_scope(scope_span,
|
||||
var_scope = Some(this.new_source_scope(scope_span,
|
||||
LintLevel::Inherited,
|
||||
None));
|
||||
// If we have lints, create a new visibility scope
|
||||
// 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.
|
||||
if lint_level.is_explicit() {
|
||||
syntactic_scope =
|
||||
this.new_visibility_scope(scope_span, lint_level, None);
|
||||
this.new_source_scope(scope_span, lint_level, None);
|
||||
}
|
||||
}
|
||||
let source_info = SourceInfo {
|
||||
|
|
@ -1114,7 +1114,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: VisibilityScope,
|
||||
syntactic_scope: SourceScope,
|
||||
mutability: Mutability,
|
||||
name: Name,
|
||||
var_id: NodeId,
|
||||
|
|
|
|||
|
|
@ -256,9 +256,9 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
|||
|
||||
/// the vector of all scopes that we have created thus far;
|
||||
/// we track this for debuginfo later
|
||||
visibility_scopes: IndexVec<VisibilityScope, VisibilityScopeData>,
|
||||
visibility_scope_info: IndexVec<VisibilityScope, VisibilityScopeInfo>,
|
||||
visibility_scope: VisibilityScope,
|
||||
source_scopes: IndexVec<SourceScope, SourceScopeData>,
|
||||
source_scope_info: IndexVec<SourceScope, SourceScopeInfo>,
|
||||
source_scope: SourceScope,
|
||||
|
||||
/// the guard-context: each time we build the guard expression for
|
||||
/// a match arm, we push onto this stack, and then pop when we
|
||||
|
|
@ -593,9 +593,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
fn_span: span,
|
||||
arg_count,
|
||||
scopes: vec![],
|
||||
visibility_scopes: IndexVec::new(),
|
||||
visibility_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
visibility_scope_info: IndexVec::new(),
|
||||
source_scopes: IndexVec::new(),
|
||||
source_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
source_scope_info: IndexVec::new(),
|
||||
guard_context: vec![],
|
||||
push_unsafe_count: 0,
|
||||
unpushed_unsafe: safety,
|
||||
|
|
@ -611,9 +611,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
|
||||
assert_eq!(builder.cfg.start_new_block(), START_BLOCK);
|
||||
assert_eq!(
|
||||
builder.new_visibility_scope(span, lint_level, Some(safety)),
|
||||
ARGUMENT_VISIBILITY_SCOPE);
|
||||
builder.visibility_scopes[ARGUMENT_VISIBILITY_SCOPE].parent_scope = None;
|
||||
builder.new_source_scope(span, lint_level, Some(safety)),
|
||||
OUTERMOST_SOURCE_SCOPE);
|
||||
builder.source_scopes[OUTERMOST_SOURCE_SCOPE].parent_scope = None;
|
||||
|
||||
builder
|
||||
}
|
||||
|
|
@ -629,8 +629,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
Mir::new(self.cfg.basic_blocks,
|
||||
self.visibility_scopes,
|
||||
ClearCrossCrate::Set(self.visibility_scope_info),
|
||||
self.source_scopes,
|
||||
ClearCrossCrate::Set(self.source_scope_info),
|
||||
IndexVec::new(),
|
||||
yield_ty,
|
||||
self.local_decls,
|
||||
|
|
@ -661,10 +661,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
mutability: Mutability::Mut,
|
||||
ty,
|
||||
source_info: SourceInfo {
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span: pattern.map_or(self.fn_span, |pat| pat.span)
|
||||
},
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
name,
|
||||
internal: false,
|
||||
is_user_variable: false,
|
||||
|
|
@ -702,9 +702,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
|
||||
}
|
||||
|
||||
// Enter the argument pattern bindings visibility scope, if it exists.
|
||||
if let Some(visibility_scope) = scope {
|
||||
self.visibility_scope = visibility_scope;
|
||||
// Enter the argument pattern bindings source scope, if it exists.
|
||||
if let Some(source_scope) = scope {
|
||||
self.source_scope = source_scope;
|
||||
}
|
||||
|
||||
let body = self.hir.mirror(ast_body);
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Scope<'tcx> {
|
||||
/// The visibility scope this scope was created in.
|
||||
visibility_scope: VisibilityScope,
|
||||
/// The source scope this scope was created in.
|
||||
source_scope: SourceScope,
|
||||
|
||||
/// the region span of this scope within source code.
|
||||
region_scope: region::Scope,
|
||||
|
|
@ -251,11 +251,11 @@ impl<'tcx> Scope<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Given a span and this scope's visibility scope, make a SourceInfo.
|
||||
/// Given a span and this scope's source scope, make a SourceInfo.
|
||||
fn source_info(&self, span: Span) -> SourceInfo {
|
||||
SourceInfo {
|
||||
span,
|
||||
scope: self.visibility_scope
|
||||
scope: self.source_scope
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -316,14 +316,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
where F: FnOnce(&mut Builder<'a, 'gcx, 'tcx>) -> BlockAnd<R>
|
||||
{
|
||||
debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block);
|
||||
let visibility_scope = self.visibility_scope;
|
||||
let source_scope = self.source_scope;
|
||||
let tcx = self.hir.tcx();
|
||||
if let LintLevel::Explicit(node_id) = lint_level {
|
||||
let same_lint_scopes = tcx.dep_graph.with_ignore(|| {
|
||||
let sets = tcx.lint_levels(LOCAL_CRATE);
|
||||
let parent_hir_id =
|
||||
tcx.hir.definitions().node_to_hir_id(
|
||||
self.visibility_scope_info[visibility_scope].lint_root
|
||||
self.source_scope_info[source_scope].lint_root
|
||||
);
|
||||
let current_hir_id =
|
||||
tcx.hir.definitions().node_to_hir_id(node_id);
|
||||
|
|
@ -332,15 +332,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
});
|
||||
|
||||
if !same_lint_scopes {
|
||||
self.visibility_scope =
|
||||
self.new_visibility_scope(region_scope.1.span, lint_level,
|
||||
self.source_scope =
|
||||
self.new_source_scope(region_scope.1.span, lint_level,
|
||||
None);
|
||||
}
|
||||
}
|
||||
self.push_scope(region_scope);
|
||||
let rv = unpack!(block = f(self));
|
||||
unpack!(block = self.pop_scope(region_scope, block));
|
||||
self.visibility_scope = visibility_scope;
|
||||
self.source_scope = source_scope;
|
||||
debug!("in_scope: exiting region_scope={:?} block={:?}", region_scope, block);
|
||||
block.and(rv)
|
||||
}
|
||||
|
|
@ -351,9 +351,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
/// wrapper maybe preferable.
|
||||
pub fn push_scope(&mut self, region_scope: (region::Scope, SourceInfo)) {
|
||||
debug!("push_scope({:?})", region_scope);
|
||||
let vis_scope = self.visibility_scope;
|
||||
let vis_scope = self.source_scope;
|
||||
self.scopes.push(Scope {
|
||||
visibility_scope: vis_scope,
|
||||
source_scope: vis_scope,
|
||||
region_scope: region_scope.0,
|
||||
region_scope_span: region_scope.1.span,
|
||||
needs_cleanup: false,
|
||||
|
|
@ -509,30 +509,30 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
Some(result)
|
||||
}
|
||||
|
||||
/// Creates a new visibility scope, nested in the current one.
|
||||
pub fn new_visibility_scope(&mut self,
|
||||
/// Creates a new source scope, nested in the current one.
|
||||
pub fn new_source_scope(&mut self,
|
||||
span: Span,
|
||||
lint_level: LintLevel,
|
||||
safety: Option<Safety>) -> VisibilityScope {
|
||||
let parent = self.visibility_scope;
|
||||
debug!("new_visibility_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
|
||||
safety: Option<Safety>) -> SourceScope {
|
||||
let parent = self.source_scope;
|
||||
debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
|
||||
span, lint_level, safety,
|
||||
parent, self.visibility_scope_info.get(parent));
|
||||
let scope = self.visibility_scopes.push(VisibilityScopeData {
|
||||
parent, self.source_scope_info.get(parent));
|
||||
let scope = self.source_scopes.push(SourceScopeData {
|
||||
span,
|
||||
parent_scope: Some(parent),
|
||||
});
|
||||
let scope_info = VisibilityScopeInfo {
|
||||
let scope_info = SourceScopeInfo {
|
||||
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
|
||||
lint_root
|
||||
} else {
|
||||
self.visibility_scope_info[parent].lint_root
|
||||
self.source_scope_info[parent].lint_root
|
||||
},
|
||||
safety: safety.unwrap_or_else(|| {
|
||||
self.visibility_scope_info[parent].safety
|
||||
self.source_scope_info[parent].safety
|
||||
})
|
||||
};
|
||||
self.visibility_scope_info.push(scope_info);
|
||||
self.source_scope_info.push(scope_info);
|
||||
scope
|
||||
}
|
||||
|
||||
|
|
@ -552,11 +552,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
.unwrap_or_else(|| span_bug!(span, "no enclosing breakable scope found"))
|
||||
}
|
||||
|
||||
/// Given a span and the current visibility scope, make a SourceInfo.
|
||||
/// Given a span and the current source scope, make a SourceInfo.
|
||||
pub fn source_info(&self, span: Span) -> SourceInfo {
|
||||
SourceInfo {
|
||||
span,
|
||||
scope: self.visibility_scope
|
||||
scope: self.source_scope
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -730,7 +730,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
let resumeblk = self.cfg.start_new_cleanup_block();
|
||||
self.cfg.terminate(resumeblk,
|
||||
SourceInfo {
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span: self.fn_span
|
||||
},
|
||||
TerminatorKind::Resume);
|
||||
|
|
@ -939,10 +939,10 @@ fn build_diverge_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
|||
// remainder. If everything is cached, we'll just walk right to
|
||||
// left reading the cached results but never create anything.
|
||||
|
||||
let visibility_scope = scope.visibility_scope;
|
||||
let source_scope = scope.source_scope;
|
||||
let source_info = |span| SourceInfo {
|
||||
span,
|
||||
scope: visibility_scope
|
||||
scope: source_scope
|
||||
};
|
||||
|
||||
// Next, build up the drops. Here we iterate the vector in
|
||||
|
|
|
|||
|
|
@ -140,8 +140,8 @@ enum CallKind {
|
|||
fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
|
||||
LocalDecl {
|
||||
mutability, ty, name: None,
|
||||
source_info: SourceInfo { scope: ARGUMENT_VISIBILITY_SCOPE, span },
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
source_info: SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span },
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
is_user_variable: false
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
let source_info = SourceInfo { span, scope: ARGUMENT_VISIBILITY_SCOPE };
|
||||
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
|
||||
|
||||
let return_block = BasicBlock::new(1);
|
||||
let mut blocks = IndexVec::new();
|
||||
|
|
@ -195,7 +195,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let mut mir = Mir::new(
|
||||
blocks,
|
||||
IndexVec::from_elem_n(
|
||||
VisibilityScopeData { span: span, parent_scope: None }, 1
|
||||
SourceScopeData { span: span, parent_scope: None }, 1
|
||||
),
|
||||
ClearCrossCrate::Clear,
|
||||
IndexVec::new(),
|
||||
|
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
|
|||
Mir::new(
|
||||
self.blocks,
|
||||
IndexVec::from_elem_n(
|
||||
VisibilityScopeData { span: self.span, parent_scope: None }, 1
|
||||
SourceScopeData { span: self.span, parent_scope: None }, 1
|
||||
),
|
||||
ClearCrossCrate::Clear,
|
||||
IndexVec::new(),
|
||||
|
|
@ -367,7 +367,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn source_info(&self) -> SourceInfo {
|
||||
SourceInfo { span: self.span, scope: ARGUMENT_VISIBILITY_SCOPE }
|
||||
SourceInfo { span: self.span, scope: OUTERMOST_SOURCE_SCOPE }
|
||||
}
|
||||
|
||||
fn block(
|
||||
|
|
@ -688,7 +688,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
debug!("build_call_shim: sig={:?}", sig);
|
||||
|
||||
let mut local_decls = local_decls_for_sig(&sig, span);
|
||||
let source_info = SourceInfo { span, scope: ARGUMENT_VISIBILITY_SCOPE };
|
||||
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
|
||||
|
||||
let rcvr_arg = Local::new(1+0);
|
||||
let rcvr_l = Place::Local(rcvr_arg);
|
||||
|
|
@ -794,7 +794,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let mut mir = Mir::new(
|
||||
blocks,
|
||||
IndexVec::from_elem_n(
|
||||
VisibilityScopeData { span: span, parent_scope: None }, 1
|
||||
SourceScopeData { span: span, parent_scope: None }, 1
|
||||
),
|
||||
ClearCrossCrate::Clear,
|
||||
IndexVec::new(),
|
||||
|
|
@ -836,7 +836,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
|
|||
|
||||
let source_info = SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
};
|
||||
|
||||
let variant_no = if adt_def.is_enum() {
|
||||
|
|
@ -869,7 +869,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
|
|||
Mir::new(
|
||||
IndexVec::from_elem_n(start_block, 1),
|
||||
IndexVec::from_elem_n(
|
||||
VisibilityScopeData { span: span, parent_scope: None }, 1
|
||||
SourceScopeData { span: span, parent_scope: None }, 1
|
||||
),
|
||||
ClearCrossCrate::Clear,
|
||||
IndexVec::new(),
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ impl MirPass for AddValidation {
|
|||
// Add an AcquireValid at the beginning of the start block.
|
||||
{
|
||||
let source_info = SourceInfo {
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span: mir.span, // FIXME: Consider using just the span covering the function
|
||||
// argument declaration.
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use util;
|
|||
|
||||
pub struct UnsafetyChecker<'a, 'tcx: 'a> {
|
||||
mir: &'a Mir<'tcx>,
|
||||
visibility_scope_info: &'a IndexVec<VisibilityScope, VisibilityScopeInfo>,
|
||||
source_scope_info: &'a IndexVec<SourceScope, SourceScopeInfo>,
|
||||
violations: Vec<UnsafetyViolation>,
|
||||
source_info: SourceInfo,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
|
@ -38,16 +38,16 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> {
|
|||
|
||||
impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> {
|
||||
fn new(mir: &'a Mir<'tcx>,
|
||||
visibility_scope_info: &'a IndexVec<VisibilityScope, VisibilityScopeInfo>,
|
||||
source_scope_info: &'a IndexVec<SourceScope, SourceScopeInfo>,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>) -> Self {
|
||||
Self {
|
||||
mir,
|
||||
visibility_scope_info,
|
||||
source_scope_info,
|
||||
violations: vec![],
|
||||
source_info: SourceInfo {
|
||||
span: mir.span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
tcx,
|
||||
param_env,
|
||||
|
|
@ -147,7 +147,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
|||
if util::is_disaligned(self.tcx, self.mir, self.param_env, place) {
|
||||
let source_info = self.source_info;
|
||||
let lint_root =
|
||||
self.visibility_scope_info[source_info.scope].lint_root;
|
||||
self.source_scope_info[source_info.scope].lint_root;
|
||||
self.register_violations(&[UnsafetyViolation {
|
||||
source_info,
|
||||
description: Symbol::intern("borrow of packed field").as_interned_str(),
|
||||
|
|
@ -212,7 +212,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
|||
} else if self.tcx.is_foreign_item(def_id) {
|
||||
let source_info = self.source_info;
|
||||
let lint_root =
|
||||
self.visibility_scope_info[source_info.scope].lint_root;
|
||||
self.source_scope_info[source_info.scope].lint_root;
|
||||
self.register_violations(&[UnsafetyViolation {
|
||||
source_info,
|
||||
description: Symbol::intern("use of extern static").as_interned_str(),
|
||||
|
|
@ -240,7 +240,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
|
|||
fn register_violations(&mut self,
|
||||
violations: &[UnsafetyViolation],
|
||||
unsafe_blocks: &[(ast::NodeId, bool)]) {
|
||||
let within_unsafe = match self.visibility_scope_info[self.source_info.scope].safety {
|
||||
let within_unsafe = match self.source_scope_info[self.source_info.scope].safety {
|
||||
Safety::Safe => {
|
||||
for violation in violations {
|
||||
if !self.violations.contains(violation) {
|
||||
|
|
@ -327,7 +327,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
|
|||
// `mir_built` force this.
|
||||
let mir = &tcx.mir_built(def_id).borrow();
|
||||
|
||||
let visibility_scope_info = match mir.visibility_scope_info {
|
||||
let source_scope_info = match mir.source_scope_info {
|
||||
ClearCrossCrate::Set(ref data) => data,
|
||||
ClearCrossCrate::Clear => {
|
||||
debug!("unsafety_violations: {:?} - remote, skipping", def_id);
|
||||
|
|
@ -340,7 +340,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
|
|||
|
||||
let param_env = tcx.param_env(def_id);
|
||||
let mut checker = UnsafetyChecker::new(
|
||||
mir, visibility_scope_info, tcx, param_env);
|
||||
mir, source_scope_info, tcx, param_env);
|
||||
checker.visit_mir(mir);
|
||||
|
||||
check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
|
|||
.bits();
|
||||
let right_size = self.tcx.layout_of(self.param_env.and(right.1)).unwrap().size;
|
||||
if r.to_bits(right_size).ok().map_or(false, |b| b >= left_bits as u128) {
|
||||
let scope_info = match self.mir.visibility_scope_info {
|
||||
let scope_info = match self.mir.source_scope_info {
|
||||
ClearCrossCrate::Set(ref data) => data,
|
||||
ClearCrossCrate::Clear => return None,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>,
|
|||
ty: ret_ty,
|
||||
name: None,
|
||||
source_info: source_info(mir),
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
is_user_variable: false,
|
||||
};
|
||||
|
|
@ -641,7 +641,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
|
|||
ty: tcx.mk_nil(),
|
||||
name: None,
|
||||
source_info,
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
is_user_variable: false,
|
||||
};
|
||||
|
|
@ -657,7 +657,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
|
|||
}),
|
||||
name: None,
|
||||
source_info,
|
||||
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
syntactic_scope: OUTERMOST_SOURCE_SCOPE,
|
||||
internal: false,
|
||||
is_user_variable: false,
|
||||
};
|
||||
|
|
@ -762,7 +762,7 @@ fn create_generator_resume_function<'a, 'tcx>(
|
|||
fn source_info<'a, 'tcx>(mir: &Mir<'tcx>) -> SourceInfo {
|
||||
SourceInfo {
|
||||
span: mir.span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,10 +380,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
|
|||
debug!("Inlined {:?} into {:?}", callsite.callee, self.source);
|
||||
|
||||
let mut local_map = IndexVec::with_capacity(callee_mir.local_decls.len());
|
||||
let mut scope_map = IndexVec::with_capacity(callee_mir.visibility_scopes.len());
|
||||
let mut scope_map = IndexVec::with_capacity(callee_mir.source_scopes.len());
|
||||
let mut promoted_map = IndexVec::with_capacity(callee_mir.promoted.len());
|
||||
|
||||
for mut scope in callee_mir.visibility_scopes.iter().cloned() {
|
||||
for mut scope in callee_mir.source_scopes.iter().cloned() {
|
||||
if scope.parent_scope.is_none() {
|
||||
scope.parent_scope = Some(callsite.location.scope);
|
||||
scope.span = callee_mir.span;
|
||||
|
|
@ -391,7 +391,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
|
|||
|
||||
scope.span = callsite.location.span;
|
||||
|
||||
let idx = caller_mir.visibility_scopes.push(scope);
|
||||
let idx = caller_mir.source_scopes.push(scope);
|
||||
scope_map.push(idx);
|
||||
}
|
||||
|
||||
|
|
@ -618,7 +618,7 @@ struct Integrator<'a, 'tcx: 'a> {
|
|||
block_idx: usize,
|
||||
args: &'a [Local],
|
||||
local_map: IndexVec<Local, Local>,
|
||||
scope_map: IndexVec<VisibilityScope, VisibilityScope>,
|
||||
scope_map: IndexVec<SourceScope, SourceScope>,
|
||||
promoted_map: IndexVec<Promoted, Promoted>,
|
||||
_callsite: CallSite<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
|
|
@ -745,7 +745,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_visibility_scope(&mut self, scope: &mut VisibilityScope) {
|
||||
fn visit_source_scope(&mut self, scope: &mut SourceScope) {
|
||||
*scope = self.scope_map[*scope];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
terminator: Some(Terminator {
|
||||
source_info: SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
kind: TerminatorKind::Return
|
||||
}),
|
||||
|
|
@ -181,7 +181,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
data.statements.push(Statement {
|
||||
source_info: SourceInfo {
|
||||
span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
kind: StatementKind::Assign(Place::Local(dest), rvalue)
|
||||
});
|
||||
|
|
@ -424,8 +424,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
|
|||
IndexVec::new(),
|
||||
// FIXME: maybe try to filter this to avoid blowing up
|
||||
// memory usage?
|
||||
mir.visibility_scopes.clone(),
|
||||
mir.visibility_scope_info.clone(),
|
||||
mir.source_scopes.clone(),
|
||||
mir.source_scope_info.clone(),
|
||||
IndexVec::new(),
|
||||
None,
|
||||
initial_locals,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ impl<'tcx> MirPatch<'tcx> {
|
|||
terminator: Some(Terminator {
|
||||
source_info: SourceInfo {
|
||||
span: mir.span,
|
||||
scope: ARGUMENT_VISIBILITY_SCOPE
|
||||
scope: OUTERMOST_SOURCE_SCOPE
|
||||
},
|
||||
kind: TerminatorKind::Resume
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -447,9 +447,9 @@ fn comment(tcx: TyCtxt, SourceInfo { span, scope }: SourceInfo) -> String {
|
|||
fn write_scope_tree(
|
||||
tcx: TyCtxt,
|
||||
mir: &Mir,
|
||||
scope_tree: &FxHashMap<VisibilityScope, Vec<VisibilityScope>>,
|
||||
scope_tree: &FxHashMap<SourceScope, Vec<SourceScope>>,
|
||||
w: &mut dyn Write,
|
||||
parent: VisibilityScope,
|
||||
parent: SourceScope,
|
||||
depth: usize,
|
||||
) -> io::Result<()> {
|
||||
let indent = depth * INDENT.len();
|
||||
|
|
@ -460,7 +460,7 @@ fn write_scope_tree(
|
|||
};
|
||||
|
||||
for &child in children {
|
||||
let data = &mir.visibility_scopes[child];
|
||||
let data = &mir.source_scopes[child];
|
||||
assert_eq!(data.parent_scope, Some(parent));
|
||||
writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?;
|
||||
|
||||
|
|
@ -519,16 +519,16 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>(
|
|||
writeln!(w, "{{")?;
|
||||
|
||||
// construct a scope tree and write it out
|
||||
let mut scope_tree: FxHashMap<VisibilityScope, Vec<VisibilityScope>> = FxHashMap();
|
||||
for (index, scope_data) in mir.visibility_scopes.iter().enumerate() {
|
||||
let mut scope_tree: FxHashMap<SourceScope, Vec<SourceScope>> = FxHashMap();
|
||||
for (index, scope_data) in mir.source_scopes.iter().enumerate() {
|
||||
if let Some(parent) = scope_data.parent_scope {
|
||||
scope_tree
|
||||
.entry(parent)
|
||||
.or_insert(vec![])
|
||||
.push(VisibilityScope::new(index));
|
||||
.push(SourceScope::new(index));
|
||||
} else {
|
||||
// Only the argument scope has no parent, because it's the root.
|
||||
assert_eq!(index, ARGUMENT_VISIBILITY_SCOPE.index());
|
||||
assert_eq!(index, OUTERMOST_SOURCE_SCOPE.index());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -541,7 +541,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>(
|
|||
indented_retptr,
|
||||
ALIGN)?;
|
||||
|
||||
write_scope_tree(tcx, mir, &scope_tree, w, ARGUMENT_VISIBILITY_SCOPE, 1)?;
|
||||
write_scope_tree(tcx, mir, &scope_tree, w, OUTERMOST_SOURCE_SCOPE, 1)?;
|
||||
|
||||
write_temp_decls(mir, w)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use rustc::mir::{Constant, Literal, Location, Local, LocalDecl};
|
|||
use rustc::mir::{Place, PlaceElem, PlaceProjection};
|
||||
use rustc::mir::{Mir, Operand, ProjectionElem};
|
||||
use rustc::mir::{Rvalue, SourceInfo, Statement, StatementKind};
|
||||
use rustc::mir::{Terminator, TerminatorKind, VisibilityScope, VisibilityScopeData};
|
||||
use rustc::mir::{Terminator, TerminatorKind, SourceScope, SourceScopeData};
|
||||
use rustc::mir::interpret::EvalErrorKind;
|
||||
use rustc::mir::visit as mir_visit;
|
||||
use rustc::ty::{self, ClosureSubsts, TyCtxt};
|
||||
|
|
@ -72,10 +72,10 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
|
|||
self.super_basic_block_data(block, data);
|
||||
}
|
||||
|
||||
fn visit_visibility_scope_data(&mut self,
|
||||
scope_data: &VisibilityScopeData) {
|
||||
self.record("VisibilityScopeData", scope_data);
|
||||
self.super_visibility_scope_data(scope_data);
|
||||
fn visit_source_scope_data(&mut self,
|
||||
scope_data: &SourceScopeData) {
|
||||
self.record("SourceScopeData", scope_data);
|
||||
self.super_source_scope_data(scope_data);
|
||||
}
|
||||
|
||||
fn visit_statement(&mut self,
|
||||
|
|
@ -278,9 +278,9 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
|
|||
self.super_local_decl(local, local_decl);
|
||||
}
|
||||
|
||||
fn visit_visibility_scope(&mut self,
|
||||
scope: &VisibilityScope) {
|
||||
fn visit_source_scope(&mut self,
|
||||
scope: &SourceScope) {
|
||||
self.record("VisiblityScope", scope);
|
||||
self.super_visibility_scope(scope);
|
||||
self.super_source_scope(scope);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue