librustc: De-@mut the node_type_substs table

This commit is contained in:
Patrick Walton 2013-12-18 15:43:49 -08:00
parent fffbe7a8cd
commit 386300d4b0
5 changed files with 28 additions and 14 deletions

View file

@ -923,7 +923,8 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}
{
let r = tcx.node_type_substs.find(&id);
let node_type_substs = tcx.node_type_substs.borrow();
let r = node_type_substs.get().find(&id);
for tys in r.iter() {
ebml_w.tag(c::tag_table_node_type_subst, |ebml_w| {
ebml_w.id(id);
@ -1228,7 +1229,10 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
}
c::tag_table_node_type_subst => {
let tys = val_dsr.read_tys(xcx);
dcx.tcx.node_type_substs.insert(id, tys);
let mut node_type_substs = dcx.tcx
.node_type_substs
.borrow_mut();
node_type_substs.get().insert(id, tys);
}
c::tag_table_freevars => {
let fv_info = @val_dsr.read_to_vec(|val_dsr| {

View file

@ -264,7 +264,8 @@ pub fn check_expr(cx: &mut Context, e: @Expr) {
None => e.id,
};
{
let r = cx.tcx.node_type_substs.find(&type_parameter_id);
let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = node_type_substs.get().find(&type_parameter_id);
for ts in r.iter() {
let type_param_defs = match e.node {
ExprPath(_) => {
@ -326,7 +327,8 @@ pub fn check_expr(cx: &mut Context, e: @Expr) {
fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node {
ty_path(_, _, id) => {
let r = cx.tcx.node_type_substs.find(&id);
let node_type_substs = cx.tcx.node_type_substs.borrow();
let r = node_type_substs.get().find(&id);
for ts in r.iter() {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
let type_param_defs =

View file

@ -284,7 +284,7 @@ struct ctxt_ {
// of this node. This only applies to nodes that refer to entities
// parameterized by type parameters, such as generic fns, types, or
// other items.
node_type_substs: @mut HashMap<NodeId, ~[t]>,
node_type_substs: RefCell<HashMap<NodeId, ~[t]>>,
// Maps from a method to the method "descriptor"
methods: @mut HashMap<DefId, @Method>,
@ -985,7 +985,7 @@ pub fn mk_ctxt(s: session::Session,
def_map: dm,
region_maps: region_maps,
node_types: @mut HashMap::new(),
node_type_substs: @mut HashMap::new(),
node_type_substs: RefCell::new(HashMap::new()),
trait_refs: @mut HashMap::new(),
trait_defs: @mut HashMap::new(),
items: amap,
@ -2676,14 +2676,16 @@ pub fn node_id_to_type(cx: ctxt, id: ast::NodeId) -> t {
// XXX(pcwalton): Makes a copy, bleh. Probably better to not do that.
pub fn node_id_to_type_params(cx: ctxt, id: ast::NodeId) -> ~[t] {
match cx.node_type_substs.find(&id) {
let node_type_substs = cx.node_type_substs.borrow();
match node_type_substs.get().find(&id) {
None => return ~[],
Some(ts) => return (*ts).clone(),
}
}
fn node_id_has_type_params(cx: ctxt, id: ast::NodeId) -> bool {
cx.node_type_substs.contains_key(&id)
let node_type_substs = cx.node_type_substs.borrow();
node_type_substs.get().contains_key(&id)
}
pub fn fn_is_variadic(fty: t) -> bool {

View file

@ -163,7 +163,7 @@ pub struct Inherited {
// Temporary tables:
node_types: @mut HashMap<ast::NodeId, ty::t>,
node_type_substs: @mut HashMap<ast::NodeId, ty::substs>,
node_type_substs: RefCell<HashMap<ast::NodeId, ty::substs>>,
adjustments: @mut HashMap<ast::NodeId, @ty::AutoAdjustment>,
method_map: method_map,
vtable_map: vtable_map,
@ -263,7 +263,7 @@ impl Inherited {
locals: @mut HashMap::new(),
param_env: param_env,
node_types: @mut HashMap::new(),
node_type_substs: @mut HashMap::new(),
node_type_substs: RefCell::new(HashMap::new()),
adjustments: @mut HashMap::new(),
method_map: @mut HashMap::new(),
vtable_map: @mut HashMap::new(),
@ -1106,7 +1106,9 @@ impl FnCtxt {
node_id,
ty::substs_to_str(self.tcx(), &substs),
self.tag());
self.inh.node_type_substs.insert(node_id, substs);
let mut node_type_substs = self.inh.node_type_substs.borrow_mut();
node_type_substs.get().insert(node_id, substs);
}
}
@ -1181,7 +1183,8 @@ impl FnCtxt {
}
pub fn node_ty_substs(&self, id: ast::NodeId) -> ty::substs {
match self.inh.node_type_substs.find(&id) {
let mut node_type_substs = self.inh.node_type_substs.borrow_mut();
match node_type_substs.get().find(&id) {
Some(ts) => (*ts).clone(),
None => {
self.tcx().sess.bug(
@ -1197,7 +1200,8 @@ impl FnCtxt {
id: ast::NodeId,
f: |&ty::substs| -> bool)
-> bool {
match self.inh.node_type_substs.find(&id) {
let node_type_substs = self.inh.node_type_substs.borrow();
match node_type_substs.get().find(&id) {
Some(s) => f(s),
None => true
}

View file

@ -248,7 +248,9 @@ pub fn write_substs_to_tcx(tcx: ty::ctxt,
debug!("write_substs_to_tcx({}, {:?})", node_id,
substs.map(|t| ppaux::ty_to_str(tcx, *t)));
assert!(substs.iter().all(|t| !ty::type_needs_infer(*t)));
tcx.node_type_substs.insert(node_id, substs);
let mut node_type_substs = tcx.node_type_substs.borrow_mut();
node_type_substs.get().insert(node_id, substs);
}
}
pub fn write_tpt_to_tcx(tcx: ty::ctxt,