From 7cf6abc84a92a2556225edbe3f6a07a39ff06a3f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Dec 2013 18:26:45 -0800 Subject: [PATCH] librustc: De-`@mut` the adjustments table in the type context --- src/librustc/middle/astencode.rs | 8 +++++-- src/librustc/middle/borrowck/check_loans.rs | 8 +++++-- .../middle/borrowck/gather_loans/mod.rs | 3 ++- src/librustc/middle/lint.rs | 6 ++++- src/librustc/middle/mem_categorization.rs | 3 ++- src/librustc/middle/moves.rs | 13 +++++++---- src/librustc/middle/trans/consts.rs | 5 +++- src/librustc/middle/trans/expr.rs | 23 ++++++++++++++----- src/librustc/middle/ty.rs | 14 +++++++---- src/librustc/middle/typeck/check/mod.rs | 7 +++--- src/librustc/middle/typeck/check/regionck.rs | 19 ++++++++++----- src/librustc/middle/typeck/check/writeback.rs | 16 +++++++++---- 12 files changed, 87 insertions(+), 38 deletions(-) diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 724499bd90fc..79b43a64f96b 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1002,7 +1002,8 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } { - let r = tcx.adjustments.find(&id); + let adjustments = tcx.adjustments.borrow(); + let r = adjustments.get().find(&id); for adj in r.iter() { ebml_w.tag(c::tag_table_adjustments, |ebml_w| { ebml_w.id(id); @@ -1268,7 +1269,10 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, c::tag_table_adjustments => { let adj: @ty::AutoAdjustment = @Decodable::decode(val_dsr); adj.tr(xcx); - dcx.tcx.adjustments.insert(id, adj); + let mut adjustments = dcx.tcx + .adjustments + .borrow_mut(); + adjustments.get().insert(id, adj); } c::tag_table_capture_map => { let cvars = diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 13c45cc8e36d..96b2637da877 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -296,9 +296,13 @@ impl<'a> CheckLoanCtxt<'a> { pub fn check_assignment(&self, expr: @ast::Expr) { // We don't use cat_expr() here because we don't want to treat // auto-ref'd parameters in overloaded operators as rvalues. - let cmt = match self.bccx.tcx.adjustments.find(&expr.id) { + let adj = { + let adjustments = self.bccx.tcx.adjustments.borrow(); + adjustments.get().find_copy(&expr.id) + }; + let cmt = match adj { None => self.bccx.cat_expr_unadjusted(expr), - Some(&adj) => self.bccx.cat_expr_autoderefd(expr, adj) + Some(adj) => self.bccx.cat_expr_autoderefd(expr, adj) }; debug!("check_assignment(cmt={})", cmt.repr(self.tcx())); diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index c07a7767c24a..7a48fad4ce59 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -208,7 +208,8 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt, // If this expression is borrowed, have to ensure it remains valid: { - let r = tcx.adjustments.find(&ex.id); + let adjustments = tcx.adjustments.borrow(); + let r = adjustments.get().find(&ex.id); for &adjustments in r.iter() { this.guarantee_adjustments(ex, *adjustments); } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index fa8c6422cb85..72140d333730 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -1073,7 +1073,11 @@ fn check_unnecessary_allocation(cx: &Context, e: &ast::Expr) { cx.span_lint(unnecessary_allocation, e.span, msg); }; - match cx.tcx.adjustments.find_copy(&e.id) { + let adjustment = { + let adjustments = cx.tcx.adjustments.borrow(); + adjustments.get().find_copy(&e.id) + }; + match adjustment { Some(@ty::AutoDerefRef(ty::AutoDerefRef { autoref, .. })) => { match (allocation, autoref) { (VectorAllocation, Some(ty::AutoBorrowVec(..))) => { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 0c44f58aeb40..2d9fbed01542 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -340,7 +340,8 @@ impl mem_categorization_ctxt { } pub fn cat_expr(&self, expr: @ast::Expr) -> cmt { - match self.tcx.adjustments.find(&expr.id) { + let adjustments = self.tcx.adjustments.borrow(); + match adjustments.get().find(&expr.id) { None => { // No adjustments. self.cat_expr_unadjusted(expr) diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index c9911480199e..311e4400bb4d 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -321,11 +321,14 @@ impl VisitContext { // `expr_mode` refers to the post-adjustment value. If one of // those adjustments is to take a reference, then it's only // reading the underlying expression, not moving it. - let comp_mode = match self.tcx.adjustments.find(&expr.id) { - Some(&@ty::AutoDerefRef( - ty::AutoDerefRef { - autoref: Some(_), ..})) => Read, - _ => expr_mode + let comp_mode = { + let adjustments = self.tcx.adjustments.borrow(); + match adjustments.get().find(&expr.id) { + Some(&@ty::AutoDerefRef( + ty::AutoDerefRef { + autoref: Some(_), ..})) => Read, + _ => expr_mode + } }; debug!("comp_mode = {:?}", comp_mode); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 91e737b2cd12..6526842d7cb8 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -186,7 +186,10 @@ pub fn const_expr(cx: @CrateContext, e: &ast::Expr) -> (ValueRef, bool) { let mut llconst = llconst; let mut inlineable = inlineable; let ety = ty::expr_ty(cx.tcx, e); - let adjustment = cx.tcx.adjustments.find_copy(&e.id); + let adjustment = { + let adjustments = cx.tcx.adjustments.borrow(); + adjustments.get().find_copy(&e.id) + }; match adjustment { None => { } Some(@ty::AutoAddEnv(ty::ReStatic, ast::BorrowedSigil)) => { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 095dee497030..cf6fca23c96b 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -180,9 +180,12 @@ pub fn trans_to_datum(bcx: @Block, expr: &ast::Expr) -> DatumBlock { let mut bcx = bcx; let mut datum = unpack_datum!(bcx, trans_to_datum_unadjusted(bcx, expr)); - let adjustment = match bcx.tcx().adjustments.find_copy(&expr.id) { - None => { return DatumBlock {bcx: bcx, datum: datum}; } - Some(adj) => { adj } + let adjustment = { + let adjustments = bcx.tcx().adjustments.borrow(); + match adjustments.get().find_copy(&expr.id) { + None => { return DatumBlock {bcx: bcx, datum: datum}; } + Some(adj) => { adj } + } }; debug!("unadjusted datum: {}", datum.to_str(bcx.ccx())); match *adjustment { @@ -415,7 +418,11 @@ pub fn trans_to_datum(bcx: @Block, expr: &ast::Expr) -> DatumBlock { } pub fn trans_into(bcx: @Block, expr: &ast::Expr, dest: Dest) -> @Block { - if bcx.tcx().adjustments.contains_key(&expr.id) { + let adjustment_found = { + let adjustments = bcx.tcx().adjustments.borrow(); + adjustments.get().contains_key(&expr.id) + }; + if adjustment_found { // use trans_to_datum, which is mildly less efficient but // which will perform the adjustments: let datumblock = trans_to_datum(bcx, expr); @@ -480,7 +487,11 @@ fn trans_lvalue(bcx: @Block, expr: &ast::Expr) -> DatumBlock { * instead, but sometimes we call trans_lvalue() directly as a * means of asserting that a particular expression is an lvalue. */ - return match bcx.tcx().adjustments.find(&expr.id) { + let adjustment_opt = { + let adjustments = bcx.tcx().adjustments.borrow(); + adjustments.get().find_copy(&expr.id) + }; + match adjustment_opt { None => trans_lvalue_unadjusted(bcx, expr), Some(_) => { bcx.sess().span_bug( @@ -488,7 +499,7 @@ fn trans_lvalue(bcx: @Block, expr: &ast::Expr) -> DatumBlock { format!("trans_lvalue() called on an expression \ with adjustments")); } - }; + } } fn trans_to_datum_unadjusted(bcx: @Block, expr: &ast::Expr) -> DatumBlock { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 92abefe31409..117b4559c2c0 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -312,7 +312,7 @@ struct ctxt_ { ast_ty_to_ty_cache: RefCell>, enum_var_cache: RefCell>, ty_param_defs: RefCell>, - adjustments: @mut HashMap, + adjustments: RefCell>, normalized_cache: @mut HashMap, lang_items: middle::lang_items::LanguageItems, // A mapping of fake provided method def_ids to the default implementation @@ -1002,7 +1002,7 @@ pub fn mk_ctxt(s: session::Session, trait_methods_cache: RefCell::new(HashMap::new()), impl_trait_cache: RefCell::new(HashMap::new()), ty_param_defs: RefCell::new(HashMap::new()), - adjustments: @mut HashMap::new(), + adjustments: RefCell::new(HashMap::new()), normalized_cache: new_ty_hash(), lang_items: lang_items, provided_method_sources: @mut HashMap::new(), @@ -2876,14 +2876,18 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: &ast::Expr) -> t { */ let unadjusted_ty = expr_ty(cx, expr); - adjust_ty(cx, expr.span, unadjusted_ty, cx.adjustments.find_copy(&expr.id)) + let adjustment = { + let adjustments = cx.adjustments.borrow(); + adjustments.get().find_copy(&expr.id) + }; + adjust_ty(cx, expr.span, unadjusted_ty, adjustment) } pub fn adjust_ty(cx: ctxt, span: Span, unadjusted_ty: ty::t, - adjustment: Option<@AutoAdjustment>) -> ty::t -{ + adjustment: Option<@AutoAdjustment>) + -> ty::t { /*! See `expr_ty_adjusted` */ return match adjustment { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index bcfe31b0eb66..1abdc43d3911 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -164,7 +164,7 @@ pub struct Inherited { // Temporary tables: node_types: @mut HashMap, node_type_substs: RefCell>, - adjustments: @mut HashMap, + adjustments: RefCell>, method_map: method_map, vtable_map: vtable_map, } @@ -264,7 +264,7 @@ impl Inherited { param_env: param_env, node_types: @mut HashMap::new(), node_type_substs: RefCell::new(HashMap::new()), - adjustments: @mut HashMap::new(), + adjustments: RefCell::new(HashMap::new()), method_map: @mut HashMap::new(), vtable_map: @mut HashMap::new(), } @@ -1137,7 +1137,8 @@ impl FnCtxt { node_id: ast::NodeId, adj: @ty::AutoAdjustment) { debug!("write_adjustment(node_id={:?}, adj={:?})", node_id, adj); - self.inh.adjustments.insert(node_id, adj); + let mut adjustments = self.inh.adjustments.borrow_mut(); + adjustments.get().insert(node_id, adj); } pub fn write_nil(&self, node_id: ast::NodeId) { diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 490405bb49d4..7c74a7b73b45 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -134,9 +134,11 @@ impl Rcx { ty_unadjusted } else { let tcx = self.fcx.tcx(); - let adjustments = self.fcx.inh.adjustments; - ty::adjust_ty(tcx, expr.span, ty_unadjusted, - adjustments.find_copy(&expr.id)) + let adjustment = { + let adjustments = self.fcx.inh.adjustments.borrow(); + adjustments.get().find_copy(&expr.id) + }; + ty::adjust_ty(tcx, expr.span, ty_unadjusted, adjustment) } } } @@ -300,7 +302,8 @@ fn visit_expr(rcx: &mut Rcx, expr: @ast::Expr) { // Check any autoderefs or autorefs that appear. { - let r = rcx.fcx.inh.adjustments.find(&expr.id); + let adjustments = rcx.fcx.inh.adjustments.borrow(); + let r = adjustments.get().find(&expr.id); for &adjustment in r.iter() { debug!("adjustment={:?}", adjustment); match *adjustment { @@ -699,7 +702,10 @@ fn constrain_regions_in_type_of_node( // is going to fail anyway, so just stop here and let typeck // report errors later on in the writeback phase. let ty0 = rcx.resolve_node_type(id); - let adjustment = rcx.fcx.inh.adjustments.find_copy(&id); + let adjustment = { + let adjustments = rcx.fcx.inh.adjustments.borrow(); + adjustments.get().find_copy(&id) + }; let ty = ty::adjust_ty(tcx, origin.span(), ty0, adjustment); debug!("constrain_regions_in_type_of_node(\ ty={}, ty0={}, id={}, minimum_lifetime={:?}, adjustment={:?})", @@ -1055,7 +1061,8 @@ pub mod guarantor { let mut expr_ct = categorize_unadjusted(rcx, expr); debug!("before adjustments, cat={:?}", expr_ct.cat); - match rcx.fcx.inh.adjustments.find(&expr.id) { + let adjustments = rcx.fcx.inh.adjustments.borrow(); + match adjustments.get().find(&expr.id) { Some(&@ty::AutoAddEnv(..)) => { // This is basically an rvalue, not a pointer, no regions // involved. diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index acccbb310d2e..a04fe1c13644 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -120,10 +120,14 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId) let tcx = fcx.ccx.tcx; // Resolve any borrowings for the node with id `id` - match fcx.inh.adjustments.find(&id) { + let adjustment = { + let adjustments = fcx.inh.adjustments.borrow(); + adjustments.get().find_copy(&id) + }; + match adjustment { None => (), - Some(&@ty::AutoAddEnv(r, s)) => { + Some(@ty::AutoAddEnv(r, s)) => { match resolve_region(fcx.infcx(), r, resolve_all | force_all) { Err(e) => { // This should not, I think, happen: @@ -134,12 +138,13 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId) Ok(r1) => { let resolved_adj = @ty::AutoAddEnv(r1, s); debug!("Adjustments for node {}: {:?}", id, resolved_adj); - fcx.tcx().adjustments.insert(id, resolved_adj); + let mut adjustments = fcx.tcx().adjustments.borrow_mut(); + adjustments.get().insert(id, resolved_adj); } } } - Some(&@ty::AutoDerefRef(adj)) => { + Some(@ty::AutoDerefRef(adj)) => { let fixup_region = |r| { match resolve_region(fcx.infcx(), r, resolve_all | force_all) { Ok(r1) => r1, @@ -163,7 +168,8 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId) autoref: resolved_autoref, }); debug!("Adjustments for node {}: {:?}", id, resolved_adj); - fcx.tcx().adjustments.insert(id, resolved_adj); + let mut adjustments = fcx.tcx().adjustments.borrow_mut(); + adjustments.get().insert(id, resolved_adj); } }