Skip to content

Commit a9976d8

Browse files
committed
rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.
1 parent 78d85fc commit a9976d8

File tree

11 files changed

+35
-44
lines changed

11 files changed

+35
-44
lines changed

src/librustc/mir/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ pub struct Body<'tcx> {
104104
/// and used for debuginfo. Indexed by a `SourceScope`.
105105
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,
106106

107-
/// Crate-local information for each source scope, that can't (and
108-
/// needn't) be tracked across crates.
109-
pub source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
110-
111107
/// The yield type of the function, if it is a generator.
112108
pub yield_ty: Option<Ty<'tcx>>,
113109

@@ -167,7 +163,6 @@ impl<'tcx> Body<'tcx> {
167163
pub fn new(
168164
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
169165
source_scopes: IndexVec<SourceScope, SourceScopeData>,
170-
source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
171166
local_decls: LocalDecls<'tcx>,
172167
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
173168
arg_count: usize,
@@ -188,7 +183,6 @@ impl<'tcx> Body<'tcx> {
188183
phase: MirPhase::Build,
189184
basic_blocks,
190185
source_scopes,
191-
source_scope_local_data,
192186
yield_ty: None,
193187
generator_drop: None,
194188
generator_layout: None,
@@ -2034,6 +2028,10 @@ rustc_index::newtype_index! {
20342028
pub struct SourceScopeData {
20352029
pub span: Span,
20362030
pub parent_scope: Option<SourceScope>,
2031+
2032+
/// Crate-local information for this source scope, that can't (and
2033+
/// needn't) be tracked across crates.
2034+
pub local_data: ClearCrossCrate<SourceScopeLocalData>,
20372035
}
20382036

20392037
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]

src/librustc/mir/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ macro_rules! make_mir_visitor {
317317
let SourceScopeData {
318318
span,
319319
parent_scope,
320+
local_data: _,
320321
} = scope_data;
321322

322323
self.visit_span(span);

src/librustc_mir/borrow_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'tcx>(
301301
mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow);
302302

303303
let scope = mbcx.body.source_info(location).scope;
304-
let lint_root = match &mbcx.body.source_scope_local_data[scope] {
304+
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
305305
ClearCrossCrate::Set(data) => data.lint_root,
306306
_ => id,
307307
};
@@ -338,7 +338,7 @@ fn do_mir_borrowck<'a, 'tcx>(
338338
let used_mut = mbcx.used_mut;
339339
for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
340340
let local_decl = &mbcx.body.local_decls[local];
341-
let lint_root = match &mbcx.body.source_scope_local_data[local_decl.source_info.scope] {
341+
let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data {
342342
ClearCrossCrate::Set(data) => data.lint_root,
343343
_ => continue,
344344
};

src/librustc_mir/build/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ struct Builder<'a, 'tcx> {
309309
/// The vector of all scopes that we have created thus far;
310310
/// we track this for debuginfo later.
311311
source_scopes: IndexVec<SourceScope, SourceScopeData>,
312-
source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
313312
source_scope: SourceScope,
314313

315314
/// The guard-context: each time we build the guard expression for
@@ -704,7 +703,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
704703
block_context: BlockContext::new(),
705704
source_scopes: IndexVec::new(),
706705
source_scope: OUTERMOST_SOURCE_SCOPE,
707-
source_scope_local_data: IndexVec::new(),
708706
guard_context: vec![],
709707
push_unsafe_count: 0,
710708
unpushed_unsafe: safety,
@@ -741,7 +739,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
741739
Body::new(
742740
self.cfg.basic_blocks,
743741
self.source_scopes,
744-
self.source_scope_local_data,
745742
self.local_decls,
746743
self.canonical_user_type_annotations,
747744
self.arg_count,
@@ -942,7 +939,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
942939
self.hir.root_lint_level
943940
);
944941
let parent_root = tcx.maybe_lint_level_root_bounded(
945-
self.source_scope_local_data[original_source_scope]
942+
self.source_scopes[original_source_scope]
943+
.local_data
946944
.as_ref()
947945
.assert_crate_local()
948946
.lint_root,

src/librustc_mir/build/scope.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
436436
// We estimate the true lint roots here to avoid creating a lot of source scopes.
437437

438438
let parent_root = tcx.maybe_lint_level_root_bounded(
439-
self.source_scope_local_data[source_scope]
439+
self.source_scopes[source_scope]
440+
.local_data
440441
.as_ref()
441442
.assert_crate_local()
442443
.lint_root,
@@ -657,23 +658,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
657658
let parent = self.source_scope;
658659
debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
659660
span, lint_level, safety,
660-
parent, self.source_scope_local_data.get(parent));
661-
let scope = self.source_scopes.push(SourceScopeData {
662-
span,
663-
parent_scope: Some(parent),
664-
});
661+
parent, self.source_scopes.get(parent));
665662
let scope_local_data = SourceScopeLocalData {
666663
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
667664
lint_root
668665
} else {
669-
self.source_scope_local_data[parent].as_ref().assert_crate_local().lint_root
666+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root
670667
},
671668
safety: safety.unwrap_or_else(|| {
672-
self.source_scope_local_data[parent].as_ref().assert_crate_local().safety
669+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().safety
673670
})
674671
};
675-
self.source_scope_local_data.push(ClearCrossCrate::Set(scope_local_data));
676-
scope
672+
self.source_scopes.push(SourceScopeData {
673+
span,
674+
parent_scope: Some(parent),
675+
local_data: ClearCrossCrate::Set(scope_local_data),
676+
})
677677
}
678678

679679
/// Given a span and the current source scope, make a SourceInfo.

src/librustc_mir/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
849849
} else {
850850
block.terminator().source_info
851851
};
852-
match &body.source_scope_local_data[source_info.scope] {
852+
match &body.source_scopes[source_info.scope].local_data {
853853
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
854854
mir::ClearCrossCrate::Clear => None,
855855
}

src/librustc_mir/shim.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,8 @@ fn new_body<'tcx>(
248248
Body::new(
249249
basic_blocks,
250250
IndexVec::from_elem_n(
251-
SourceScopeData { span, parent_scope: None }, 1
252-
),
253-
IndexVec::from_elem_n(
254-
ClearCrossCrate::Clear, 1
251+
SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear },
252+
1,
255253
),
256254
local_decls,
257255
IndexVec::new(),

src/librustc_mir/transform/check_unsafety.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
214214
if context.is_borrow() {
215215
if util::is_disaligned(self.tcx, self.body, self.param_env, place) {
216216
let source_info = self.source_info;
217-
let lint_root = self.body.source_scope_local_data[source_info.scope]
217+
let lint_root = self.body.source_scopes[source_info.scope]
218+
.local_data
218219
.as_ref()
219220
.assert_crate_local()
220221
.lint_root;
@@ -343,7 +344,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
343344
fn register_violations(&mut self,
344345
violations: &[UnsafetyViolation],
345346
unsafe_blocks: &[(hir::HirId, bool)]) {
346-
let safety = self.body.source_scope_local_data[self.source_info.scope]
347+
let safety = self.body.source_scopes[self.source_info.scope]
348+
.local_data
347349
.as_ref()
348350
.assert_crate_local()
349351
.safety;

src/librustc_mir/transform/const_prop.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::hir::def_id::DefId;
99
use rustc::mir::{
1010
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue, Local, UnOp,
1111
StatementKind, Statement, LocalKind, TerminatorKind, Terminator, ClearCrossCrate, SourceInfo,
12-
BinOp, SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock, RETURN_PLACE,
12+
BinOp, SourceScope, SourceScopeData, LocalDecl, BasicBlock, RETURN_PLACE,
1313
};
1414
use rustc::mir::visit::{
1515
Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext,
@@ -77,8 +77,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
7777
let dummy_body =
7878
&Body::new(
7979
body.basic_blocks().clone(),
80-
Default::default(),
81-
body.source_scope_local_data.clone(),
80+
body.source_scopes.clone(),
8281
body.local_decls.clone(),
8382
Default::default(),
8483
body.arg_count,
@@ -254,7 +253,7 @@ struct ConstPropagator<'mir, 'tcx> {
254253
param_env: ParamEnv<'tcx>,
255254
// FIXME(eddyb) avoid cloning these two fields more than once,
256255
// by accessing them through `ecx` instead.
257-
source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
256+
source_scopes: IndexVec<SourceScope, SourceScopeData>,
258257
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
259258
ret: Option<OpTy<'tcx, ()>>,
260259
}
@@ -325,7 +324,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
325324
can_const_prop,
326325
// FIXME(eddyb) avoid cloning these two fields more than once,
327326
// by accessing them through `ecx` instead.
328-
source_scope_local_data: body.source_scope_local_data.clone(),
327+
source_scopes: body.source_scopes.clone(),
329328
//FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it
330329
local_decls: body.local_decls.clone(),
331330
ret: ret.map(Into::into),
@@ -362,9 +361,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
362361
{
363362
self.ecx.tcx.span = source_info.span;
364363
// FIXME(eddyb) move this to the `Panic(_)` error case, so that
365-
// `f(self)` is always called, and that the only difference when
366-
// `source_scope_local_data` is missing, is that the lint isn't emitted.
367-
let lint_root = match &self.source_scope_local_data[source_info.scope] {
364+
// `f(self)` is always called, and that the only difference when the
365+
// scope's `local_data` is missing, is that the lint isn't emitted.
366+
let lint_root = match &self.source_scopes[source_info.scope].local_data {
368367
ClearCrossCrate::Set(data) => data.lint_root,
369368
ClearCrossCrate::Clear => return None,
370369
};
@@ -489,7 +488,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
489488
let right_size = r.layout.size;
490489
let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size));
491490
if r_bits.ok().map_or(false, |b| b >= left_bits as u128) {
492-
let lint_root = match &self.source_scope_local_data[source_info.scope] {
491+
let lint_root = match &self.source_scopes[source_info.scope].local_data {
493492
ClearCrossCrate::Set(data) => data.lint_root,
494493
ClearCrossCrate::Clear => return None,
495494
};

src/librustc_mir/transform/inline.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ impl Inliner<'tcx> {
388388
let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len());
389389
let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len());
390390

391-
for (callee_idx, scope) in callee_body.source_scopes.iter_enumerated() {
392-
let mut scope = scope.clone();
391+
for mut scope in callee_body.source_scopes.iter().cloned() {
393392
if scope.parent_scope.is_none() {
394393
scope.parent_scope = Some(callsite.location.scope);
395394
// FIXME(eddyb) is this really needed?
@@ -404,9 +403,6 @@ impl Inliner<'tcx> {
404403

405404
let idx = caller_body.source_scopes.push(scope);
406405
scope_map.push(idx);
407-
408-
let local_data = callee_body.source_scope_local_data[callee_idx].clone();
409-
assert_eq!(idx, caller_body.source_scope_local_data.push(local_data));
410406
}
411407

412408
for loc in callee_body.vars_and_temps_iter() {

src/librustc_mir/transform/promote_consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,6 @@ pub fn promote_candidates<'tcx>(
10811081
// FIXME: maybe try to filter this to avoid blowing up
10821082
// memory usage?
10831083
body.source_scopes.clone(),
1084-
body.source_scope_local_data.clone(),
10851084
initial_locals,
10861085
IndexVec::new(),
10871086
0,

0 commit comments

Comments
 (0)