Skip to content

Commit 57312ce

Browse files
committed
---
yaml --- r: 83925 b: refs/heads/dist-snap c: f80d6dc h: refs/heads/master i: 83923: 254527f v: v3
1 parent 63bc8d1 commit 57312ce

File tree

13 files changed

+745
-87
lines changed

13 files changed

+745
-87
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 3c0a1621b550936e862585667d8a58f7a2ab72c5
9+
refs/heads/dist-snap: f80d6dc4c1b9da9d4181742efe1a2206c7d6f5c5
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/borrowck/mod.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,12 @@ impl BorrowckCtxt {
538538

539539
move_data::MoveExpr(expr) => {
540540
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
541-
let suggestion = move_suggestion(self.tcx, expr_ty,
542-
"moved by default (use `copy` to override)");
543541
self.tcx.sess.span_note(
544542
expr.span,
545-
fmt!("`%s` moved here because it has type `%s`, which is %s",
543+
fmt!("`%s` moved here because it has type `%s`, \
544+
which is moved by default (use `copy` to override)",
546545
self.loan_path_to_str(moved_lp),
547-
expr_ty.user_string(self.tcx), suggestion));
546+
expr_ty.user_string(self.tcx)));
548547
}
549548

550549
move_data::MovePat(pat) => {
@@ -558,28 +557,12 @@ impl BorrowckCtxt {
558557
}
559558

560559
move_data::Captured(expr) => {
561-
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
562-
let suggestion = move_suggestion(self.tcx, expr_ty,
563-
"moved by default (make a copy and \
564-
capture that instead to override)");
565560
self.tcx.sess.span_note(
566561
expr.span,
567-
fmt!("`%s` moved into closure environment here because it \
568-
has type `%s`, which is %s",
569-
self.loan_path_to_str(moved_lp),
570-
expr_ty.user_string(self.tcx), suggestion));
571-
}
572-
}
573-
574-
fn move_suggestion(tcx: ty::ctxt, ty: ty::t, default_msg: &'static str)
575-
-> &'static str {
576-
match ty::get(ty).sty {
577-
ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
578-
"a non-copyable stack closure (capture it in a new closure, \
579-
e.g. `|x| f(x)`, to override)",
580-
_ if !ty::type_is_copyable(tcx, ty) =>
581-
"non-copyable (perhaps you meant to use clone()?)",
582-
_ => default_msg,
562+
fmt!("`%s` moved into closure environment here \
563+
because its type is moved by default \
564+
(make a copy and capture that instead to override)",
565+
self.loan_path_to_str(moved_lp)));
583566
}
584567
}
585568
}

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ use std::uint;
7272
use std::vec;
7373
use std::local_data;
7474
use extra::time;
75+
use extra::sort;
7576
use syntax::ast::ident;
7677
use syntax::ast_map::{path, path_elt_to_str, path_name};
7778
use syntax::ast_util::{local_def, path_to_ident};
@@ -141,6 +142,48 @@ fn fcx_has_nonzero_span(fcx: fn_ctxt) -> bool {
141142
}
142143
}
143144

145+
struct StatRecorder<'self> {
146+
ccx: @mut CrateContext,
147+
name: &'self str,
148+
start: u64,
149+
istart: uint,
150+
}
151+
152+
impl<'self> StatRecorder<'self> {
153+
pub fn new(ccx: @mut CrateContext,
154+
name: &'self str) -> StatRecorder<'self> {
155+
let start = if ccx.sess.trans_stats() {
156+
time::precise_time_ns()
157+
} else {
158+
0
159+
};
160+
let istart = ccx.stats.n_llvm_insns;
161+
StatRecorder {
162+
ccx: ccx,
163+
name: name,
164+
start: start,
165+
istart: istart,
166+
}
167+
}
168+
}
169+
170+
#[unsafe_destructor]
171+
impl<'self> Drop for StatRecorder<'self> {
172+
pub fn drop(&self) {
173+
if self.ccx.sess.trans_stats() {
174+
let end = time::precise_time_ns();
175+
let elapsed = ((end - self.start) / 1_000_000) as uint;
176+
let iend = self.ccx.stats.n_llvm_insns;
177+
self.ccx.stats.fn_stats.push((self.name.to_owned(),
178+
elapsed,
179+
iend - self.istart));
180+
self.ccx.stats.n_fns += 1;
181+
// Reset LLVM insn count to avoid compound costs.
182+
self.ccx.stats.n_llvm_insns = self.istart;
183+
}
184+
}
185+
}
186+
144187
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, ty: Type) -> ValueRef {
145188
let llfn: ValueRef = do name.as_c_str |buf| {
146189
unsafe {
@@ -1866,18 +1909,16 @@ pub fn trans_fn(ccx: @mut CrateContext,
18661909
param_substs: Option<@param_substs>,
18671910
id: ast::node_id,
18681911
attrs: &[ast::attribute]) {
1869-
let do_time = ccx.sess.trans_stats();
1870-
let start = if do_time { time::get_time() }
1871-
else { time::Timespec::new(0, 0) };
1912+
1913+
let the_path_str = path_str(ccx.sess, path);
1914+
let _s = StatRecorder::new(ccx, the_path_str);
18721915
debug!("trans_fn(self_arg=%?, param_substs=%s)",
18731916
self_arg,
18741917
param_substs.repr(ccx.tcx));
18751918
let _icx = push_ctxt("trans_fn");
1876-
ccx.stats.n_fns += 1;
1877-
let the_path_str = path_str(ccx.sess, path);
18781919
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx, id));
18791920
trans_closure(ccx,
1880-
path,
1921+
copy path,
18811922
decl,
18821923
body,
18831924
llfndecl,
@@ -1893,10 +1934,6 @@ pub fn trans_fn(ccx: @mut CrateContext,
18931934
}
18941935
},
18951936
|_bcx| { });
1896-
if do_time {
1897-
let end = time::get_time();
1898-
ccx.log_fn_time(the_path_str, start, end);
1899-
}
19001937
}
19011938

