Skip to content

Commit d775570

Browse files
committed
Remove scope_auxiliary.
This reduces the peak RSS for a cut-down version of the program in #36799 by 10%, from 951MB to 856MB.
1 parent ea02f87 commit d775570

File tree

7 files changed

+30
-129
lines changed

7 files changed

+30
-129
lines changed

src/librustc_mir/build/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5454
let tcx = this.hir.tcx();
5555

5656
// Enter the remainder scope, i.e. the bindings' destruction scope.
57-
this.push_scope(remainder_scope, block);
57+
this.push_scope(remainder_scope);
5858
let_extent_stack.push(remainder_scope);
5959

6060
// Declare the bindings, which may create a visibility scope.

src/librustc_mir/build/cfg.rs

-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ impl<'tcx> CFG<'tcx> {
4040
self.block_data_mut(block).statements.push(statement);
4141
}
4242

43-
pub fn current_location(&mut self, block: BasicBlock) -> Location {
44-
let index = self.block_data(block).statements.len();
45-
Location { block: block, statement_index: index }
46-
}
47-
4843
pub fn push_assign(&mut self,
4944
block: BasicBlock,
5045
source_info: SourceInfo,

src/librustc_mir/build/mod.rs

+14-46
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ pub struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
3636
/// see the `scope` module for more details
3737
scopes: Vec<scope::Scope<'tcx>>,
3838

39-
/// for each scope, a span of blocks that defines it;
40-
/// we track these for use in region and borrow checking,
41-
/// but these are liable to get out of date once optimization
42-
/// begins. They are also hopefully temporary, and will be
43-
/// no longer needed when we adopt graph-based regions.
44-
scope_auxiliary: IndexVec<ScopeId, ScopeAuxiliary>,
45-
4639
/// the current set of loops; see the `scope` module for more
4740
/// details
4841
loop_scopes: Vec<scope::LoopScope>,
@@ -82,30 +75,6 @@ impl Idx for ScopeId {
8275
}
8376
}
8477

85-
/// For each scope, we track the extent (from the HIR) and a
86-
/// single-entry-multiple-exit subgraph that contains all the
87-
/// statements/terminators within it.
88-
///
89-
/// This information is separated out from the main `ScopeData`
90-
/// because it is short-lived. First, the extent contains node-ids,
91-
/// so it cannot be saved and re-loaded. Second, any optimization will mess up
92-
/// the dominator/postdominator information.
93-
///
94-
/// The intention is basically to use this information to do
95-
/// regionck/borrowck and then throw it away once we are done.
96-
pub struct ScopeAuxiliary {
97-
/// extent of this scope from the MIR.
98-
pub extent: CodeExtent,
99-
100-
/// "entry point": dominator of all nodes in the scope
101-
pub dom: Location,
102-
103-
/// "exit points": mutual postdominators of all nodes in the scope
104-
pub postdoms: Vec<Location>,
105-
}
106-
107-
pub type ScopeAuxiliaryVec = IndexVec<ScopeId, ScopeAuxiliary>;
108-
10978
///////////////////////////////////////////////////////////////////////////
11079
/// The `BlockAnd` "monad" packages up the new basic block along with a
11180
/// produced value (sometimes just unit, of course). The `unpack!`
@@ -158,7 +127,7 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
158127
abi: Abi,
159128
return_ty: Ty<'gcx>,
160129
ast_body: &'gcx hir::Expr)
161-
-> (Mir<'tcx>, ScopeAuxiliaryVec)
130+
-> Mir<'tcx>
162131
where A: Iterator<Item=(Ty<'gcx>, Option<&'gcx hir::Pat>)>
163132
{
164133
let arguments: Vec<_> = arguments.collect();
@@ -221,15 +190,15 @@ pub fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
221190
}).collect()
222191
});
223192

224-
let (mut mir, aux) = builder.finish(upvar_decls, return_ty);
193+
let mut mir = builder.finish(upvar_decls, return_ty);
225194
mir.spread_arg = spread_arg;
226-
(mir, aux)
195+
mir
227196
}
228197

