Skip to content

Commit 6891f00

Browse files
committed
---
yaml --- r: 22450 b: refs/heads/master c: 668285b h: refs/heads/master v: v3
1 parent ce9a0b5 commit 6891f00

File tree

5 files changed

+65
-18
lines changed

5 files changed

+65
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9b7d9a9a1bcfba81979f6f1165b5274c93b03039
2+
refs/heads/master: 668285b9c85bebc5d1a4e8d346e99b580420be8e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/driver/session.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ const ppregions: uint = 1u;
2828
const time_passes: uint = 2u;
2929
const count_llvm_insns: uint = 4u;
3030
const time_llvm_passes: uint = 8u;
31-
const stats: uint = 16u;
31+
const trans_stats: uint = 16u;
3232
const no_asm_comments: uint = 32u;
3333
const no_verify: uint = 64u;
3434
const trace: uint = 128u;
3535
// FIXME (#2377): This exists to transition to a Rust crate runtime
3636
// It should be removed
3737
const no_rt: uint = 256u;
3838
const coherence: uint = 512u;
39+
const borrowck_stats: uint = 1024u;
3940

4041
fn debugging_opts_map() -> ~[(str, str, uint)] {
4142
~[("ppregions", "prettyprint regions with \
@@ -49,7 +50,8 @@ fn debugging_opts_map() -> ~[(str, str, uint)] {
4950
("no-verify", "skip LLVM verification", no_verify),
5051
("trace", "emit trace logs", trace),
5152
("no-rt", "do not link to the runtime", no_rt),
52-
("coherence", "perform coherence checking", coherence)
53+
("coherence", "perform coherence checking", coherence),
54+
("borrowck-stats", "gather borrowck statistics", borrowck_stats)
5355
]
5456
}
5557

@@ -160,11 +162,12 @@ impl session for session {
160162
fn time_passes() -> bool { self.debugging_opt(time_passes) }
161163
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) }
162164
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
163-
fn stats() -> bool { self.debugging_opt(stats) }
165+
fn trans_stats() -> bool { self.debugging_opt(trans_stats) }
164166
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
165167
fn no_verify() -> bool { self.debugging_opt(no_verify) }
166168
fn trace() -> bool { self.debugging_opt(trace) }
167169
fn coherence() -> bool { self.debugging_opt(coherence) }
170+
fn borrowck_stats() -> bool { self.debugging_opt(borrowck_stats) }
168171
}
169172

170173
/// Some reasonable defaults

trunk/src/rustc/middle/borrowck.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,37 @@ fn check_crate(tcx: ty::ctxt,
175175
last_use_map: last_use_map,
176176
binding_map: int_hash(),
177177
root_map: root_map(),
178-
mutbl_map: int_hash()};
178+
mutbl_map: int_hash(),
179+
mut loaned_paths_same: 0,
180+
mut loaned_paths_imm: 0,
181+
mut stable_paths: 0,
182+
mut req_pure_paths: 0,
183+
mut guaranteed_paths: 0};
179184

180185
let req_maps = gather_loans::gather_loans(bccx, crate);
181186
check_loans::check_loans(bccx, req_maps, crate);
187+
188+
if tcx.sess.borrowck_stats() {
189+
io::println("--- borrowck stats ---");
190+
io::println(#fmt["paths requiring guarantees: %u",
191+
bccx.guaranteed_paths]);
192+
io::println(#fmt["paths requiring loans : %s",
193+
make_stat(bccx, bccx.loaned_paths_same)]);
194+
io::println(#fmt["paths requiring imm loans : %s",
195+
make_stat(bccx, bccx.loaned_paths_imm)]);
196+
io::println(#fmt["stable paths : %s",
197+
make_stat(bccx, bccx.stable_paths)]);
198+
io::println(#fmt["paths requiring purity : %s",
199+
make_stat(bccx, bccx.req_pure_paths)]);
200+
}
201+
182202
ret (bccx.root_map, bccx.mutbl_map);
203+
204+
fn make_stat(bccx: borrowck_ctxt, stat: uint) -> str {
205+
let stat_f = stat as float;
206+
let total = bccx.guaranteed_paths as float;
207+
#fmt["%u (%.0f%%)", stat , stat_f * 100f / total]
208+
}
183209
}
184210

185211
// ----------------------------------------------------------------------
@@ -190,7 +216,14 @@ type borrowck_ctxt = @{tcx: ty::ctxt,
190216
last_use_map: liveness::last_use_map,
191217
binding_map: binding_map,
192218
root_map: root_map,
193-
mutbl_map: mutbl_map};
219+
mutbl_map: mutbl_map,
220+
221+
// Statistics:
222+
mut loaned_paths_same: uint,
223+
mut loaned_paths_imm: uint,
224+
mut stable_paths: uint,
225+
mut req_pure_paths: uint,
226+
mut guaranteed_paths: uint};
194227

