Skip to content

Commit 3990fad

Browse files
committed
Widen TypeId from 64 bits to 128.
1 parent ba4c446 commit 3990fad

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

library/core/src/any.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ impl dyn Any + Send + Sync {
415415
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
416416
#[stable(feature = "rust1", since = "1.0.0")]
417417
pub struct TypeId {
418+
#[cfg(bootstrap)]
418419
t: u64,
420+
#[cfg(not(bootstrap))]
421+
t: u128,
419422
}
420423

421424
impl TypeId {

library/core/src/intrinsics.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,18 @@ extern "rust-intrinsic" {
808808
///
809809
/// The stabilized version of this intrinsic is [`crate::any::TypeId::of`].
810810
#[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
811+
#[cfg(bootstrap)]
811812
pub fn type_id<T: ?Sized + 'static>() -> u64;
812813

814+
/// Gets an identifier which is globally unique to the specified type. This
815+
/// function will return the same value for a type regardless of whichever
816+
/// crate it is invoked in.
817+
///
818+
/// The stabilized version of this intrinsic is [`crate::any::TypeId::of`].
819+
#[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
820+
#[cfg(not(bootstrap))]
821+
pub fn type_id<T: ?Sized + 'static>() -> u128;
822+
813823
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
814824
/// This will statically either panic, or do nothing.
815825
///

src/librustc_middle/mir/interpret/value.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ impl<'tcx> ConstValue<'tcx> {
9595
ConstValue::Scalar(Scalar::from_bool(b))
9696
}
9797

98-
pub fn from_u64(i: u64) -> Self {
99-
ConstValue::Scalar(Scalar::from_u64(i))
98+
pub fn from_u128(i: u128) -> Self {
99+
ConstValue::Scalar(Scalar::from_u128(i))
100100
}
101101

102102
pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self {
@@ -324,6 +324,11 @@ impl<'tcx, Tag> Scalar<Tag> {
324324
Scalar::Raw { data: i.into(), size: 8 }
325325
}
326326

327+
#[inline]
328+
pub fn from_u128(i: u128) -> Self {
329+
Scalar::Raw { data: i, size: 16 }
330+
}
331+
327332
#[inline]
328333
pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self {
329334
Self::from_uint(i, cx.data_layout().pointer_size)

src/librustc_middle/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub enum Representability {
154154
impl<'tcx> TyCtxt<'tcx> {
155155
/// Creates a hash of the type `Ty` which will be the same no matter what crate
156156
/// context it's calculated within. This is used by the `type_id` intrinsic.
157-
pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
157+
pub fn type_id_hash(self, ty: Ty<'tcx>) -> u128 {
158158
let mut hasher = StableHasher::new();
159159
let mut hcx = self.create_stable_hashing_context();
160160

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
7373
}
7474
sym::type_id => {
7575
ensure_monomorphic_enough(tcx, tp_ty)?;
76-
ConstValue::from_u64(tcx.type_id_hash(tp_ty))
76+
ConstValue::from_u128(tcx.type_id_hash(tp_ty))
7777
}
7878
sym::variant_count => {
7979
if let ty::Adt(ref adt, _) = tp_ty.kind {
@@ -146,7 +146,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
146146
self.tcx.types.usize
147147
}
148148
sym::needs_drop => self.tcx.types.bool,
149-
sym::type_id => self.tcx.types.u64,
149+
sym::type_id => self.tcx.types.u128,
150150
sym::type_name => self.tcx.mk_static_str(),
151151
_ => bug!("already checked for nullary intrinsics"),
152152
};

src/librustc_typeck/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
194194
sym::needs_drop => (1, Vec::new(), tcx.types.bool),
195195

196196
sym::type_name => (1, Vec::new(), tcx.mk_static_str()),
197-
sym::type_id => (1, Vec::new(), tcx.types.u64),
197+
sym::type_id => (1, Vec::new(), tcx.types.u128),
198198
sym::offset | sym::arith_offset => (
199199
1,
200200
vec![

0 commit comments

Comments
 (0)