@@ -38,7 +38,8 @@ use rustc::session::{early_error, early_warn};
3838use rustc:: lint:: Lint ;
3939use rustc:: lint;
4040use rustc:: hir:: def_id:: LOCAL_CRATE ;
41- use rustc:: util:: common:: { time, ErrorReported , install_panic_hook} ;
41+ use rustc:: util:: common:: { ErrorReported , install_panic_hook, print_time_passes_entry} ;
42+ use rustc:: util:: common:: { set_time_depth, time} ;
4243use rustc_metadata:: locator;
4344use rustc_metadata:: cstore:: CStore ;
4445use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
@@ -54,11 +55,12 @@ use std::default::Default;
5455use std:: env;
5556use std:: ffi:: OsString ;
5657use std:: io:: { self , Read , Write } ;
58+ use std:: mem;
5759use std:: panic:: { self , catch_unwind} ;
5860use std:: path:: PathBuf ;
5961use std:: process:: { self , Command , Stdio } ;
6062use std:: str;
61- use std:: mem ;
63+ use std:: time :: Instant ;
6264
6365use syntax:: ast;
6466use syntax:: source_map:: FileLoader ;
@@ -72,7 +74,7 @@ pub mod pretty;
7274/// Exit status code used for successful compilation and help output.
7375pub const EXIT_SUCCESS : i32 = 0 ;
7476
75- /// Exit status code used for compilation failures and invalid flags.
77+ /// Exit status code used for compilation failures and invalid flags.
7678pub const EXIT_FAILURE : i32 = 1 ;
7779
7880const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
@@ -118,6 +120,18 @@ pub struct DefaultCallbacks;
118120
119121impl Callbacks for DefaultCallbacks { }
120122
123+ #[ derive( Default ) ]
124+ pub struct TimePassesCallbacks {
125+ time_passes : bool ,
126+ }
127+
128+ impl Callbacks for TimePassesCallbacks {
129+ fn config ( & mut self , config : & mut interface:: Config ) {
130+ self . time_passes =
131+ config. opts . debugging_opts . time_passes || config. opts . debugging_opts . time ;
132+ }
133+ }
134+
121135// Parse args and run the compiler. This is the primary entry point for rustc.
122136// See comments on CompilerCalls below for details about the callbacks argument.
123137// The FileLoader provides a way to load files from sources other than the file system.
@@ -1169,18 +1183,24 @@ pub fn init_rustc_env_logger() {
11691183}
11701184
11711185pub fn main ( ) {
1186+ let start = Instant :: now ( ) ;
11721187 init_rustc_env_logger ( ) ;
1188+ let mut callbacks = TimePassesCallbacks :: default ( ) ;
11731189 let result = report_ices_to_stderr_if_any ( || {
11741190 let args = env:: args_os ( ) . enumerate ( )
11751191 . map ( |( i, arg) | arg. into_string ( ) . unwrap_or_else ( |arg| {
11761192 early_error ( ErrorOutputType :: default ( ) ,
11771193 & format ! ( "Argument {} is not valid Unicode: {:?}" , i, arg) )
11781194 } ) )
11791195 . collect :: < Vec < _ > > ( ) ;
1180- run_compiler ( & args, & mut DefaultCallbacks , None , None )
1196+ run_compiler ( & args, & mut callbacks , None , None )
11811197 } ) . and_then ( |result| result) ;
1182- process :: exit ( match result {
1198+ let exit_code = match result {
11831199 Ok ( _) => EXIT_SUCCESS ,
11841200 Err ( _) => EXIT_FAILURE ,
1185- } ) ;
1201+ } ;
1202+ // The extra `\t` is necessary to align this label with the others.
1203+ set_time_depth ( 0 ) ;
1204+ print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
1205+ process:: exit ( exit_code) ;
11861206}
0 commit comments