Skip to content
8 changes: 4 additions & 4 deletions src/librustc/ich/impls_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
ty,
name,
source_info,
visibility_scope,
internal,
syntactic_scope,
is_user_variable
});
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref, mutability });
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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::SourceScopeLocalData {
lint_root, safety
});

Expand Down
106 changes: 54 additions & 52 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,

/// 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
Expand Down Expand Up @@ -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_local_data: ClearCrossCrate<IndexVec<SourceScope,
SourceScopeLocalData>>,
promoted: IndexVec<Promoted, Mir<'tcx>>,
yield_ty: Option<Ty<'tcx>>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
Expand All @@ -153,8 +153,8 @@ impl<'tcx> Mir<'tcx> {

Mir {
basic_blocks,
visibility_scopes,
visibility_scope_info,
source_scopes,
source_scope_local_data,
promoted,
yield_ty,
generator_drop: None,
Expand Down Expand Up @@ -308,14 +308,6 @@ impl<'tcx> Mir<'tcx> {
}
}

#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct VisibilityScopeInfo {
/// A NodeId with lint levels equivalent to this scope's lint levels.
pub lint_root: ast::NodeId,
/// The unsafe block that contains this node.
pub safety: Safety,
}

#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum Safety {
Safe,
Expand All @@ -329,8 +321,8 @@ pub enum Safety {

impl_stable_hash_for!(struct Mir<'tcx> {
basic_blocks,
visibility_scopes,
visibility_scope_info,
source_scopes,
source_scope_local_data,
promoted,
yield_ty,
generator_drop,
Expand Down Expand Up @@ -376,8 +368,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
}

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -512,16 +505,13 @@ pub struct LocalDecl<'tcx> {
/// to generate better debuginfo.
pub name: Option<Name>,

/// Source info of the local.
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
Expand Down Expand Up @@ -566,9 +556,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 `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 `visibility_scope` represents the "local variable"
/// scope (where the "rest" of a block is under all prior let-statements).
///
/// The end result looks like this:
Expand All @@ -580,21 +570,25 @@ pub struct LocalDecl<'tcx> {
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
/// │ │ // in practice because I'm lazy.
/// │ │
/// │ │← x.syntactic_scope
/// │ │← x.source_info.scope
/// │ │← `x.parse().unwrap()`
/// │ │
/// │ │ │← y.syntactic_scope
/// │ │ │← y.source_info.scope
/// │ │
/// │ │ │{ let y: u32 }
/// │ │ │
/// │ │ │← y.source_info.scope
/// │ │ │← y.visibility_scope
/// │ │ │← `y + 2`
/// │
/// │ │{ let x: u32 }
/// │ │← x.source_info.scope
/// │ │← x.visibility_scope
/// │ │← `drop(x)` // this accesses `x: u32`
/// ```
pub syntactic_scope: VisibilityScope,
pub source_info: SourceInfo,

/// Source scope within which the local is visible (for debuginfo)
/// (see `source_info` for more details).
pub visibility_scope: SourceScope,
}

impl<'tcx> LocalDecl<'tcx> {
Expand All @@ -607,9 +601,9 @@ impl<'tcx> LocalDecl<'tcx> {
name: None,
source_info: SourceInfo {
span,
scope: ARGUMENT_VISIBILITY_SCOPE
scope: OUTERMOST_SOURCE_SCOPE
},
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
visibility_scope: OUTERMOST_SOURCE_SCOPE,
internal: false,
is_user_variable: false
}
Expand All @@ -624,9 +618,9 @@ impl<'tcx> LocalDecl<'tcx> {
name: None,
source_info: SourceInfo {
span,
scope: ARGUMENT_VISIBILITY_SCOPE
scope: OUTERMOST_SOURCE_SCOPE
},
syntactic_scope: ARGUMENT_VISIBILITY_SCOPE,
visibility_scope: OUTERMOST_SOURCE_SCOPE,
internal: true,
is_user_variable: false
}
Expand All @@ -642,9 +636,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,
visibility_scope: OUTERMOST_SOURCE_SCOPE,
internal: false,
name: None, // FIXME maybe we do want some name here?
is_user_variable: false
Expand Down Expand Up @@ -1047,7 +1041,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
});
Expand Down Expand Up @@ -1501,16 +1495,24 @@ 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>,
}

#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct SourceScopeLocalData {
/// A NodeId with lint levels equivalent to this scope's lint levels.
pub lint_root: ast::NodeId,
/// The unsafe block that contains this node.
pub safety: Safety,
}

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2153,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! {
SourceInfo,
UpvarDecl,
ValidationOp,
VisibilityScopeData,
VisibilityScope,
VisibilityScopeInfo,
SourceScope,
SourceScopeData,
SourceScopeLocalData,
}

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
basic_blocks,
visibility_scopes,
visibility_scope_info,
source_scopes,
source_scope_local_data,
promoted,
yield_ty,
generator_drop,
Expand Down Expand Up @@ -2190,7 +2192,7 @@ BraceStructTypeFoldableImpl! {
ty,
name,
source_info,
syntactic_scope,
visibility_scope,
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
}));
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -715,8 +715,8 @@ macro_rules! make_mir_visitor {
ref $($mutability)* ty,
name: _,
ref $($mutability)* source_info,
ref $($mutability)* visibility_scope,
internal: _,
ref $($mutability)* syntactic_scope,
is_user_variable: _,
} = *local_decl;

Expand All @@ -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(visibility_scope);
}

fn super_visibility_scope(&mut self,
_scope: & $($mutability)* VisibilityScope) {
fn super_source_scope(&mut self,
_scope: & $($mutability)* SourceScope) {
}

fn super_branch(&mut self,
Expand Down Expand Up @@ -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>) {
Expand Down
Loading