1
Fork 0

Rollup merge of #135880 - bjorn3:misc_driver_refactors, r=oli-obk

Get rid of RunCompiler

The various `set_*` methods that have been removed can be replaced by setting the respective fields in the `Callbacks::config` implementation. `set_using_internal_features` was often forgotten and it's equivalent is now done automatically.
This commit is contained in:
Matthias Krüger 2025-01-23 19:54:26 +01:00 committed by GitHub
commit 7d31ae7f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 68 additions and 174 deletions

View file

@ -28,8 +28,8 @@ use std::io::{self, IsTerminal, Read, Write};
use std::panic::{self, PanicHookInfo, catch_unwind}; use std::panic::{self, PanicHookInfo, catch_unwind};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{self, Command, Stdio}; use std::process::{self, Command, Stdio};
use std::sync::OnceLock;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
use std::time::{Instant, SystemTime}; use std::time::{Instant, SystemTime};
use std::{env, str}; use std::{env, str};
@ -60,7 +60,6 @@ use rustc_session::lint::{Lint, LintId};
use rustc_session::output::collect_crate_types; use rustc_session::output::collect_crate_types;
use rustc_session::{EarlyDiagCtxt, Session, config, filesearch}; use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
use rustc_span::FileName; use rustc_span::FileName;
use rustc_span::source_map::FileLoader;
use rustc_target::json::ToJson; use rustc_target::json::ToJson;
use rustc_target::spec::{Target, TargetTuple}; use rustc_target::spec::{Target, TargetTuple};
use time::OffsetDateTime; use time::OffsetDateTime;
@ -208,84 +207,7 @@ pub fn diagnostics_registry() -> Registry {
} }
/// This is the primary entry point for rustc. /// This is the primary entry point for rustc.
pub struct RunCompiler<'a> { pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
at_args: &'a [String],
callbacks: &'a mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
}
impl<'a> RunCompiler<'a> {
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
Self {
at_args,
callbacks,
file_loader: None,
make_codegen_backend: None,
using_internal_features: Arc::default(),
}
}
/// Set a custom codegen backend.
///
/// Has no uses within this repository, but is used by bjorn3 for "the
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
/// custom driver where the custom codegen backend has arbitrary data."
/// (See #102759.)
pub fn set_make_codegen_backend(
&mut self,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
) -> &mut Self {
self.make_codegen_backend = make_codegen_backend;
self
}
/// Load files from sources other than the file system.
///
/// Has no uses within this repository, but may be used in the future by
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub fn set_file_loader(
&mut self,
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
) -> &mut Self {
self.file_loader = file_loader;
self
}
/// Set the session-global flag that checks whether internal features have been used,
/// suppressing the message about submitting an issue in ICEs when enabled.
#[must_use]
pub fn set_using_internal_features(mut self, using_internal_features: Arc<AtomicBool>) -> Self {
self.using_internal_features = using_internal_features;
self
}
/// Parse args and run the compiler.
pub fn run(self) {
run_compiler(
self.at_args,
self.callbacks,
self.file_loader,
self.make_codegen_backend,
self.using_internal_features,
);
}
}
fn run_compiler(
at_args: &[String],
callbacks: &mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
) {
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
// Throw away the first argument, the name of the binary. // Throw away the first argument, the name of the binary.
@ -322,16 +244,16 @@ fn run_compiler(
output_file: ofile, output_file: ofile,
output_dir: odir, output_dir: odir,
ice_file, ice_file,
file_loader, file_loader: None,
locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(), locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(),
lint_caps: Default::default(), lint_caps: Default::default(),
psess_created: None, psess_created: None,
hash_untracked_state: None, hash_untracked_state: None,
register_lints: None, register_lints: None,
override_queries: None, override_queries: None,
make_codegen_backend, make_codegen_backend: None,
registry: diagnostics_registry(), registry: diagnostics_registry(),
using_internal_features, using_internal_features: &USING_INTERNAL_FEATURES,
expanded_args: args, expanded_args: args,
}; };
@ -1350,6 +1272,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
}) })
} }
pub static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
/// Installs a panic hook that will print the ICE message on unexpected panics. /// Installs a panic hook that will print the ICE message on unexpected panics.
/// ///
/// The hook is intended to be useable even by external tools. You can pass a custom /// 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
/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to /// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
/// extra_info. /// extra_info.
/// ///
/// Returns a flag that can be set to disable the note for submitting a bug. This can be passed to
/// [`RunCompiler::set_using_internal_features`] to let macro expansion set it when encountering
/// internal features.
///
/// A custom rustc driver can skip calling this to set up a custom ICE hook. /// A custom rustc driver can skip calling this to set up a custom ICE hook.
pub fn install_ice_hook( pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt)) {
bug_report_url: &'static str,
extra_info: fn(&DiagCtxt),
) -> Arc<AtomicBool> {
// If the user has not explicitly overridden "RUST_BACKTRACE", then produce // If the user has not explicitly overridden "RUST_BACKTRACE", then produce
// full backtraces. When a compiler ICE happens, we want to gather // full backtraces. When a compiler ICE happens, we want to gather
// as much information as possible to present in the issue opened // as much information as possible to present in the issue opened
@ -1385,8 +1302,6 @@ pub fn install_ice_hook(
} }
} }
let using_internal_features = Arc::new(std::sync::atomic::AtomicBool::default());
let using_internal_features_hook = Arc::clone(&using_internal_features);
panic::update_hook(Box::new( panic::update_hook(Box::new(
move |default_hook: &(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static), move |default_hook: &(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static),
info: &PanicHookInfo<'_>| { info: &PanicHookInfo<'_>| {
@ -1438,11 +1353,9 @@ pub fn install_ice_hook(
} }
// Print the ICE message // Print the ICE message
report_ice(info, bug_report_url, extra_info, &using_internal_features_hook); report_ice(info, bug_report_url, extra_info, &USING_INTERNAL_FEATURES);
}, },
)); ));
using_internal_features
} }
/// Prints the ICE message, including query stack, but without backtrace. /// Prints the ICE message, including query stack, but without backtrace.
@ -1583,13 +1496,11 @@ pub fn main() -> ! {
init_rustc_env_logger(&early_dcx); init_rustc_env_logger(&early_dcx);
signal_handler::install(); signal_handler::install();
let mut callbacks = TimePassesCallbacks::default(); let mut callbacks = TimePassesCallbacks::default();
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ()); install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
install_ctrlc_handler(); install_ctrlc_handler();
let exit_code = catch_with_exit_code(|| { let exit_code = catch_with_exit_code(|| {
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks) run_compiler(&args::raw_args(&early_dcx)?, &mut callbacks);
.set_using_internal_features(using_internal_features)
.run();
Ok(()) Ok(())
}); });

