Skip to content

Commit

Permalink
rustc: turn mir::LocalDecl's visibility_source_info into a SourceScope.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed May 30, 2018
1 parent 3da186b commit 6c53972
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_mir.rs
Expand Up @@ -26,7 +26,7 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
ty,
name,
syntactic_source_info,
visibility_source_info,
visibility_scope,
internal,
is_user_variable
});
Expand Down
29 changes: 10 additions & 19 deletions src/librustc/mir/mod.rs
Expand Up @@ -558,7 +558,7 @@ pub struct LocalDecl<'tcx> {
/// To allow both uses to work, we need to have more than a single scope
/// 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 `visibility_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 @@ -577,18 +577,18 @@ pub struct LocalDecl<'tcx> {
/// │ │
/// │ │ │{ let y: u32 }
/// │ │ │
/// │ │ │← y.visibility_source_info.scope
/// │ │ │← y.visibility_scope
/// │ │ │← `y + 2`
/// │
/// │ │{ let x: u32 }
/// │ │← x.visibility_source_info.scope
/// │ │← x.visibility_scope
/// │ │← `drop(x)` // this accesses `x: u32`
/// ```
pub syntactic_source_info: SourceInfo,

/// Source info of the local. The `SourceScope` is the *visibility* one,
/// not the the *syntactic* one (see `syntactic_source_info` for more details).
pub visibility_source_info: SourceInfo,
/// Source scope within which the local is visible (for debuginfo)
/// (see `syntactic_source_info` for more details).
pub visibility_scope: SourceScope,
}

impl<'tcx> LocalDecl<'tcx> {
Expand All @@ -603,10 +603,7 @@ impl<'tcx> LocalDecl<'tcx> {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
visibility_source_info: SourceInfo {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
visibility_scope: OUTERMOST_SOURCE_SCOPE,
internal: false,
is_user_variable: false
}
Expand All @@ -623,10 +620,7 @@ impl<'tcx> LocalDecl<'tcx> {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
visibility_source_info: SourceInfo {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
visibility_scope: OUTERMOST_SOURCE_SCOPE,
internal: true,
is_user_variable: false
}
Expand All @@ -644,10 +638,7 @@ impl<'tcx> LocalDecl<'tcx> {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
visibility_source_info: SourceInfo {
span,
scope: OUTERMOST_SOURCE_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 @@ -2201,7 +2192,7 @@ BraceStructTypeFoldableImpl! {
ty,
name,
syntactic_source_info,
visibility_source_info,
visibility_scope,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/visit.rs
Expand Up @@ -715,7 +715,7 @@ macro_rules! make_mir_visitor {
ref $($mutability)* ty,
name: _,
ref $($mutability)* syntactic_source_info,
ref $($mutability)* visibility_source_info,
ref $($mutability)* visibility_scope,
internal: _,
is_user_variable: _,
} = *local_decl;
Expand All @@ -725,7 +725,7 @@ macro_rules! make_mir_visitor {
source_info: *syntactic_source_info,
});
self.visit_source_info(syntactic_source_info);
self.visit_source_info(visibility_source_info);
self.visit_source_scope(visibility_scope);
}

fn super_source_scope(&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Expand Up @@ -65,7 +65,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
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.visibility_source_info.scope.index());
has_variables.insert(decl.visibility_scope.index());
}

// Instantiate all scopes.
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_codegen_llvm/mir/mod.rs
Expand Up @@ -265,7 +265,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(

if let Some(name) = decl.name {
// User variable
let debug_scope = fx.scopes[decl.visibility_source_info.scope];
let debug_scope = fx.scopes[decl.visibility_scope];
let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;

if !memory_locals.contains(local.index()) && !dbg {
Expand All @@ -276,7 +276,10 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
debug!("alloc: {:?} ({}) -> place", local, name);
let place = PlaceRef::alloca(&bx, layout, &name.as_str());
if dbg {
let (scope, span) = fx.debug_loc(decl.visibility_source_info);
let (scope, span) = fx.debug_loc(mir::SourceInfo {
span: decl.syntactic_source_info.span,
scope: decl.visibility_scope,
});
declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
VariableAccess::DirectVariable { alloca: place.llval },
VariableKind::LocalVariable, span);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/error_reporting.rs
Expand Up @@ -398,7 +398,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

let borrow_span = self.mir.source_info(borrow.reserve_location).span;
let proper_span = match *root_place {
Place::Local(local) => self.mir.local_decls[local].visibility_source_info.span,
Place::Local(local) => self.mir.local_decls[local].syntactic_source_info.span,
_ => drop_span,
};

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -306,13 +306,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
None => continue,
}

let source_info = local_decl.visibility_source_info;
let mut_span = tcx.sess.codemap().span_until_non_whitespace(source_info.span);
let span = local_decl.syntactic_source_info.span;
let mut_span = tcx.sess.codemap().span_until_non_whitespace(span);

tcx.struct_span_lint_node(
UNUSED_MUT,
vsi[local_decl.syntactic_source_info.scope].lint_root,
source_info.span,
span,
"variable does not need to be mutable"
)
.span_suggestion_short(mut_span, "remove this `mut`", "".to_owned())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Expand Up @@ -67,7 +67,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}
None => {
err.span_label(
mir.local_decls[local].visibility_source_info.span,
mir.local_decls[local].syntactic_source_info.span,
"borrow may end up in a temporary, created here",
);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/type_check/mod.rs
Expand Up @@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
LocalKind::Var | LocalKind::Temp => {}
}

let span = local_decl.visibility_source_info.span;
let span = local_decl.syntactic_source_info.span;
let ty = local_decl.ty;

// Erase the regions from `ty` to get a global type. The
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/into.rs
Expand Up @@ -247,7 +247,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
ty: ptr_ty,
name: None,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
internal: true,
is_user_variable: false
});
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_mir/build/matches/mod.rs
Expand Up @@ -324,11 +324,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
span,
scope: syntactic_scope,
};
let visibility_source_info = SourceInfo {
span,
scope: visibility_scope.unwrap()
};
this.declare_binding(syntactic_source_info, visibility_source_info, mutability, name, var,
let visibility_scope = visibility_scope.unwrap();
this.declare_binding(syntactic_source_info, visibility_scope, mutability, name, var,
ty, has_guard);
});
visibility_scope
Expand Down Expand Up @@ -1118,24 +1115,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
/// in the arm body, which will have type `T`.
fn declare_binding(&mut self,
syntactic_source_info: SourceInfo,
visibility_source_info: SourceInfo,
visibility_scope: SourceScope,
mutability: Mutability,
name: Name,
var_id: NodeId,
var_ty: Ty<'tcx>,
has_guard: ArmHasGuard)
{
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_source_info={:?}, \
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, visibility_scope={:?}, \
syntactic_source_info={:?})",
var_id, name, var_ty, visibility_source_info, syntactic_source_info);
var_id, name, var_ty, visibility_scope, syntactic_source_info);

