Remove set_make_codegen_backend and set_file_loader
They can both be set inside the config callback too.
This commit is contained in:
parent
4f9b9a43c1
commit
974db1a6e4
4 changed files with 27 additions and 59 deletions
|
@ -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;
|
||||||
|
@ -211,59 +210,20 @@ pub fn diagnostics_registry() -> Registry {
|
||||||
pub struct RunCompiler<'a> {
|
pub struct RunCompiler<'a> {
|
||||||
at_args: &'a [String],
|
at_args: &'a [String],
|
||||||
callbacks: &'a mut (dyn Callbacks + Send),
|
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>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RunCompiler<'a> {
|
impl<'a> RunCompiler<'a> {
|
||||||
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
|
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 }
|
Self { at_args, callbacks }
|
||||||
}
|
|
||||||
|
|
||||||
/// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse args and run the compiler.
|
/// Parse args and run the compiler.
|
||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend);
|
run_compiler(self.at_args, self.callbacks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_compiler(
|
fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
|
||||||
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>,
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
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.
|
||||||
|
@ -300,14 +260,14 @@ 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: &USING_INTERNAL_FEATURES,
|
||||||
expanded_args: args,
|
expanded_args: args,
|
||||||
|
|
|
@ -308,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).
|
||||||
|
@ -336,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>>,
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ 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, RunCompiler};
|
||||||
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) {
|
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
|
||||||
mut compiler => {
|
|
||||||
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
|
|
||||||
compiler.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ 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, RunCompiler};
|
||||||
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) {
|
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
|
||||||
mut compiler => {
|
|
||||||
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
|
|
||||||
compiler.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue