@@ -37,7 +37,8 @@ use rustc::session::{early_error, early_warn};
3737use rustc:: lint:: Lint ;
3838use rustc:: lint;
3939use rustc:: hir:: def_id:: LOCAL_CRATE ;
40- use rustc:: util:: common:: { time, ErrorReported , install_panic_hook} ;
40+ use rustc:: util:: common:: { ErrorReported , install_panic_hook, print_time_passes_entry} ;
41+ use rustc:: util:: common:: { set_time_depth, time} ;
4142use rustc_metadata:: locator;
4243use rustc_metadata:: cstore:: CStore ;
4344use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
@@ -53,11 +54,12 @@ use std::default::Default;
5354use std:: env;
5455use std:: ffi:: OsString ;
5556use std:: io:: { self , Read , Write } ;
57+ use std:: mem;
5658use std:: panic:: { self , catch_unwind} ;
5759use std:: path:: PathBuf ;
5860use std:: process:: { self , Command , Stdio } ;
5961use std:: str;
60- use std:: mem ;
62+ use std:: time :: Instant ;
6163
6264use syntax:: ast;
6365use syntax:: source_map:: FileLoader ;
@@ -71,7 +73,7 @@ pub mod pretty;
7173/// Exit status code used for successful compilation and help output.
7274pub const EXIT_SUCCESS : i32 = 0 ;
7375
74- /// Exit status code used for compilation failures and invalid flags.
76+ /// Exit status code used for compilation failures and invalid flags.
7577pub const EXIT_FAILURE : i32 = 1 ;
7678
7779const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
@@ -117,6 +119,18 @@ pub struct DefaultCallbacks;
117119
118120impl Callbacks for DefaultCallbacks { }
119121
122+ #[ derive( Default ) ]
123+ pub struct TimePassesCallbacks {
124+ time_passes : bool ,
125+ }
126+
127+ impl Callbacks for TimePassesCallbacks {
128+ fn config ( & mut self , config : & mut interface:: Config ) {
129+ self . time_passes =
130+ config. opts . debugging_opts . time_passes || config. opts . debugging_opts . time ;
131+ }
132+ }
133+
120134// Parse args and run the compiler. This is the primary entry point for rustc.
121135// See comments on CompilerCalls below for details about the callbacks argument.
122136// The FileLoader provides a way to load files from sources other than the file system.
@@ -1168,18 +1182,24 @@ pub fn init_rustc_env_logger() {
11681182}
11691183
11701184pub fn main ( ) {
1185+ let start = Instant :: now ( ) ;
11711186 init_rustc_env_logger ( ) ;
1187+ let mut callbacks = TimePassesCallbacks :: default ( ) ;
11721188 let result = report_ices_to_stderr_if_any ( || {
11731189 let args = env:: args_os ( ) . enumerate ( )
11741190 . map ( |( i, arg) | arg. into_string ( ) . unwrap_or_else ( |arg| {
11751191 early_error ( ErrorOutputType :: default ( ) ,
11761192 & format ! ( "Argument {} is not valid Unicode: {:?}" , i, arg) )
11771193 } ) )
11781194 . collect :: < Vec < _ > > ( ) ;
1179- run_compiler ( & args, & mut DefaultCallbacks , None , None )
1195+ run_compiler ( & args, & mut callbacks , None , None )
11801196 } ) . and_then ( |result| result) ;
1181- process :: exit ( match result {
1197+ let exit_code = match result {
11821198 Ok ( _) => EXIT_SUCCESS ,
11831199 Err ( _) => EXIT_FAILURE ,
1184- } ) ;
1200+ } ;
1201+ // The extra `\t` is necessary to align this label with the others.
1202+ set_time_depth ( 0 ) ;
1203+ print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
1204+ process:: exit ( exit_code) ;
11851205}
0 commit comments