@@ -81,7 +81,6 @@ pub struct Queries<'comp> {
81
81
prepare_outputs : Query < OutputFilenames > ,
82
82
global_ctxt : Query < BoxedGlobalCtxt > ,
83
83
ongoing_codegen : Query < Box < dyn Any > > ,
84
- link : Query < ( ) > ,
85
84
}
86
85
87
86
impl < ' comp > Queries < ' comp > {
@@ -98,7 +97,6 @@ impl<'comp> Queries<'comp> {
98
97
prepare_outputs : Default :: default ( ) ,
99
98
global_ctxt : Default :: default ( ) ,
100
99
ongoing_codegen : Default :: default ( ) ,
101
- link : Default :: default ( ) ,
102
100
}
103
101
}
104
102
@@ -278,35 +276,54 @@ impl<'comp> Queries<'comp> {
278
276
} )
279
277
}
280
278
281
- pub fn link ( & self ) -> Result < & Query < ( ) > > {
282
- self . link . compute ( || {
283
- let sess = self . session ( ) ;
279
+ pub fn linker ( self ) -> Result < Linker > {
280
+ let dep_graph = self . dep_graph ( ) ?;
281
+ let prepare_outputs = self . prepare_outputs ( ) ?;
282
+ let ongoing_codegen = self . ongoing_codegen ( ) ?;
284
283
285
- let ongoing_codegen = self . ongoing_codegen ( ) ?. take ( ) ;
284
+ let sess = self . session ( ) . clone ( ) ;
285
+ let codegen_backend = self . codegen_backend ( ) . clone ( ) ;
286
286
287
- self . codegen_backend ( ) . join_codegen_and_link (
288
- ongoing_codegen,
289
- sess,
290
- & * self . dep_graph ( ) ?. peek ( ) ,
291
- & * self . prepare_outputs ( ) ?. peek ( ) ,
292
- ) . map_err ( |_| ErrorReported ) ?;
293
-
294
- Ok ( ( ) )
287
+ Ok ( Linker {
288
+ sess,
289
+ dep_graph : dep_graph. take ( ) ,
290
+ prepare_outputs : prepare_outputs. take ( ) ,
291
+ ongoing_codegen : ongoing_codegen. take ( ) ,
292
+ codegen_backend,
295
293
} )
296
294
}
297
295
}
298
296
297
+ pub struct Linker {
298
+ sess : Lrc < Session > ,
299
+ dep_graph : DepGraph ,
300
+ prepare_outputs : OutputFilenames ,
301
+ ongoing_codegen : Box < dyn Any > ,
302
+ codegen_backend : Lrc < Box < dyn CodegenBackend > > ,
303
+ }
304
+
305
+ impl Linker {
306
+ pub fn link ( self ) -> Result < ( ) > {
307
+ self . codegen_backend . join_codegen_and_link (
308
+ self . ongoing_codegen ,
309
+ & self . sess ,
310
+ & self . dep_graph ,
311
+ & self . prepare_outputs ,
312
+ ) . map_err ( |_| ErrorReported )
313
+ }
314
+ }
315
+
299
316
impl Compiler {
300
317
// This method is different to all the other methods in `Compiler` because
301
318
// it lacks a `Queries` entry. It's also not currently used. It does serve
302
319
// as an example of how `Compiler` can be used, with additional steps added
303
320
// between some passes. And see `rustc_driver::run_compiler` for a more
304
321
// complex example.
305
322
pub fn enter < ' c , F , T > ( & ' c self , f : F ) -> Result < T >
306
- where F : for < ' q > FnOnce ( & ' q Queries < ' c > ) -> Result < T >
323
+ where F : FnOnce ( Queries < ' c > ) -> Result < T >
307
324
{
308
325
let queries = Queries :: new ( & self ) ;
309
- f ( & queries)
326
+ f ( queries)
310
327
}
311
328
312
329
// This method is different to all the other methods in `Compiler` because
@@ -315,13 +332,13 @@ impl Compiler {
315
332
// between some passes. And see `rustc_driver::run_compiler` for a more
316
333
// complex example.
317
334
pub fn compile ( & self ) -> Result < ( ) > {
318
- self . enter ( |queries| {
335
+ let linker = self . enter ( |queries| {
319
336
queries. prepare_outputs ( ) ?;
320
337
321
338
if self . session ( ) . opts . output_types . contains_key ( & OutputType :: DepInfo )
322
339
&& self . session ( ) . opts . output_types . len ( ) == 1
323
340
{
324
- return Ok ( ( ) )
341
+ return Ok ( None )
325
342
}
326
343
327
344
queries. global_ctxt ( ) ?;
@@ -334,7 +351,14 @@ impl Compiler {
334
351
// Drop GlobalCtxt after starting codegen to free memory.
335
352
mem:: drop ( queries. global_ctxt ( ) ?. take ( ) ) ;
336
353
337
- queries. link ( ) . map ( |_| ( ) )
338
- } )
354
+ let linker = queries. linker ( ) ?;
355
+ Ok ( Some ( linker) )
356
+ } ) ?;
357
+
358
+ if let Some ( linker) = linker {
359
+ linker. link ( ) ?
360
+ }
361
+
362
+ Ok ( ( ) )
339
363
}
340
364
}
0 commit comments