Skip to content

Commit 4fefe40

Browse files
committed
Remove RunCompiler and related things.
I tried removing two methods in `RunCompiler` that were marked as being used by RLS. Tugging on this loose thread led to lots of code removal, including: - `RunCompiler` - `DiagnosticOutput` - `FileLoader` and `RealFileLoader` - Three fields in `Config` Note also that the "Ideally, ..." comment in `SourceMap::load_binary_file` is removed because it's no longer relevant.
1 parent 0922559 commit 4fefe40

File tree

16 files changed

+58
-262
lines changed

16 files changed

+58
-262
lines changed

compiler/rustc_driver/src/lib.rs

+5-71
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr
3535
use rustc_session::cstore::MetadataLoader;
3636
use rustc_session::getopts;
3737
use rustc_session::lint::{Lint, LintId};
38-
use rustc_session::{config, DiagnosticOutput, Session};
38+
use rustc_session::{config, Session};
3939
use rustc_session::{early_error, early_error_no_abort, early_warn};
40-
use rustc_span::source_map::{FileLoader, FileName};
40+
use rustc_span::source_map::FileName;
4141
use rustc_span::symbol::sym;
4242
use rustc_target::json::ToJson;
4343

@@ -139,76 +139,13 @@ pub fn diagnostics_registry() -> Registry {
139139
Registry::new(rustc_error_codes::DIAGNOSTICS)
140140
}
141141

142-
/// This is the primary entry point for rustc.
143-
pub struct RunCompiler<'a, 'b> {
144-
at_args: &'a [String],
145-
callbacks: &'b mut (dyn Callbacks + Send),
146-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
147-
emitter: Option<Box<dyn Write + Send>>,
148-
make_codegen_backend:
149-
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
150-
}
151-
152-
impl<'a, 'b> RunCompiler<'a, 'b> {
153-
pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self {
154-
Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None }
155-
}
156-
157-
/// Set a custom codegen backend.
158-
///
159-
/// Used by cg_clif.
160-
pub fn set_make_codegen_backend(
161-
&mut self,
162-
make_codegen_backend: Option<
163-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
164-
>,
165-
) -> &mut Self {
166-
self.make_codegen_backend = make_codegen_backend;
167-
self
168-
}
169-
170-
/// Emit diagnostics to the specified location.
171-
///
172-
/// Used by RLS.
173-
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self {
174-
self.emitter = emitter;
175-
self
176-
}
177-
178-
/// Load files from sources other than the file system.
179-
///
180-
/// Used by RLS.
181-
pub fn set_file_loader(
182-
&mut self,
183-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
184-
) -> &mut Self {
185-
self.file_loader = file_loader;
186-
self
187-
}
188-
189-
/// Parse args and run the compiler.
190-
pub fn run(self) -> interface::Result<()> {
191-
run_compiler(
192-
self.at_args,
193-
self.callbacks,
194-
self.file_loader,
195-
self.emitter,
196-
self.make_codegen_backend,
197-
)
198-
}
199-
}
200-
fn run_compiler(
142+
// Primary entry point used by rustc, clippy, and miri.
143+
pub fn run_compiler(
201144
at_args: &[String],
202145
callbacks: &mut (dyn Callbacks + Send),
203-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
204-
emitter: Option<Box<dyn Write + Send>>,
205-
make_codegen_backend: Option<
206-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
207-
>,
208146
) -> interface::Result<()> {
209147
let args = args::arg_expand_all(at_args);
210148

211-
let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw);
212149
let Some(matches) = handle_options(&args) else { return Ok(()) };
213150

214151
let sopts = config::build_session_options(&matches);
@@ -229,13 +166,10 @@ fn run_compiler(
229166
input_path: None,
230167
output_file: ofile,
231168
output_dir: odir,
232-
file_loader,
233-
diagnostic_output,
234169
lint_caps: Default::default(),
235170
parse_sess_created: None,
236171
register_lints: None,
237172
override_queries: None,
238-
make_codegen_backend,
239173
registry: diagnostics_registry(),
240174
};
241175

@@ -1371,7 +1305,7 @@ pub fn main() -> ! {
13711305
})
13721306
})
13731307
.collect::<Vec<_>>();
1374-
RunCompiler::new(&args, &mut callbacks).run()
1308+
run_compiler(&args, &mut callbacks)
13751309
});
13761310

