@@ -906,6 +906,7 @@ fn load_query_result_cache<'tcx>(
906
906
}
907
907
908
908
pub fn default_provide ( providers : & mut ty:: query:: Providers < ' _ > ) {
909
+ providers. ongoing_codegen = ongoing_codegen;
909
910
providers. analysis = analysis;
910
911
providers. hir_map = hir_map;
911
912
providers. lower_ast_to_hir = lower_ast_to_hir;
@@ -963,7 +964,6 @@ impl BoxedGlobalCtxt {
963
964
pub fn create_global_ctxt (
964
965
compiler : & Compiler ,
965
966
io : InputsAndOutputs ,
966
- tx : mpsc:: Sender < Box < dyn Any + Send > > ,
967
967
) -> BoxedGlobalCtxt {
968
968
let sess = compiler. session ( ) . clone ( ) ;
969
969
let cstore = compiler. cstore . clone ( ) ;
@@ -985,6 +985,13 @@ pub fn create_global_ctxt(
985
985
default_provide_extern ( & mut extern_providers) ;
986
986
codegen_backend. provide_extern ( & mut extern_providers) ;
987
987
988
+ // Move the dyn Any coercion outside the generator to avoid lifetime issues
989
+ fn codegen_backend_any (
990
+ i : Arc < dyn CodegenBackend + Send + Sync >
991
+ ) -> Box < dyn Any + Send + Sync > {
992
+ Box :: new ( i)
993
+ }
994
+
988
995
let gcx = TyCtxt :: create_global_ctxt (
989
996
sess,
990
997
& * * cstore,
@@ -993,7 +1000,7 @@ pub fn create_global_ctxt(
993
1000
extern_providers,
994
1001
& arenas,
995
1002
crate_name,
996
- tx ,
1003
+ codegen_backend_any ( codegen_backend . clone ( ) ) ,
997
1004
io,
998
1005
) ;
999
1006
@@ -1211,12 +1218,23 @@ fn encode_and_write_metadata(
1211
1218
1212
1219
/// Runs the codegen backend, after which the AST and analysis can
1213
1220
/// be discarded.
1214
- pub fn start_codegen < ' tcx > (
1215
- codegen_backend : & dyn CodegenBackend ,
1221
+ fn ongoing_codegen < ' tcx > (
1216
1222
tcx : TyCtxt < ' tcx > ,
1217
- rx : mpsc:: Receiver < Box < dyn Any + Send > > ,
1218
- outputs : & OutputFilenames ,
1219
- ) -> Box < dyn Any > {
1223
+ cnum : CrateNum ,
1224
+ ) -> Result < Lrc < ty:: OngoingCodegen > > {
1225
+ tcx. analysis ( cnum) ?;
1226
+
1227
+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
1228
+ // Don't do code generation if there were any errors
1229
+ tcx. sess . compile_status ( ) ?;
1230
+
1231
+ let outputs = tcx. prepare_outputs ( ( ) ) ?;
1232
+
1233
+ let rx = OneThread :: into_inner ( tcx. rx_to_llvm_workers . steal ( ) ) ;
1234
+ let codegen_backend: & dyn Any = & * tcx. codegen_backend ;
1235
+ let codegen_backend = codegen_backend. downcast_ref :: < Arc < dyn CodegenBackend + Send + Sync > > ( )
1236
+ . unwrap ( ) ;
1237
+
1220
1238
if log_enabled ! ( :: log:: Level :: Info ) {
1221
1239
println ! ( "Pre-codegen" ) ;
1222
1240
tcx. print_debug_stats ( ) ;
@@ -1227,7 +1245,7 @@ pub fn start_codegen<'tcx>(
1227
1245
} ) ;
1228
1246
1229
1247
let ( metadata, need_metadata_module) = time ( tcx. sess , "metadata encoding and writing" , || {
1230
- encode_and_write_metadata ( tcx, outputs)
1248
+ encode_and_write_metadata ( tcx, & outputs)
1231
1249
} ) ;
1232
1250
1233
1251
tcx. sess . profiler ( |p| p. start_activity ( "codegen crate" ) ) ;
@@ -1242,11 +1260,15 @@ pub fn start_codegen<'tcx>(
1242
1260
}
1243
1261
1244
1262
if tcx. sess . opts . output_types . contains_key ( & OutputType :: Mir ) {
1245
- if let Err ( e) = mir:: transform:: dump_mir:: emit_mir ( tcx, outputs) {
1263
+ if let Err ( e) = mir:: transform:: dump_mir:: emit_mir ( tcx, & outputs) {
1246
1264
tcx. sess . err ( & format ! ( "could not emit MIR: {}" , e) ) ;
1247
1265
tcx. sess . abort_if_errors ( ) ;
1248
1266
}
1249
1267
}
1250
1268
1251
- codegen
1269
+ Ok ( Lrc :: new ( ty:: OngoingCodegen {
1270
+ outputs,
1271
+ dep_graph : tcx. dep_graph ( ) . clone ( ) ,
1272
+ codegen_object : Steal :: new ( OneThread :: new ( codegen) ) ,
1273
+ } ) )
1252
1274
}
0 commit comments