Skip to content

Commit c6117d9

Browse files
committed
Merge Compiler::{ongoing_codegen,link}.
They each have two call sites, and the sequencing is almost identical in both cases.
1 parent cd0c21b commit c6117d9

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

src/librustc_driver/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,12 @@ pub fn run_compiler(
383383
mem::drop(compiler.expansion()?.take());
384384
}
385385

386-
compiler.ongoing_codegen()?;
387-
388-
// Drop GlobalCtxt after starting codegen to free memory
389-
mem::drop(compiler.global_ctxt()?.take());
386+
compiler.codegen_and_link()?;
390387

391388
if sess.opts.debugging_opts.print_type_sizes {
392389
sess.code_stats.borrow().print_type_sizes();
393390
}
394391

395-
compiler.link()?;
396-
397392
if sess.opts.debugging_opts.perf_stats {
398393
sess.print_perf_stats();
399394
}

src/librustc_interface/queries.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ pub(crate) struct Queries {
8383
codegen_channel: Query<(Steal<mpsc::Sender<Box<dyn Any + Send>>>,
8484
Steal<mpsc::Receiver<Box<dyn Any + Send>>>)>,
8585
global_ctxt: Query<BoxedGlobalCtxt>,
86-
ongoing_codegen: Query<Box<dyn Any>>,
87-
link: Query<()>,
86+
codegen_and_link: Query<()>,
8887
}
8988

9089
impl Compiler {
@@ -230,14 +229,14 @@ impl Compiler {
230229
})
231230
}
232231

233-
pub fn ongoing_codegen(&self) -> Result<&Query<Box<dyn Any>>> {
234-
self.queries.ongoing_codegen.compute(|| {
232+
pub fn codegen_and_link(&self) -> Result<&Query<()>> {
233+
self.queries.codegen_and_link.compute(|| {
235234
let rx = self.codegen_channel()?.peek().1.steal();
236235
let outputs = self.prepare_outputs()?;
237-
self.global_ctxt()?.peek_mut().enter(|tcx| {
236+
let ongoing_codegen = self.global_ctxt()?.peek_mut().enter(|tcx| {
238237
tcx.analysis(LOCAL_CRATE).ok();
239238

240-
// Don't do code generation if there were any errors
239+
// Don't do code generation if there were any errors.
241240
self.session().compile_status()?;
242241

243242
Ok(passes::start_codegen(
@@ -246,21 +245,16 @@ impl Compiler {
246245
rx,
247246
&*outputs.peek()
248247
))
249-
})
250-
})
251-
}
252-
253-
pub fn link(&self) -> Result<&Query<()>> {
254-
self.queries.link.compute(|| {
255-
let sess = self.session();
248+
})?;
256249

257-
let ongoing_codegen = self.ongoing_codegen()?.take();
250+
// Drop GlobalCtxt after starting codegen to free memory.
251+
mem::drop(self.global_ctxt()?.take());
258252

259253
self.codegen_backend().join_codegen_and_link(
260254
ongoing_codegen,
261-
sess,
255+
self.session(),
262256
&*self.dep_graph()?.peek(),
263-
&*self.prepare_outputs()?.peek(),
257+
&*outputs.peek(),
264258
).map_err(|_| ErrorReported)?;
265259

266260
Ok(())
@@ -281,11 +275,6 @@ impl Compiler {
281275
// Drop AST after creating GlobalCtxt to free memory
282276
mem::drop(self.expansion()?.take());
283277

284-
self.ongoing_codegen()?;
285-
286-
// Drop GlobalCtxt after starting codegen to free memory
287-
mem::drop(self.global_ctxt()?.take());
288-
289-
self.link().map(|_| ())
278+
self.codegen_and_link().map(|_| ())
290279
}
291280
}

0 commit comments

Comments
 (0)