Skip to content

Commit

Permalink
Discard MTWT & interner tables from TLD after they stop being useful.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 19, 2014
1 parent 87e72c3 commit c04d484
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/librustc/driver/driver.rs
Expand Up @@ -305,6 +305,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
time(time_passes, "resolution", (), |_|
middle::resolve::resolve_crate(&sess, lang_items, krate));

// Discard MTWT tables that aren't required past resolution.
syntax::ext::mtwt::clear_tables();

let named_region_map = time(time_passes, "lifetime resolution", (),
|_| middle::resolve_lifetime::krate(&sess, krate));

Expand Down Expand Up @@ -585,6 +588,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
analysis, &outputs);

// Discard interned strings as they are no longer required.
token::get_ident_interner().clear();

(outputs, trans, tcx.sess)
};
phase_5_run_llvm_passes(&sess, &trans, &outputs);
Expand Down
9 changes: 9 additions & 0 deletions src/libsyntax/ext/mtwt.rs
Expand Up @@ -126,6 +126,15 @@ pub fn display_sctable(table: &SCTable) {
}
}

/// Clear the tables from TLD to reclaim memory.
pub fn clear_tables() {
with_sctable(|table| {
*table.table.borrow_mut().get() = Vec::new();
*table.mark_memo.borrow_mut().get() = HashMap::new();
*table.rename_memo.borrow_mut().get() = HashMap::new();
});
with_resolve_table_mut(|table| *table = HashMap::new());
}

// Add a value to the end of a vec, return its index
fn idx_push<T>(vec: &mut Vec<T> , val: T) -> u32 {
Expand Down
10 changes: 10 additions & 0 deletions src/libsyntax/util/interner.rs
Expand Up @@ -84,6 +84,11 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
None => None,
}
}

pub fn clear(&self) {
*self.map.borrow_mut().get() = HashMap::new();
*self.vect.borrow_mut().get() = Vec::new();
}
}

#[deriving(Clone, Eq, Hash, Ord)]
Expand Down Expand Up @@ -222,6 +227,11 @@ impl StrInterner {
None => None,
}
}

pub fn clear(&self) {
*self.map.borrow_mut().get() = HashMap::new();
*self.vect.borrow_mut().get() = Vec::new();
}
}

#[cfg(test)]
Expand Down

5 comments on commit c04d484

@bors
Copy link
Contributor

@bors bors commented on c04d484 Mar 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at eddyb@c04d484

@bors
Copy link
Contributor

@bors bors commented on c04d484 Mar 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/drop-tld = c04d484 into auto

@bors
Copy link
Contributor

@bors bors commented on c04d484 Mar 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/drop-tld = c04d484 merged ok, testing candidate = 4ca51ae

@bors
Copy link
Contributor

@bors bors commented on c04d484 Mar 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c04d484 Mar 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4ca51ae

Please sign in to comment.