19021939
pub fn trans_enum_variant(ccx: @mut CrateContext,
@@ -2961,8 +2998,14 @@ pub fn trans_crate(sess: session::Session,
29612998
io::println(fmt!("n_monos: %u", ccx.stats.n_monos));
29622999
io::println(fmt!("n_inlines: %u", ccx.stats.n_inlines));
29633000
io::println(fmt!("n_closures: %u", ccx.stats.n_closures));
3001+
io::println("fn stats:");
3002+
do sort::quick_sort(ccx.stats.fn_stats) |&(_, _, insns_a), &(_, _, insns_b)| {
3003+
insns_a > insns_b
3004+
}
3005+
for ccx.stats.fn_stats.iter().advance |&(name, ms, insns)| {
3006+
io::println(fmt!("%u insns, %u ms, %s", insns, ms, name));
3007+
}
29643008
}
2965-
29663009
if ccx.sess.count_llvm_insns() {
29673010
for ccx.stats.llvm_insns.iter().advance |(&k, &v)| {
29683011
io::println(fmt!("%-7u %s", v, k));

branches/dist-snap/src/librustc/middle/trans/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub fn B(cx: block) -> BuilderRef {
4646
}
4747

4848
pub fn count_insn(cx: block, category: &str) {
49+
if cx.ccx().sess.trans_stats() {
50+
cx.ccx().stats.n_llvm_insns += 1;
51+
}
4952
do base::with_insn_ctxt |v| {
5053
let h = &mut cx.ccx().stats.llvm_insns;
5154

branches/dist-snap/src/librustc/middle/trans/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ pub struct Stats {
9696
n_monos: uint,
9797
n_inlines: uint,
9898
n_closures: uint,
99+
n_llvm_insns: uint,
100+
llvm_insn_ctxt: ~[~str],
99101
llvm_insns: HashMap<~str, uint>,
100-
fn_times: ~[(~str, int)] // (ident, time)
102+
fn_stats: ~[(~str, uint, uint)] // (ident, time-in-ms, llvm-instructions)
101103
}
102104

103105
pub struct BuilderRef_res {

branches/dist-snap/src/librustc/middle/trans/context.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ impl CrateContext {
210210
n_monos: 0u,
211211
n_inlines: 0u,
212212
n_closures: 0u,
213+
n_llvm_insns: 0u,
214+
llvm_insn_ctxt: ~[],
213215
llvm_insns: HashMap::new(),
214-
fn_times: ~[]
216+
fn_stats: ~[]
215217
},
216218
upcalls: upcall::declare_upcalls(targ_cfg, llmod),
217219
tydesc_type: tydesc_type,
@@ -226,12 +228,6 @@ impl CrateContext {
226228
}
227229
}
228230
}
229-
230-
pub fn log_fn_time(&mut self, name: ~str, start: time::Timespec, end: time::Timespec) {
231-
let elapsed = 1000 * ((end.sec - start.sec) as int) +
232-
((end.nsec as int) - (start.nsec as int)) / 1000000;
233-
self.stats.fn_times.push((name, elapsed));
234-
}
235231
}
236232

237233
#[unsafe_destructor]

branches/dist-snap/src/librustc/middle/trans/glue.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,9 @@ pub fn make_generic_glue(ccx: @mut CrateContext,
738738
name: &str)
739739
-> ValueRef {
740740
let _icx = push_ctxt("make_generic_glue");
741-
if !ccx.sess.trans_stats() {
742-
return make_generic_glue_inner(ccx, t, llfn, helper);
743-
}
744-
745-
let start = time::get_time();
746-
let llval = make_generic_glue_inner(ccx, t, llfn, helper);
747-
let end = time::get_time();
748-
ccx.log_fn_time(fmt!("glue %s %s", name, ty_to_short_str(ccx.tcx, t)), start, end);
749-
return llval;
741+
let glue_name = fmt!("glue %s %s", name, ty_to_short_str(ccx.tcx, t));
742+
let _s = StatRecorder::new(ccx, glue_name);
743+
make_generic_glue_inner(ccx, t, llfn, helper)
750744
}
751745

752746
pub fn emit_tydescs(ccx: &mut CrateContext) {

0 commit comments

Comments
 (0)