@@ -2,17 +2,16 @@ use std::collections::hash_map::Entry::*;
2
2
3
3
use rustc_ast:: expand:: allocator:: ALLOCATOR_METHODS ;
4
4
use rustc_data_structures:: fx:: FxHashMap ;
5
- use rustc_hir as hir ;
5
+ use rustc_hir:: def :: DefKind ;
6
6
use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LOCAL_CRATE } ;
7
- use rustc_hir:: Node ;
8
7
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
9
8
use rustc_middle:: middle:: exported_symbols:: {
10
9
metadata_symbol_name, ExportedSymbol , SymbolExportInfo , SymbolExportKind , SymbolExportLevel ,
11
10
} ;
12
11
use rustc_middle:: ty:: query:: { ExternProviders , Providers } ;
13
12
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
14
13
use rustc_middle:: ty:: Instance ;
15
- use rustc_middle:: ty:: { self , SymbolName , TyCtxt } ;
14
+ use rustc_middle:: ty:: { self , DefIdTree , SymbolName , TyCtxt } ;
16
15
use rustc_session:: config:: { CrateType , OomStrategy } ;
17
16
use rustc_target:: spec:: SanitizerSet ;
18
17
@@ -74,32 +73,34 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
74
73
//
75
74
// As a result, if this id is an FFI item (foreign item) then we only
76
75
// let it through if it's included statically.
77
- match tcx. hir ( ) . get_by_def_id ( def_id) {
78
- Node :: ForeignItem ( ..) => {
79
- tcx. native_library ( def_id) . map_or ( false , |library| library. kind . is_statically_included ( ) ) . then_some ( def_id)
80
- }
76
+ if let Some ( parent_id) = tcx. opt_local_parent ( def_id)
77
+ && let DefKind :: ForeignMod = tcx. def_kind ( parent_id)
78
+ {
79
+ let library = tcx. native_library ( def_id) ?;
80
+ return library. kind . is_statically_included ( ) . then_some ( def_id) ;
81
+ }
81
82
82
- // Only consider nodes that actually have exported symbols.
83
- Node :: Item ( & hir:: Item {
84
- kind : hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Fn ( ..) ,
85
- ..
86
- } )
87
- | Node :: ImplItem ( & hir:: ImplItem { kind : hir:: ImplItemKind :: Fn ( ..) , .. } ) => {
88
- let generics = tcx. generics_of ( def_id) ;
89
- if !generics. requires_monomorphization ( tcx)
90
- // Functions marked with #[inline] are codegened with "internal"
91
- // linkage and are not exported unless marked with an extern
92
- // indicator
93
- && ( !Instance :: mono ( tcx, def_id. to_def_id ( ) ) . def . generates_cgu_internal_copy ( tcx)
94
- || tcx. codegen_fn_attrs ( def_id. to_def_id ( ) ) . contains_extern_indicator ( ) )
95
- {
96
- Some ( def_id)
97
- } else {
98
- None
99
- }
100
- }
83
+ // Only consider nodes that actually have exported symbols.
84
+ match tcx. def_kind ( def_id) {
85
+ DefKind :: Fn | DefKind :: Static ( _) => { }
86
+ DefKind :: AssocFn if tcx. impl_of_method ( def_id. to_def_id ( ) ) . is_some ( ) => { }
87
+ _ => return None ,
88
+ } ;
101
89
102
- _ => None ,
90
+ let generics = tcx. generics_of ( def_id) ;
91
+ if generics. requires_monomorphization ( tcx) {
92
+ return None ;
93
+ }
94
+
95
+ // Functions marked with #[inline] are codegened with "internal"
96
+ // linkage and are not exported unless marked with an extern
97
+ // indicator
98
+ if !Instance :: mono ( tcx, def_id. to_def_id ( ) ) . def . generates_cgu_internal_copy ( tcx)
99
+ || tcx. codegen_fn_attrs ( def_id. to_def_id ( ) ) . contains_extern_indicator ( )
100
+ {
101
+ Some ( def_id)
102
+ } else {
103
+ None
103
104
}
104
105
} )
105
106
. map ( |def_id| {
@@ -118,7 +119,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
118
119
tcx. symbol_name( Instance :: mono( tcx, def_id. to_def_id( ) ) ) ,
119
120
export_level
120
121
) ;
121
- ( def_id . to_def_id ( ) , SymbolExportInfo {
122
+ let info = SymbolExportInfo {
122
123
level : export_level,
123
124
kind : if tcx. is_static ( def_id. to_def_id ( ) ) {
124
125
if codegen_attrs. flags . contains ( CodegenFnAttrFlags :: THREAD_LOCAL ) {
@@ -130,8 +131,10 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
130
131
SymbolExportKind :: Text
131
132
} ,
132
133
used : codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED )
133
- || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER ) || used,
134
- } )
134
+ || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER )
135
+ || used,
136
+ } ;
137
+ ( def_id. to_def_id ( ) , info)
135
138
} )
136
139
. collect ( ) ;
137
140
@@ -457,9 +460,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
457
460
let target = & tcx. sess . target . llvm_target ;
458
461
// WebAssembly cannot export data symbols, so reduce their export level
459
462
if target. contains ( "emscripten" ) {
460
- if let Some ( Node :: Item ( & hir:: Item { kind : hir:: ItemKind :: Static ( ..) , .. } ) ) =
461
- tcx. hir ( ) . get_if_local ( sym_def_id)
462
- {
463
+ if let DefKind :: Static ( _) = tcx. def_kind ( sym_def_id) {
463
464
return SymbolExportLevel :: Rust ;
464
465
}
465
466
}
0 commit comments