View file

@ -1,6 +1,5 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::result; use std::result;
use std::sync::Arc;
use rustc_ast::{LitKind, MetaItemKind, token}; use rustc_ast::{LitKind, MetaItemKind, token};
use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::traits::CodegenBackend;
@ -309,6 +308,11 @@ pub struct Config {
pub output_dir: Option<PathBuf>, pub output_dir: Option<PathBuf>,
pub output_file: Option<OutFileName>, pub output_file: Option<OutFileName>,
pub ice_file: Option<PathBuf>, pub ice_file: Option<PathBuf>,
/// Load files from sources other than the file system.
///
/// Has no uses within this repository, but may be used in the future by
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>, pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
/// The list of fluent resources, used for lints declared with /// The list of fluent resources, used for lints declared with
/// [`Diagnostic`](rustc_errors::Diagnostic) and [`LintDiagnostic`](rustc_errors::LintDiagnostic). /// [`Diagnostic`](rustc_errors::Diagnostic) and [`LintDiagnostic`](rustc_errors::LintDiagnostic).
@ -337,6 +341,11 @@ pub struct Config {
pub override_queries: Option<fn(&Session, &mut Providers)>, pub override_queries: Option<fn(&Session, &mut Providers)>,
/// This is a callback from the driver that is called to create a codegen backend. /// This is a callback from the driver that is called to create a codegen backend.
///
/// Has no uses within this repository, but is used by bjorn3 for "the
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
/// custom driver where the custom codegen backend has arbitrary data."
/// (See #102759.)
pub make_codegen_backend: pub make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>, Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
@ -346,8 +355,7 @@ pub struct Config {
/// The inner atomic value is set to true when a feature marked as `internal` is /// The inner atomic value is set to true when a feature marked as `internal` is
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with /// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
/// internal features are wontfix, and they are usually the cause of the ICEs. /// internal features are wontfix, and they are usually the cause of the ICEs.
/// None signifies that this is not tracked. pub using_internal_features: &'static std::sync::atomic::AtomicBool,
pub using_internal_features: Arc<std::sync::atomic::AtomicBool>,
/// All commandline args used to invoke the compiler, with @file args fully expanded. /// All commandline args used to invoke the compiler, with @file args fully expanded.
/// This will only be used within debug info, e.g. in the pdb file on windows /// This will only be used within debug info, e.g. in the pdb file on windows

View file

@ -2,7 +2,7 @@
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::num::NonZero; use std::num::NonZero;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::atomic::AtomicBool;
use rustc_data_structures::profiling::TimePassesFormat; use rustc_data_structures::profiling::TimePassesFormat;
use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::emitter::HumanReadableErrorType;
@ -62,6 +62,8 @@ where
temps_dir, temps_dir,
}; };
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
let sess = build_session( let sess = build_session(
early_dcx, early_dcx,
sessopts, sessopts,
@ -74,7 +76,7 @@ where
sysroot, sysroot,
"", "",
None, None,
Arc::default(), &USING_INTERNAL_FEATURES,
Default::default(), Default::default(),
); );
let cfg = parse_cfg(sess.dcx(), matches.opt_strs("cfg")); let cfg = parse_cfg(sess.dcx(), matches.opt_strs("cfg"));

View file

@ -189,7 +189,7 @@ pub struct Session {
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with /// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
/// internal features are wontfix, and they are usually the cause of the ICEs. /// internal features are wontfix, and they are usually the cause of the ICEs.
/// None signifies that this is not tracked. /// None signifies that this is not tracked.
pub using_internal_features: Arc<AtomicBool>, pub using_internal_features: &'static AtomicBool,
/// All commandline args used to invoke the compiler, with @file args fully expanded. /// All commandline args used to invoke the compiler, with @file args fully expanded.
/// This will only be used within debug info, e.g. in the pdb file on windows /// This will only be used within debug info, e.g. in the pdb file on windows
@ -966,7 +966,7 @@ pub fn build_session(
sysroot: PathBuf, sysroot: PathBuf,
cfg_version: &'static str, cfg_version: &'static str,
ice_file: Option<PathBuf>, ice_file: Option<PathBuf>,
using_internal_features: Arc<AtomicBool>, using_internal_features: &'static AtomicBool,
expanded_args: Vec<String>, expanded_args: Vec<String>,
) -> Session { ) -> Session {
// FIXME: This is not general enough to make the warning lint completely override // FIXME: This is not general enough to make the warning lint completely override

View file

@ -316,7 +316,7 @@ macro_rules! optional {
#[doc(hidden)] #[doc(hidden)]
macro_rules! run_driver { macro_rules! run_driver {
($args:expr, $callback:expr $(, $with_tcx:ident)?) => {{ ($args:expr, $callback:expr $(, $with_tcx:ident)?) => {{
use rustc_driver::{Callbacks, Compilation, RunCompiler}; use rustc_driver::{Callbacks, Compilation, run_compiler};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_interface::interface; use rustc_interface::interface;
use stable_mir::CompilerError; use stable_mir::CompilerError;
@ -347,7 +347,7 @@ macro_rules! run_driver {
/// Runs the compiler against given target and tests it with `test_function` /// Runs the compiler against given target and tests it with `test_function`
pub fn run(&mut self) -> Result<C, CompilerError<B>> { pub fn run(&mut self) -> Result<C, CompilerError<B>> {
let compiler_result = rustc_driver::catch_fatal_errors(|| -> interface::Result::<()> { let compiler_result = rustc_driver::catch_fatal_errors(|| -> interface::Result::<()> {
RunCompiler::new(&self.args.clone(), self).run(); run_compiler(&self.args.clone(), self);
Ok(()) Ok(())
}); });
match (compiler_result, self.result.take()) { match (compiler_result, self.result.take()) {

View file

@ -18,8 +18,8 @@ use std::path::Path;
use rustc_ast_pretty::pprust::item_to_string; use rustc_ast_pretty::pprust::item_to_string;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_driver::{Compilation, RunCompiler}; use rustc_driver::{Compilation, run_compiler};
use rustc_interface::interface::Compiler; use rustc_interface::interface::{Compiler, Config};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
struct MyFileLoader; struct MyFileLoader;
@ -51,6 +51,10 @@ fn main() {
struct MyCallbacks; struct MyCallbacks;
impl rustc_driver::Callbacks for MyCallbacks { impl rustc_driver::Callbacks for MyCallbacks {
fn config(&mut self, config: &mut Config) {
config.file_loader = Some(Box::new(MyFileLoader));
}
fn after_crate_root_parsing( fn after_crate_root_parsing(
&mut self, &mut self,
_compiler: &Compiler, _compiler: &Compiler,
@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
} }
fn main() { fn main() {
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) { run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
mut compiler => {
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
compiler.run();
}
}
} }

View file

@ -18,8 +18,8 @@ use std::path::Path;
use rustc_ast_pretty::pprust::item_to_string; use rustc_ast_pretty::pprust::item_to_string;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_driver::{Compilation, RunCompiler}; use rustc_driver::{Compilation, run_compiler};
use rustc_interface::interface::Compiler; use rustc_interface::interface::{Compiler, Config};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
struct MyFileLoader; struct MyFileLoader;
@ -51,6 +51,10 @@ fn main() {
struct MyCallbacks; struct MyCallbacks;
impl rustc_driver::Callbacks for MyCallbacks { impl rustc_driver::Callbacks for MyCallbacks {
fn config(&mut self, config: &mut Config) {
config.file_loader = Some(Box::new(MyFileLoader));
}
fn after_crate_root_parsing( fn after_crate_root_parsing(
&mut self, &mut self,
_compiler: &Compiler, _compiler: &Compiler,
@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
} }
fn main() { fn main() {
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) { run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
mut compiler => {
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
compiler.run();
}
}
} }

View file

@ -6,7 +6,7 @@ The [`rustc_driver`] is essentially `rustc`'s `main` function.
It acts as the glue for running the various phases of the compiler in the correct order, It acts as the glue for running the various phases of the compiler in the correct order,
using the interface defined in the [`rustc_interface`] crate. Where possible, using [`rustc_driver`] rather than [`rustc_interface`] is recommended. using the interface defined in the [`rustc_interface`] crate. Where possible, using [`rustc_driver`] rather than [`rustc_interface`] is recommended.
The main entry point of [`rustc_driver`] is [`rustc_driver::RunCompiler`][rd_rc]. The main entry point of [`rustc_driver`] is [`rustc_driver::run_compiler`][rd_rc].
This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`][cb] and a couple of other optional options. This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`][cb] and a couple of other optional options.
[`Callbacks`][cb] is a `trait` that allows for custom compiler configuration, [`Callbacks`][cb] is a `trait` that allows for custom compiler configuration,
as well as allowing custom code to run after different phases of the compilation. as well as allowing custom code to run after different phases of the compilation.
@ -40,7 +40,7 @@ specifically [`rustc_driver_impl::run_compiler`][rdi_rc]
[cb]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html [cb]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html
[example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-interface-example.rs [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-interface-example.rs
[i_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html [i_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html
[rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/struct.RunCompiler.html [rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.run_compiler.html
[rdi_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html [rdi_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html
[stupid-stats]: https://github.com/nrc/stupid-stats [stupid-stats]: https://github.com/nrc/stupid-stats
[`nightly-rustc`]: https://doc.rust-lang.org/nightly/nightly-rustc/ [`nightly-rustc`]: https://doc.rust-lang.org/nightly/nightly-rustc/

View file

@ -1,10 +1,10 @@
use std::sync::atomic::AtomicBool; use std::sync::LazyLock;
use std::sync::{Arc, LazyLock};
use std::{io, mem}; use std::{io, mem};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_driver::USING_INTERNAL_FEATURES;
use rustc_errors::TerminalUrl; use rustc_errors::TerminalUrl;
use rustc_errors::codes::*; use rustc_errors::codes::*;
use rustc_errors::emitter::{ use rustc_errors::emitter::{
@ -221,7 +221,6 @@ pub(crate) fn create_config(
.. ..
}: RustdocOptions, }: RustdocOptions,
RenderOptions { document_private, .. }: &RenderOptions, RenderOptions { document_private, .. }: &RenderOptions,
using_internal_features: Arc<AtomicBool>,
) -> rustc_interface::Config { ) -> rustc_interface::Config {
// Add the doc cfg into the doc build. // Add the doc cfg into the doc build.
cfgs.push("doc".to_string()); cfgs.push("doc".to_string());
@ -316,7 +315,7 @@ pub(crate) fn create_config(
make_codegen_backend: None, make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(), registry: rustc_driver::diagnostics_registry(),
ice_file: None, ice_file: None,
using_internal_features, using_internal_features: &USING_INTERNAL_FEATURES,
expanded_args, expanded_args,
} }
} }

View file

@ -193,7 +193,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
make_codegen_backend: None, make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(), registry: rustc_driver::diagnostics_registry(),
ice_file: None, ice_file: None,
using_internal_features: Arc::default(), using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
expanded_args: options.expanded_args.clone(), expanded_args: options.expanded_args.clone(),
}; };

View file

@ -74,8 +74,6 @@ extern crate tikv_jemalloc_sys as jemalloc_sys;
use std::env::{self, VarError}; use std::env::{self, VarError};
use std::io::{self, IsTerminal}; use std::io::{self, IsTerminal};
use std::process; use std::process;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use rustc_errors::DiagCtxtHandle; use rustc_errors::DiagCtxtHandle;
use rustc_interface::interface; use rustc_interface::interface;
@ -159,7 +157,7 @@ pub fn main() {
let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
let using_internal_features = rustc_driver::install_ice_hook( rustc_driver::install_ice_hook(
"https://github.com/rust-lang/rust/issues/new\ "https://github.com/rust-lang/rust/issues/new\
?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md", ?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md",
|_| (), |_| (),
@ -180,7 +178,7 @@ pub fn main() {
let exit_code = rustc_driver::catch_with_exit_code(|| { let exit_code = rustc_driver::catch_with_exit_code(|| {
let at_args = rustc_driver::args::raw_args(&early_dcx)?; let at_args = rustc_driver::args::raw_args(&early_dcx)?;
main_args(&mut early_dcx, &at_args, using_internal_features); main_args(&mut early_dcx, &at_args);
Ok(()) Ok(())
}); });
process::exit(exit_code); process::exit(exit_code);
@ -769,11 +767,7 @@ fn run_merge_finalize(opt: config::RenderOptions) -> Result<(), error::Error> {
Ok(()) Ok(())
} }
fn main_args( fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
early_dcx: &mut EarlyDiagCtxt,
at_args: &[String],
using_internal_features: Arc<AtomicBool>,
) {
// Throw away the first argument, the name of the binary. // Throw away the first argument, the name of the binary.
// In case of at_args being empty, as might be the case by // In case of at_args being empty, as might be the case by
// passing empty argument array to execve under some platforms, // passing empty argument array to execve under some platforms,
@ -826,8 +820,7 @@ fn main_args(
(false, Some(md_input)) => { (false, Some(md_input)) => {
let md_input = md_input.to_owned(); let md_input = md_input.to_owned();
let edition = options.edition; let edition = options.edition;
let config = let config = core::create_config(input, options, &render_options);
core::create_config(input, options, &render_options, using_internal_features);
// `markdown::render` can invoke `doctest::make_test`, which // `markdown::render` can invoke `doctest::make_test`, which
// requires session globals and a thread pool, so we use // requires session globals and a thread pool, so we use
@ -860,7 +853,7 @@ fn main_args(
let scrape_examples_options = options.scrape_examples_options.clone(); let scrape_examples_options = options.scrape_examples_options.clone();
let bin_crate = options.bin_crate; let bin_crate = options.bin_crate;
let config = core::create_config(input, options, &render_options, using_internal_features); let config = core::create_config(input, options, &render_options);
let registered_lints = config.register_lints.is_some(); let registered_lints = config.register_lints.is_some();

View file

@ -186,7 +186,7 @@ pub fn main() {
rustc_driver::init_rustc_env_logger(&early_dcx); rustc_driver::init_rustc_env_logger(&early_dcx);
let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| { rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| {
// FIXME: this macro calls unwrap internally but is called in a panicking context! It's not // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
// as simple as moving the call from the hook to main, because `install_ice_hook` doesn't // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
// accept a generic closure. // accept a generic closure.
@ -236,7 +236,7 @@ pub fn main() {
let mut args: Vec<String> = orig_args.clone(); let mut args: Vec<String> = orig_args.clone();
pass_sysroot_env_if_given(&mut args, sys_root_env); pass_sysroot_env_if_given(&mut args, sys_root_env);
rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); rustc_driver::run_compiler(&args, &mut DefaultCallbacks);
return Ok(()); return Ok(());
} }
@ -295,13 +295,9 @@ pub fn main() {
let clippy_enabled = !cap_lints_allow && relevant_package && !info_query; let clippy_enabled = !cap_lints_allow && relevant_package && !info_query;
if clippy_enabled { if clippy_enabled {
args.extend(clippy_args); args.extend(clippy_args);
rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }) rustc_driver::run_compiler(&args, &mut ClippyCallbacks { clippy_args_var });
.set_using_internal_features(using_internal_features)
.run();
} else { } else {
rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }) rustc_driver::run_compiler(&args, &mut RustcCallbacks { clippy_args_var });
.set_using_internal_features(using_internal_features)
.run();
} }
Ok(()) Ok(())
})) }))

View file

@ -30,7 +30,7 @@ use std::ops::Range;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use std::sync::atomic::{AtomicI32, Ordering}; use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::{Arc, Once}; use std::sync::Once;
use miri::{ use miri::{
BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType,ProvenanceMode, RetagFields, ValidationMode, BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType,ProvenanceMode, RetagFields, ValidationMode,
@ -370,13 +370,10 @@ fn init_late_loggers(early_dcx: &EarlyDiagCtxt, tcx: TyCtxt<'_>) {
fn run_compiler_and_exit( fn run_compiler_and_exit(
args: &[String], args: &[String],
callbacks: &mut (dyn rustc_driver::Callbacks + Send), callbacks: &mut (dyn rustc_driver::Callbacks + Send),
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
) -> ! { ) -> ! {
// Invoke compiler, and handle return code. // Invoke compiler, and handle return code.
let exit_code = rustc_driver::catch_with_exit_code(move || { let exit_code = rustc_driver::catch_with_exit_code(move || {
rustc_driver::RunCompiler::new(args, callbacks) rustc_driver::run_compiler(args, callbacks);
.set_using_internal_features(using_internal_features)
.run();
Ok(()) Ok(())
}); });
std::process::exit(exit_code) std::process::exit(exit_code)
@ -467,8 +464,7 @@ fn main() {
// If the environment asks us to actually be rustc, then do that. // If the environment asks us to actually be rustc, then do that.
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") { if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
// Earliest rustc setup. // Earliest rustc setup.
let using_internal_features = rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
rustc_driver::init_rustc_env_logger(&early_dcx); rustc_driver::init_rustc_env_logger(&early_dcx);
let target_crate = if crate_kind == "target" { let target_crate = if crate_kind == "target" {
@ -492,16 +488,11 @@ fn main() {
} }
// We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments. // We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments.
run_compiler_and_exit( run_compiler_and_exit(&args, &mut MiriBeRustCompilerCalls { target_crate })
&args,
&mut MiriBeRustCompilerCalls { target_crate },
using_internal_features,
)
} }
// Add an ICE bug report hook. // Add an ICE bug report hook.
let using_internal_features = rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
// Init loggers the Miri way. // Init loggers the Miri way.
init_early_loggers(&early_dcx); init_early_loggers(&early_dcx);
@ -735,9 +726,5 @@ fn main() {
debug!("rustc arguments: {:?}", rustc_args); debug!("rustc arguments: {:?}", rustc_args);
debug!("crate arguments: {:?}", miri_config.args); debug!("crate arguments: {:?}", miri_config.args);
run_compiler_and_exit( run_compiler_and_exit(&rustc_args, &mut MiriCompilerCalls::new(miri_config, many_seeds))
&rustc_args,
&mut MiriCompilerCalls::new(miri_config, many_seeds),
using_internal_features,
)
} }

View file

@ -25,7 +25,7 @@ fn main() {
let mut count = 1; let mut count = 1;
let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()]; let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
rustc_driver::catch_fatal_errors(|| -> interface::Result<()> { rustc_driver::catch_fatal_errors(|| -> interface::Result<()> {
rustc_driver::RunCompiler::new(&args, &mut TestCalls { count: &mut count }).run(); rustc_driver::run_compiler(&args, &mut TestCalls { count: &mut count });
Ok(()) Ok(())
}) })
.ok(); .ok();

View file

@ -47,7 +47,7 @@ fn main() {
rustc_args.push("-Zpolonius".to_owned()); rustc_args.push("-Zpolonius".to_owned());
let mut callbacks = CompilerCalls::default(); let mut callbacks = CompilerCalls::default();
// Call the Rust compiler with our callbacks. // Call the Rust compiler with our callbacks.
rustc_driver::RunCompiler::new(&rustc_args, &mut callbacks).run(); rustc_driver::run_compiler(&rustc_args, &mut callbacks);
Ok(()) Ok(())
}); });
std::process::exit(exit_code); std::process::exit(exit_code);

View file

@ -72,7 +72,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path
override_queries: None, override_queries: None,
make_codegen_backend: None, make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(), registry: rustc_driver::diagnostics_registry(),
using_internal_features: std::sync::Arc::default(), using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
expanded_args: Default::default(), expanded_args: Default::default(),
}; };