@@ -98,6 +98,19 @@ fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
98
98
ret rv;
99
99
}
100
100
101
+ // FIXME (issue #1005): Needed to work around a segfault. If |time| is used
102
+ // instead, we crash.
103
+ fn time_unit ( do_it : bool , what : str , thunk : fn ( ) ) {
104
+ if !do_it { ret thunk ( ) ; }
105
+ let start = std:: time:: precise_time_s ( ) ;
106
+ let rv = thunk ( ) ;
107
+ let end = std:: time:: precise_time_s ( ) ;
108
+ log_err #fmt[ "time: %s took %s s" , what,
109
+ common:: float_to_str ( end - start, 3 u) ] ;
110
+ ret rv;
111
+ }
112
+
113
+
101
114
fn compile_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ,
102
115
output : str ) {
103
116
let time_passes = sess. get_opts ( ) . time_passes ;
@@ -119,36 +132,38 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
119
132
let ast_map =
120
133
time ( time_passes, "ast indexing" ,
121
134
bind middle:: ast_map:: map_crate ( * crate ) ) ;
122
- time ( time_passes, "external crate/lib resolution" ,
123
- bind creader:: read_crates ( sess, * crate ) ) ;
135
+ time_unit ( time_passes, "external crate/lib resolution" ,
136
+ bind creader:: read_crates ( sess, * crate ) ) ;
124
137
let { def_map: def_map , ext_map : ext_map } =
125
138
time ( time_passes, "resolution" ,
126
139
bind resolve:: resolve_crate ( sess, ast_map, crate ) ) ;
127
140
let freevars =
128
141
time ( time_passes, "freevar finding" ,
129
142
bind freevars:: annotate_freevars ( def_map, crate ) ) ;
130
143
let ty_cx = ty:: mk_ctxt ( sess, def_map, ext_map, ast_map, freevars) ;
131
- time ( time_passes, "typechecking" , bind typeck:: check_crate ( ty_cx, crate ) ) ;
132
- time ( time_passes, "alt checking" ,
144
+ time_unit ( time_passes, "typechecking" , bind
145
+ typeck:: check_crate ( ty_cx, crate ) ) ;
146
+ time_unit ( time_passes, "alt checking" ,
133
147
bind middle:: check_alt:: check_crate ( ty_cx, crate ) ) ;
134
148
if sess. get_opts ( ) . run_typestate {
135
- time ( time_passes, "typestate checking" ,
136
- bind middle:: tstate:: ck:: check_crate ( ty_cx, crate ) ) ;
149
+ time_unit ( time_passes, "typestate checking" ,
150
+ bind middle:: tstate:: ck:: check_crate ( ty_cx, crate ) ) ;
137
151
}
138
152
let mut_map =
139
153
time ( time_passes, "mutability checking" ,
140
154
bind middle:: mut:: check_crate ( ty_cx, crate ) ) ;
141
155
let copy_map =
142
156
time ( time_passes, "alias checking" ,
143
157
bind middle:: alias:: check_crate ( ty_cx, crate ) ) ;
144
- time ( time_passes, "kind checking" , bind kind:: check_crate ( ty_cx, crate ) ) ;
158
+ time_unit ( time_passes, "kind checking" ,
159
+ bind kind:: check_crate ( ty_cx, crate ) ) ;
145
160
if sess. get_opts ( ) . no_trans { ret; }
146
161
let llmod =
147
162
time ( time_passes, "translation" ,
148
163
bind trans:: trans_crate ( sess, crate , ty_cx, output, ast_map,
149
164
mut_map, copy_map) ) ;
150
- time ( time_passes, "LLVM passes" ,
151
- bind link:: write:: run_passes ( sess, llmod, output) ) ;
165
+ time_unit ( time_passes, "LLVM passes" ,
166
+ bind link:: write:: run_passes ( sess, llmod, output) ) ;
152
167
}
153
168
154
169
fn pretty_print_input ( sess : session:: session , cfg : ast:: crate_cfg , input : str ,
0 commit comments