195228
// a map mapping id's of expressions of gc'd type (@T, @[], etc) where
196229
// the box needs to be kept live to the id of the scope for which they

trunk/src/rustc/middle/borrowck/gather_loans.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,36 @@ impl methods for gather_loan_ctxt {
172172
req_mutbl: ast::mutability,
173173
scope_r: ty::region) {
174174

175+
self.bccx.guaranteed_paths += 1;
176+
175177
#debug["guarantee_valid(cmt=%s, req_mutbl=%s, scope_r=%s)",
176178
self.bccx.cmt_to_repr(cmt),
177179
self.bccx.mut_to_str(req_mutbl),
178180
region_to_str(self.tcx(), scope_r)];
179181
let _i = indenter();
180182

181183
alt cmt.lp {
182-
// If this expression is a loanable path, we MUST take out a loan.
183-
// This is somewhat non-obvious. You might think, for example, that
184-
// if we have an immutable local variable `x` whose value is being
185-
// borrowed, we could rely on `x` not to change. This is not so,
186-
// however, because even immutable locals can be moved. So we take
187-
// out a loan on `x`, guaranteeing that it remains immutable for the
188-
// duration of the reference: if there is an attempt to move it
189-
// within that scope, the loan will be detected and an error will be
190-
// reported.
184+
// If this expression is a loanable path, we MUST take out a
185+
// loan. This is somewhat non-obvious. You might think,
186+
// for example, that if we have an immutable local variable
187+
// `x` whose value is being borrowed, we could rely on `x`
188+
// not to change. This is not so, however, because even
189+
// immutable locals can be moved. So we take out a loan on
190+
// `x`, guaranteeing that it remains immutable for the
191+
// duration of the reference: if there is an attempt to move
192+
// it within that scope, the loan will be detected and an
193+
// error will be reported.
191194
some(_) {
192195
alt scope_r {
193196
ty::re_scope(scope_id) {
194197
let loans = self.bccx.loan(cmt, req_mutbl);
195198
self.add_loans(scope_id, loans);
199+
200+
if req_mutbl == m_imm && cmt.mutbl != m_imm {
201+
self.bccx.loaned_paths_imm += 1;
202+
} else {
203+
self.bccx.loaned_paths_same += 1;
204+
}
196205
}
197206
_ {
198207
self.bccx.span_err(
@@ -225,6 +234,7 @@ impl methods for gather_loan_ctxt {
225234
// we were able guarantee the validity of the ptr,
226235
// perhaps by rooting or because it is immutably
227236
// rooted. good.
237+
self.bccx.stable_paths += 1;
228238
}
229239
err(e) {
230240
// not able to guarantee the validity of the ptr.
@@ -235,6 +245,7 @@ impl methods for gather_loan_ctxt {
235245
alt opt_scope_id {
236246
some(scope_id) {
237247
self.req_maps.pure_map.insert(scope_id, e);
248+
self.bccx.req_pure_paths += 1;
238249
}
239250
none {
240251
// otherwise, fine, I give up.

trunk/src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ fn make_generic_glue(ccx: @crate_ctxt, t: ty::t, llfn: ValueRef,
551551
helper: glue_helper, name: str)
552552
-> ValueRef {
553553
let _icx = ccx.insn_ctxt("make_generic_glue");
554-
if !ccx.sess.stats() {
554+
if !ccx.sess.trans_stats() {
555555
ret make_generic_glue_inner(ccx, t, llfn, helper);
556556
}
557557

@@ -4550,7 +4550,7 @@ fn trans_fn(ccx: @crate_ctxt,
45504550
ty_self: self_arg,
45514551
param_substs: option<param_substs>,
45524552
id: ast::node_id) {
4553-
let do_time = ccx.sess.stats();
4553+
let do_time = ccx.sess.trans_stats();
45544554
let start = if do_time { time::get_time() }
45554555
else { {sec: 0i64, nsec: 0i32} };
45564556
let _icx = ccx.insn_ctxt("trans_fn");
@@ -5591,7 +5591,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
55915591

55925592
// Translate the metadata.
55935593
write_metadata(ccx, crate);
5594-
if ccx.sess.stats() {
5594+
if ccx.sess.trans_stats() {
55955595
io::println("--- trans stats ---");
55965596
io::println(#fmt("n_static_tydescs: %u",
55975597
ccx.stats.n_static_tydescs));

0 commit comments

Comments
 (0)