@@ -100,67 +100,45 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
100
100
// has been applied to the definition (wherever that definition may be).
101
101
let is_generic = instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ;
102
102
103
- if is_generic {
104
- // This is a monomorphization. Its expected visibility depends
105
- // on whether we are in share-generics mode.
106
-
107
- if cx. tcx . sess . opts . share_generics ( ) {
108
- // We are in share_generics mode.
109
-
103
+ let is_hidden = if is_generic {
104
+ // This is a monomorphization of a generic function.
105
+ if !( cx. tcx . sess . opts . share_generics ( )
106
+ || tcx. codegen_fn_attrs ( instance_def_id) . inline
107
+ == rustc_attr:: InlineAttr :: Never )
108
+ {
109
+ // When not sharing generics, all instances are in the same
110
+ // crate and have hidden visibility.
111
+ true
112
+ } else {
110
113
if let Some ( instance_def_id) = instance_def_id. as_local ( ) {
111
- // This is a definition from the current crate. If the
112
- // definition is unreachable for downstream crates or
113
- // the current crate does not re-export generics, the
114
- // definition of the instance will have been declared
115
- // as `hidden`.
116
- if cx. tcx . is_unreachable_local_definition ( instance_def_id)
114
+ // This is a monomorphization of a generic function
115
+ // defined in the current crate. It is hidden if:
116
+ // - the definition is unreachable for downstream
117
+ // crates, or
118
+ // - the current crate does not re-export generics
119
+ // (because the crate is a C library or executable)
120
+ cx. tcx . is_unreachable_local_definition ( instance_def_id)
117
121
|| !cx. tcx . local_crate_exports_generics ( )
118
- {
119
- #[ cfg( feature = "master" ) ]
120
- func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
121
- }
122
122
} else {
123
123
// This is a monomorphization of a generic function
124
- // defined in an upstream crate.
125
- if instance. upstream_monomorphization ( tcx) . is_some ( ) {
126
- // This is instantiated in another crate. It cannot
127
- // be `hidden`.
128
- } else {
129
- // This is a local instantiation of an upstream definition.
130
- // If the current crate does not re-export it
131
- // (because it is a C library or an executable), it
132
- // will have been declared `hidden`.
133
- if !cx. tcx . local_crate_exports_generics ( ) {
134
- #[ cfg( feature = "master" ) ]
135
- func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
136
- }
137
- }
124
+ // defined in an upstream crate. It is hidden if:
125
+ // - it is instantiated in this crate, and
126
+ // - the current crate does not re-export generics
127
+ instance. upstream_monomorphization ( tcx) . is_none ( )
128
+ && !cx. tcx . local_crate_exports_generics ( )
138
129
}
139
- } else {
140
- // When not sharing generics, all instances are in the same
141
- // crate and have hidden visibility
142
- #[ cfg( feature = "master" ) ]
143
- func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
144
130
}
145
131
} else {
146
- // This is a non-generic function
147
- if cx. tcx . is_codegened_item ( instance_def_id) {
148
- // This is a function that is instantiated in the local crate
149
-
150
- if instance_def_id. is_local ( ) {
151
- // This is function that is defined in the local crate.
152
- // If it is not reachable, it is hidden.
153
- if !cx. tcx . is_reachable_non_generic ( instance_def_id) {
154
- #[ cfg( feature = "master" ) ]
155
- func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
156
- }
157
- } else {
158
- // This is a function from an upstream crate that has
159
- // been instantiated here. These are always hidden.
160
- #[ cfg( feature = "master" ) ]
161
- func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
162
- }
163
- }
132
+ // This is a non-generic function. It is hidden if:
133
+ // - it is instantiated in the local crate, and
134
+ // - it is defined an upstream crate (non-local), or
135
+ // - it is not reachable
136
+ cx. tcx . is_codegened_item ( instance_def_id)
137
+ && ( !instance_def_id. is_local ( )
138
+ || !cx. tcx . is_reachable_non_generic ( instance_def_id) )
139
+ } ;
140
+ if is_hidden {
141
+ func. add_attribute ( FnAttribute :: Visibility ( Visibility :: Hidden ) ) ;
164
142
}
165
143
166
144
func
0 commit comments