Skip to content

Commit c4661fd

Browse files
committed
librustc: De-@mut node_types in the type context
1 parent 727fa3a commit c4661fd

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

src/librustc/middle/astencode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
911911
}
912912

913913
{
914-
let r = tcx.node_types.find(&(id as uint));
914+
let node_types = tcx.node_types.borrow();
915+
let r = node_types.get().find(&(id as uint));
915916
for &ty in r.iter() {
916917
ebml_w.tag(c::tag_table_node_type, |ebml_w| {
917918
ebml_w.id(id);
@@ -1230,7 +1231,8 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
12301231
let ty = val_dsr.read_ty(xcx);
12311232
debug!("inserting ty for node {:?}: {}",
12321233
id, ty_to_str(dcx.tcx, ty));
1233-
dcx.tcx.node_types.insert(id as uint, ty);
1234+
let mut node_types = dcx.tcx.node_types.borrow_mut();
1235+
node_types.get().insert(id as uint, ty);
12341236
}
12351237
c::tag_table_node_type_subst => {
12361238
let tys = val_dsr.read_tys(xcx);

src/librustc/middle/trans/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,9 @@ fn insert_synthetic_type_entries(bcx: @Block,
20182018

20192019
let pat_id = fn_args[i].pat.id;
20202020
let arg_ty = arg_tys[i];
2021-
tcx.node_types.insert(pat_id as uint, arg_ty);
2021+
2022+
let mut node_types = tcx.node_types.borrow_mut();
2023+
node_types.get().insert(pat_id as uint, arg_ty);
20222024
}
20232025
}
20242026

src/librustc/middle/trans/debuginfo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,8 @@ fn fn_should_be_ignored(fcx: &FunctionContext) -> bool {
22592259
}
22602260

22612261
fn assert_type_for_node_id(cx: &CrateContext, node_id: ast::NodeId, error_span: Span) {
2262-
if !cx.tcx.node_types.contains_key(&(node_id as uint)) {
2262+
let node_types = cx.tcx.node_types.borrow();
2263+
if !node_types.get().contains_key(&(node_id as uint)) {
22632264
cx.sess.span_bug(error_span, "debuginfo: Could not find type for node id!");
22642265
}
22652266
}

src/librustc/middle/ty.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ pub struct ty_param_substs_and_ty {
955955

956956
type type_cache = RefCell<HashMap<ast::DefId, ty_param_bounds_and_ty>>;
957957

958-
pub type node_type_table = @mut HashMap<uint,t>;
958+
pub type node_type_table = RefCell<HashMap<uint,t>>;
959959

960960
pub fn mk_ctxt(s: session::Session,
961961
dm: resolve::DefMap,
@@ -975,7 +975,7 @@ pub fn mk_ctxt(s: session::Session,
975975
sess: s,
976976
def_map: dm,
977977
region_maps: region_maps,
978-
node_types: @mut HashMap::new(),
978+
node_types: RefCell::new(HashMap::new()),
979979
node_type_substs: RefCell::new(HashMap::new()),
980980
trait_refs: RefCell::new(HashMap::new()),
981981
trait_defs: RefCell::new(HashMap::new()),
@@ -2674,7 +2674,8 @@ pub fn node_id_to_trait_ref(cx: ctxt, id: ast::NodeId) -> @ty::TraitRef {
26742674

26752675
pub fn node_id_to_type(cx: ctxt, id: ast::NodeId) -> t {
26762676
//printfln!("{:?}/{:?}", id, cx.node_types.len());
2677-
match cx.node_types.find(&(id as uint)) {
2677+
let node_types = cx.node_types.borrow();
2678+
match node_types.get().find(&(id as uint)) {
26782679
Some(&t) => t,
26792680
None => cx.sess.bug(
26802681
format!("node_id_to_type: no type for node `{}`",
@@ -3172,7 +3173,8 @@ pub fn expr_kind(tcx: ctxt,
31723173
}
31733174

31743175
ast::ExprCast(..) => {
3175-
match tcx.node_types.find(&(expr.id as uint)) {
3176+
let node_types = tcx.node_types.borrow();
3177+
match node_types.get().find(&(expr.id as uint)) {
31763178
Some(&t) => {
31773179
if type_is_trait(t) {
31783180
RvalueDpsExpr

src/librustc/middle/typeck/check/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub struct Inherited {
162162
param_env: ty::ParameterEnvironment,
163163

164164
// Temporary tables:
165-
node_types: @mut HashMap<ast::NodeId, ty::t>,
165+
node_types: RefCell<HashMap<ast::NodeId, ty::t>>,
166166
node_type_substs: RefCell<HashMap<ast::NodeId, ty::substs>>,
167167
adjustments: RefCell<HashMap<ast::NodeId, @ty::AutoAdjustment>>,
168168
method_map: method_map,
@@ -262,7 +262,7 @@ impl Inherited {
262262
infcx: infer::new_infer_ctxt(tcx),
263263
locals: @mut HashMap::new(),
264264
param_env: param_env,
265-
node_types: @mut HashMap::new(),
265+
node_types: RefCell::new(HashMap::new()),
266266
node_type_substs: RefCell::new(HashMap::new()),
267267
adjustments: RefCell::new(HashMap::new()),
268268
method_map: @mut HashMap::new(),
@@ -1097,7 +1097,8 @@ impl FnCtxt {
10971097
pub fn write_ty(&self, node_id: ast::NodeId, ty: ty::t) {
10981098
debug!("write_ty({}, {}) in fcx {}",
10991099
node_id, ppaux::ty_to_str(self.tcx(), ty), self.tag());
1100-
self.inh.node_types.insert(node_id, ty);
1100+
let mut node_types = self.inh.node_types.borrow_mut();
1101+
node_types.get().insert(node_id, ty);
11011102
}
11021103

11031104
pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::substs) {
@@ -1160,7 +1161,8 @@ impl FnCtxt {
11601161
}
11611162

11621163
pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t {
1163-
match self.inh.node_types.find(&ex.id) {
1164+
let node_types = self.inh.node_types.borrow();
1165+
match node_types.get().find(&ex.id) {
11641166
Some(&t) => t,
11651167
None => {
11661168
self.tcx().sess.bug(format!("no type for expr in fcx {}",
@@ -1170,7 +1172,8 @@ impl FnCtxt {
11701172
}
11711173

11721174
pub fn node_ty(&self, id: ast::NodeId) -> ty::t {
1173-
match self.inh.node_types.find(&id) {
1175+
let node_types = self.inh.node_types.borrow();
1176+
match node_types.get().find(&id) {
11741177
Some(&t) => t,
11751178
None => {
11761179
self.tcx().sess.bug(

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ fn maybe_resolve_type_vars_for_node(wbcx: &mut WbCtxt,
206206
sp: Span,
207207
id: ast::NodeId)
208208
-> Option<ty::t> {
209-
if wbcx.fcx.inh.node_types.contains_key(&id) {
209+
let contained = {
210+
let node_types = wbcx.fcx.inh.node_types.borrow();
211+
node_types.get().contains_key(&id)
212+
};
213+
if contained {
210214
resolve_type_vars_for_node(wbcx, sp, id)
211215
} else {
212216
None

src/librustc/middle/typeck/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ pub struct CrateCtxt {
240240
pub fn write_ty_to_tcx(tcx: ty::ctxt, node_id: ast::NodeId, ty: ty::t) {
241241
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_str(tcx, ty));
242242
assert!(!ty::type_needs_infer(ty));
243-
tcx.node_types.insert(node_id as uint, ty);
243+
let mut node_types = tcx.node_types.borrow_mut();
244+
node_types.get().insert(node_id as uint, ty);
244245
}
245246
pub fn write_substs_to_tcx(tcx: ty::ctxt,
246247
node_id: ast::NodeId,

0 commit comments

Comments
 (0)