Skip to content

Commit 11475b5

Browse files
committed
Remove set_make_codegen_backend and set_file_loader
They can both be set inside the config callback too.
1 parent 40e9122 commit 11475b5

File tree

4 files changed

+27
-59
lines changed

4 files changed

+27
-59
lines changed

compiler/rustc_driver_impl/src/lib.rs

+5-45
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use rustc_session::lint::{Lint, LintId};
6060
use rustc_session::output::collect_crate_types;
6161
use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
6262
use rustc_span::FileName;
63-
use rustc_span::source_map::FileLoader;
6463
use rustc_target::json::ToJson;
6564
use rustc_target::spec::{Target, TargetTuple};
6665
use time::OffsetDateTime;
@@ -211,59 +210,20 @@ pub fn diagnostics_registry() -> Registry {
211210
pub struct RunCompiler<'a> {
212211
at_args: &'a [String],
213212
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>>,
217213
}
218214

219215
impl<'a> RunCompiler<'a> {
220216
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
221-
Self { at_args, callbacks, file_loader: None, make_codegen_backend: None }
222-
}
223-
224-
/// Set a custom codegen backend.
225-
///
226-
/// Has no uses within this repository, but is used by bjorn3 for "the
227-
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
228-
/// custom driver where the custom codegen backend has arbitrary data."
229-
/// (See #102759.)
230-
pub fn set_make_codegen_backend(
231-
&mut self,
232-
make_codegen_backend: Option<
233-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
234-
>,
235-
) -> &mut Self {
236-
self.make_codegen_backend = make_codegen_backend;
237-
self
238-
}
239-
240-
/// Load files from sources other than the file system.
241-
///
242-
/// Has no uses within this repository, but may be used in the future by
243-
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
244-
/// running rustc without having to save". (See #102759.)
245-
pub fn set_file_loader(
246-
&mut self,
247-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
248-
) -> &mut Self {
249-
self.file_loader = file_loader;
250-
self
217+
Self { at_args, callbacks }
251218
}
252219

253220
/// Parse args and run the compiler.
254221
pub fn run(self) {
255-
run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend);
222+
run_compiler(self.at_args, self.callbacks);
256223
}
257224
}
258225

259-
fn run_compiler(
260-
at_args: &[String],
261-
callbacks: &mut (dyn Callbacks + Send),
262-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
263-
make_codegen_backend: Option<
264-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
265-
>,
266-
) {
226+
fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
267227
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
268228

269229
// Throw away the first argument, the name of the binary.
@@ -300,14 +260,14 @@ fn run_compiler(
300260
output_file: ofile,
301261
output_dir: odir,
302262
ice_file,
303-
file_loader,
263+
file_loader: None,
304264
locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(),
305265
lint_caps: Default::default(),
306266
psess_created: None,
307267
hash_untracked_state: None,
308268
register_lints: None,
309269
override_queries: None,
310-
make_codegen_backend,
270+
make_codegen_backend: None,
311271
registry: diagnostics_registry(),
312272
using_internal_features: &USING_INTERNAL_FEATURES,
313273
expanded_args: args,

compiler/rustc_interface/src/interface.rs

+10
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ pub struct Config {
308308
pub output_dir: Option<PathBuf>,
309309
pub output_file: Option<OutFileName>,
310310
pub ice_file: Option<PathBuf>,
311+
/// Load files from sources other than the file system.
312+
///
313+
/// Has no uses within this repository, but may be used in the future by
314+
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
315+
/// running rustc without having to save". (See #102759.)
311316
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
312317
/// The list of fluent resources, used for lints declared with
313318
/// [`Diagnostic`](rustc_errors::Diagnostic) and [`LintDiagnostic`](rustc_errors::LintDiagnostic).
@@ -336,6 +341,11 @@ pub struct Config {
336341
pub override_queries: Option<fn(&Session, &mut Providers)>,
337342

338343
/// This is a callback from the driver that is called to create a codegen backend.
344+
///
345+
/// Has no uses within this repository, but is used by bjorn3 for "the
346+
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
347+
/// custom driver where the custom codegen backend has arbitrary data."
348+
/// (See #102759.)
339349
pub make_codegen_backend:
340350
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
341351

src/doc/rustc-dev-guide/examples/rustc-driver-example.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::Path;
1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
2121
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
8387
}
8488

8589
fn main() {
86-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
87-
mut compiler => {
88-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
89-
compiler.run();
90-
}
91-
}
90+
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
9291
}

src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::Path;
1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
2121
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
9094
}
9195

9296
fn main() {
93-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
94-
mut compiler => {
95-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
96-
compiler.run();
97-
}
98-
}
97+
RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks).run();
9998
}

0 commit comments

Comments
 (0)