Skip to content

Commit d3f58c5

Browse files
committed
librustc: De-@mut the monomorphizing field in CrateContext
1 parent b5218ba commit d3f58c5

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/librustc/middle/trans/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct CrateContext {
7070
non_inlineable_statics: HashSet<ast::NodeId>,
7171
// Cache instances of monomorphized functions
7272
monomorphized: RefCell<HashMap<mono_id, ValueRef>>,
73-
monomorphizing: HashMap<ast::DefId, uint>,
73+
monomorphizing: RefCell<HashMap<ast::DefId, uint>>,
7474
// Cache generated vtables
7575
vtables: HashMap<(ty::t, mono_id), ValueRef>,
7676
// Cache of constant strings,
@@ -201,7 +201,7 @@ impl CrateContext {
201201
external_srcs: HashMap::new(),
202202
non_inlineable_statics: HashSet::new(),
203203
monomorphized: RefCell::new(HashMap::new()),
204-
monomorphizing: HashMap::new(),
204+
monomorphizing: RefCell::new(HashMap::new()),
205205
vtables: HashMap::new(),
206206
const_cstr_cache: HashMap::new(),
207207
const_globals: HashMap::new(),

src/librustc/middle/trans/monomorphize.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,22 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
184184

185185
ccx.stats.n_monos += 1;
186186

187-
let depth = match ccx.monomorphizing.find(&fn_id) {
188-
Some(&d) => d, None => 0
189-
};
190-
// Random cut-off -- code that needs to instantiate the same function
191-
// recursively more than thirty times can probably safely be assumed to be
192-
// causing an infinite expansion.
193-
if depth > 30 {
194-
ccx.sess.span_fatal(
195-
span, "overly deep expansion of inlined function");
187+
let depth;
188+
{
189+
let mut monomorphizing = ccx.monomorphizing.borrow_mut();
190+
depth = match monomorphizing.get().find(&fn_id) {
191+
Some(&d) => d, None => 0
192+
};
193+
194+
// Random cut-off -- code that needs to instantiate the same function
195+
// recursively more than thirty times can probably safely be assumed
196+
// to be causing an infinite expansion.
197+
if depth > 30 {
198+
ccx.sess.span_fatal(
199+
span, "overly deep expansion of inlined function");
200+
}
201+
monomorphizing.get().insert(fn_id, depth + 1);
196202
}
197-
ccx.monomorphizing.insert(fn_id, depth + 1);
198203

199204
let (_, elt) = gensym_name(ccx.sess.str_of(name));
200205
let mut pt = (*pt).clone();
@@ -292,7 +297,11 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
292297
ccx.tcx.sess.bug(format!("Can't monomorphize a {:?}", map_node))
293298
}
294299
};
295-
ccx.monomorphizing.insert(fn_id, depth);
300+
301+
{
302+
let mut monomorphizing = ccx.monomorphizing.borrow_mut();
303+
monomorphizing.get().insert(fn_id, depth);
304+
}
296305

297306
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx, fn_id));
298307
(lldecl, must_cast)

0 commit comments

Comments
 (0)