Skip to content

Commit aa13981

Browse files
committed
Mucho debug instrumentation.
1 parent b0fd67b commit aa13981

File tree

2 files changed

+91
-43
lines changed

2 files changed

+91
-43
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -295,23 +295,29 @@ pub trait Typer<'tcx> : ty::ClosureTyper<'tcx> {
295295

296296
impl MutabilityCategory {
297297
pub fn from_mutbl(m: ast::Mutability) -> MutabilityCategory {
298-
match m {
298+
let ret = match m {
299299
MutImmutable => McImmutable,
300300
MutMutable => McDeclared
301-
}
301+
};
302+
debug!("MutabilityCategory::{}({:?}) => {:?}",
303+
"from_mutbl", m, ret);
304+
ret
302305
}
303306

304307
pub fn from_borrow_kind(borrow_kind: ty::BorrowKind) -> MutabilityCategory {
305-
match borrow_kind {
308+
let ret = match borrow_kind {
306309
ty::ImmBorrow => McImmutable,
307310
ty::UniqueImmBorrow => McImmutable,
308311
ty::MutBorrow => McDeclared,
309-
}
312+
};
313+
debug!("MutabilityCategory::{}({:?}) => {:?}",
314+
"from_borrow_kind", borrow_kind, ret);
315+
ret
310316
}
311317

312318
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
313319
ptr: PointerKind) -> MutabilityCategory {
314-
match ptr {
320+
let ret = match ptr {
315321
Unique => {
316322
base_mutbl.inherit()
317323
}
@@ -321,11 +327,14 @@ impl MutabilityCategory {
321327
UnsafePtr(m) => {
322328
MutabilityCategory::from_mutbl(m)
323329
}
324-
}
330+
};
331+
debug!("MutabilityCategory::{}({:?}, {:?}) => {:?}",
332+
"from_pointer_kind", base_mutbl, ptr, ret);
333+
ret
325334
}
326335

327336
fn from_local(tcx: &ty::ctxt, id: ast::NodeId) -> MutabilityCategory {
328-
match tcx.map.get(id) {
337+
let ret = match tcx.map.get(id) {
329338
ast_map::NodeLocal(p) | ast_map::NodeArg(p) => match p.node {
330339
ast::PatIdent(bind_mode, _, _) => {
331340
if bind_mode == ast::BindByValue(ast::MutMutable) {
@@ -337,30 +346,39 @@ impl MutabilityCategory {
337346
_ => tcx.sess.span_bug(p.span, "expected identifier pattern")
338347
},
339348
_ => tcx.sess.span_bug(tcx.map.span(id), "expected identifier pattern")
340-
}
349+
};
350+
debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}",
351+
"from_local", id, ret);
352+
ret
341353
}
342354

343355
pub fn inherit(&self) -> MutabilityCategory {
344-
match *self {
356+
let ret = match *self {
345357
McImmutable => McImmutable,
346358
McDeclared => McInherited,
347359
McInherited => McInherited,
348-
}
360+
};
361+
debug!("{:?}.inherit() => {:?}", self, ret);
362+
ret
349363
}
350364

351365
pub fn is_mutable(&self) -> bool {
352-
match *self {
366+
let ret = match *self {
353367
McImmutable => false,
354368
McInherited => true,
355369
McDeclared => true,
356-
}
370+
};
371+
debug!("{:?}.is_mutable() => {:?}", self, ret);
372+
ret
357373
}
358374

359375
pub fn is_immutable(&self) -> bool {
360-
match *self {
376+
let ret = match *self {
361377
McImmutable => true,
362378
McDeclared | McInherited => false
363-
}
379+
};
380+
debug!("{:?}.is_immutable() => {:?}", self, ret);
381+
ret
364382
}
365383

366384
pub fn to_user_str(&self) -> &'static str {
@@ -733,7 +751,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
733751
}
734752
};
735753

736-
Ok(Rc::new(cmt_result))
754+
let ret = Rc::new(cmt_result);
755+
debug!("cat_upvar ret={}", ret.repr(self.tcx()));
756+
Ok(ret)
737757
}
738758

739759
fn env_deref(&self,
@@ -794,14 +814,18 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
794814
McDeclared | McInherited => { }
795815
}
796816

