1
Fork 0

librustc: De-@mut the external and external_srcs fields of

`CrateContext`
This commit is contained in:
Patrick Walton 2013-12-18 18:32:52 -08:00
parent 1e654f5ff7
commit 462a791c34
4 changed files with 72 additions and 38 deletions

View file

@ -2496,12 +2496,17 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
// using the current crate's name/version
// information in the hash of the symbol
debug!("making {}", sym);
let sym = match ccx.external_srcs.find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
csearch::get_symbol(ccx.sess.cstore, did)
let sym = {
let external_srcs = ccx.external_srcs
.borrow();
match external_srcs.get().find(&i.id) {
Some(&did) => {
debug!("but found in other crate...");
csearch::get_symbol(ccx.sess.cstore,
did)
}
None => sym
}
None => sym
};
// We need the translated value here, because for enums the

View file

@ -57,10 +57,10 @@ pub struct CrateContext {
// created.
finished_tydescs: bool,
// Track mapping of external ids to local items imported for inlining
external: HashMap<ast::DefId, Option<ast::NodeId>>,
external: RefCell<HashMap<ast::DefId, Option<ast::NodeId>>>,
// Backwards version of the `external` map (inlined items to where they
// came from)
external_srcs: HashMap<ast::NodeId, ast::DefId>,
external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>,
// A set of static items which cannot be inlined into other crates. This
// will pevent in ii_item() structures from being encoded into the metadata
// that is generated
@ -190,8 +190,8 @@ impl CrateContext {
link_meta: link_meta,
tydescs: RefCell::new(HashMap::new()),
finished_tydescs: false,
external: HashMap::new(),
external_srcs: HashMap::new(),
external: RefCell::new(HashMap::new()),
external_srcs: RefCell::new(HashMap::new()),
non_inlineable_statics: RefCell::new(HashSet::new()),
monomorphized: RefCell::new(HashMap::new()),
monomorphizing: RefCell::new(HashMap::new()),

View file

@ -1796,11 +1796,15 @@ pub fn trans_log_level(bcx: @Block) -> DatumBlock {
let ccx = bcx.ccx();
let (modpath, modname) = {
let srccrate = match ccx.external_srcs.find(&bcx.fcx.id) {
Some(&src) => {
ccx.sess.cstore.get_crate_data(src.crate).name
}
None => ccx.link_meta.pkgid.name.to_managed(),
let srccrate;
{
let external_srcs = ccx.external_srcs.borrow();
srccrate = match external_srcs.get().find(&bcx.fcx.id) {
Some(&src) => {
ccx.sess.cstore.get_crate_data(src.crate).name
}
None => ccx.link_meta.pkgid.name.to_managed(),
};
};
let mut modpath = ~[path_mod(ccx.sess.ident_of(srccrate))];
for e in bcx.fcx.path.iter() {

View file

@ -26,18 +26,21 @@ use syntax::attr;
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
-> ast::DefId {
let _icx = push_ctxt("maybe_instantiate_inline");
match ccx.external.find(&fn_id) {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx, fn_id), node_id);
return local_def(node_id);
}
Some(&None) => {
return fn_id; // Not inlinable
}
None => {
// Not seen yet
{
let external = ccx.external.borrow();
match external.get().find(&fn_id) {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx, fn_id), node_id);
return local_def(node_id);
}
Some(&None) => {
return fn_id; // Not inlinable
}
None => {
// Not seen yet
}
}
}
@ -49,12 +52,18 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
});
return match csearch_result {
csearch::not_found => {
ccx.external.insert(fn_id, None);
let mut external = ccx.external.borrow_mut();
external.get().insert(fn_id, None);
fn_id
}
csearch::found(ast::ii_item(item)) => {
ccx.external.insert(fn_id, Some(item.id));
ccx.external_srcs.insert(item.id, fn_id);
{
let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(item.id));
external_srcs.get().insert(item.id, fn_id);
}
ccx.stats.n_inlines += 1;
trans_item(ccx, item);
@ -82,13 +91,22 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
local_def(item.id)
}
csearch::found(ast::ii_foreign(item)) => {
ccx.external.insert(fn_id, Some(item.id));
ccx.external_srcs.insert(item.id, fn_id);
local_def(item.id)
{
let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(item.id));
external_srcs.get().insert(item.id, fn_id);
}
local_def(item.id)
}
csearch::found_parent(parent_id, ast::ii_item(item)) => {
ccx.external.insert(parent_id, Some(item.id));
ccx.external_srcs.insert(item.id, parent_id);
{
let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(parent_id, Some(item.id));
external_srcs.get().insert(item.id, parent_id);
}
let mut my_id = 0;
match item.node {
ast::item_enum(_, _) => {
@ -96,14 +114,16 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
for (here, there) in vs_here.iter().zip(vs_there.iter()) {
if there.id == fn_id { my_id = here.id.node; }
ccx.external.insert(there.id, Some(here.id.node));
let mut external = ccx.external.borrow_mut();
external.get().insert(there.id, Some(here.id.node));
}
}
ast::item_struct(ref struct_def, _) => {
match struct_def.ctor_id {
None => {}
Some(ctor_id) => {
let _ = ccx.external.insert(fn_id, Some(ctor_id));
let mut external = ccx.external.borrow_mut();
let _ = external.get().insert(fn_id, Some(ctor_id));
my_id = ctor_id;
}
}
@ -119,9 +139,14 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
with a non-item parent");
}
csearch::found(ast::ii_method(impl_did, is_provided, mth)) => {
{
let mut external = ccx.external.borrow_mut();
let mut external_srcs = ccx.external_srcs.borrow_mut();
external.get().insert(fn_id, Some(mth.id));
external_srcs.get().insert(mth.id, fn_id);
}
ccx.stats.n_inlines += 1;
ccx.external.insert(fn_id, Some(mth.id));
ccx.external_srcs.insert(mth.id, fn_id);
// If this is a default method, we can't look up the
// impl type. But we aren't going to translate anyways, so don't.
if is_provided { return local_def(mth.id); }