Skip to content

Commit 4180d10

Browse files
committed
Move Session out of Linker.
It can easily be passed in. And that removes the single clone of `Compiler::session`, which means it no longer needs to be `Lrc`.
1 parent 570d74c commit 4180d10

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fn run_compiler(
493493

494494
if let Some(linker) = linker {
495495
let _timer = sess.timer("link");
496-
linker.link()?
496+
linker.link(sess)?
497497
}
498498

499499
if sess.opts.unstable_opts.print_fuel.is_some() {

compiler/rustc_interface/src/interface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ pub type Result<T> = result::Result<T, ErrorGuaranteed>;
3838
/// Can be used to run `rustc_interface` queries.
3939
/// Created by passing [`Config`] to [`run_compiler`].
4040
pub struct Compiler {
41-
pub(crate) sess: Lrc<Session>,
41+
pub(crate) sess: Session,
4242
codegen_backend: Lrc<dyn CodegenBackend>,
4343
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
4444
pub(crate) override_queries: Option<fn(&Session, &mut Providers)>,
4545
}
4646

4747
impl Compiler {
48-
pub fn session(&self) -> &Lrc<Session> {
48+
pub fn session(&self) -> &Session {
4949
&self.sess
5050
}
5151
pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
@@ -474,7 +474,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
474474
}
475475

476476
let compiler = Compiler {
477-
sess: Lrc::new(sess),
477+
sess,
478478
codegen_backend: Lrc::from(codegen_backend),
479479
register_lints: config.register_lints,
480480
override_queries: config.override_queries,

compiler/rustc_interface/src/queries.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ impl<'tcx> Queries<'tcx> {
101101
}
102102
}
103103

104-
fn session(&self) -> &Lrc<Session> {
104+
fn session(&self) -> &Session {
105105
&self.compiler.sess
106106
}
107+
107108
fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
108109
self.compiler.codegen_backend()
109110
}
@@ -241,7 +242,6 @@ impl<'tcx> Queries<'tcx> {
241242
pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> {
242243
self.global_ctxt()?.enter(|tcx| {
243244
Ok(Linker {
244-
sess: self.session().clone(),
245245
codegen_backend: self.codegen_backend().clone(),
246246
dep_graph: tcx.dep_graph.clone(),
247247
prepare_outputs: tcx.output_filenames(()).clone(),
@@ -258,7 +258,6 @@ impl<'tcx> Queries<'tcx> {
258258

259259
pub struct Linker {
260260
// compilation inputs
261-
sess: Lrc<Session>,
262261
codegen_backend: Lrc<dyn CodegenBackend>,
263262

264263
// compilation outputs
@@ -270,30 +269,25 @@ pub struct Linker {
270269
}
271270

272271
impl Linker {
273-
pub fn link(self) -> Result<()> {
274-
let (codegen_results, work_products) = self.codegen_backend.join_codegen(
275-
self.ongoing_codegen,
276-
&self.sess,
277-
&self.prepare_outputs,
278-
)?;
272+
pub fn link(self, sess: &Session) -> Result<()> {
273+
let (codegen_results, work_products) =
274+
self.codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.prepare_outputs)?;
279275

280-
self.sess.compile_status()?;
276+
sess.compile_status()?;
281277

282-
let sess = &self.sess;
283278
let dep_graph = self.dep_graph;
284279
sess.time("serialize_work_products", || {
285280
rustc_incremental::save_work_product_index(sess, &dep_graph, work_products)
286281
});
287282

288-
let prof = self.sess.prof.clone();
283+
let prof = sess.prof.clone();
289284
prof.generic_activity("drop_dep_graph").run(move || drop(dep_graph));
290285

291286
// Now that we won't touch anything in the incremental compilation directory
292287
// any more, we can finalize it (which involves renaming it)
293-
rustc_incremental::finalize_session_directory(&self.sess, self.crate_hash);
288+
rustc_incremental::finalize_session_directory(sess, self.crate_hash);
294289

295-
if !self
296-
.sess
290+
if !sess
297291
.opts
298292
.output_types
299293
.keys()
@@ -310,7 +304,7 @@ impl Linker {
310304
}
311305

312306
let _timer = sess.prof.verbose_generic_activity("link_crate");
313-
self.codegen_backend.link(&self.sess, codegen_results, &self.prepare_outputs)
307+
self.codegen_backend.link(sess, codegen_results, &self.prepare_outputs)
314308
}
315309
}
316310

tests/run-make-fulldeps/issue-19371/foo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
7272
let ongoing_codegen = queries.ongoing_codegen()?;
7373
queries.linker(ongoing_codegen)
7474
});
75-
linker.unwrap().link().unwrap();
75+
linker.unwrap().link(compiler.session()).unwrap();
7676
});
7777
}

0 commit comments

Comments
 (0)