Mucho debug instrumentation.
This commit is contained in:
parent
b0fd67b3e7
commit
aa1398176e
@ -295,23 +295,29 @@ pub trait Typer<'tcx> : ty::ClosureTyper<'tcx> {
|
||||
|
||||
impl MutabilityCategory {
|
||||
pub fn from_mutbl(m: ast::Mutability) -> MutabilityCategory {
|
||||
match m {
|
||||
let ret = match m {
|
||||
MutImmutable => McImmutable,
|
||||
MutMutable => McDeclared
|
||||
}
|
||||
};
|
||||
debug!("MutabilityCategory::{}({:?}) => {:?}",
|
||||
"from_mutbl", m, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn from_borrow_kind(borrow_kind: ty::BorrowKind) -> MutabilityCategory {
|
||||
match borrow_kind {
|
||||
let ret = match borrow_kind {
|
||||
ty::ImmBorrow => McImmutable,
|
||||
ty::UniqueImmBorrow => McImmutable,
|
||||
ty::MutBorrow => McDeclared,
|
||||
}
|
||||
};
|
||||
debug!("MutabilityCategory::{}({:?}) => {:?}",
|
||||
"from_borrow_kind", borrow_kind, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
|
||||
ptr: PointerKind) -> MutabilityCategory {
|
||||
match ptr {
|
||||
let ret = match ptr {
|
||||
Unique => {
|
||||
base_mutbl.inherit()
|
||||
}
|
||||
@ -321,11 +327,14 @@ impl MutabilityCategory {
|
||||
UnsafePtr(m) => {
|
||||
MutabilityCategory::from_mutbl(m)
|
||||
}
|
||||
}
|
||||
};
|
||||
debug!("MutabilityCategory::{}({:?}, {:?}) => {:?}",
|
||||
"from_pointer_kind", base_mutbl, ptr, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
fn from_local(tcx: &ty::ctxt, id: ast::NodeId) -> MutabilityCategory {
|
||||
match tcx.map.get(id) {
|
||||
let ret = match tcx.map.get(id) {
|
||||
ast_map::NodeLocal(p) | ast_map::NodeArg(p) => match p.node {
|
||||
ast::PatIdent(bind_mode, _, _) => {
|
||||
if bind_mode == ast::BindByValue(ast::MutMutable) {
|
||||
@ -337,30 +346,39 @@ impl MutabilityCategory {
|
||||
_ => tcx.sess.span_bug(p.span, "expected identifier pattern")
|
||||
},
|
||||
_ => tcx.sess.span_bug(tcx.map.span(id), "expected identifier pattern")
|
||||
}
|
||||
};
|
||||
debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}",
|
||||
"from_local", id, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn inherit(&self) -> MutabilityCategory {
|
||||
match *self {
|
||||
let ret = match *self {
|
||||
McImmutable => McImmutable,
|
||||
McDeclared => McInherited,
|
||||
McInherited => McInherited,
|
||||
}
|
||||
};
|
||||
debug!("{:?}.inherit() => {:?}", self, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn is_mutable(&self) -> bool {
|
||||
match *self {
|
||||
let ret = match *self {
|
||||
McImmutable => false,
|
||||
McInherited => true,
|
||||
McDeclared => true,
|
||||
}
|
||||
};
|
||||
debug!("{:?}.is_mutable() => {:?}", self, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn is_immutable(&self) -> bool {
|
||||
match *self {
|
||||
let ret = match *self {
|
||||
McImmutable => true,
|
||||
McDeclared | McInherited => false
|
||||
}
|
||||
};
|
||||
debug!("{:?}.is_immutable() => {:?}", self, ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn to_user_str(&self) -> &'static str {
|
||||
@ -733,7 +751,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Rc::new(cmt_result))
|
||||
let ret = Rc::new(cmt_result);
|
||||
debug!("cat_upvar ret={}", ret.repr(self.tcx()));
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
fn env_deref(&self,
|
||||
@ -794,14 +814,18 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
McDeclared | McInherited => { }
|
||||
}
|
||||
|
||||
cmt_ {
|
||||
let ret = cmt_ {
|
||||
id: id,
|
||||
span: span,
|
||||
cat: cat_deref(Rc::new(cmt_result), 0, env_ptr),
|
||||
mutbl: deref_mutbl,
|
||||
ty: var_ty,
|
||||
note: NoteClosureEnv(upvar_id)
|
||||
}
|
||||
};
|
||||
|
||||
debug!("env_deref ret {}", ret.repr(self.tcx()));
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_rvalue_node(&self,
|
||||
@ -831,7 +855,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
}
|
||||
}
|
||||
};
|
||||
self.cat_rvalue(id, span, re, expr_ty)
|
||||
let ret = self.cat_rvalue(id, span, re, expr_ty);
|
||||
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_rvalue(&self,
|
||||
@ -839,14 +865,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
span: Span,
|
||||
temp_scope: ty::Region,
|
||||
expr_ty: Ty<'tcx>) -> cmt<'tcx> {
|
||||
Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id:cmt_id,
|
||||
span:span,
|
||||
cat:cat_rvalue(temp_scope),
|
||||
mutbl:McDeclared,
|
||||
ty:expr_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
});
|
||||
debug!("cat_rvalue ret {}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_field<N:ast_node>(&self,
|
||||
@ -855,14 +883,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
f_name: ast::Name,
|
||||
f_ty: Ty<'tcx>)
|
||||
-> cmt<'tcx> {
|
||||
Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
mutbl: base_cmt.mutbl.inherit(),
|
||||
cat: cat_interior(base_cmt, InteriorField(NamedField(f_name))),
|
||||
ty: f_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
});
|
||||
debug!("cat_field ret {}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_tup_field<N:ast_node>(&self,
|
||||
@ -871,14 +901,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
f_idx: uint,
|
||||
f_ty: Ty<'tcx>)
|
||||
-> cmt<'tcx> {
|
||||
Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
mutbl: base_cmt.mutbl.inherit(),
|
||||
cat: cat_interior(base_cmt, InteriorField(PositionalField(f_idx))),
|
||||
ty: f_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
});
|
||||
debug!("cat_tup_field ret {}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
fn cat_deref<N:ast_node>(&self,
|
||||
@ -913,10 +945,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
};
|
||||
let base_cmt_ty = base_cmt.ty;
|
||||
match ty::deref(base_cmt_ty, true) {
|
||||
Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt,
|
||||
Some(mt) => {
|
||||
let ret = self.cat_deref_common(node, base_cmt, deref_cnt,
|
||||
mt.ty,
|
||||
deref_context,
|
||||
/* implicit: */ false),
|
||||
/* implicit: */ false);
|
||||
debug!("cat_deref ret {}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
None => {
|
||||
debug!("Explicit deref of non-derefable type: {}",
|
||||
base_cmt_ty.repr(self.tcx()));
|
||||
@ -954,14 +990,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
(base_cmt.mutbl.inherit(), cat_interior(base_cmt, interior))
|
||||
}
|
||||
};
|
||||
Ok(Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
cat: cat,
|
||||
mutbl: m,
|
||||
ty: deref_ty,
|
||||
note: NoteNone
|
||||
}))
|
||||
});
|
||||
debug!("cat_deref_common ret {}", ret.repr(self.tcx()));
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub fn cat_index<N:ast_node>(&self,
|
||||
@ -1009,8 +1047,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
};
|
||||
|
||||
let m = base_cmt.mutbl.inherit();
|
||||
return Ok(interior(elt, base_cmt.clone(), base_cmt.ty,
|
||||
m, context, element_ty));
|
||||
let ret = interior(elt, base_cmt.clone(), base_cmt.ty,
|
||||
m, context, element_ty);
|
||||
debug!("cat_index ret {}", ret.repr(self.tcx()));
|
||||
return Ok(ret);
|
||||
|
||||
fn interior<'tcx, N: ast_node>(elt: &N,
|
||||
of_cmt: cmt<'tcx>,
|
||||
@ -1039,14 +1079,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
context: InteriorOffsetKind)
|
||||
-> McResult<cmt<'tcx>>
|
||||
{
|
||||
match try!(deref_kind(base_cmt.ty, Some(context))) {
|
||||
let ret = match try!(deref_kind(base_cmt.ty, Some(context))) {
|
||||
deref_ptr(ptr) => {
|
||||
// for unique ptrs, we inherit mutability from the
|
||||
// owning reference.
|
||||
let m = MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr);
|
||||
|
||||
// the deref is explicit in the resulting cmt
|
||||
Ok(Rc::new(cmt_ {
|
||||
Rc::new(cmt_ {
|
||||
id:elt.id(),
|
||||
span:elt.span(),
|
||||
cat:cat_deref(base_cmt.clone(), 0, ptr),
|
||||
@ -1056,13 +1096,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
None => self.tcx().sess.bug("Found non-derefable type")
|
||||
},
|
||||
note: NoteNone
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
deref_interior(_) => {
|
||||
Ok(base_cmt)
|
||||
base_cmt
|
||||
}
|
||||
}
|
||||
};
|
||||
debug!("deref_vec ret {}", ret.repr(self.tcx()));
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
/// Given a pattern P like: `[_, ..Q, _]`, where `vec_cmt` is the cmt for `P`, `slice_pat` is
|
||||
@ -1112,14 +1154,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
interior_ty: Ty<'tcx>,
|
||||
interior: InteriorKind)
|
||||
-> cmt<'tcx> {
|
||||
Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
mutbl: base_cmt.mutbl.inherit(),
|
||||
cat: cat_interior(base_cmt, interior),
|
||||
ty: interior_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
});
|
||||
debug!("cat_imm_interior ret={}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_downcast<N:ast_node>(&self,
|
||||
@ -1128,14 +1172,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
|
||||
downcast_ty: Ty<'tcx>,
|
||||
variant_did: ast::DefId)
|
||||
-> cmt<'tcx> {
|
||||
Rc::new(cmt_ {
|
||||
let ret = Rc::new(cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
mutbl: base_cmt.mutbl.inherit(),
|
||||
cat: cat_downcast(base_cmt, variant_did),
|
||||
ty: downcast_ty,
|
||||
note: NoteNone
|
||||
})
|
||||
});
|
||||
debug!("cat_downcast ret={}", ret.repr(self.tcx()));
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) -> McResult<()>
|
||||
|
@ -151,10 +151,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
|
||||
assignee_cmt: mc::cmt<'tcx>,
|
||||
mode: euv::MutateMode)
|
||||
{
|
||||
debug!("mutate(assignment_id={}, assignee_cmt={})",
|
||||
assignment_id, assignee_cmt.repr(self.tcx()));
|
||||
let opt_lp = opt_loan_path(&assignee_cmt);
|
||||
debug!("mutate(assignment_id={}, assignee_cmt={}) opt_lp={:?}",
|
||||
assignment_id, assignee_cmt.repr(self.tcx()), opt_lp);
|
||||
|
||||
match opt_loan_path(&assignee_cmt) {
|
||||
match opt_lp {
|
||||
Some(lp) => {
|
||||
gather_moves::gather_assignment(self.bccx, &self.move_data,
|
||||
assignment_id, assignment_span,
|
||||
@ -376,7 +377,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
|
||||
req_kind: ty::BorrowKind)
|
||||
-> Result<(),()> {
|
||||
//! Implements the M-* rules in README.md.
|
||||
|
||||
debug!("check_mutability(cause={:?} cmt={} req_kind={:?}",
|
||||
cause, cmt.repr(bccx.tcx), req_kind);
|
||||
match req_kind {
|
||||
ty::UniqueImmBorrow | ty::ImmBorrow => {
|
||||
match cmt.mutbl {
|
||||
|
Loading…
x
Reference in New Issue
Block a user