@@ -41,7 +41,7 @@ use tracing::debug;
41
41
use super :: link:: { self , ensure_removed} ;
42
42
use super :: lto:: { self , SerializedModule } ;
43
43
use super :: symbol_export:: symbol_name_for_instance_in_crate;
44
- use crate :: errors:: { AutodiffWithoutLto , ErrorCreatingRemarkDir } ;
44
+ use crate :: errors:: { AutodiffLibraryBuild , AutodiffWithoutLto , ErrorCreatingRemarkDir } ;
45
45
use crate :: traits:: * ;
46
46
use crate :: {
47
47
CachedModuleCodegen , CodegenResults , CompiledModule , CrateInfo , ModuleCodegen , ModuleKind ,
@@ -419,7 +419,12 @@ fn generate_lto_work<B: ExtraBackendMethods>(
419
419
} else {
420
420
if !autodiff. is_empty ( ) {
421
421
let dcx = cgcx. create_dcx ( ) ;
422
- dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
422
+ if cgcx. crate_types . contains ( & CrateType :: Rlib ) {
423
+ dcx. handle ( ) . emit_fatal ( AutodiffLibraryBuild { } ) ;
424
+ }
425
+ if cgcx. lto != Lto :: Fat {
426
+ dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
427
+ }
423
428
}
424
429
assert ! ( needs_fat_lto. is_empty( ) ) ;
425
430
let ( lto_modules, copy_jobs) = B :: run_thin_lto ( cgcx, needs_thin_lto, import_only_modules)
@@ -1456,6 +1461,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1456
1461
if needs_fat_lto. is_empty ( )
1457
1462
&& needs_thin_lto. is_empty ( )
1458
1463
&& lto_import_only_modules. is_empty ( )
1464
+ && autodiff_items. is_empty ( )
1459
1465
{
1460
1466
// Nothing more to do!
1461
1467
break ;
@@ -1469,13 +1475,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
1469
1475
assert ! ( !started_lto) ;
1470
1476
started_lto = true ;
1471
1477
1478
+ let autodiff_items = mem:: take ( & mut autodiff_items) ;
1472
1479
let needs_fat_lto = mem:: take ( & mut needs_fat_lto) ;
1473
1480
let needs_thin_lto = mem:: take ( & mut needs_thin_lto) ;
1474
1481
let import_only_modules = mem:: take ( & mut lto_import_only_modules) ;
1475
1482
1476
1483
for ( work, cost) in generate_lto_work (
1477
1484
& cgcx,
1478
- autodiff_items. clone ( ) ,
1485
+ autodiff_items,
1479
1486
needs_fat_lto,
1480
1487
needs_thin_lto,
1481
1488
import_only_modules,
0 commit comments