@@ -109,8 +109,8 @@ use rustc_middle::bug;
109
109
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
110
110
use rustc_middle:: middle:: exported_symbols:: { SymbolExportInfo , SymbolExportLevel } ;
111
111
use rustc_middle:: mir:: mono:: {
112
- CodegenUnit , CodegenUnitNameBuilder , InstantiationMode , Linkage , MonoItem , MonoItemData ,
113
- Visibility ,
112
+ CodegenUnit , CodegenUnitNameBuilder , InstantiationMode , Linkage , LinkageInfo , MonoItem ,
113
+ MonoItemData , Visibility ,
114
114
} ;
115
115
use rustc_middle:: ty:: print:: { characteristic_def_id_of_type, with_no_trimmed_paths} ;
116
116
use rustc_middle:: ty:: visit:: TypeVisitableExt ;
@@ -244,7 +244,7 @@ where
244
244
let cgu = codegen_units. entry ( cgu_name) . or_insert_with ( || CodegenUnit :: new ( cgu_name) ) ;
245
245
246
246
let mut can_be_internalized = true ;
247
- let ( linkage , visibility) = mono_item_linkage_and_visibility (
247
+ let ( linkage_info , visibility) = mono_item_linkage_info_and_visibility (
248
248
cx. tcx ,
249
249
& mono_item,
250
250
& mut can_be_internalized,
@@ -255,8 +255,10 @@ where
255
255
}
256
256
let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
257
257
258
- cgu. items_mut ( )
259
- . insert ( mono_item, MonoItemData { inlined : false , linkage, visibility, size_estimate } ) ;
258
+ cgu. items_mut ( ) . insert (
259
+ mono_item,
260
+ MonoItemData { inlined : false , linkage_info, visibility, size_estimate } ,
261
+ ) ;
260
262
261
263
// Get all inlined items that are reachable from `mono_item` without
262
264
// going via another root item. This includes drop-glue, functions from
@@ -272,7 +274,7 @@ where
272
274
// This is a CGU-private copy.
273
275
cgu. items_mut ( ) . entry ( inlined_item) . or_insert_with ( || MonoItemData {
274
276
inlined : true ,
275
- linkage : Linkage :: Internal ,
277
+ linkage_info : LinkageInfo :: ImplicitInternal ,
276
278
visibility : Visibility :: Default ,
277
279
size_estimate : inlined_item. size_estimate ( cx. tcx ) ,
278
280
} ) ;
@@ -585,7 +587,8 @@ fn internalize_symbols<'tcx>(
585
587
586
588
// If we got here, we did not find any uses from other CGUs, so
587
589
// it's fine to make this monomorphization internal.
588
- data. linkage = Linkage :: Internal ;
590
+ debug_assert_eq ! ( data. linkage_info, LinkageInfo :: ImplicitExternal ) ;
591
+ data. linkage_info = LinkageInfo :: ImplicitInternal ;
589
592
data. visibility = Visibility :: Default ;
590
593
}
591
594
}
@@ -603,7 +606,7 @@ fn mark_code_coverage_dead_code_cgu<'tcx>(codegen_units: &mut [CodegenUnit<'tcx>
603
606
// function symbols to be included via `-u` or `/include` linker args.
604
607
let dead_code_cgu = codegen_units
605
608
. iter_mut ( )
606
- . filter ( |cgu| cgu. items ( ) . iter ( ) . any ( |( _, data) | data. linkage == Linkage :: External ) )
609
+ . filter ( |cgu| cgu. items ( ) . iter ( ) . any ( |( _, data) | data. linkage_info . is_external ( ) ) )
607
610
. min_by_key ( |cgu| cgu. size_estimate ( ) ) ;
608
611
609
612
// If there are no CGUs that have externally linked items, then we just
@@ -731,17 +734,18 @@ fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
731
734
name_builder. build_cgu_name ( LOCAL_CRATE , & [ "fallback" ] , Some ( "cgu" ) )
732
735
}
733
736
734
- fn mono_item_linkage_and_visibility < ' tcx > (
737
+ fn mono_item_linkage_info_and_visibility < ' tcx > (
735
738
tcx : TyCtxt < ' tcx > ,
736
739
mono_item : & MonoItem < ' tcx > ,
737
740
can_be_internalized : & mut bool ,
738
741
export_generics : bool ,
739
- ) -> ( Linkage , Visibility ) {
742
+ ) -> ( LinkageInfo , Visibility ) {
740
743
if let Some ( explicit_linkage) = mono_item. explicit_linkage ( tcx) {
741
- return ( explicit_linkage, Visibility :: Default ) ;
744
+ ( LinkageInfo :: Explicit ( explicit_linkage) , Visibility :: Default )
745
+ } else {
746
+ let vis = mono_item_visibility ( tcx, mono_item, can_be_internalized, export_generics) ;
747
+ ( LinkageInfo :: ImplicitExternal , vis)
742
748
}
743
- let vis = mono_item_visibility ( tcx, mono_item, can_be_internalized, export_generics) ;
744
- ( Linkage :: External , vis)
745
749
}
746
750
747
751
type CguNameCache = UnordMap < ( DefId , bool ) , Symbol > ;
@@ -1012,15 +1016,15 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
1012
1016
writeln ! ( s, " - items: {num_items}, mean size: {mean_size:.1}, sizes: {sizes}" , ) ;
1013
1017
1014
1018
for ( item, data) in cgu. items_in_deterministic_order ( tcx) {
1015
- let linkage = data. linkage ;
1019
+ let linkage_info = data. linkage_info ;
1016
1020
let symbol_name = item. symbol_name ( tcx) . name ;
1017
1021
let symbol_hash_start = symbol_name. rfind ( 'h' ) ;
1018
1022
let symbol_hash = symbol_hash_start. map_or ( "<no hash>" , |i| & symbol_name[ i..] ) ;
1019
1023
let kind = if !data. inlined { "root" } else { "inlined" } ;
1020
1024
let size = data. size_estimate ;
1021
1025
let _ = with_no_trimmed_paths ! ( writeln!(
1022
1026
s,
1023
- " - {item} [{linkage :?}] [{symbol_hash}] ({kind}, size: {size})"
1027
+ " - {item} [{linkage_info :?}] [{symbol_hash}] ({kind}, size: {size})"
1024
1028
) ) ;
1025
1029
}
1026
1030
@@ -1173,7 +1177,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
1173
1177
1174
1178
for cgu in codegen_units {
1175
1179
for ( & mono_item, & data) in cgu. items ( ) {
1176
- item_to_cgus. entry ( mono_item) . or_default ( ) . push ( ( cgu. name ( ) , data. linkage ) ) ;
1180
+ item_to_cgus. entry ( mono_item) . or_default ( ) . push ( ( cgu. name ( ) , data. linkage_info ) ) ;
1177
1181
}
1178
1182
}
1179
1183
@@ -1186,11 +1190,11 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
1186
1190
let cgus = item_to_cgus. get_mut ( i) . unwrap_or ( & mut empty) ;
1187
1191
cgus. sort_by_key ( |( name, _) | * name) ;
1188
1192
cgus. dedup ( ) ;
1189
- for & ( ref cgu_name, linkage ) in cgus. iter ( ) {
1193
+ for & ( ref cgu_name, linkage_info ) in cgus. iter ( ) {
1190
1194
output. push ( ' ' ) ;
1191
1195
output. push_str ( cgu_name. as_str ( ) ) ;
1192
1196
1193
- let linkage_abbrev = match linkage {
1197
+ let linkage_abbrev = match linkage_info . into_linkage ( ) {
1194
1198
Linkage :: External => "External" ,
1195
1199
Linkage :: AvailableExternally => "Available" ,
1196
1200
Linkage :: LinkOnceAny => "OnceAny" ,
0 commit comments