797-
cmt_ {
817+
let ret = cmt_ {
798818
id: id,
799819
span: span,
800820
cat: cat_deref(Rc::new(cmt_result), 0, env_ptr),
801821
mutbl: deref_mutbl,
802822
ty: var_ty,
803823
note: NoteClosureEnv(upvar_id)
804-
}
824+
};
825+
826+
debug!("env_deref ret {}", ret.repr(self.tcx()));
827+
828+
ret
805829
}
806830

807831
pub fn cat_rvalue_node(&self,
@@ -831,22 +855,26 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
831855
}
832856
}
833857
};
834-
self.cat_rvalue(id, span, re, expr_ty)
858+
let ret = self.cat_rvalue(id, span, re, expr_ty);
859+
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));
860+
ret
835861
}
836862

837863
pub fn cat_rvalue(&self,
838864
cmt_id: ast::NodeId,
839865
span: Span,
840866
temp_scope: ty::Region,
841867
expr_ty: Ty<'tcx>) -> cmt<'tcx> {
842-
Rc::new(cmt_ {
868+
let ret = Rc::new(cmt_ {
843869
id:cmt_id,
844870
span:span,
845871
cat:cat_rvalue(temp_scope),
846872
mutbl:McDeclared,
847873
ty:expr_ty,
848874
note: NoteNone
849-
})
875+
});
876+
debug!("cat_rvalue ret {}", ret.repr(self.tcx()));
877+
ret
850878
}
851879

852880
pub fn cat_field<N:ast_node>(&self,
@@ -855,14 +883,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
855883
f_name: ast::Name,
856884
f_ty: Ty<'tcx>)
857885
-> cmt<'tcx> {
858-
Rc::new(cmt_ {
886+
let ret = Rc::new(cmt_ {
859887
id: node.id(),
860888
span: node.span(),
861889
mutbl: base_cmt.mutbl.inherit(),
862890
cat: cat_interior(base_cmt, InteriorField(NamedField(f_name))),
863891
ty: f_ty,
864892
note: NoteNone
865-
})
893+
});
894+
debug!("cat_field ret {}", ret.repr(self.tcx()));
895+
ret
866896
}
867897

868898
pub fn cat_tup_field<N:ast_node>(&self,
@@ -871,14 +901,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
871901
f_idx: uint,
872902
f_ty: Ty<'tcx>)
873903
-> cmt<'tcx> {
874-
Rc::new(cmt_ {
904+
let ret = Rc::new(cmt_ {
875905
id: node.id(),
876906
span: node.span(),
877907
mutbl: base_cmt.mutbl.inherit(),
878908
cat: cat_interior(base_cmt, InteriorField(PositionalField(f_idx))),
879909
ty: f_ty,
880910
note: NoteNone
881-
})
911+
});
912+
debug!("cat_tup_field ret {}", ret.repr(self.tcx()));
913+
ret
882914
}
883915

884916
fn cat_deref<N:ast_node>(&self,
@@ -913,10 +945,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
913945
};
914946
let base_cmt_ty = base_cmt.ty;
915947
match ty::deref(base_cmt_ty, true) {
916-
Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt,
948+
Some(mt) => {
949+
let ret = self.cat_deref_common(node, base_cmt, deref_cnt,
917950
mt.ty,
918951
deref_context,
919-
/* implicit: */ false),
952+
/* implicit: */ false);
953+
debug!("cat_deref ret {}", ret.repr(self.tcx()));
954+
ret
955+
}
920956
None => {
921957
debug!("Explicit deref of non-derefable type: {}",
922958
base_cmt_ty.repr(self.tcx()));
@@ -954,14 +990,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
954990
(base_cmt.mutbl.inherit(), cat_interior(base_cmt, interior))
955991
}
956992
};
957-
Ok(Rc::new(cmt_ {
993+
let ret = Rc::new(cmt_ {
958994
id: node.id(),
959995
span: node.span(),
960996
cat: cat,
961997
mutbl: m,
962998
ty: deref_ty,
963999
note: NoteNone
964-
}))
1000+
});
1001+
debug!("cat_deref_common ret {}", ret.repr(self.tcx()));
1002+
Ok(ret)
9651003
}
9661004

9671005
pub fn cat_index<N:ast_node>(&self,
@@ -1009,8 +1047,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10091047
};
10101048

