Inline and remove create_compiler_and_run
.
It has a single call site.
This commit is contained in:
parent
dcc194e4bf
commit
b6ae1453cb
@ -275,58 +275,6 @@ pub struct Config {
|
||||
pub registry: Registry,
|
||||
}
|
||||
|
||||
fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
|
||||
crate::callbacks::setup_callbacks();
|
||||
|
||||
let registry = &config.registry;
|
||||
let (mut sess, codegen_backend) = util::create_session(
|
||||
config.opts,
|
||||
config.crate_cfg,
|
||||
config.crate_check_cfg,
|
||||
config.file_loader,
|
||||
config.input_path.clone(),
|
||||
config.lint_caps,
|
||||
config.make_codegen_backend,
|
||||
registry.clone(),
|
||||
);
|
||||
|
||||
if let Some(parse_sess_created) = config.parse_sess_created {
|
||||
parse_sess_created(
|
||||
&mut Lrc::get_mut(&mut sess)
|
||||
.expect("create_session() should never share the returned session")
|
||||
.parse_sess,
|
||||
);
|
||||
}
|
||||
|
||||
let temps_dir = sess.opts.unstable_opts.temps_dir.as_ref().map(|o| PathBuf::from(&o));
|
||||
|
||||
let compiler = Compiler {
|
||||
sess,
|
||||
codegen_backend,
|
||||
input: config.input,
|
||||
input_path: config.input_path,
|
||||
output_dir: config.output_dir,
|
||||
output_file: config.output_file,
|
||||
temps_dir,
|
||||
register_lints: config.register_lints,
|
||||
override_queries: config.override_queries,
|
||||
};
|
||||
|
||||
rustc_span::with_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
|
||||
let r = {
|
||||
let _sess_abort_error = OnDrop(|| {
|
||||
compiler.sess.finish_diagnostics(registry);
|
||||
});
|
||||
|
||||
f(&compiler)
|
||||
};
|
||||
|
||||
let prof = compiler.sess.prof.clone();
|
||||
prof.generic_activity("drop_compiler").run(move || drop(compiler));
|
||||
r
|
||||
})
|
||||
}
|
||||
|
||||
// JUSTIFICATION: before session exists, only config
|
||||
#[allow(rustc::bad_opt_access)]
|
||||
pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
|
||||
@ -334,7 +282,57 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||
util::run_in_thread_pool_with_globals(
|
||||
config.opts.edition,
|
||||
config.opts.unstable_opts.threads,
|
||||
|| create_compiler_and_run(config, f),
|
||||
|| {
|
||||
crate::callbacks::setup_callbacks();
|
||||
|
||||
let registry = &config.registry;
|
||||
let (mut sess, codegen_backend) = util::create_session(
|
||||
config.opts,
|
||||
config.crate_cfg,
|
||||
config.crate_check_cfg,
|
||||
config.file_loader,
|
||||
config.input_path.clone(),
|
||||
config.lint_caps,
|
||||
config.make_codegen_backend,
|
||||
registry.clone(),
|
||||
);
|
||||
|
||||
if let Some(parse_sess_created) = config.parse_sess_created {
|
||||
parse_sess_created(
|
||||
&mut Lrc::get_mut(&mut sess)
|
||||
.expect("create_session() should never share the returned session")
|
||||
.parse_sess,
|
||||
);
|
||||
}
|
||||
|
||||
let temps_dir = sess.opts.unstable_opts.temps_dir.as_ref().map(|o| PathBuf::from(&o));
|
||||
|
||||
let compiler = Compiler {
|
||||
sess,
|
||||
codegen_backend,
|
||||
input: config.input,
|
||||
input_path: config.input_path,
|
||||
output_dir: config.output_dir,
|
||||
output_file: config.output_file,
|
||||
temps_dir,
|
||||
register_lints: config.register_lints,
|
||||
override_queries: config.override_queries,
|
||||
};
|
||||
|
||||
rustc_span::with_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
|
||||
let r = {
|
||||
let _sess_abort_error = OnDrop(|| {
|
||||
compiler.sess.finish_diagnostics(registry);
|
||||
});
|
||||
|
||||
f(&compiler)
|
||||
};
|
||||
|
||||
let prof = compiler.sess.prof.clone();
|
||||
prof.generic_activity("drop_compiler").run(move || drop(compiler));
|
||||
r
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user