Skip to content

Commit f7393d8

Browse files
committed
librustc: De-@mut the method map
1 parent b9568cd commit f7393d8

File tree

21 files changed

+109
-56
lines changed

21 files changed

+109
-56
lines changed

src/librustc/middle/astencode.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
990990
}
991991

992992
{
993-
let r = maps.method_map.find(&id);
993+
let method_map = maps.method_map.borrow();
994+
let r = method_map.get().find(&id);
994995
for &mme in r.iter() {
995996
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
996997
ebml_w.id(id);
@@ -1274,9 +1275,9 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
12741275
ty_param_defs.get().insert(id, bounds);
12751276
}
12761277
c::tag_table_method_map => {
1277-
dcx.maps.method_map.insert(
1278-
id,
1279-
val_dsr.read_method_map_entry(xcx));
1278+
let entry = val_dsr.read_method_map_entry(xcx);
1279+
let mut method_map = dcx.maps.method_map.borrow_mut();
1280+
method_map.get().insert(id, entry);
12801281
}
12811282
c::tag_table_vtable_map => {
12821283
let vtable_res =

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
767767
this.check_for_conflicting_loans(expr.id);
768768
this.check_move_out_from_expr(expr);
769769

770+
let method_map = this.bccx.method_map.borrow();
770771
match expr.node {
771772
ast::ExprSelf |
772773
ast::ExprPath(..) => {
@@ -791,15 +792,15 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
791792
}
792793
ast::ExprIndex(callee_id, _, rval) |
793794
ast::ExprBinary(callee_id, _, _, rval)
794-
if this.bccx.method_map.contains_key(&expr.id) => {
795+
if method_map.get().contains_key(&expr.id) => {
795796
this.check_call(expr,
796797
None,
797798
callee_id,
798799
expr.span,
799800
[rval]);
800801
}
801802
ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
802-
if this.bccx.method_map.contains_key(&expr.id) => {
803+
if method_map.get().contains_key(&expr.id) => {
803804
this.check_call(expr,
804805
None,
805806
callee_id,

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
223223
}
224224

225225
// Special checks for various kinds of expressions:
226+
let method_map = this.bccx.method_map.borrow();
226227
match ex.node {
227228
ast::ExprAddrOf(mutbl, base) => {
228229
let base_cmt = this.bccx.cat_expr(base);
@@ -270,7 +271,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
270271

271272
ast::ExprIndex(_, _, arg) |
272273
ast::ExprBinary(_, _, _, arg)
273-
if this.bccx.method_map.contains_key(&ex.id) => {
274+
if method_map.get().contains_key(&ex.id) => {
274275
// Arguments in method calls are always passed by ref.
275276
//
276277
// Currently these do not use adjustments, so we have to

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ impl CFGBuilder {
519519
}
520520

521521
fn is_method_call(&self, expr: &ast::Expr) -> bool {
522-
self.method_map.contains_key(&expr.id)
522+
let method_map = self.method_map.borrow();
523+
method_map.get().contains_key(&expr.id)
523524
}
524525
}

src/librustc/middle/check_const.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
122122
}
123123
ExprLit(@codemap::Spanned {node: lit_str(..), ..}) => { }
124124
ExprBinary(..) | ExprUnary(..) => {
125-
if method_map.contains_key(&e.id) {
125+
let method_map = method_map.borrow();
126+
if method_map.get().contains_key(&e.id) {
126127
sess.span_err(e.span, "user-defined operators are not \
127128
allowed in constant expressions");
128129
}

src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
121121
}
122122
let maps = astencode::Maps {
123123
root_map: @RefCell::new(HashMap::new()),
124-
method_map: @mut HashMap::new(),
124+
method_map: @RefCell::new(HashMap::new()),
125125
vtable_map: @RefCell::new(HashMap::new()),
126126
write_guard_map: @RefCell::new(HashSet::new()),
127127
capture_map: @RefCell::new(HashMap::new())
@@ -171,7 +171,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
171171
}
172172
let maps = astencode::Maps {
173173
root_map: @RefCell::new(HashMap::new()),
174-
method_map: @mut HashMap::new(),
174+
method_map: @RefCell::new(HashMap::new()),
175175
vtable_map: @RefCell::new(HashMap::new()),
176176
write_guard_map: @RefCell::new(HashSet::new()),
177177
capture_map: @RefCell::new(HashMap::new())

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
899899
}
900900

901901
fn is_method_call(&self, expr: &ast::Expr) -> bool {
902-
self.dfcx.method_map.contains_key(&expr.id)
902+
let method_map = self.dfcx.method_map.borrow();
903+
method_map.get().contains_key(&expr.id)
903904
}
904905

905906
fn reset(&mut self, bits: &mut [uint]) {

src/librustc/middle/dead.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ impl Visitor<()> for MarkSymbolVisitor {
134134
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
135135
match expr.node {
136136
ast::ExprMethodCall(..) => {
137-
match self.method_map.find(&expr.id) {
137+
let method_map = self.method_map.borrow();
138+
match method_map.get().find(&expr.id) {
138139
Some(&typeck::method_map_entry {
139140
origin: typeck::method_static(def_id),
140141
..

src/librustc/middle/lint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,8 @@ fn check_stability(cx: &Context, e: &ast::Expr) {
12021202
}
12031203
}
12041204
ast::ExprMethodCall(..) => {
1205-
match cx.method_map.find(&e.id) {
1205+
let method_map = cx.method_map.borrow();
1206+
match method_map.get().find(&e.id) {
12061207
Some(&typeck::method_map_entry { origin, .. }) => {
12071208
match origin {
12081209
typeck::method_static(def_id) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ impl mem_categorization_ctxt {
390390
let expr_ty = self.expr_ty(expr);
391391
match expr.node {
392392
ast::ExprUnary(_, ast::UnDeref, e_base) => {
393-
if self.method_map.contains_key(&expr.id) {
393+
let method_map = self.method_map.borrow();
394+
if method_map.get().contains_key(&expr.id) {
394395
return self.cat_rvalue_node(expr, expr_ty);
395396
}
396397

@@ -401,14 +402,16 @@ impl mem_categorization_ctxt {
401402
ast::ExprField(base, f_name, _) => {
402403
// Method calls are now a special syntactic form,
403404
// so `a.b` should always be a field.
404-
assert!(!self.method_map.contains_key(&expr.id));
405+
let method_map = self.method_map.borrow();
406+
assert!(!method_map.get().contains_key(&expr.id));
405407

406408
let base_cmt = self.cat_expr(base);
407409
self.cat_field(expr, base_cmt, f_name, self.expr_ty(expr))
408410
}
409411

410412
ast::ExprIndex(_, base, _) => {
411-
if self.method_map.contains_key(&expr.id) {
413+
let method_map = self.method_map.borrow();
414+
if method_map.get().contains_key(&expr.id) {
412415
return self.cat_rvalue_node(expr, expr_ty);
413416
}
414417

src/librustc/middle/moves.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ and so on.
130130
use middle::pat_util::{pat_bindings};
131131
use middle::freevars;
132132
use middle::ty;
133-
use middle::typeck::{method_map};
133+
use middle::typeck::method_map;
134134
use util::ppaux;
135135
use util::ppaux::Repr;
136136
use util::common::indenter;
@@ -591,7 +591,8 @@ impl VisitContext {
591591
receiver_expr: @Expr,
592592
arg_exprs: &[@Expr])
593593
-> bool {
594-
if !self.method_map.contains_key(&expr.id) {
594+
let method_map = self.method_map.borrow();
595+
if !method_map.get().contains_key(&expr.id) {
595596
return false;
596597
}
597598

src/librustc/middle/privacy.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
622622
ast::ExprField(base, ident, _) => {
623623
// Method calls are now a special syntactic form,
624624
// so `a.b` should always be a field.
625-
assert!(!self.method_map.contains_key(&expr.id));
625+
let method_map = self.method_map.borrow();
626+
assert!(!method_map.get().contains_key(&expr.id));
626627

627628
// With type_autoderef, make sure we don't
628629
// allow pointers to violate privacy
@@ -641,7 +642,8 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
641642
ty::expr_ty(self.tcx, base));
642643
match ty::get(t).sty {
643644
ty::ty_enum(_, _) | ty::ty_struct(_, _) => {
644-
let entry = match self.method_map.find(&expr.id) {
645+
let method_map = self.method_map.borrow();
646+
let entry = match method_map.get().find(&expr.id) {
645647
None => {
646648
self.tcx.sess.span_bug(expr.span,
647649
"method call not in \

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ impl Visitor<()> for MarkSymbolVisitor {
139139
}
140140
}
141141
ast::ExprMethodCall(..) => {
142-
match self.method_map.find(&expr.id) {
142+
let method_map = self.method_map.borrow();
143+
match method_map.get().find(&expr.id) {
143144
Some(&typeck::method_map_entry {
144145
origin: typeck::method_static(def_id),
145146
..

src/librustc/middle/resolve.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ fn Resolver(session: Session,
792792

793793
graph_root: graph_root,
794794

795-
method_map: @mut HashMap::new(),
795+
method_map: @RefCell::new(HashMap::new()),
796796
structs: HashSet::new(),
797797

798798
unresolved_imports: 0,
@@ -834,7 +834,7 @@ struct Resolver {
834834

835835
graph_root: @NameBindings,
836836

837-
method_map: @mut HashMap<Name, HashSet<DefId>>,
837+
method_map: @RefCell<HashMap<Name, HashSet<DefId>>>,
838838
structs: HashSet<DefId>,
839839

840840
// The number of imports that are currently unresolved.
@@ -1378,10 +1378,11 @@ impl Resolver {
13781378

13791379
let def_id = local_def(item.id);
13801380
for (name, _) in method_names.iter() {
1381-
if !self.method_map.contains_key(name) {
1382-
self.method_map.insert(*name, HashSet::new());
1381+
let mut method_map = self.method_map.borrow_mut();
1382+
if !method_map.get().contains_key(name) {
1383+
method_map.get().insert(*name, HashSet::new());
13831384
}
1384-
match self.method_map.find_mut(name) {
1385+
match method_map.get().find_mut(name) {
13851386
Some(s) => { s.insert(def_id); },
13861387
_ => fail!("Can't happen"),
13871388
}
@@ -1699,10 +1700,11 @@ impl Resolver {
16991700
}
17001701
}
17011702
for name in interned_method_names.iter() {
1702-
if !self.method_map.contains_key(name) {
1703-
self.method_map.insert(*name, HashSet::new());
1703+
let mut method_map = self.method_map.borrow_mut();
1704+
if !method_map.get().contains_key(name) {
1705+
method_map.get().insert(*name, HashSet::new());
17041706
}
1705-
match self.method_map.find_mut(name) {
1707+
match method_map.get().find_mut(name) {
17061708
Some(s) => { s.insert(def_id); },
17071709
_ => fail!("Can't happen"),
17081710
}
@@ -4833,7 +4835,8 @@ impl Resolver {
48334835
};
48344836
match containing_module.kind.get() {
48354837
TraitModuleKind | ImplModuleKind => {
4836-
match self.method_map.find(&ident.name) {
4838+
let method_map = self.method_map.borrow();
4839+
match method_map.get().find(&ident.name) {
48374840
Some(s) => {
48384841
match containing_module.def_id.get() {
48394842
Some(def_id) if s.contains(&def_id) => {
@@ -5322,7 +5325,8 @@ impl Resolver {
53225325

53235326
let mut found_traits = ~[];
53245327
let mut search_module = self.current_module;
5325-
match self.method_map.find(&name.name) {
5328+
let method_map = self.method_map.borrow();
5329+
match method_map.get().find(&name.name) {
53265330
Some(candidate_traits) => loop {
53275331
// Look for the current trait.
53285332
match self.current_trait_refs {

src/librustc/middle/trans/callee.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,11 @@ pub fn trans_method_call(in_cx: @Block,
479479
node_id_type(in_cx, callee_id),
480480
expr_ty(in_cx, call_ex),
481481
|cx| {
482-
match cx.ccx().maps.method_map.find_copy(&call_ex.id) {
482+
let origin_opt = {
483+
let mut method_map = cx.ccx().maps.method_map.borrow_mut();
484+
method_map.get().find_copy(&call_ex.id)
485+
};
486+
match origin_opt {
483487
Some(origin) => {
484488
debug!("origin for {}: {}",
485489
call_ex.repr(in_cx.tcx()),

src/librustc/middle/trans/expr.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,10 @@ fn trans_rvalue_datum_unadjusted(bcx: @Block, expr: &ast::Expr) -> DatumBlock {
590590
}
591591
ast::ExprBinary(_, op, lhs, rhs) => {
592592
// if overloaded, would be RvalueDpsExpr
593-
assert!(!bcx.ccx().maps.method_map.contains_key(&expr.id));
593+
{
594+
let method_map = bcx.ccx().maps.method_map.borrow();
595+
assert!(!method_map.get().contains_key(&expr.id));
596+
}
594597

595598
return trans_binary(bcx, expr, op, lhs, rhs);
596599
}
@@ -1346,7 +1349,10 @@ fn trans_unary_datum(bcx: @Block,
13461349
assert!(op != ast::UnDeref);
13471350

13481351
// if overloaded, would be RvalueDpsExpr
1349-
assert!(!bcx.ccx().maps.method_map.contains_key(&un_expr.id));
1352+
{
1353+
let method_map = bcx.ccx().maps.method_map.borrow();
1354+
assert!(!method_map.get().contains_key(&un_expr.id));
1355+
}
13501356

13511357
let un_ty = expr_ty(bcx, un_expr);
13521358
let sub_ty = expr_ty(bcx, sub_expr);
@@ -1618,7 +1624,10 @@ fn trans_overloaded_op(bcx: @Block,
16181624
ret_ty: ty::t,
16191625
dest: Dest)
16201626
-> @Block {
1621-
let origin = bcx.ccx().maps.method_map.get_copy(&expr.id);
1627+
let origin = {
1628+
let method_map = bcx.ccx().maps.method_map.borrow();
1629+
method_map.get().get_copy(&expr.id)
1630+
};
16221631
let fty = node_id_type(bcx, callee_id);
16231632
callee::trans_call_inner(bcx,
16241633
expr.info(),
@@ -1780,7 +1789,11 @@ fn trans_assign_op(bcx: @Block,
17801789
let dst_datum = unpack_datum!(bcx, trans_lvalue_unadjusted(bcx, dst));
17811790

17821791
// A user-defined operator method
1783-
if bcx.ccx().maps.method_map.find(&expr.id).is_some() {
1792+
let found = {
1793+
let method_map = bcx.ccx().maps.method_map.borrow();
1794+
method_map.get().find(&expr.id).is_some()
1795+
};
1796+
if found {
17841797
// FIXME(#2528) evaluates the receiver twice!!
17851798
let scratch = scratch_datum(bcx, dst_datum.ty, "__assign_op", false);
17861799
let bcx = trans_overloaded_op(bcx,

src/librustc/middle/ty.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,8 @@ pub fn method_call_type_param_defs(tcx: ctxt,
30493049
method_map: typeck::method_map,
30503050
id: ast::NodeId)
30513051
-> Option<@~[TypeParameterDef]> {
3052-
method_map.find(&id).map(|method| {
3052+
let method_map = method_map.borrow();
3053+
method_map.get().find(&id).map(|method| {
30533054
match method.origin {
30543055
typeck::method_static(did) => {
30553056
// n.b.: When we encode impl methods, the bounds
@@ -3112,14 +3113,17 @@ pub enum ExprKind {
31123113
pub fn expr_kind(tcx: ctxt,
31133114
method_map: typeck::method_map,
31143115
expr: &ast::Expr) -> ExprKind {
3115-
if method_map.contains_key(&expr.id) {
3116-
// Overloaded operations are generally calls, and hence they are
3117-
// generated via DPS. However, assign_op (e.g., `x += y`) is an
3118-
// exception, as its result is always unit.
3119-
return match expr.node {
3120-
ast::ExprAssignOp(..) => RvalueStmtExpr,
3121-
_ => RvalueDpsExpr
3122-
};
3116+
{
3117+
let method_map = method_map.borrow();
3118+
if method_map.get().contains_key(&expr.id) {
3119+
// Overloaded operations are generally calls, and hence they are
3120+
// generated via DPS. However, assign_op (e.g., `x += y`) is an
3121+
// exception, as its result is always unit.
3122+
return match expr.node {
3123+
ast::ExprAssignOp(..) => RvalueStmtExpr,
3124+
_ => RvalueDpsExpr
3125+
};
3126+
}
31233127
}
31243128

31253129
match expr.node {

0 commit comments

Comments
 (0)