@@ -28,8 +28,8 @@ use std::io::{self, IsTerminal, Read, Write};
28
28
use std:: panic:: { self , PanicHookInfo , catch_unwind} ;
29
29
use std:: path:: { Path , PathBuf } ;
30
30
use std:: process:: { self , Command , Stdio } ;
31
+ use std:: sync:: OnceLock ;
31
32
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
32
- use std:: sync:: { Arc , OnceLock } ;
33
33
use std:: time:: { Instant , SystemTime } ;
34
34
use std:: { env, str} ;
35
35
@@ -60,7 +60,6 @@ use rustc_session::lint::{Lint, LintId};
60
60
use rustc_session:: output:: collect_crate_types;
61
61
use rustc_session:: { EarlyDiagCtxt , Session , config, filesearch} ;
62
62
use rustc_span:: FileName ;
63
- use rustc_span:: source_map:: FileLoader ;
64
63
use rustc_target:: json:: ToJson ;
65
64
use rustc_target:: spec:: { Target , TargetTuple } ;
66
65
use time:: OffsetDateTime ;
@@ -208,84 +207,7 @@ pub fn diagnostics_registry() -> Registry {
208
207
}
209
208
210
209
/// This is the primary entry point for rustc.
211
- pub struct RunCompiler <' a> {
212
- at_args: & ' a [ String ] ,
213
- callbacks: & ' a mut ( dyn Callbacks + Send ) ,
214
- file_loader: Option <Box <dyn FileLoader + Send + Sync >>,
215
- make_codegen_backend:
216
- Option <Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >>,
217
- using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
218
- }
219
-
220
- impl <' a> RunCompiler <' a> {
221
- pub fn new( at_args: & ' a [ String ] , callbacks: & ' a mut ( dyn Callbacks + Send ) ) -> Self {
222
- Self {
223
- at_args,
224
- callbacks,
225
- file_loader: None ,
226
- make_codegen_backend: None ,
227
- using_internal_features: Arc :: default ( ) ,
228
- }
229
- }
230
-
231
- /// Set a custom codegen backend.
232
- ///
233
- /// Has no uses within this repository, but is used by bjorn3 for "the
234
- /// hotswapping branch of cg_clif" for "setting the codegen backend from a
235
- /// custom driver where the custom codegen backend has arbitrary data."
236
- /// (See #102759.)
237
- pub fn set_make_codegen_backend(
238
- & mut self ,
239
- make_codegen_backend: Option <
240
- Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >,
241
- >,
242
- ) -> & mut Self {
243
- self . make_codegen_backend = make_codegen_backend;
244
- self
245
- }
246
-
247
- /// Load files from sources other than the file system.
248
- ///
249
- /// Has no uses within this repository, but may be used in the future by
250
- /// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
251
- /// running rustc without having to save". (See #102759.)
252
- pub fn set_file_loader(
253
- & mut self ,
254
- file_loader: Option <Box <dyn FileLoader + Send + Sync >>,
255
- ) -> & mut Self {
256
- self . file_loader = file_loader;
257
- self
258
- }
259
-
260
- /// Set the session-global flag that checks whether internal features have been used,
261
- /// suppressing the message about submitting an issue in ICEs when enabled.
262
- #[ must_use]
263
- pub fn set_using_internal_features( mut self , using_internal_features: Arc <AtomicBool >) -> Self {
264
- self . using_internal_features = using_internal_features;
265
- self
266
- }
267
-
268
- /// Parse args and run the compiler.
269
- pub fn run( self ) {
270
- run_compiler(
271
- self . at_args,
272
- self . callbacks,
273
- self . file_loader,
274
- self . make_codegen_backend,
275
- self . using_internal_features,
276
- ) ;
277
- }
278
- }
279
-
280
- fn run_compiler(
281
- at_args: & [ String ] ,
282
- callbacks: & mut ( dyn Callbacks + Send ) ,
283
- file_loader: Option <Box <dyn FileLoader + Send + Sync >>,
284
- make_codegen_backend: Option <
285
- Box <dyn FnOnce ( & config:: Options ) -> Box <dyn CodegenBackend > + Send >,
286
- >,
287
- using_internal_features: Arc <std:: sync:: atomic:: AtomicBool >,
288
- ) {
210
+ pub fn run_compiler( at_args: & [ String ] , callbacks: & mut ( dyn Callbacks + Send ) ) {
289
211
let mut default_early_dcx = EarlyDiagCtxt :: new( ErrorOutputType :: default ( ) ) ;
290
212
291
213
// Throw away the first argument, the name of the binary.
@@ -322,16 +244,16 @@ fn run_compiler(
322
244
output_file: ofile,
323
245
output_dir: odir,
324
246
ice_file,
325
- file_loader,
247
+ file_loader: None ,
326
248
locale_resources: DEFAULT_LOCALE_RESOURCES . to_vec( ) ,
327
249
lint_caps: Default :: default ( ) ,
328
250
psess_created: None ,
329
251
hash_untracked_state: None ,
330
252
register_lints: None ,
331
253
override_queries: None ,
332
- make_codegen_backend,
254
+ make_codegen_backend: None ,
333
255
registry: diagnostics_registry( ) ,
334
- using_internal_features,
256
+ using_internal_features: & USING_INTERNAL_FEATURES ,
335
257
expanded_args: args,
336
258
} ;
337
259
@@ -1350,6 +1272,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
1350
1272
} )
1351
1273
}
1352
1274
1275
+ pub static USING_INTERNAL_FEATURES : AtomicBool = AtomicBool :: new( false ) ;
1276
+
1353
1277
/// Installs a panic hook that will print the ICE message on unexpected panics.
1354
1278
///
1355
1279
/// The hook is intended to be useable even by external tools. You can pass a custom
@@ -1360,15 +1284,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
1360
1284
/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
1361
1285
/// extra_info.
1362
1286
///
1363
- /// Returns a flag that can be set to disable the note for submitting a bug. This can be passed to
1364
- /// [`RunCompiler::set_using_internal_features`] to let macro expansion set it when encountering
1365
- /// internal features.
1366
- ///
1367
1287
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
1368
- pub fn install_ice_hook(
1369
- bug_report_url: & ' static str ,
1370
- extra_info: fn ( & DiagCtxt ) ,
1371
- ) -> Arc <AtomicBool > {
1288
+ pub fn install_ice_hook( bug_report_url: & ' static str , extra_info: fn ( & DiagCtxt ) ) {
1372
1289
// If the user has not explicitly overridden "RUST_BACKTRACE", then produce
1373
1290
// full backtraces. When a compiler ICE happens, we want to gather
1374
1291
// as much information as possible to present in the issue opened
@@ -1385,8 +1302,6 @@ pub fn install_ice_hook(
1385
1302
}
1386
1303
}
1387
1304
1388
- let using_internal_features = Arc :: new( std:: sync:: atomic:: AtomicBool :: default ( ) ) ;
1389
- let using_internal_features_hook = Arc :: clone( & using_internal_features) ;
1390
1305
panic:: update_hook( Box :: new(
1391
1306
move |default_hook: & ( dyn Fn ( & PanicHookInfo <' _>) + Send + Sync + ' static ) ,
1392
1307
info: & PanicHookInfo <' _>| {
@@ -1438,11 +1353,9 @@ pub fn install_ice_hook(
1438
1353
}
1439
1354
1440
1355
// Print the ICE message
1441
- report_ice( info, bug_report_url, extra_info, & using_internal_features_hook ) ;
1356
+ report_ice( info, bug_report_url, extra_info, & USING_INTERNAL_FEATURES ) ;
1442
1357
} ,
1443
1358
) ) ;
1444
-
1445
- using_internal_features
1446
1359
}
1447
1360
1448
1361
/// Prints the ICE message, including query stack, but without backtrace.
@@ -1583,13 +1496,11 @@ pub fn main() -> ! {
1583
1496
init_rustc_env_logger( & early_dcx) ;
1584
1497
signal_handler:: install( ) ;
1585
1498
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1586
- let using_internal_features = install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1499
+ install_ice_hook( DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
1587
1500
install_ctrlc_handler( ) ;
1588
1501
1589
1502
let exit_code = catch_with_exit_code( || {
1590
- RunCompiler :: new( & args:: raw_args( & early_dcx) ?, & mut callbacks)
1591
- . set_using_internal_features( using_internal_features)
1592
- . run( ) ;
1503
+ run_compiler( & args:: raw_args( & early_dcx) ?, & mut callbacks) ;
1593
1504
Ok ( ( ) )
1594
1505
} ) ;
1595
1506
0 commit comments