13771311
if callbacks.time_passes {

compiler/rustc_expand/src/module.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans};
44
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed};
55
use rustc_parse::new_parser_from_file;
66
use rustc_parse::validate_attr;
7-
use rustc_session::parse::ParseSess;
87
use rustc_session::Session;
98
use rustc_span::symbol::{sym, Ident};
109
use rustc_span::Span;
@@ -151,7 +150,7 @@ fn mod_file_path<'a>(
151150
DirOwnership::Owned { relative } => relative,
152151
DirOwnership::UnownedViaBlock => None,
153152
};
154-
let result = default_submod_path(&sess.parse_sess, ident, relative, dir_path);
153+
let result = default_submod_path(ident, relative, dir_path);
155154
match dir_ownership {
156155
DirOwnership::Owned { .. } => result,
157156
DirOwnership::UnownedViaBlock => Err(ModError::ModInBlock(match result {
@@ -201,7 +200,6 @@ fn mod_file_path_from_attr(
201200
/// Returns a path to a module.
202201
// Public for rustfmt usage.
203202
pub fn default_submod_path<'a>(
204-
sess: &'a ParseSess,
205203
ident: Ident,
206204
relative: Option<Ident>,
207205
dir_path: &Path,
@@ -223,8 +221,8 @@ pub fn default_submod_path<'a>(
223221
format!("{}{}{}mod.rs", relative_prefix, ident.name, path::MAIN_SEPARATOR);
224222
let default_path = dir_path.join(&default_path_str);
225223
let secondary_path = dir_path.join(&secondary_path_str);
226-
let default_exists = sess.source_map().file_exists(&default_path);
227-
let secondary_exists = sess.source_map().file_exists(&secondary_path);
224+
let default_exists = default_path.exists();
225+
let secondary_exists = secondary_path.exists();
228226

229227
match (default_exists, secondary_exists) {
230228
(true, false) => Ok(ModulePathSuccess {

compiler/rustc_interface/src/interface.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilena
1717
use rustc_session::early_error;
1818
use rustc_session::lint;
1919
use rustc_session::parse::{CrateConfig, ParseSess};
20-
use rustc_session::{DiagnosticOutput, Session};
21-
use rustc_span::source_map::{FileLoader, FileName};
20+
use rustc_session::Session;
21+
use rustc_span::source_map::FileName;
2222
use rustc_span::symbol::sym;
2323
use std::path::PathBuf;
2424
use std::result;
@@ -246,8 +246,6 @@ pub struct Config {
246246
pub input_path: Option<PathBuf>,
247247
pub output_dir: Option<PathBuf>,
248248
pub output_file: Option<PathBuf>,
249-
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
250-
pub diagnostic_output: DiagnosticOutput,
251249

252250
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
253251

@@ -268,10 +266,6 @@ pub struct Config {
268266
pub override_queries:
269267
Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::ExternProviders)>,
270268

271-
/// This is a callback from the driver that is called to create a codegen backend.
272-
pub make_codegen_backend:
273-
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
274-
275269
/// Registry of diagnostics codes.
276270
pub registry: Registry,
277271
}
@@ -284,11 +278,8 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
284278
config.opts,
285279
config.crate_cfg,
286280
config.crate_check_cfg,
287-
config.diagnostic_output,
288-
config.file_loader,
289281
config.input_path.clone(),
290282
config.lint_caps,
291-
config.make_codegen_backend,
292283
registry.clone(),
293284
);
294285

compiler/rustc_interface/src/tests.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, Switc
1717
use rustc_session::lint::Level;
1818
use rustc_session::search_paths::SearchPath;
1919
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
20-
use rustc_session::{build_session, getopts, DiagnosticOutput, Session};
20+
use rustc_session::{build_session, getopts, Session};
2121
use rustc_span::edition::{Edition, DEFAULT_EDITION};
2222
use rustc_span::symbol::sym;
2323
use rustc_span::SourceFileHashAlgorithm;
@@ -40,16 +40,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options
4040
fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
4141
let registry = registry::Registry::new(&[]);
4242
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
43-
let sess = build_session(
44-
sessopts,
45-
None,
46-
None,
47-
registry,
48-
DiagnosticOutput::Default,
49-
Default::default(),
50-
None,
51-
None,
52-
);
43+
let sess = build_session(sessopts, None, None, registry, Default::default(), None);
5344
(sess, cfg)
5445
}
5546

compiler/rustc_interface/src/util.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ use rustc_session::config::{self, CrateType};
1818
use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
1919
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
2020
use rustc_session::parse::CrateConfig;
21-
use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session};
21+
use rustc_session::{early_error, filesearch, output, Session};
2222
use rustc_span::edition::Edition;
2323
use rustc_span::lev_distance::find_best_match_for_name;
24-
use rustc_span::source_map::FileLoader;
2524
use rustc_span::symbol::{sym, Symbol};
2625
use std::env;
2726
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
@@ -65,23 +64,14 @@ pub fn create_session(
6564
sopts: config::Options,
6665
cfg: FxHashSet<(String, Option<String>)>,
6766
check_cfg: CheckCfg,
68-
diagnostic_output: DiagnosticOutput,
69-
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
7067
input_path: Option<PathBuf>,
7168
lint_caps: FxHashMap<lint::LintId, lint::Level>,
72-
make_codegen_backend: Option<
73-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
74-
>,
7569
descriptions: Registry,
7670
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
77-
let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
78-
make_codegen_backend(&sopts)
79-
} else {
80-
get_codegen_backend(
81-
&sopts.maybe_sysroot,
82-
sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]),
83-
)
84-
};
71+
let codegen_backend = get_codegen_backend(
72+
&sopts.maybe_sysroot,
73+
sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]),
74+
);
8575

8676
// target_override is documented to be called before init(), so this is okay
8777
let target_override = codegen_backend.target_override(&sopts);
@@ -99,16 +89,8 @@ pub fn create_session(
9989
}
10090
};
10191

102-
let mut sess = session::build_session(
103-
sopts,
104-
input_path,
105-
bundle,
106-
descriptions,
107-
diagnostic_output,
108-
lint_caps,
109-
file_loader,
110-
target_override,
111-
);
92+
let mut sess =
93+
session::build_session(sopts, input_path, bundle, descriptions, lint_caps, target_override);
11294

11395
codegen_backend.init(&sess);
11496

0 commit comments

Comments
 (0)