@@ -196,6 +196,10 @@ impl CStore {
196
196
CrateMetadataRef { cdata, cstore : self }
197
197
}
198
198
199
+ pub ( crate ) fn get_crate_data_mut ( & mut self , cnum : CrateNum ) -> & mut CrateMetadata {
200
+ self . metas [ cnum] . as_mut ( ) . unwrap_or_else ( || panic ! ( "Failed to get crate data for {cnum:?}" ) )
201
+ }
202
+
199
203
fn set_crate_data ( & mut self , cnum : CrateNum , data : CrateMetadata ) {
200
204
assert ! ( self . metas[ cnum] . is_none( ) , "Overwriting crate metadata entry" ) ;
201
205
self . metas [ cnum] = Some ( Box :: new ( data) ) ;
@@ -207,6 +211,12 @@ impl CStore {
207
211
. filter_map ( |( cnum, data) | data. as_deref ( ) . map ( |data| ( cnum, data) ) )
208
212
}
209
213
214
+ fn iter_crate_data_mut ( & mut self ) -> impl Iterator < Item = ( CrateNum , & mut CrateMetadata ) > {
215
+ self . metas
216
+ . iter_enumerated_mut ( )
217
+ . filter_map ( |( cnum, data) | data. as_deref_mut ( ) . map ( |data| ( cnum, data) ) )
218
+ }
219
+
210
220
fn push_dependencies_in_postorder ( & self , deps : & mut Vec < CrateNum > , cnum : CrateNum ) {
211
221
if !deps. contains ( & cnum) {
212
222
let data = self . get_crate_data ( cnum) ;
@@ -586,11 +596,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
586
596
587
597
match result {
588
598
( LoadResult :: Previous ( cnum) , None ) => {
589
- let data = self . cstore . get_crate_data ( cnum) ;
599
+ let data = self . cstore . get_crate_data_mut ( cnum) ;
590
600
if data. is_proc_macro_crate ( ) {
591
601
dep_kind = CrateDepKind :: MacrosOnly ;
592
602
}
593
- data. update_dep_kind ( |data_dep_kind| cmp:: max ( data_dep_kind , dep_kind) ) ;
603
+ data. set_dep_kind ( cmp:: max ( data . dep_kind ( ) , dep_kind) ) ;
594
604
if let Some ( private_dep) = private_dep {
595
605
data. update_and_private_dep ( private_dep) ;
596
606
}
@@ -637,17 +647,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
637
647
} ) )
638
648
}
639
649
640
- fn update_extern_crate ( & self , cnum : CrateNum , extern_crate : ExternCrate ) {
641
- let cmeta = self . cstore . get_crate_data ( cnum) ;
642
- if cmeta. update_extern_crate ( extern_crate) {
643
- // Propagate the extern crate info to dependencies if it was updated.
644
- let extern_crate = ExternCrate { dependency_of : cnum, ..extern_crate } ;
645
- for dep_cnum in cmeta. dependencies ( ) {
646
- self . update_extern_crate ( dep_cnum, extern_crate) ;
647
- }
648
- }
649
- }
650
-
651
650
// Go through the crate metadata and load any crates that it references
652
651
fn resolve_crate_deps (
653
652
& mut self ,
@@ -726,17 +725,19 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
726
725
let mut runtime_found = false ;
727
726
let mut needs_panic_runtime = attr:: contains_name ( & krate. attrs , sym:: needs_panic_runtime) ;
728
727
728
+ let mut panic_runtimes = Vec :: new ( ) ;
729
729
for ( cnum, data) in self . cstore . iter_crate_data ( ) {
730
730
needs_panic_runtime = needs_panic_runtime || data. needs_panic_runtime ( ) ;
731
731
if data. is_panic_runtime ( ) {
732
732
// Inject a dependency from all #![needs_panic_runtime] to this
733
733
// #![panic_runtime] crate.
734
- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| {
735
- data. needs_panic_runtime ( )
736
- } ) ;
734
+ panic_runtimes. push ( cnum) ;
737
735
runtime_found = runtime_found || data. dep_kind ( ) == CrateDepKind :: Explicit ;
738
736
}
739
737
}
738
+ for cnum in panic_runtimes {
739
+ self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
740
+ }
740
741
741
742
// If an explicitly linked and matching panic runtime was found, or if
742
743
// we just don't need one at all, then we're done here and there's
@@ -917,7 +918,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
917
918
}
918
919
919
920
fn inject_dependency_if (
920
- & self ,
921
+ & mut self ,
921
922
krate : CrateNum ,
922
923
what : & str ,
923
924
needs_dep : & dyn Fn ( & CrateMetadata ) -> bool ,
@@ -947,7 +948,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
947
948
// crate provided for this compile, but in order for this compilation to
948
949
// be successfully linked we need to inject a dependency (to order the
949
950
// crates on the command line correctly).
950
- for ( cnum, data) in self . cstore . iter_crate_data ( ) {
951
+ for ( cnum, data) in self . cstore . iter_crate_data_mut ( ) {
951
952
if needs_dep ( data) {
952
953
info ! ( "injecting a dep from {} to {}" , cnum, krate) ;
953
954
data. add_dependency ( krate) ;
@@ -1031,7 +1032,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1031
1032
let cnum = self . resolve_crate ( name, item. span , dep_kind) ?;
1032
1033
1033
1034
let path_len = definitions. def_path ( def_id) . data . len ( ) ;
1034
- self . update_extern_crate (
1035
+ self . cstore . update_extern_crate (
1035
1036
cnum,
1036
1037
ExternCrate {
1037
1038
src : ExternCrateSource :: Extern ( def_id. to_def_id ( ) ) ,
@@ -1049,7 +1050,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1049
1050
pub fn process_path_extern ( & mut self , name : Symbol , span : Span ) -> Option < CrateNum > {
1050
1051
let cnum = self . resolve_crate ( name, span, CrateDepKind :: Explicit ) ?;
1051
1052
1052
- self . update_extern_crate (
1053
+ self . cstore . update_extern_crate (
1053
1054
cnum,
1054
1055
ExternCrate {
1055
1056
src : ExternCrateSource :: Path ,
0 commit comments