Skip to content

Commit 3aead85

Browse files
committed
rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.
1 parent 314f8d5 commit 3aead85

File tree

11 files changed

+45
-56
lines changed

11 files changed

+45
-56
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

@@ -163,7 +159,6 @@ impl<'tcx> Body<'tcx> {
163159
pub fn new(
164160
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
165161
source_scopes: IndexVec<SourceScope, SourceScopeData>,
166-
source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
167162
local_decls: LocalDecls<'tcx>,
168163
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
169164
arg_count: usize,
@@ -183,7 +178,6 @@ impl<'tcx> Body<'tcx> {
183178
phase: MirPhase::Build,
184179
basic_blocks,
185180
source_scopes,
186-
source_scope_local_data,
187181
yield_ty: None,
188182
generator_drop: None,
189183
generator_layout: None,
@@ -2028,6 +2022,10 @@ rustc_index::newtype_index! {
20282022
pub struct SourceScopeData {
20292023
pub span: Span,
20302024
pub parent_scope: Option<SourceScope>,
2025+
2026+
/// Crate-local information for this source scope, that can't (and
2027+
/// needn't) be tracked across crates.
2028+
pub local_data: ClearCrossCrate<SourceScopeLocalData>,
20312029
}
20322030

20332031
#[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,
@@ -941,7 +938,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
941938
self.hir.root_lint_level
942939
);
943940
let parent_root = tcx.maybe_lint_level_root_bounded(
944-
self.source_scope_local_data[original_source_scope]
941+
self.source_scopes[original_source_scope]
942+
.local_data
945943
.as_ref()
946944
.assert_crate_local()
947945
.lint_root,

src/librustc_mir/build/scope.rs

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

432432
let parent_root = tcx.maybe_lint_level_root_bounded(
433-
self.source_scope_local_data[source_scope]
433+
self.source_scopes[source_scope]
434+
.local_data
434435
.as_ref()
435436
.assert_crate_local()
436437
.lint_root,
@@ -651,23 +652,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
651652
let parent = self.source_scope;
652653
debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
653654
span, lint_level, safety,
654-
parent, self.source_scope_local_data.get(parent));
655-
let scope = self.source_scopes.push(SourceScopeData {
656-
span,
657-
parent_scope: Some(parent),
658-
});
655+
parent, self.source_scopes.get(parent));
659656
let scope_local_data = SourceScopeLocalData {
660657
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
661658
lint_root
662659
} else {
663-
self.source_scope_local_data[parent].as_ref().assert_crate_local().lint_root
660+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root
664661
},
665662
safety: safety.unwrap_or_else(|| {
666-
self.source_scope_local_data[parent].as_ref().assert_crate_local().safety
663+
self.source_scopes[parent].local_data.as_ref().assert_crate_local().safety
667664
})
668665
};
669-
self.source_scope_local_data.push(ClearCrossCrate::Set(scope_local_data));
670-
scope
666+
self.source_scopes.push(SourceScopeData {
667+
span,
668+
parent_scope: Some(parent),
669+
local_data: ClearCrossCrate::Set(scope_local_data),
670+
})
671671
}
672672

673673
/// 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

+12-16
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
199199
let mut body = Body::new(
200200
blocks,
201201
IndexVec::from_elem_n(
202-
SourceScopeData { span: span, parent_scope: None }, 1
203-
),
204-
IndexVec::from_elem_n(
205-
ClearCrossCrate::Clear, 1
202+
SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear },
203+
1,
206204
),
207205
local_decls_for_sig(&sig, span),
208206
IndexVec::new(),
@@ -367,10 +365,12 @@ impl CloneShimBuilder<'tcx> {
367365
Body::new(
368366
self.blocks,
369367
IndexVec::from_elem_n(
370-
SourceScopeData { span: self.span, parent_scope: None }, 1
371-
),
372-
IndexVec::from_elem_n(
373-
ClearCrossCrate::Clear, 1
368+
SourceScopeData {
369+
span: self.span,
370+
parent_scope: None,
371+
local_data: ClearCrossCrate::Clear,
372+
},
373+
1,
374374
),
375375
self.local_decls,
376376
IndexVec::new(),
@@ -829,10 +829,8 @@ fn build_call_shim<'tcx>(
829829
let mut body = Body::new(
830830
blocks,
831831
IndexVec::from_elem_n(
832-
SourceScopeData { span: span, parent_scope: None }, 1
833-
),
834-
IndexVec::from_elem_n(
835-
ClearCrossCrate::Clear, 1
832+
SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear },
833+
1,
836834
),
837835
local_decls,
838836
IndexVec::new(),
@@ -917,10 +915,8 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &Body<'_> {
917915
let body = Body::new(
918916
IndexVec::from_elem_n(start_block, 1),
919917
IndexVec::from_elem_n(
920-
SourceScopeData { span: span, parent_scope: None }, 1
921-
),
922-
IndexVec::from_elem_n(
923-
ClearCrossCrate::Clear, 1
918+
SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear },
919+
1,
924920
),
925921
local_decls,
926922
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,
@@ -253,7 +252,7 @@ struct ConstPropagator<'mir, 'tcx> {
253252
param_env: ParamEnv<'tcx>,
254253
// FIXME(eddyb) avoid cloning these two fields more than once,
255254
// by accessing them through `ecx` instead.
256-
source_scope_local_data: IndexVec<SourceScope, ClearCrossCrate<SourceScopeLocalData>>,
255+
source_scopes: IndexVec<SourceScope, SourceScopeData>,
257256
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
258257
ret: Option<OpTy<'tcx, ()>>,
259258
}
@@ -324,7 +323,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
324323
can_const_prop,
325324
// FIXME(eddyb) avoid cloning these two fields more than once,
326325
// by accessing them through `ecx` instead.
327-
source_scope_local_data: body.source_scope_local_data.clone(),
326+
source_scopes: body.source_scopes.clone(),
328327
//FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it
329328
local_decls: body.local_decls.clone(),
330329
ret: ret.map(Into::into),
@@ -361,9 +360,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
361360
{
362361
self.ecx.tcx.span = source_info.span;
363362
// FIXME(eddyb) move this to the `Panic(_)` error case, so that
364-
// `f(self)` is always called, and that the only difference when
365-
// `source_scope_local_data` is missing, is that the lint isn't emitted.
366-
let lint_root = match &self.source_scope_local_data[source_info.scope] {
363+
// `f(self)` is always called, and that the only difference when the
364+
// scope's `local_data` is missing, is that the lint isn't emitted.
365+
let lint_root = match &self.source_scopes[source_info.scope].local_data {
367366
ClearCrossCrate::Set(data) => data.lint_root,
368367
ClearCrossCrate::Clear => return None,
369368
};
@@ -488,7 +487,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
488487
let right_size = r.layout.size;
489488
let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size));
490489
if r_bits.ok().map_or(false, |b| b >= left_bits as u128) {
491-
let lint_root = match &self.source_scope_local_data[source_info.scope] {
490+
let lint_root = match &self.source_scopes[source_info.scope].local_data {
492491
ClearCrossCrate::Set(data) => data.lint_root,
493492
ClearCrossCrate::Clear => return None,
494493
};

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
@@ -1097,7 +1097,6 @@ pub fn promote_candidates<'tcx>(
10971097
// FIXME: maybe try to filter this to avoid blowing up
10981098
// memory usage?
10991099
body.source_scopes.clone(),
1100-
body.source_scope_local_data.clone(),
11011100
initial_locals,
11021101
IndexVec::new(),
11031102
0,

0 commit comments

Comments
 (0)