Skip to content

Commit de91b6d

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 3560122 commit de91b6d

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
@@ -482,7 +482,7 @@ fn run_compiler(
482482

483483
if let Some(linker) = linker {
484484
let _timer = sess.timer("link");
485-
linker.link()?
485+
linker.link(sess)?
486486
}
487487

488488
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,13 +38,13 @@ 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) override_queries: Option<fn(&Session, &mut Providers)>,
4444
}
4545

4646
impl Compiler {
47-
pub fn session(&self) -> &Lrc<Session> {
47+
pub fn session(&self) -> &Session {
4848
&self.sess
4949
}
5050
pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
@@ -492,7 +492,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
492492
sess.lint_store = Some(Lrc::new(lint_store));
493493

494494
let compiler = Compiler {
495-
sess: Lrc::new(sess),
495+
sess,
496496
codegen_backend: Lrc::from(codegen_backend),
497497
override_queries: config.override_queries,
498498
};

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
}
@@ -238,7 +239,6 @@ impl<'tcx> Queries<'tcx> {
238239
pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> {
239240
self.global_ctxt()?.enter(|tcx| {
240241
Ok(Linker {
241-
sess: self.session().clone(),
242242
codegen_backend: self.codegen_backend().clone(),
243243
dep_graph: tcx.dep_graph.clone(),
244244
prepare_outputs: tcx.output_filenames(()).clone(),
@@ -255,7 +255,6 @@ impl<'tcx> Queries<'tcx> {
255255

256256
pub struct Linker {
257257
// compilation inputs
258-
sess: Lrc<Session>,
259258
codegen_backend: Lrc<dyn CodegenBackend>,
260259

261260
// compilation outputs
@@ -267,30 +266,25 @@ pub struct Linker {
267266
}
268267

269268
impl Linker {
270-
pub fn link(self) -> Result<()> {
271-
let (codegen_results, work_products) = self.codegen_backend.join_codegen(
272-
self.ongoing_codegen,
273-
&self.sess,
274-
&self.prepare_outputs,
275-
)?;
269+
pub fn link(self, sess: &Session) -> Result<()> {
270+
let (codegen_results, work_products) =
271+
self.codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.prepare_outputs)?;
276272

277-
self.sess.compile_status()?;
273+
sess.compile_status()?;
278274

279-
let sess = &self.sess;
280275
let dep_graph = self.dep_graph;
281276
sess.time("serialize_work_products", || {
282277
rustc_incremental::save_work_product_index(sess, &dep_graph, work_products)
283278
});
284279

285-
let prof = self.sess.prof.clone();
280+
let prof = sess.prof.clone();
286281
prof.generic_activity("drop_dep_graph").run(move || drop(dep_graph));
287282

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

292-
if !self
293-
.sess
287+
if !sess
294288
.opts
295289
.output_types
296290
.keys()
@@ -307,7 +301,7 @@ impl Linker {
307301
}
308302

309303
let _timer = sess.prof.verbose_generic_activity("link_crate");
310-
self.codegen_backend.link(&self.sess, codegen_results, &self.prepare_outputs)
304+
self.codegen_backend.link(sess, codegen_results, &self.prepare_outputs)
311305
}
312306
}
313307

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)