Skip to content

Commit 53c6de5

Browse files
committed
Improve debug spew in _match.
1 parent 7dbc5ae commit 53c6de5

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

src/librustc/middle/trans/_match.rs

+40-41
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ use middle::trans::tvec;
171171
use middle::trans::type_of;
172172
use middle::ty;
173173
use util::common::indenter;
174+
use util::ppaux::{Repr, vec_map_to_str};
174175

175176
use std::hashmap::HashMap;
176177
use std::vec;
@@ -179,7 +180,6 @@ use syntax::ast::ident;
179180
use syntax::ast_util::path_to_ident;
180181
use syntax::ast_util;
181182
use syntax::codemap::{span, dummy_sp};
182-
use syntax::print::pprust::pat_to_str;
183183

184184
// An option identifying a literal: either a unit-like struct or an
185185
// expression.
@@ -353,19 +353,17 @@ pub struct Match<'self> {
353353
data: ArmData<'self>
354354
}
355355

356-
pub fn match_to_str(bcx: @mut Block, m: &Match) -> ~str {
357-
if bcx.sess().verbose() {
358-
// for many programs, this just take too long to serialize
359-
fmt!("%?", m.pats.map(|p| pat_to_str(*p, bcx.sess().intr())))
360-
} else {
361-
fmt!("%u pats", m.pats.len())
356+
impl<'self> Repr for Match<'self> {
357+
fn repr(&self, tcx: ty::ctxt) -> ~str {
358+
if tcx.sess.verbose() {
359+
// for many programs, this just take too long to serialize
360+
self.pats.repr(tcx)
361+
} else {
362+
fmt!("%u pats", self.pats.len())
363+
}
362364
}
363365
}
364366

365-
pub fn matches_to_str(bcx: @mut Block, m: &[Match]) -> ~str {
366-
fmt!("%?", m.map(|n| match_to_str(bcx, n)))
367-
}
368-
369367
pub fn has_nested_bindings(m: &[Match], col: uint) -> bool {
370368
for br in m.iter() {
371369
match br.pats[col].node {
@@ -381,9 +379,9 @@ pub fn expand_nested_bindings<'r>(bcx: @mut Block,
381379
col: uint,
382380
val: ValueRef)
383381
-> ~[Match<'r>] {
384-
debug!("expand_nested_bindings(bcx=%s, m=%s, col=%u, val=%?)",
382+
debug!("expand_nested_bindings(bcx=%s, m=%s, col=%u, val=%s)",
385383
bcx.to_str(),
386-
matches_to_str(bcx, m),
384+
m.repr(bcx.tcx()),
387385
col,
388386
bcx.val_to_str(val));
389387
let _indenter = indenter();
@@ -416,7 +414,7 @@ pub fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::pat) {
416414
bcx.sess().span_bug(
417415
p.span,
418416
fmt!("Expected an identifier pattern but found p: %s",
419-
pat_to_str(p, bcx.sess().intr())));
417+
p.repr(bcx.tcx())));
420418
}
421419
}
422420

@@ -429,9 +427,9 @@ pub fn enter_match<'r>(bcx: @mut Block,
429427
val: ValueRef,
430428
e: enter_pat)
431429
-> ~[Match<'r>] {
432-
debug!("enter_match(bcx=%s, m=%s, col=%u, val=%?)",
430+
debug!("enter_match(bcx=%s, m=%s, col=%u, val=%s)",
433431
bcx.to_str(),
434-
matches_to_str(bcx, m),
432+
m.repr(bcx.tcx()),
435433
col,
436434
bcx.val_to_str(val));
437435
let _indenter = indenter();
@@ -467,7 +465,7 @@ pub fn enter_match<'r>(bcx: @mut Block,
467465
}
468466
}
469467

470-
debug!("result=%s", matches_to_str(bcx, result));
468+
debug!("result=%s", result.repr(bcx.tcx()));
471469

472470
return result;
473471
}
@@ -478,9 +476,9 @@ pub fn enter_default<'r>(bcx: @mut Block,
478476
col: uint,
479477
val: ValueRef)
480478
-> ~[Match<'r>] {
481-
debug!("enter_default(bcx=%s, m=%s, col=%u, val=%?)",
479+
debug!("enter_default(bcx=%s, m=%s, col=%u, val=%s)",
482480
bcx.to_str(),
483-
matches_to_str(bcx, m),
481+
m.repr(bcx.tcx()),
484482
col,
485483
bcx.val_to_str(val));
486484
let _indenter = indenter();
@@ -525,9 +523,9 @@ pub fn enter_opt<'r>(bcx: @mut Block,
525523
variant_size: uint,
526524
val: ValueRef)
527525
-> ~[Match<'r>] {
528-
debug!("enter_opt(bcx=%s, m=%s, col=%u, val=%?)",
526+
debug!("enter_opt(bcx=%s, m=%s, col=%u, val=%s)",
529527
bcx.to_str(),
530-
matches_to_str(bcx, m),
528+
m.repr(bcx.tcx()),
531529
col,
532530
bcx.val_to_str(val));
533531
let _indenter = indenter();
@@ -637,9 +635,9 @@ pub fn enter_rec_or_struct<'r>(bcx: @mut Block,
637635
fields: &[ast::ident],
638636
val: ValueRef)
639637
-> ~[Match<'r>] {
640-
debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%?)",
638+
debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%s)",
641639
bcx.to_str(),
642-
matches_to_str(bcx, m),
640+
m.repr(bcx.tcx()),
643641
col,
644642
bcx.val_to_str(val));
645643
let _indenter = indenter();
@@ -672,9 +670,9 @@ pub fn enter_tup<'r>(bcx: @mut Block,
672670
val: ValueRef,
673671
n_elts: uint)
674672
-> ~[Match<'r>] {
675-
debug!("enter_tup(bcx=%s, m=%s, col=%u, val=%?)",
673+
debug!("enter_tup(bcx=%s, m=%s, col=%u, val=%s)",
676674
bcx.to_str(),
677-
matches_to_str(bcx, m),
675+
m.repr(bcx.tcx()),
678676
col,
679677
bcx.val_to_str(val));
680678
let _indenter = indenter();
@@ -698,9 +696,9 @@ pub fn enter_tuple_struct<'r>(bcx: @mut Block,
698696
val: ValueRef,
699697
n_elts: uint)
700698
-> ~[Match<'r>] {
701-
debug!("enter_tuple_struct(bcx=%s, m=%s, col=%u, val=%?)",
699+
debug!("enter_tuple_struct(bcx=%s, m=%s, col=%u, val=%s)",
702700
bcx.to_str(),
703-
matches_to_str(bcx, m),
701+
m.repr(bcx.tcx()),
704702
col,
705703
bcx.val_to_str(val));
706704
let _indenter = indenter();
@@ -723,9 +721,9 @@ pub fn enter_box<'r>(bcx: @mut Block,
723721
col: uint,
724722
val: ValueRef)
725723
-> ~[Match<'r>] {
726-
debug!("enter_box(bcx=%s, m=%s, col=%u, val=%?)",
724+
debug!("enter_box(bcx=%s, m=%s, col=%u, val=%s)",
727725
bcx.to_str(),
728-
matches_to_str(bcx, m),
726+
m.repr(bcx.tcx()),
729727
col,
730728
bcx.val_to_str(val));
731729
let _indenter = indenter();
@@ -750,9 +748,9 @@ pub fn enter_uniq<'r>(bcx: @mut Block,
750748
col: uint,
751749
val: ValueRef)
752750
-> ~[Match<'r>] {
753-
debug!("enter_uniq(bcx=%s, m=%s, col=%u, val=%?)",
751+
debug!("enter_uniq(bcx=%s, m=%s, col=%u, val=%s)",
754752
bcx.to_str(),
755-
matches_to_str(bcx, m),
753+
m.repr(bcx.tcx()),
756754
col,
757755
bcx.val_to_str(val));
758756
let _indenter = indenter();
@@ -777,9 +775,9 @@ pub fn enter_region<'r>(bcx: @mut Block,
777775
col: uint,
778776
val: ValueRef)
779777
-> ~[Match<'r>] {
780-
debug!("enter_region(bcx=%s, m=%s, col=%u, val=%?)",
778+
debug!("enter_region(bcx=%s, m=%s, col=%u, val=%s)",
781779
bcx.to_str(),
782-
matches_to_str(bcx, m),
780+
m.repr(bcx.tcx()),
783781
col,
784782
bcx.val_to_str(val));
785783
let _indenter = indenter();
@@ -1213,11 +1211,11 @@ pub fn compile_guard(bcx: @mut Block,
12131211
vals: &[ValueRef],
12141212
chk: Option<mk_fail>)
12151213
-> @mut Block {
1216-
debug!("compile_guard(bcx=%s, guard_expr=%s, m=%s, vals=%?)",
1214+
debug!("compile_guard(bcx=%s, guard_expr=%s, m=%s, vals=%s)",
12171215
bcx.to_str(),
12181216
bcx.expr_to_str(guard_expr),
1219-
matches_to_str(bcx, m),
1220-
vals.map(|v| bcx.val_to_str(*v)));
1217+
m.repr(bcx.tcx()),
1218+
vec_map_to_str(vals, |v| bcx.val_to_str(*v)));
12211219
let _indenter = indenter();
12221220

12231221
let mut bcx = bcx;
@@ -1267,10 +1265,10 @@ pub fn compile_submatch(bcx: @mut Block,
12671265
m: &[Match],
12681266
vals: &[ValueRef],
12691267
chk: Option<mk_fail>) {
1270-
debug!("compile_submatch(bcx=%s, m=%s, vals=%?)",
1268+
debug!("compile_submatch(bcx=%s, m=%s, vals=%s)",
12711269
bcx.to_str(),
1272-
matches_to_str(bcx, m),
1273-
vals.map(|v| bcx.val_to_str(*v)));
1270+
m.repr(bcx.tcx()),
1271+
vec_map_to_str(vals, |v| bcx.val_to_str(*v)));
12741272
let _indenter = indenter();
12751273

12761274
/*
@@ -1427,6 +1425,7 @@ fn compile_submatch_continue(mut bcx: @mut Block,
14271425

14281426
// Decide what kind of branch we need
14291427
let opts = get_options(bcx, m, col);
1428+
debug!("options=%?", opts);
14301429
let mut kind = no_branch;
14311430
let mut test_val = val;
14321431
if opts.len() > 0u {
@@ -1914,12 +1913,12 @@ fn bind_irrefutable_pat(bcx: @mut Block,
19141913

19151914
debug!("bind_irrefutable_pat(bcx=%s, pat=%s, binding_mode=%?)",
19161915
bcx.to_str(),
1917-
pat_to_str(pat, bcx.sess().intr()),
1916+
pat.repr(bcx.tcx()),
19181917
binding_mode);
19191918

19201919
if bcx.sess().asm_comments() {
19211920
add_comment(bcx, fmt!("bind_irrefutable_pat(pat=%s)",
1922-
pat_to_str(pat, bcx.sess().intr())));
1921+
pat.repr(bcx.tcx())));
19231922
}
19241923

19251924
let _indenter = indenter();

src/librustc/util/ppaux.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,13 @@ pub fn vstore_ty_to_str(cx: ctxt, mt: &mt, vs: ty::vstore) -> ~str {
280280
}
281281
}
282282

283+
pub fn vec_map_to_str<T>(ts: &[T], f: &fn(t: &T) -> ~str) -> ~str {
284+
let tstrs = ts.map(f);
285+
fmt!("[%s]", tstrs.connect(", "))
286+
}
287+
283288
pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str {
284-
let tstrs = ts.map(|t| ty_to_str(cx, *t));
285-
fmt!("(%s)", tstrs.connect(", "))
289+
vec_map_to_str(ts, |t| ty_to_str(cx, *t))
286290
}
287291

288292
pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str {
@@ -529,7 +533,7 @@ impl<T:Repr> Repr for ~T {
529533
}
530534

531535
fn repr_vec<T:Repr>(tcx: ctxt, v: &[T]) -> ~str {
532-
fmt!("[%s]", v.map(|t| t.repr(tcx)).connect(","))
536+
vec_map_to_str(v, |t| t.repr(tcx))
533537
}
534538

535539
impl<'self, T:Repr> Repr for &'self [T] {

0 commit comments

Comments
 (0)