summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty/instance.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_middle/src/ty/instance.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/ty/instance.rs')
-rw-r--r--compiler/rustc_middle/src/ty/instance.rs55
1 files changed, 50 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs
index f4028a5a9..e73225f70 100644
--- a/compiler/rustc_middle/src/ty/instance.rs
+++ b/compiler/rustc_middle/src/ty/instance.rs
@@ -82,6 +82,11 @@ pub enum InstanceDef<'tcx> {
/// The `DefId` is the ID of the `call_once` method in `FnOnce`.
ClosureOnceShim { call_once: DefId, track_caller: bool },
+ /// Compiler-generated accessor for thread locals which returns a reference to the thread local
+ /// the `DefId` defines. This is used to export thread locals from dylibs on platforms lacking
+ /// native support.
+ ThreadLocalShim(DefId),
+
/// `core::ptr::drop_in_place::<T>`.
///
/// The `DefId` is for `core::ptr::drop_in_place`.
@@ -96,6 +101,13 @@ pub enum InstanceDef<'tcx> {
///
/// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl.
CloneShim(DefId, Ty<'tcx>),
+
+ /// Compiler-generated `<T as FnPtr>::addr` implementation.
+ ///
+ /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types.
+ ///
+ /// The `DefId` is for `FnPtr::addr`, the `Ty` is the type `T`.
+ FnPtrAddrShim(DefId, Ty<'tcx>),
}
impl<'tcx> Instance<'tcx> {
@@ -149,9 +161,11 @@ impl<'tcx> InstanceDef<'tcx> {
| InstanceDef::FnPtrShim(def_id, _)
| InstanceDef::Virtual(def_id, _)
| InstanceDef::Intrinsic(def_id)
+ | InstanceDef::ThreadLocalShim(def_id)
| InstanceDef::ClosureOnceShim { call_once: def_id, track_caller: _ }
| InstanceDef::DropGlue(def_id, _)
- | InstanceDef::CloneShim(def_id, _) => def_id,
+ | InstanceDef::CloneShim(def_id, _)
+ | InstanceDef::FnPtrAddrShim(def_id, _) => def_id,
}
}
@@ -159,7 +173,9 @@ impl<'tcx> InstanceDef<'tcx> {
pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
match self {
ty::InstanceDef::Item(def) => Some(def.did),
- ty::InstanceDef::DropGlue(def_id, Some(_)) => Some(def_id),
+ ty::InstanceDef::DropGlue(def_id, Some(_)) | InstanceDef::ThreadLocalShim(def_id) => {
+ Some(def_id)
+ }
InstanceDef::VTableShim(..)
| InstanceDef::ReifyShim(..)
| InstanceDef::FnPtrShim(..)
@@ -167,7 +183,8 @@ impl<'tcx> InstanceDef<'tcx> {
| InstanceDef::Intrinsic(..)
| InstanceDef::ClosureOnceShim { .. }
| InstanceDef::DropGlue(..)
- | InstanceDef::CloneShim(..) => None,
+ | InstanceDef::CloneShim(..)
+ | InstanceDef::FnPtrAddrShim(..) => None,
}
}
@@ -182,12 +199,18 @@ impl<'tcx> InstanceDef<'tcx> {
| InstanceDef::Intrinsic(def_id)
| InstanceDef::ClosureOnceShim { call_once: def_id, track_caller: _ }
| InstanceDef::DropGlue(def_id, _)
- | InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::unknown(def_id),
+ | InstanceDef::CloneShim(def_id, _)
+ | InstanceDef::ThreadLocalShim(def_id)
+ | InstanceDef::FnPtrAddrShim(def_id, _) => ty::WithOptConstParam::unknown(def_id),
}
}
#[inline]
- pub fn get_attrs(&self, tcx: TyCtxt<'tcx>, attr: Symbol) -> ty::Attributes<'tcx> {
+ pub fn get_attrs(
+ &self,
+ tcx: TyCtxt<'tcx>,
+ attr: Symbol,
+ ) -> impl Iterator<Item = &'tcx rustc_ast::Attribute> {
tcx.get_attrs(self.def_id(), attr)
}
@@ -201,6 +224,7 @@ impl<'tcx> InstanceDef<'tcx> {
let def_id = match *self {
ty::InstanceDef::Item(def) => def.did,
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
+ ty::InstanceDef::ThreadLocalShim(_) => return false,
_ => return true,
};
matches!(
@@ -241,6 +265,9 @@ impl<'tcx> InstanceDef<'tcx> {
)
});
}
+ if let ty::InstanceDef::ThreadLocalShim(..) = *self {
+ return false;
+ }
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
}
@@ -264,6 +291,8 @@ impl<'tcx> InstanceDef<'tcx> {
pub fn has_polymorphic_mir_body(&self) -> bool {
match *self {
InstanceDef::CloneShim(..)
+ | InstanceDef::ThreadLocalShim(..)
+ | InstanceDef::FnPtrAddrShim(..)
| InstanceDef::FnPtrShim(..)
| InstanceDef::DropGlue(_, Some(_)) => false,
InstanceDef::ClosureOnceShim { .. }
@@ -295,6 +324,7 @@ fn fmt_instance(
InstanceDef::Item(_) => Ok(()),
InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
+ InstanceDef::ThreadLocalShim(_) => write!(f, " - shim(tls)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
@@ -302,6 +332,7 @@ fn fmt_instance(
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
+ InstanceDef::FnPtrAddrShim(_, ty) => write!(f, " - shim({})", ty),
}
}
@@ -781,6 +812,12 @@ fn needs_fn_once_adapter_shim(
#[derive(Debug, Copy, Clone, Eq, PartialEq, Decodable, Encodable, HashStable)]
pub struct UnusedGenericParams(FiniteBitSet<u32>);
+impl Default for UnusedGenericParams {
+ fn default() -> Self {
+ UnusedGenericParams::new_all_used()
+ }
+}
+
impl UnusedGenericParams {
pub fn new_all_unused(amount: u32) -> Self {
let mut bitset = FiniteBitSet::new_empty();
@@ -807,4 +844,12 @@ impl UnusedGenericParams {
pub fn all_used(&self) -> bool {
self.0.is_empty()
}
+
+ pub fn bits(&self) -> u32 {
+ self.0.0
+ }
+
+ pub fn from_bits(bits: u32) -> UnusedGenericParams {
+ UnusedGenericParams(FiniteBitSet(bits))
+ }
}