Skip to content

Commit 462a791

Browse files
committed
librustc: De-@mut the external and external_srcs fields of
`CrateContext`
1 parent 1e654f5 commit 462a791

File tree

4 files changed

+72
-38
lines changed

4 files changed

+72
-38
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,12 +2496,17 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
24962496
// using the current crate's name/version
24972497
// information in the hash of the symbol
24982498
debug!("making {}", sym);
2499-
let sym = match ccx.external_srcs.find(&i.id) {
2500-
Some(&did) => {
2501-
debug!("but found in other crate...");
2502-
csearch::get_symbol(ccx.sess.cstore, did)
2499+
let sym = {
2500+
let external_srcs = ccx.external_srcs
2501+
.borrow();
2502+
match external_srcs.get().find(&i.id) {
2503+
Some(&did) => {
2504+
debug!("but found in other crate...");
2505+
csearch::get_symbol(ccx.sess.cstore,
2506+
did)
2507+
}
2508+
None => sym
25032509
}
2504-
None => sym
25052510
};
25062511

25072512
// We need the translated value here, because for enums the

src/librustc/middle/trans/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ pub struct CrateContext {
5757
// created.
5858
finished_tydescs: bool,
5959
// Track mapping of external ids to local items imported for inlining
60-
external: HashMap<ast::DefId, Option<ast::NodeId>>,
60+
external: RefCell<HashMap<ast::DefId, Option<ast::NodeId>>>,
6161
// Backwards version of the `external` map (inlined items to where they
6262
// came from)
63-
external_srcs: HashMap<ast::NodeId, ast::DefId>,
63+
external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>,
6464
// A set of static items which cannot be inlined into other crates. This
6565
// will pevent in ii_item() structures from being encoded into the metadata
6666
// that is generated
@@ -190,8 +190,8 @@ impl CrateContext {
190190
link_meta: link_meta,
191191
tydescs: RefCell::new(HashMap::new()),
192192
finished_tydescs: false,
193-
external: HashMap::new(),
194-
external_srcs: HashMap::new(),
193+
external: RefCell::new(HashMap::new()),
194+
external_srcs: RefCell::new(HashMap::new()),
195195
non_inlineable_statics: RefCell::new(HashSet::new()),
196196
monomorphized: RefCell::new(HashMap::new()),
197197
monomorphizing: RefCell::new(HashMap::new()),

src/librustc/middle/trans/expr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,11 +1796,15 @@ pub fn trans_log_level(bcx: @Block) -> DatumBlock {
17961796
let ccx = bcx.ccx();
17971797

17981798
let (modpath, modname) = {
1799-
let srccrate = match ccx.external_srcs.find(&bcx.fcx.id) {
1800-
Some(&src) => {
1801-
ccx.sess.cstore.get_crate_data(src.crate).name
1802-
}
1803-
None => ccx.link_meta.pkgid.name.to_managed(),
1799+
let srccrate;
1800+
{
1801+
let external_srcs = ccx.external_srcs.borrow();
1802+
srccrate = match external_srcs.get().find(&bcx.fcx.id) {
1803+
Some(&src) => {
1804+
ccx.sess.cstore.get_crate_data(src.crate).name
1805+
}
1806+
None => ccx.link_meta.pkgid.name.to_managed(),
1807+
};
18041808
};
18051809
let mut modpath = ~[path_mod(ccx.sess.ident_of(srccrate))];
18061810
for e in bcx.fcx.path.iter() {

src/librustc/middle/trans/inline.rs

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ use syntax::attr;
2626
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
2727
-> ast::DefId {
2828
let _icx = push_ctxt("maybe_instantiate_inline");
29-
match ccx.external.find(&fn_id) {
30-
Some(&Some(node_id)) => {
31-
// Already inline
32-
debug!("maybe_instantiate_inline({}): already inline as node id {}",
33-
ty::item_path_str(ccx.tcx, fn_id), node_id);
34-
return local_def(node_id);
35-
}
36-
Some(&None) => {
37-
return fn_id; // Not inlinable
38-
}
39-
None => {
40-
// Not seen yet
29+
{
30+
let external = ccx.external.borrow();
31+
match external.get().find(&fn_id) {
32+
Some(&Some(node_id)) => {
33+
// Already inline
34+
debug!("maybe_instantiate_inline({}): already inline as node id {}",
35+
ty::item_path_str(ccx.tcx, fn_id), node_id);
36+
return local_def(node_id);
37+
}
38+
Some(&None) => {
39+
return fn_id; // Not inlinable
40+
}
41+
None => {
42+
// Not seen yet
43+
}
4144
}
4245
}
4346

@@ -49,12 +52,18 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
4952
});
5053
return match csearch_result {
5154
csearch::not_found => {
52-
ccx.external.insert(fn_id, None);
55+
let mut external = ccx.external.borrow_mut();
56+
external.get().insert(fn_id, None);
5357
fn_id
5458
}
5559
csearch::found(ast::ii_item(item)) => {
56-
ccx.external.insert(fn_id, Some(item.id));
57-
ccx.external_srcs.insert(item.id, fn_id);
60+
{
61+
let mut external = ccx.external.borrow_mut();
62+
let mut external_srcs = ccx.external_srcs.borrow_mut();
63+
external.get().insert(fn_id, Some(item.id));
64+
external_srcs.get().insert(item.id, fn_id);
65+
}
66+
5867
ccx.stats.n_inlines += 1;
5968
trans_item(ccx, item);
6069

@@ -82,28 +91,39 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
8291
local_def(item.id)
8392
}
8493
csearch::found(ast::ii_foreign(item)) => {
85-
ccx.external.insert(fn_id, Some(item.id));
86-
ccx.external_srcs.insert(item.id, fn_id);
87-
local_def(item.id)
94+
{
95+
let mut external = ccx.external.borrow_mut();
96+
let mut external_srcs = ccx.external_srcs.borrow_mut();
97+
external.get().insert(fn_id, Some(item.id));
98+
external_srcs.get().insert(item.id, fn_id);
99+
}
100+
local_def(item.id)
88101
}
89102
csearch::found_parent(parent_id, ast::ii_item(item)) => {
90-
ccx.external.insert(parent_id, Some(item.id));
91-
ccx.external_srcs.insert(item.id, parent_id);
103+
{
104+
let mut external = ccx.external.borrow_mut();
105+
let mut external_srcs = ccx.external_srcs.borrow_mut();
106+
external.get().insert(parent_id, Some(item.id));
107+
external_srcs.get().insert(item.id, parent_id);
108+
}
109+
92110
let mut my_id = 0;
93111
match item.node {
94112
ast::item_enum(_, _) => {
95113
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
96114
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
97115
for (here, there) in vs_here.iter().zip(vs_there.iter()) {
98116
if there.id == fn_id { my_id = here.id.node; }
99-
ccx.external.insert(there.id, Some(here.id.node));
117+
let mut external = ccx.external.borrow_mut();
118+
external.get().insert(there.id, Some(here.id.node));
100119
}
101120
}
102121
ast::item_struct(ref struct_def, _) => {
103122
match struct_def.ctor_id {
104123
None => {}
105124
Some(ctor_id) => {
106-
let _ = ccx.external.insert(fn_id, Some(ctor_id));
125+
let mut external = ccx.external.borrow_mut();
126+
let _ = external.get().insert(fn_id, Some(ctor_id));
107127
my_id = ctor_id;
108128
}
109129
}
@@ -119,9 +139,14 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
119139
with a non-item parent");
120140
}
121141
csearch::found(ast::ii_method(impl_did, is_provided, mth)) => {
142+
{
143+
let mut external = ccx.external.borrow_mut();
144+
let mut external_srcs = ccx.external_srcs.borrow_mut();
145+
external.get().insert(fn_id, Some(mth.id));
146+
external_srcs.get().insert(mth.id, fn_id);
147+
}
148+
122149
ccx.stats.n_inlines += 1;
123-
ccx.external.insert(fn_id, Some(mth.id));
124-
ccx.external_srcs.insert(mth.id, fn_id);
125150
// If this is a default method, we can't look up the
126151
// impl type. But we aren't going to translate anyways, so don't.
127152
if is_provided { return local_def(mth.id); }

0 commit comments

Comments
 (0)