@@ -82,6 +82,11 @@ pub enum InstanceDef<'tcx> {
8282 /// The `DefId` is the ID of the `call_once` method in `FnOnce`.
8383 ClosureOnceShim { call_once : DefId , track_caller : bool } ,
8484
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+
8590 /// `core::ptr::drop_in_place::<T>`.
8691 ///
8792 /// The `DefId` is for `core::ptr::drop_in_place`.
@@ -156,6 +161,7 @@ impl<'tcx> InstanceDef<'tcx> {
156161 | InstanceDef :: FnPtrShim ( def_id, _)
157162 | InstanceDef :: Virtual ( def_id, _)
158163 | InstanceDef :: Intrinsic ( def_id)
164+ | InstanceDef :: ThreadLocalShim ( def_id)
159165 | InstanceDef :: ClosureOnceShim { call_once : def_id, track_caller : _ }
160166 | InstanceDef :: DropGlue ( def_id, _)
161167 | InstanceDef :: CloneShim ( def_id, _)
@@ -167,7 +173,9 @@ impl<'tcx> InstanceDef<'tcx> {
167173 pub fn def_id_if_not_guaranteed_local_codegen ( self ) -> Option < DefId > {
168174 match self {
169175 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+ }
171179 InstanceDef :: VTableShim ( ..)
172180 | InstanceDef :: ReifyShim ( ..)
173181 | InstanceDef :: FnPtrShim ( ..)
@@ -192,6 +200,7 @@ impl<'tcx> InstanceDef<'tcx> {
192200 | InstanceDef :: ClosureOnceShim { call_once : def_id, track_caller : _ }
193201 | InstanceDef :: DropGlue ( def_id, _)
194202 | InstanceDef :: CloneShim ( def_id, _)
203+ | InstanceDef :: ThreadLocalShim ( def_id)
195204 | InstanceDef :: FnPtrAddrShim ( def_id, _) => ty:: WithOptConstParam :: unknown ( def_id) ,
196205 }
197206 }
@@ -215,6 +224,7 @@ impl<'tcx> InstanceDef<'tcx> {
215224 let def_id = match * self {
216225 ty:: InstanceDef :: Item ( def) => def. did ,
217226 ty:: InstanceDef :: DropGlue ( _, Some ( _) ) => return false ,
227+ ty:: InstanceDef :: ThreadLocalShim ( _) => return false ,
218228 _ => return true ,
219229 } ;
220230 matches ! (
@@ -255,6 +265,9 @@ impl<'tcx> InstanceDef<'tcx> {
255265 )
256266 } ) ;
257267 }
268+ if let ty:: InstanceDef :: ThreadLocalShim ( ..) = * self {
269+ return false ;
270+ }
258271 tcx. codegen_fn_attrs ( self . def_id ( ) ) . requests_inline ( )
259272 }
260273
@@ -278,6 +291,7 @@ impl<'tcx> InstanceDef<'tcx> {
278291 pub fn has_polymorphic_mir_body ( & self ) -> bool {
279292 match * self {
280293 InstanceDef :: CloneShim ( ..)
294+ | InstanceDef :: ThreadLocalShim ( ..)
281295 | InstanceDef :: FnPtrAddrShim ( ..)
282296 | InstanceDef :: FnPtrShim ( ..)
283297 | InstanceDef :: DropGlue ( _, Some ( _) ) => false ,
@@ -310,6 +324,7 @@ fn fmt_instance(
310324 InstanceDef :: Item ( _) => Ok ( ( ) ) ,
311325 InstanceDef :: VTableShim ( _) => write ! ( f, " - shim(vtable)" ) ,
312326 InstanceDef :: ReifyShim ( _) => write ! ( f, " - shim(reify)" ) ,
327+ InstanceDef :: ThreadLocalShim ( _) => write ! ( f, " - shim(tls)" ) ,
313328 InstanceDef :: Intrinsic ( _) => write ! ( f, " - intrinsic" ) ,
314329 InstanceDef :: Virtual ( _, num) => write ! ( f, " - virtual#{}" , num) ,
315330 InstanceDef :: FnPtrShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
0 commit comments