librustc: De-@mut the adjustments table in the type context

This commit is contained in:
Patrick Walton 2013-12-19 18:26:45 -08:00
parent 3e9bcea018
commit 7cf6abc84a
12 changed files with 87 additions and 38 deletions

View File

@ -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 =

View File

@ -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()));

View File

@ -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);
}

View File

@ -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(..))) => {

View File

@ -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)

View File

@ -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);

View File

@ -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)) => {

View File

@ -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 {

View File

@ -312,7 +312,7 @@ struct ctxt_ {
ast_ty_to_ty_cache: RefCell<HashMap<NodeId, ast_ty_to_ty_cache_entry>>,
enum_var_cache: RefCell<HashMap<DefId, @~[@VariantInfo]>>,
ty_param_defs: RefCell<HashMap<ast::NodeId, TypeParameterDef>>,
adjustments: @mut HashMap<ast::NodeId, @AutoAdjustment>,
adjustments: RefCell<HashMap<ast::NodeId, @AutoAdjustment>>,
normalized_cache: @mut HashMap<t, t>,
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 {

View File

@ -164,7 +164,7 @@ pub struct Inherited {
// Temporary tables:
node_types: @mut HashMap<ast::NodeId, ty::t>,
node_type_substs: RefCell<HashMap<ast::NodeId, ty::substs>>,
adjustments: @mut HashMap<ast::NodeId, @ty::AutoAdjustment>,
adjustments: RefCell<HashMap<ast::NodeId, @ty::AutoAdjustment>>,
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) {

View File

@ -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.

View File

@ -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);
}
}