229198
pub fn construct_const<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
230199
item_id: ast::NodeId,
231200
ast_expr: &'tcx hir::Expr)
232-
-> (Mir<'tcx>, ScopeAuxiliaryVec) {
201+
-> Mir<'tcx> {
233202
let tcx = hir.tcx();
234203
let ty = tcx.tables().expr_ty_adjusted(ast_expr);
235204
let span = tcx.map.span(item_id);
@@ -269,7 +238,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
269238
scopes: vec![],
270239
visibility_scopes: IndexVec::new(),
271240
visibility_scope: ARGUMENT_VISIBILITY_SCOPE,
272-
scope_auxiliary: IndexVec::new(),
273241
loop_scopes: vec![],
274242
local_decls: IndexVec::from_elem_n(LocalDecl::new_return_pointer(return_ty), 1),
275243
var_indices: NodeMap(),
@@ -288,22 +256,22 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
288256
fn finish(self,
289257
upvar_decls: Vec<UpvarDecl>,
290258
return_ty: Ty<'tcx>)
291-
-> (Mir<'tcx>, ScopeAuxiliaryVec) {
259+
-> Mir<'tcx> {
292260
for (index, block) in self.cfg.basic_blocks.iter().enumerate() {
293261
if block.terminator.is_none() {
294262
span_bug!(self.fn_span, "no terminator on block {:?}", index);
295263
}
296264
}
297265

298-
(Mir::new(self.cfg.basic_blocks,
299-
self.visibility_scopes,
300-
IndexVec::new(),
301-
return_ty,
302-
self.local_decls,
303-
self.arg_count,
304-
upvar_decls,
305-
self.fn_span
306-
), self.scope_auxiliary)
266+
Mir::new(self.cfg.basic_blocks,
267+
self.visibility_scopes,
268+
IndexVec::new(),
269+
return_ty,
270+
self.local_decls,
271+
self.arg_count,
272+
upvar_decls,
273+
self.fn_span
274+
)
307275
}
308276

309277
fn args_and_body(&mut self,

src/librustc_mir/build/scope.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ should go to.
8686
8787
*/
8888

89-
use build::{BlockAnd, BlockAndExtension, Builder, CFG, ScopeAuxiliary, ScopeId};
89+
use build::{BlockAnd, BlockAndExtension, Builder, CFG};
9090
use rustc::middle::region::{CodeExtent, CodeExtentData};
9191
use rustc::middle::lang_items;
9292
use rustc::ty::subst::{Kind, Subst};
@@ -97,14 +97,10 @@ use rustc_data_structures::indexed_vec::Idx;
9797
use rustc_data_structures::fx::FxHashMap;
9898

9999
pub struct Scope<'tcx> {
100-
/// the scope-id within the scope_auxiliary
101-
id: ScopeId,
102-
103100
/// The visibility scope this scope was created in.
104101
visibility_scope: VisibilityScope,
105102

106-
/// the extent of this scope within source code; also stored in
107-
/// `ScopeAuxiliary`, but kept here for convenience
103+
/// the extent of this scope within source code.
108104
extent: CodeExtent,
109105

110106
/// Whether there's anything to do for the cleanup path, that is,
@@ -276,7 +272,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
276272
where F: FnOnce(&mut Builder<'a, 'gcx, 'tcx>) -> BlockAnd<R>
277273
{
278274
debug!("in_scope(extent={:?}, block={:?})", extent, block);
279-
self.push_scope(extent, block);
275+
self.push_scope(extent);
280276
let rv = unpack!(block = f(self));
281277
unpack!(block = self.pop_scope(extent, block));
282278
debug!("in_scope: exiting extent={:?} block={:?}", extent, block);
@@ -287,24 +283,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
287283
/// scope and call `pop_scope` afterwards. Note that these two
288284
/// calls must be paired; using `in_scope` as a convenience
289285
/// wrapper maybe preferable.
290-
pub fn push_scope(&mut self, extent: CodeExtent, entry: BasicBlock) {
286+
pub fn push_scope(&mut self, extent: CodeExtent) {
291287
debug!("push_scope({:?})", extent);
292-
let id = ScopeId::new(self.scope_auxiliary.len());
293288
let vis_scope = self.visibility_scope;
294289
self.scopes.push(Scope {
295-
id: id,
296290
visibility_scope: vis_scope,
297291
extent: extent,
298292
needs_cleanup: false,
299293
drops: vec![],
300294
free: None,
301295
cached_exits: FxHashMap()
302296
});
303-
self.scope_auxiliary.push(ScopeAuxiliary {
304-
extent: extent,
305-
dom: self.cfg.current_location(entry),
306-
postdoms: vec![]
307-
});
308297
}
309298

310299
/// Pops a scope, which should have extent `extent`, adding any
@@ -325,9 +314,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
325314
&self.scopes,
326315
block,
327316
self.arg_count));
328-
self.scope_auxiliary[scope.id]
329-
.postdoms
330-
.push(self.cfg.current_location(block));
331317
block.unit()
332318
}
333319

@@ -375,9 +361,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
375361
self.cfg.terminate(block, scope.source_info(span), free);
376362
block = next;
377363
}
378-
self.scope_auxiliary[scope.id]
379-
.postdoms
380-
.push(self.cfg.current_location(block));
381364
}
382365
}
383366
let scope = &self.scopes[len - scope_count];

