Skip to content

Commit 4ca51ae

Browse files
committed
auto merge of #12770 : eddyb/rust/drop-tld, r=cmr
Sadly, this seems to make memory usage worse (unless `Vec<T>` makes it worse and this PR doesn't change that much, which is entirely possible).
2 parents 7532d20 + c04d484 commit 4ca51ae

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/librustc/driver/driver.rs

+7
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
305305
time(time_passes, "resolution", (), |_|
306306
middle::resolve::resolve_crate(&sess, lang_items, krate));
307307

308+
// Discard MTWT tables that aren't required past resolution.
309+
syntax::ext::mtwt::clear_tables();
310+
308311
let named_region_map = time(time_passes, "lifetime resolution", (),
309312
|_| middle::resolve_lifetime::krate(&sess, krate));
310313

@@ -585,6 +588,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
585588
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
586589
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
587590
analysis, &outputs);
591+
592+
// Discard interned strings as they are no longer required.
593+
token::get_ident_interner().clear();
594+
588595
(outputs, trans, tcx.sess)
589596
};
590597
phase_5_run_llvm_passes(&sess, &trans, &outputs);

src/libsyntax/ext/mtwt.rs

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ pub fn display_sctable(table: &SCTable) {
126126
}
127127
}
128128

129+
/// Clear the tables from TLD to reclaim memory.
130+
pub fn clear_tables() {
131+
with_sctable(|table| {
132+
*table.table.borrow_mut().get() = Vec::new();
133+
*table.mark_memo.borrow_mut().get() = HashMap::new();
134+
*table.rename_memo.borrow_mut().get() = HashMap::new();
135+
});
136+
with_resolve_table_mut(|table| *table = HashMap::new());
137+
}
129138

130139
// Add a value to the end of a vec, return its index
131140
fn idx_push<T>(vec: &mut Vec<T> , val: T) -> u32 {

src/libsyntax/util/interner.rs

+10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
8484
None => None,
8585
}
8686
}
87+
88+
pub fn clear(&self) {
89+
*self.map.borrow_mut().get() = HashMap::new();
90+
*self.vect.borrow_mut().get() = Vec::new();
91+
}
8792
}
8893

8994
#[deriving(Clone, Eq, Hash, Ord)]
@@ -222,6 +227,11 @@ impl StrInterner {
222227
None => None,
223228
}
224229
}
230+
231+
pub fn clear(&self) {
232+
*self.map.borrow_mut().get() = HashMap::new();
233+
*self.vect.borrow_mut().get() = Vec::new();
234+
}
225235
}
226236

227237
#[cfg(test)]

0 commit comments

Comments
 (0)