let tcx = self.hir.tcx();
let local = LocalDecl::<'tcx> {
mutability,
ty: var_ty.clone(),
name: Some(name),
syntactic_source_info,
visibility_source_info,
visibility_scope,
internal: false,
is_user_variable: true,
};
Expand All @@ -1147,7 +1144,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty),
name: Some(name),
syntactic_source_info,
visibility_source_info,
visibility_scope,
internal: false,
is_user_variable: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/mod.rs
Expand Up @@ -665,7 +665,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
mutability: Mutability::Mut,
ty,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
name,
internal: false,
is_user_variable: false,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/move_paths/builder.rs
Expand Up @@ -233,7 +233,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
fn gather_args(&mut self) {
for arg in self.mir.args_iter() {
let path = self.data.rev_lookup.locals[arg];
let span = self.mir.local_decls[arg].visibility_source_info.span;
let span = self.mir.local_decls[arg].syntactic_source_info.span;

let init = self.data.inits.push(Init {
path, span, kind: InitKind::Deep
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/shim.rs
Expand Up @@ -142,7 +142,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
LocalDecl {
mutability, ty, name: None,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
internal: false,
is_user_variable: false
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/generator.rs
Expand Up @@ -301,7 +301,7 @@ fn replace_result_variable<'tcx>(ret_ty: Ty<'tcx>,
ty: ret_ty,
name: None,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
internal: false,
is_user_variable: false,
};
Expand Down Expand Up @@ -642,7 +642,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
ty: tcx.mk_nil(),
name: None,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
internal: false,
is_user_variable: false,
};
Expand All @@ -658,7 +658,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
}),
name: None,
syntactic_source_info: source_info,
visibility_source_info: source_info,
visibility_scope: source_info.scope,
internal: false,
is_user_variable: false,
};
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/transform/inline.rs
Expand Up @@ -401,9 +401,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
local.syntactic_source_info.scope =
scope_map[local.syntactic_source_info.scope];
local.syntactic_source_info.span = callsite.location.span;
local.visibility_source_info.scope =
scope_map[local.visibility_source_info.scope];
local.visibility_source_info.span = callsite.location.span;
local.visibility_scope = scope_map[local.visibility_scope];

let idx = caller_mir.local_decls.push(local);
local_map.push(idx);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/promote_consts.rs
Expand Up @@ -210,7 +210,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
let no_stmts = self.source[loc.block].statements.len();
let new_temp = self.promoted.local_decls.push(
LocalDecl::new_temp(self.source.local_decls[temp].ty,
self.source.local_decls[temp].visibility_source_info.span));
self.source.local_decls[temp].syntactic_source_info.span));

debug!("promote({:?} @ {:?}/{:?}, {:?})",
temp, loc, no_stmts, self.keep_original);
Expand Down Expand Up @@ -335,7 +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.syntactic_source_info = statement.source_info;
promoted_ref.visibility_source_info = statement.source_info;
promoted_ref.visibility_scope = statement.source_info.scope;
let promoted_ref = local_decls.push(promoted_ref);
assert_eq!(self.temps.push(TempState::Unpromotable), promoted_ref);
self.extra_statements.push((loc, Statement {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -1046,7 +1046,7 @@ This does not pose a problem by itself because they can't be accessed directly."
// conservatively, that drop elaboration will do.
let needs_drop = if let Place::Local(local) = *place {
if self.local_qualif[local].map_or(true, |q| q.intersects(Qualif::NEEDS_DROP)) {
Some(self.mir.local_decls[local].visibility_source_info.span)
Some(self.mir.local_decls[local].syntactic_source_info.span)
} else {
None
}
Expand Down Expand Up @@ -1102,7 +1102,7 @@ This does not pose a problem by itself because they can't be accessed directly."
let mut err = feature_err(
&self.tcx.sess.parse_sess,
"const_let",
decl.visibility_source_info.span,
decl.syntactic_source_info.span,
GateIssue::Language,
"arguments of constant functions can only be immutable by-value bindings"
);
Expand Down

0 comments on commit 6c53972

Please sign in to comment.