src/librustc_mir/mir_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ impl<'a, 'gcx, 'tcx> BuildMir<'a, 'gcx> {
103103

104104
impl<'a, 'gcx, 'tcx> CxBuilder<'a, 'gcx, 'tcx> {
105105
fn build<F>(&'tcx mut self, f: F)
106-
where F: for<'b> FnOnce(Cx<'b, 'gcx, 'tcx>) -> (Mir<'tcx>, build::ScopeAuxiliaryVec)
106+
where F: for<'b> FnOnce(Cx<'b, 'gcx, 'tcx>) -> Mir<'tcx>
107107
{
108108
let (src, def_id) = (self.src, self.def_id);
109109
self.infcx.enter(|infcx| {
110-
let (mut mir, scope_auxiliary) = f(Cx::new(&infcx, src));
110+
let mut mir = f(Cx::new(&infcx, src));
111111

112112
// Convert the Mir to global types.
113113
let tcx = infcx.tcx.global_tcx();
@@ -120,7 +120,7 @@ impl<'a, 'gcx, 'tcx> CxBuilder<'a, 'gcx, 'tcx> {
120120
mem::transmute::<Mir, Mir<'gcx>>(mir)
121121
};
122122

123-
pretty::dump_mir(tcx, "mir_map", &0, src, &mir, Some(&scope_auxiliary));
123+
pretty::dump_mir(tcx, "mir_map", &0, src, &mir);
124124

125125
let mir = tcx.alloc_mir(mir);
126126
assert!(tcx.mir_map.borrow_mut().insert(def_id, mir).is_none());

src/librustc_mir/pretty.rs

+7-51
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use build::{ScopeAuxiliaryVec, ScopeId};
1211
use rustc::hir;
1312
use rustc::hir::def_id::DefId;
1413
use rustc::mir::*;
@@ -43,8 +42,7 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4342
pass_name: &str,
4443
disambiguator: &Display,
4544
src: MirSource,
46-
mir: &Mir<'tcx>,
47-
auxiliary: Option<&ScopeAuxiliaryVec>) {
45+
mir: &Mir<'tcx>) {
4846
let filters = match tcx.sess.opts.debugging_opts.dump_mir {
4947
None => return,
5048
Some(ref filters) => filters,
@@ -81,7 +79,7 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
8179
writeln!(file, "// pass_name = {}", pass_name)?;
8280
writeln!(file, "// disambiguator = {}", disambiguator)?;
8381
writeln!(file, "")?;
84-
write_mir_fn(tcx, src, mir, &mut file, auxiliary)?;
82+
write_mir_fn(tcx, src, mir, &mut file)?;
8583
Ok(())
8684
});
8785
}
@@ -106,52 +104,24 @@ pub fn write_mir_pretty<'a, 'b, 'tcx, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
106104

107105
let id = tcx.map.as_local_node_id(def_id).unwrap();
108106
let src = MirSource::from_node(tcx, id);
109-
write_mir_fn(tcx, src, mir, w, None)?;
107+
write_mir_fn(tcx, src, mir, w)?;
110108

111109
for (i, mir) in mir.promoted.iter_enumerated() {
112110
writeln!(w, "")?;
113-
write_mir_fn(tcx, MirSource::Promoted(id, i), mir, w, None)?;
111+
write_mir_fn(tcx, MirSource::Promoted(id, i), mir, w)?;
114112
}
115113
}
116114
Ok(())
117115
}
118116