10111049
let m = base_cmt.mutbl.inherit();
1012-
return Ok(interior(elt, base_cmt.clone(), base_cmt.ty,
1013-
m, context, element_ty));
1050+
let ret = interior(elt, base_cmt.clone(), base_cmt.ty,
1051+
m, context, element_ty);
1052+
debug!("cat_index ret {}", ret.repr(self.tcx()));
1053+
return Ok(ret);
10141054

10151055
fn interior<'tcx, N: ast_node>(elt: &N,
10161056
of_cmt: cmt<'tcx>,
@@ -1039,14 +1079,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10391079
context: InteriorOffsetKind)
10401080
-> McResult<cmt<'tcx>>
10411081
{
1042-
match try!(deref_kind(base_cmt.ty, Some(context))) {
1082+
let ret = match try!(deref_kind(base_cmt.ty, Some(context))) {
10431083
deref_ptr(ptr) => {
10441084
// for unique ptrs, we inherit mutability from the
10451085
// owning reference.
10461086
let m = MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr);
10471087

10481088
// the deref is explicit in the resulting cmt
1049-
Ok(Rc::new(cmt_ {
1089+
Rc::new(cmt_ {
10501090
id:elt.id(),
10511091
span:elt.span(),
10521092
cat:cat_deref(base_cmt.clone(), 0, ptr),
@@ -1056,13 +1096,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10561096
None => self.tcx().sess.bug("Found non-derefable type")
10571097
},
10581098
note: NoteNone
1059-
}))
1099+
})
10601100
}
10611101

10621102
deref_interior(_) => {
1063-
Ok(base_cmt)
1103+
base_cmt
10641104
}
1065-
}
1105+
};
1106+
debug!("deref_vec ret {}", ret.repr(self.tcx()));
1107+
Ok(ret)
10661108
}
10671109

10681110
/// 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> {
11121154
interior_ty: Ty<'tcx>,
11131155
interior: InteriorKind)
11141156
-> cmt<'tcx> {
1115-
Rc::new(cmt_ {
1157+
let ret = Rc::new(cmt_ {
11161158
id: node.id(),
11171159
span: node.span(),
11181160
mutbl: base_cmt.mutbl.inherit(),
11191161
cat: cat_interior(base_cmt, interior),
11201162
ty: interior_ty,
11211163
note: NoteNone
1122-
})
1164+
});
1165+
debug!("cat_imm_interior ret={}", ret.repr(self.tcx()));
1166+
ret
11231167
}
11241168

11251169
pub fn cat_downcast<N:ast_node>(&self,
@@ -1128,14 +1172,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
11281172
downcast_ty: Ty<'tcx>,
11291173
variant_did: ast::DefId)
11301174
-> cmt<'tcx> {
1131-
Rc::new(cmt_ {
1175+
let ret = Rc::new(cmt_ {
11321176
id: node.id(),
11331177
span: node.span(),
11341178
mutbl: base_cmt.mutbl.inherit(),
11351179
cat: cat_downcast(base_cmt, variant_did),
11361180
ty: downcast_ty,
11371181
note: NoteNone
1138-
})
1182+
});
1183+
debug!("cat_downcast ret={}", ret.repr(self.tcx()));
1184+
ret
11391185
}
11401186

11411187
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) -> McResult<()>

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
151151
assignee_cmt: mc::cmt<'tcx>,
152152
mode: euv::MutateMode)
153153
{
154-
debug!("mutate(assignment_id={}, assignee_cmt={})",
155-
assignment_id, assignee_cmt.repr(self.tcx()));
154+
let opt_lp = opt_loan_path(&assignee_cmt);
155+
debug!("mutate(assignment_id={}, assignee_cmt={}) opt_lp={:?}",
156+
assignment_id, assignee_cmt.repr(self.tcx()), opt_lp);
156157

157-
match opt_loan_path(&assignee_cmt) {
158+
match opt_lp {
158159
Some(lp) => {
159160
gather_moves::gather_assignment(self.bccx, &self.move_data,
160161
assignment_id, assignment_span,
@@ -376,7 +377,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
376377
req_kind: ty::BorrowKind)
377378
-> Result<(),()> {
378379
//! Implements the M-* rules in README.md.
379-
380+
debug!("check_mutability(cause={:?} cmt={} req_kind={:?}",
381+
cause, cmt.repr(bccx.tcx), req_kind);
380382
match req_kind {
381383
ty::UniqueImmBorrow | ty::ImmBorrow => {
382384
match cmt.mutbl {

0 commit comments

Comments
 (0)