@@ -13,6 +13,7 @@ use crate::mir::place::PlaceRef;
1313use  crate :: traits:: * ; 
1414use  crate :: { CachedModuleCodegen ,  CompiledModule ,  CrateInfo ,  MemFlags ,  ModuleCodegen ,  ModuleKind } ; 
1515
16+ use  rustc_ast:: expand:: allocator:: AllocatorKind ; 
1617use  rustc_attr as  attr; 
1718use  rustc_data_structures:: fx:: { FxHashMap ,  FxHashSet } ; 
1819use  rustc_data_structures:: profiling:: { get_resident_set_size,  print_time_passes_entry} ; 
@@ -545,6 +546,23 @@ pub fn collect_debugger_visualizers_transitive(
545546        . collect :: < BTreeSet < _ > > ( ) 
546547} 
547548
549+ /// Decide allocator kind to codegen. If `Some(_)` this will be the same as 
550+ /// `tcx.allocator_kind`, but it may be `None` in more cases (e.g. if using 
551+ /// allocator definitions from a dylib dependency). 
552+ pub  fn  allocator_kind_for_codegen ( tcx :  TyCtxt < ' _ > )  -> Option < AllocatorKind >  { 
553+     // If the crate doesn't have an `allocator_kind` set then there's definitely 
554+     // no shim to generate. Otherwise we also check our dependency graph for all 
555+     // our output crate types. If anything there looks like its a `Dynamic` 
556+     // linkage, then it's already got an allocator shim and we'll be using that 
557+     // one instead. If nothing exists then it's our job to generate the 
558+     // allocator! 
559+     let  any_dynamic_crate = tcx. dependency_formats ( ( ) ) . iter ( ) . any ( |( _,  list) | { 
560+         use  rustc_middle:: middle:: dependency_format:: Linkage ; 
561+         list. iter ( ) . any ( |& linkage| linkage == Linkage :: Dynamic ) 
562+     } ) ; 
563+     if  any_dynamic_crate {  None  }  else  {  tcx. allocator_kind ( ( ) )  } 
564+ } 
565+ 
548566pub  fn  codegen_crate < B :  ExtraBackendMethods > ( 
549567    backend :  B , 
550568    tcx :  TyCtxt < ' _ > , 
@@ -615,20 +633,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
615633    ) ; 
616634
617635    // Codegen an allocator shim, if necessary. 
618-     // 
619-     // If the crate doesn't have an `allocator_kind` set then there's definitely 
620-     // no shim to generate. Otherwise we also check our dependency graph for all 
621-     // our output crate types. If anything there looks like its a `Dynamic` 
622-     // linkage, then it's already got an allocator shim and we'll be using that 
623-     // one instead. If nothing exists then it's our job to generate the 
624-     // allocator! 
625-     let  any_dynamic_crate = tcx. dependency_formats ( ( ) ) . iter ( ) . any ( |( _,  list) | { 
626-         use  rustc_middle:: middle:: dependency_format:: Linkage ; 
627-         list. iter ( ) . any ( |& linkage| linkage == Linkage :: Dynamic ) 
628-     } ) ; 
629-     let  allocator_module = if  any_dynamic_crate { 
630-         None 
631-     }  else  if  let  Some ( kind)  = tcx. allocator_kind ( ( ) )  { 
636+     if  let  Some ( kind)  = allocator_kind_for_codegen ( tcx)  { 
632637        let  llmod_id =
633638            cgu_name_builder. build_cgu_name ( LOCAL_CRATE ,  & [ "crate" ] ,  Some ( "allocator" ) ) . to_string ( ) ; 
634639        let  module_llvm = tcx. sess . time ( "write_allocator_module" ,  || { 
@@ -642,13 +647,10 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
642647            ) 
643648        } ) ; 
644649
645-         Some ( ModuleCodegen  {  name :  llmod_id,  module_llvm,  kind :  ModuleKind :: Allocator  } ) 
646-     }  else  { 
647-         None 
648-     } ; 
649- 
650-     if  let  Some ( allocator_module)  = allocator_module { 
651-         ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx,  allocator_module) ; 
650+         ongoing_codegen. submit_pre_codegened_module_to_llvm ( 
651+             tcx, 
652+             ModuleCodegen  {  name :  llmod_id,  module_llvm,  kind :  ModuleKind :: Allocator  } , 
653+         ) ; 
652654    } 
653655
654656    // For better throughput during parallel processing by LLVM, we used to sort 
0 commit comments