rustc: make MemCategorizationContext immutable.
This commit is contained in:
parent
45c8cb3597
commit
250ae7923f
@ -381,8 +381,7 @@ impl<'a> GatherLoanCtxt<'a> {
|
||||
Some(method) => {
|
||||
// Treat overloaded autoderefs as if an AutoRef adjustment
|
||||
// was applied on the base type, as that is always the case.
|
||||
let mut mc = self.bccx.mc();
|
||||
let cmt = match mc.cat_expr_autoderefd(expr, i) {
|
||||
let cmt = match self.bccx.mc().cat_expr_autoderefd(expr, i) {
|
||||
Ok(v) => v,
|
||||
Err(()) => self.tcx().sess.span_bug(expr.span, "Err from mc")
|
||||
};
|
||||
@ -431,7 +430,7 @@ impl<'a> GatherLoanCtxt<'a> {
|
||||
autoref: Some(ref autoref),
|
||||
autoderefs}) => {
|
||||
self.guarantee_autoderefs(expr, autoderefs);
|
||||
let mut mc = self.bccx.mc();
|
||||
let mc = self.bccx.mc();
|
||||
let cmt = match mc.cat_expr_autoderefd(expr, autoderefs) {
|
||||
Ok(v) => v,
|
||||
Err(()) => self.tcx().sess.span_bug(expr.span, "Err from mc")
|
||||
@ -793,7 +792,7 @@ impl<'a> GatherLoanCtxt<'a> {
|
||||
* `gather_pat()`.
|
||||
*/
|
||||
|
||||
let mut mc = self.bccx.mc();
|
||||
let mc = self.bccx.mc();
|
||||
for arg in decl.inputs.iter() {
|
||||
let arg_ty = ty::node_id_to_type(self.tcx(), arg.pat.id);
|
||||
|
||||
|
@ -910,7 +910,7 @@ impl<'a> mc::Typer for &'a ty::ctxt {
|
||||
*self
|
||||
}
|
||||
|
||||
fn node_ty(&mut self, id: ast::NodeId) -> mc::McResult<ty::t> {
|
||||
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<ty::t> {
|
||||
Ok(ty::node_id_to_type(*self, id))
|
||||
}
|
||||
|
||||
@ -922,15 +922,15 @@ impl<'a> mc::Typer for &'a ty::ctxt {
|
||||
&self.adjustments
|
||||
}
|
||||
|
||||
fn is_method_call(&mut self, id: ast::NodeId) -> bool {
|
||||
fn is_method_call(&self, id: ast::NodeId) -> bool {
|
||||
self.method_map.borrow().contains_key(&typeck::MethodCall::expr(id))
|
||||
}
|
||||
|
||||
fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> {
|
||||
fn temporary_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
|
||||
self.region_maps.temporary_scope(id)
|
||||
}
|
||||
|
||||
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
|
||||
fn upvar_borrow(&self, id: ty::UpvarId) -> ty::UpvarBorrow {
|
||||
self.upvar_borrow_map.borrow().get_copy(&id)
|
||||
}
|
||||
}
|
||||
|
@ -266,12 +266,12 @@ pub type McResult<T> = Result<T, ()>;
|
||||
*/
|
||||
pub trait Typer {
|
||||
fn tcx<'a>(&'a self) -> &'a ty::ctxt;
|
||||
fn node_ty(&mut self, id: ast::NodeId) -> McResult<ty::t>;
|
||||
fn node_ty(&self, id: ast::NodeId) -> McResult<ty::t>;
|
||||
fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t>;
|
||||
fn is_method_call(&mut self, id: ast::NodeId) -> bool;
|
||||
fn temporary_scope(&mut self, rvalue_id: ast::NodeId) -> Option<ast::NodeId>;
|
||||
fn upvar_borrow(&mut self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow;
|
||||
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>>;
|
||||
fn is_method_call(&self, id: ast::NodeId) -> bool;
|
||||
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<ast::NodeId>;
|
||||
fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow;
|
||||
}
|
||||
|
||||
impl MutabilityCategory {
|
||||
@ -353,30 +353,26 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
self.typer.tcx()
|
||||
}
|
||||
|
||||
fn adjustment(&mut self, id: ast::NodeId) -> Option<@ty::AutoAdjustment> {
|
||||
self.typer.adjustment(id)
|
||||
}
|
||||
|
||||
fn expr_ty(&mut self, expr: &ast::Expr) -> McResult<ty::t> {
|
||||
fn expr_ty(&self, expr: &ast::Expr) -> McResult<ty::t> {
|
||||
self.typer.node_ty(expr.id)
|
||||
}
|
||||
|
||||
fn expr_ty_adjusted(&mut self, expr: &ast::Expr) -> McResult<ty::t> {
|
||||
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<ty::t> {
|
||||
let unadjusted_ty = if_ok!(self.expr_ty(expr));
|
||||
Ok(ty::adjust_ty(self.tcx(), expr.span, expr.id, unadjusted_ty,
|
||||
self.typer.adjustments().borrow().find(&expr.id),
|
||||
|method_call| self.typer.node_method_ty(method_call)))
|
||||
}
|
||||
|
||||
fn node_ty(&mut self, id: ast::NodeId) -> McResult<ty::t> {
|
||||
fn node_ty(&self, id: ast::NodeId) -> McResult<ty::t> {
|
||||
self.typer.node_ty(id)
|
||||
}
|
||||
|
||||
fn pat_ty(&mut self, pat: @ast::Pat) -> McResult<ty::t> {
|
||||
fn pat_ty(&self, pat: @ast::Pat) -> McResult<ty::t> {
|
||||
self.typer.node_ty(pat.id)
|
||||
}
|
||||
|
||||
pub fn cat_expr(&mut self, expr: &ast::Expr) -> McResult<cmt> {
|
||||
pub fn cat_expr(&self, expr: &ast::Expr) -> McResult<cmt> {
|
||||
match self.typer.adjustments().borrow().find(&expr.id) {
|
||||
None => {
|
||||
// No adjustments.
|
||||
@ -420,7 +416,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_expr_autoderefd(&mut self, expr: &ast::Expr, autoderefs: uint)
|
||||
pub fn cat_expr_autoderefd(&self, expr: &ast::Expr, autoderefs: uint)
|
||||
-> McResult<cmt> {
|
||||
let mut cmt = if_ok!(self.cat_expr_unadjusted(expr));
|
||||
for deref in range(1u, autoderefs + 1) {
|
||||
@ -429,7 +425,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
return Ok(cmt);
|
||||
}
|
||||
|
||||
pub fn cat_expr_unadjusted(&mut self, expr: &ast::Expr) -> McResult<cmt> {
|
||||
pub fn cat_expr_unadjusted(&self, expr: &ast::Expr) -> McResult<cmt> {
|
||||
debug!("cat_expr: id={} expr={}", expr.id, expr.repr(self.tcx()));
|
||||
|
||||
let expr_ty = if_ok!(self.expr_ty(expr));
|
||||
@ -478,7 +474,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_def(&mut self,
|
||||
pub fn cat_def(&self,
|
||||
id: ast::NodeId,
|
||||
span: Span,
|
||||
expr_ty: ty::t,
|
||||
@ -593,7 +589,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_upvar(&mut self,
|
||||
fn cat_upvar(&self,
|
||||
id: ast::NodeId,
|
||||
span: Span,
|
||||
var_id: ast::NodeId,
|
||||
@ -643,7 +639,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
Ok(deref_cmt)
|
||||
}
|
||||
|
||||
pub fn cat_rvalue_node(&mut self,
|
||||
pub fn cat_rvalue_node(&self,
|
||||
id: ast::NodeId,
|
||||
span: Span,
|
||||
expr_ty: ty::t)
|
||||
@ -658,7 +654,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_rvalue(&mut self,
|
||||
pub fn cat_rvalue(&self,
|
||||
cmt_id: ast::NodeId,
|
||||
span: Span,
|
||||
temp_scope: ty::Region,
|
||||
@ -672,7 +668,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_field<N:ast_node>(&mut self,
|
||||
pub fn cat_field<N:ast_node>(&self,
|
||||
node: &N,
|
||||
base_cmt: cmt,
|
||||
f_name: ast::Ident,
|
||||
@ -687,11 +683,11 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_deref_obj<N:ast_node>(&mut self, node: &N, base_cmt: cmt) -> cmt {
|
||||
pub fn cat_deref_obj<N:ast_node>(&self, node: &N, base_cmt: cmt) -> cmt {
|
||||
self.cat_deref_common(node, base_cmt, 0, ty::mk_nil())
|
||||
}
|
||||
|
||||
fn cat_deref<N:ast_node>(&mut self,
|
||||
fn cat_deref<N:ast_node>(&self,
|
||||
node: &N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint)
|
||||
@ -723,7 +719,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_deref_common<N:ast_node>(&mut self,
|
||||
fn cat_deref_common<N:ast_node>(&self,
|
||||
node: &N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint,
|
||||
@ -749,7 +745,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_index<N:ast_node>(&mut self,
|
||||
pub fn cat_index<N:ast_node>(&self,
|
||||
elt: &N,
|
||||
base_cmt: cmt,
|
||||
derefs: uint)
|
||||
@ -836,7 +832,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_slice_pattern(&mut self,
|
||||
pub fn cat_slice_pattern(&self,
|
||||
vec_cmt: cmt,
|
||||
slice_pat: @ast::Pat)
|
||||
-> McResult<(cmt, ast::Mutability, ty::Region)> {
|
||||
@ -883,7 +879,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_imm_interior<N:ast_node>(&mut self,
|
||||
pub fn cat_imm_interior<N:ast_node>(&self,
|
||||
node: &N,
|
||||
base_cmt: cmt,
|
||||
interior_ty: ty::t,
|
||||
@ -898,7 +894,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_downcast<N:ast_node>(&mut self,
|
||||
pub fn cat_downcast<N:ast_node>(&self,
|
||||
node: &N,
|
||||
base_cmt: cmt,
|
||||
downcast_ty: ty::t)
|
||||
@ -912,12 +908,12 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat_pattern(&mut self,
|
||||
pub fn cat_pattern(&self,
|
||||
cmt: cmt,
|
||||
pat: @ast::Pat,
|
||||
op: |&mut MemCategorizationContext<TYPER>,
|
||||
pat: &ast::Pat,
|
||||
op: |&MemCategorizationContext<TYPER>,
|
||||
cmt,
|
||||
@ast::Pat|)
|
||||
&ast::Pat|)
|
||||
-> McResult<()> {
|
||||
// Here, `cmt` is the categorization for the value being
|
||||
// matched and pat is the pattern it is being matched against.
|
||||
|
@ -236,7 +236,7 @@ impl<'a> Rcx<'a> {
|
||||
}
|
||||
|
||||
/// Try to resolve the type for the given node.
|
||||
fn resolve_node_type(&mut self, id: ast::NodeId) -> ty::t {
|
||||
fn resolve_node_type(&self, id: ast::NodeId) -> ty::t {
|
||||
let t = self.fcx.node_ty(id);
|
||||
self.resolve_type(t)
|
||||
}
|
||||
@ -261,12 +261,12 @@ impl<'a> Rcx<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
|
||||
impl<'a, 'b> mc::Typer for &'a Rcx<'b> {
|
||||
fn tcx<'a>(&'a self) -> &'a ty::ctxt {
|
||||
self.fcx.tcx()
|
||||
}
|
||||
|
||||
fn node_ty(&mut self, id: ast::NodeId) -> mc::McResult<ty::t> {
|
||||
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<ty::t> {
|
||||
let t = self.resolve_node_type(id);
|
||||
if ty::type_is_error(t) {Err(())} else {Ok(t)}
|
||||
}
|
||||
@ -279,15 +279,15 @@ impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
|
||||
&self.fcx.inh.adjustments
|
||||
}
|
||||
|
||||
fn is_method_call(&mut self, id: ast::NodeId) -> bool {
|
||||
fn is_method_call(&self, id: ast::NodeId) -> bool {
|
||||
self.fcx.inh.method_map.borrow().contains_key(&MethodCall::expr(id))
|
||||
}
|
||||
|
||||
fn temporary_scope(&mut self, id: ast::NodeId) -> Option<ast::NodeId> {
|
||||
fn temporary_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
|
||||
self.tcx().region_maps.temporary_scope(id)
|
||||
}
|
||||
|
||||
fn upvar_borrow(&mut self, id: ty::UpvarId) -> ty::UpvarBorrow {
|
||||
fn upvar_borrow(&self, id: ty::UpvarId) -> ty::UpvarBorrow {
|
||||
self.fcx.inh.upvar_borrow_map.borrow().get_copy(&id)
|
||||
}
|
||||
}
|
||||
@ -870,7 +870,7 @@ fn constrain_autoderefs(rcx: &mut Rcx,
|
||||
method.ty.repr(rcx.tcx())))
|
||||
};
|
||||
{
|
||||
let mut mc = mc::MemCategorizationContext { typer: &mut *rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: &*rcx };
|
||||
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
|
||||
link_region(mc.typer, deref_expr.span, r, m, self_cmt);
|
||||
}
|
||||
@ -1027,13 +1027,13 @@ fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
|
||||
debug!("link_addr_of(base=?)");
|
||||
|
||||
let cmt = {
|
||||
let mut mc = mc::MemCategorizationContext { typer: &mut *rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: &*rcx };
|
||||
ignore_err!(mc.cat_expr(base))
|
||||
};
|
||||
link_region_from_node_type(rcx, expr.span, expr.id, mutability, cmt);
|
||||
}
|
||||
|
||||
fn link_local(rcx: &mut Rcx, local: &ast::Local) {
|
||||
fn link_local(rcx: &Rcx, local: &ast::Local) {
|
||||
/*!
|
||||
* Computes the guarantors for any ref bindings in a `let` and
|
||||
* then ensures that the lifetime of the resulting pointer is
|
||||
@ -1045,12 +1045,12 @@ fn link_local(rcx: &mut Rcx, local: &ast::Local) {
|
||||
None => { return; }
|
||||
Some(expr) => expr,
|
||||
};
|
||||
let mut mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
|
||||
link_pattern(&mut mc, discr_cmt, local.pat);
|
||||
link_pattern(mc, discr_cmt, local.pat);
|
||||
}
|
||||
|
||||
fn link_match(rcx: &mut Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
|
||||
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
|
||||
/*!
|
||||
* Computes the guarantors for any ref bindings in a match and
|
||||
* then ensures that the lifetime of the resulting pointer is
|
||||
@ -1058,19 +1058,19 @@ fn link_match(rcx: &mut Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
|
||||
*/
|
||||
|
||||
debug!("regionck::for_match()");
|
||||
let mut mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let discr_cmt = ignore_err!(mc.cat_expr(discr));
|
||||
debug!("discr_cmt={}", discr_cmt.repr(mc.typer.tcx()));
|
||||
for arm in arms.iter() {
|
||||
for &root_pat in arm.pats.iter() {
|
||||
link_pattern(&mut mc, discr_cmt, root_pat);
|
||||
link_pattern(mc, discr_cmt, root_pat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn link_pattern(mc: &mut mc::MemCategorizationContext<&mut Rcx>,
|
||||
fn link_pattern(mc: mc::MemCategorizationContext<&Rcx>,
|
||||
discr_cmt: mc::cmt,
|
||||
root_pat: @ast::Pat) {
|
||||
root_pat: &ast::Pat) {
|
||||
/*!
|
||||
* Link lifetimes of any ref bindings in `root_pat` to
|
||||
* the pointers found in the discriminant, if needed.
|
||||
@ -1100,7 +1100,7 @@ fn link_pattern(mc: &mut mc::MemCategorizationContext<&mut Rcx>,
|
||||
});
|
||||
}
|
||||
|
||||
fn link_autoref(rcx: &mut Rcx,
|
||||
fn link_autoref(rcx: &Rcx,
|
||||
expr: &ast::Expr,
|
||||
autoderefs: uint,
|
||||
autoref: &ty::AutoRef) {
|
||||
@ -1110,7 +1110,7 @@ fn link_autoref(rcx: &mut Rcx,
|
||||
*/
|
||||
|
||||
debug!("link_autoref(autoref={:?})", autoref);
|
||||
let mut mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
|
||||
debug!("expr_cmt={}", expr_cmt.repr(mc.typer.tcx()));
|
||||
|
||||
@ -1133,7 +1133,7 @@ fn link_autoref(rcx: &mut Rcx,
|
||||
}
|
||||
}
|
||||
|
||||
fn link_by_ref(rcx: &mut Rcx,
|
||||
fn link_by_ref(rcx: &Rcx,
|
||||
expr: &ast::Expr,
|
||||
callee_scope: ast::NodeId) {
|
||||
/*!
|
||||
@ -1145,13 +1145,13 @@ fn link_by_ref(rcx: &mut Rcx,
|
||||
let tcx = rcx.tcx();
|
||||
debug!("link_by_ref(expr={}, callee_scope={})",
|
||||
expr.repr(tcx), callee_scope);
|
||||
let mut mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let expr_cmt = ignore_err!(mc.cat_expr(expr));
|
||||
let region_min = ty::ReScope(callee_scope);
|
||||
link_region(mc.typer, expr.span, region_min, ast::MutImmutable, expr_cmt);
|
||||
}
|
||||
|
||||
fn link_region_from_node_type(rcx: &mut Rcx,
|
||||
fn link_region_from_node_type(rcx: &Rcx,
|
||||
span: Span,
|
||||
id: ast::NodeId,
|
||||
mutbl: ast::Mutability,
|
||||
@ -1171,7 +1171,7 @@ fn link_region_from_node_type(rcx: &mut Rcx,
|
||||
}
|
||||
}
|
||||
|
||||
fn link_region(rcx: &mut Rcx,
|
||||
fn link_region(rcx: &Rcx,
|
||||
span: Span,
|
||||
region_min: ty::Region,
|
||||
mutbl: ast::Mutability,
|
||||
@ -1282,7 +1282,7 @@ fn link_region(rcx: &mut Rcx,
|
||||
}
|
||||
}
|
||||
|
||||
fn adjust_borrow_kind_for_assignment_lhs(rcx: &mut Rcx,
|
||||
fn adjust_borrow_kind_for_assignment_lhs(rcx: &Rcx,
|
||||
lhs: &ast::Expr) {
|
||||
/*!
|
||||
* Adjusts the inferred borrow_kind as needed to account
|
||||
@ -1290,12 +1290,12 @@ fn adjust_borrow_kind_for_assignment_lhs(rcx: &mut Rcx,
|
||||
* expression.
|
||||
*/
|
||||
|
||||
let mut mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let mc = mc::MemCategorizationContext { typer: rcx };
|
||||
let cmt = ignore_err!(mc.cat_expr(lhs));
|
||||
adjust_upvar_borrow_kind_for_mut(mc.typer, cmt);
|
||||
}
|
||||
|
||||
fn adjust_upvar_borrow_kind_for_mut(rcx: &mut Rcx,
|
||||
fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx,
|
||||
cmt: mc::cmt) {
|
||||
let mut cmt = cmt;
|
||||
loop {
|
||||
@ -1350,8 +1350,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &mut Rcx,
|
||||
}
|
||||
}
|
||||
|
||||
fn adjust_upvar_borrow_kind_for_unique(rcx: &mut Rcx,
|
||||
cmt: mc::cmt) {
|
||||
fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) {
|
||||
let mut cmt = cmt;
|
||||
loop {
|
||||
debug!("adjust_upvar_borrow_kind_for_unique(cmt={})",
|
||||
|
Loading…
Reference in New Issue
Block a user