@@ -19,6 +19,7 @@ extern crate tracing;
19
19
20
20
use rustc_ast as ast;
21
21
use rustc_codegen_ssa:: { traits:: CodegenBackend , CodegenErrors , CodegenResults } ;
22
+ use rustc_const_eval:: CTRL_C_RECEIVED ;
22
23
use rustc_data_structures:: profiling:: {
23
24
get_resident_set_size, print_time_passes_entry, TimePassesFormat ,
24
25
} ;
@@ -1518,6 +1519,22 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
1518
1519
}
1519
1520
}
1520
1521
1522
+ /// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
1523
+ /// Making this handler optional lets tools can install a different handler, if they wish.
1524
+ pub fn install_ctrlc_handler( ) {
1525
+ ctrlc:: set_handler( move || {
1526
+ // Indicate that we have been signaled to stop. If we were already signaled, exit
1527
+ // immediately. In our interpreter loop we try to consult this value often, but if for
1528
+ // whatever reason we don't get to that check or the cleanup we do upon finding that
1529
+ // this bool has become true takes a long time, the exit here will promptly exit the
1530
+ // process on the second Ctrl-C.
1531
+ if CTRL_C_RECEIVED . swap( true , Ordering :: Relaxed ) {
1532
+ std:: process:: exit( 1 ) ;
1533
+ }
1534
+ } )
1535
+ . expect( "Unable to install ctrlc handler" ) ;
1536
+ }
1537
+
1521
1538
pub fn main( ) -> ! {
1522
1539
let start_time = Instant :: now( ) ;
1523
1540
let start_rss = get_resident_set_size( ) ;
@@ -1528,6 +1545,8 @@ pub fn main() -> ! {
1528
1545
signal_handler:: install( ) ;
1529
1546
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1530
1547
let using_internal_features = install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1548
+ install_ctrlc_handler( ) ;
1549
+
1531
1550
let exit_code = catch_with_exit_code( || {
1532
1551
RunCompiler :: new( & args:: raw_args( & early_dcx) ?, & mut callbacks)
1533
1552
. set_using_internal_features( using_internal_features)
0 commit comments