@@ -82,6 +82,11 @@ pub enum InstanceDef<'tcx> {
82
82
/// The `DefId` is the ID of the `call_once` method in `FnOnce`.
83
83
ClosureOnceShim { call_once : DefId , track_caller : bool } ,
84
84
85
+ /// Compiler-generated accessor for thread locals which returns a reference to the thread local
86
+ /// the `DefId` defines. This is used to export thread locals from dylibs on platforms lacking
87
+ /// native support.
88
+ ThreadLocalShim ( DefId ) ,
89
+
85
90
/// `core::ptr::drop_in_place::<T>`.
86
91
///
87
92
/// The `DefId` is for `core::ptr::drop_in_place`.
@@ -156,6 +161,7 @@ impl<'tcx> InstanceDef<'tcx> {
156
161
| InstanceDef :: FnPtrShim ( def_id, _)
157
162
| InstanceDef :: Virtual ( def_id, _)
158
163
| InstanceDef :: Intrinsic ( def_id)
164
+ | InstanceDef :: ThreadLocalShim ( def_id)
159
165
| InstanceDef :: ClosureOnceShim { call_once : def_id, track_caller : _ }
160
166
| InstanceDef :: DropGlue ( def_id, _)
161
167
| InstanceDef :: CloneShim ( def_id, _)
@@ -167,7 +173,9 @@ impl<'tcx> InstanceDef<'tcx> {
167
173
pub fn def_id_if_not_guaranteed_local_codegen ( self ) -> Option < DefId > {
168
174
match self {
169
175
ty:: InstanceDef :: Item ( def) => Some ( def. did ) ,
170
- ty:: InstanceDef :: DropGlue ( def_id, Some ( _) ) => Some ( def_id) ,
176
+ ty:: InstanceDef :: DropGlue ( def_id, Some ( _) ) | InstanceDef :: ThreadLocalShim ( def_id) => {
177
+ Some ( def_id)
178
+ }
171
179
InstanceDef :: VTableShim ( ..)
172
180
| InstanceDef :: ReifyShim ( ..)
173
181
| InstanceDef :: FnPtrShim ( ..)
@@ -192,6 +200,7 @@ impl<'tcx> InstanceDef<'tcx> {
192
200
| InstanceDef :: ClosureOnceShim { call_once : def_id, track_caller : _ }
193
201
| InstanceDef :: DropGlue ( def_id, _)
194
202
| InstanceDef :: CloneShim ( def_id, _)
203
+ | InstanceDef :: ThreadLocalShim ( def_id)
195
204
| InstanceDef :: FnPtrAddrShim ( def_id, _) => ty:: WithOptConstParam :: unknown ( def_id) ,
196
205
}
197
206
}
@@ -215,6 +224,7 @@ impl<'tcx> InstanceDef<'tcx> {
215
224
let def_id = match * self {
216
225
ty:: InstanceDef :: Item ( def) => def. did ,
217
226
ty:: InstanceDef :: DropGlue ( _, Some ( _) ) => return false ,
227
+ ty:: InstanceDef :: ThreadLocalShim ( _) => return false ,
218
228
_ => return true ,
219
229
} ;
220
230
matches ! (
@@ -255,6 +265,9 @@ impl<'tcx> InstanceDef<'tcx> {
255
265
)
256
266
} ) ;
257
267
}
268
+ if let ty:: InstanceDef :: ThreadLocalShim ( ..) = * self {
269
+ return false ;
270
+ }
258
271
tcx. codegen_fn_attrs ( self . def_id ( ) ) . requests_inline ( )
259
272
}
260
273
@@ -278,6 +291,7 @@ impl<'tcx> InstanceDef<'tcx> {
278
291
pub fn has_polymorphic_mir_body ( & self ) -> bool {
279
292
match * self {
280
293
InstanceDef :: CloneShim ( ..)
294
+ | InstanceDef :: ThreadLocalShim ( ..)
281
295
| InstanceDef :: FnPtrAddrShim ( ..)
282
296
| InstanceDef :: FnPtrShim ( ..)
283
297
| InstanceDef :: DropGlue ( _, Some ( _) ) => false ,
@@ -310,6 +324,7 @@ fn fmt_instance(
310
324
InstanceDef :: Item ( _) => Ok ( ( ) ) ,
311
325
InstanceDef :: VTableShim ( _) => write ! ( f, " - shim(vtable)" ) ,
312
326
InstanceDef :: ReifyShim ( _) => write ! ( f, " - shim(reify)" ) ,
327
+ InstanceDef :: ThreadLocalShim ( _) => write ! ( f, " - shim(tls)" ) ,
313
328
InstanceDef :: Intrinsic ( _) => write ! ( f, " - intrinsic" ) ,
314
329
InstanceDef :: Virtual ( _, num) => write ! ( f, " - virtual#{}" , num) ,
315
330
InstanceDef :: FnPtrShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
0 commit comments