119-
enum Annotation {
120-
EnterScope(ScopeId),
121-
ExitScope(ScopeId),
122-
}
123-
124-
fn scope_entry_exit_annotations(auxiliary: Option<&ScopeAuxiliaryVec>)
125-
-> FxHashMap<Location, Vec<Annotation>>
126-
{
127-
// compute scope/entry exit annotations
128-
let mut annotations = FxHashMap();
129-
if let Some(auxiliary) = auxiliary {
130-
for (scope_id, auxiliary) in auxiliary.iter_enumerated() {
131-
annotations.entry(auxiliary.dom)
132-
.or_insert(vec![])
133-
.push(Annotation::EnterScope(scope_id));
134-
135-
for &loc in &auxiliary.postdoms {
136-
annotations.entry(loc)
137-
.or_insert(vec![])
138-
.push(Annotation::ExitScope(scope_id));
139-
}
140-
}
141-
}
142-
return annotations;
143-
}
144-
145117
pub fn write_mir_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
146118
src: MirSource,
147119
mir: &Mir<'tcx>,
148-
w: &mut Write,
149-
auxiliary: Option<&ScopeAuxiliaryVec>)
120+
w: &mut Write)
150121
-> io::Result<()> {
151-
let annotations = scope_entry_exit_annotations(auxiliary);
152122
write_mir_intro(tcx, src, mir, w)?;
153123
for block in mir.basic_blocks().indices() {
154-
write_basic_block(tcx, block, mir, w, &annotations)?;
124+
write_basic_block(tcx, block, mir, w)?;
155125
if block.index() + 1 != mir.basic_blocks().len() {
156126
writeln!(w, "")?;
157127
}
@@ -165,8 +135,7 @@ pub fn write_mir_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
165135
fn write_basic_block(tcx: TyCtxt,
166136
block: BasicBlock,
167137
mir: &Mir,
168-
w: &mut Write,
169-
annotations: &FxHashMap<Location, Vec<Annotation>>)
138+
w: &mut Write)
170139
-> io::Result<()> {
171140
let data = &mir[block];
172141

@@ -176,19 +145,6 @@ fn write_basic_block(tcx: TyCtxt,
176145
// List of statements in the middle.
177146
let mut current_location = Location { block: block, statement_index: 0 };
178147
for statement in &data.statements {
179-
if let Some(ref annotations) = annotations.get(&current_location) {
180-
for annotation in annotations.iter() {
181-
match *annotation {
182-
Annotation::EnterScope(id) =>
183-
writeln!(w, "{0}{0}// Enter Scope({1})",
184-
INDENT, id.index())?,
185-
Annotation::ExitScope(id) =>
186-
writeln!(w, "{0}{0}// Exit Scope({1})",
187-
INDENT, id.index())?,
188-
}
189-
}
190-
}
191-
192148
let indented_mir = format!("{0}{0}{1:?};", INDENT, statement);
193149
writeln!(w, "{0:1$} // {2}",
194150
indented_mir,

src/librustc_mir/transform/dump_mir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl<'tcx> MirPassHook<'tcx> for DumpMir {
6464
is_after: is_after
6565
},
6666
src,
67-
mir,
68-
None
67+
mir
6968
);
7069
}
7170
}

0 commit comments

Comments
 (0)