From 3990fadb81699609a3f0f56b2a92018954dd3b68 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 26 Aug 2020 01:43:38 +0300 Subject: [PATCH] Widen TypeId from 64 bits to 128. --- library/core/src/any.rs | 3 +++ library/core/src/intrinsics.rs | 10 ++++++++++ src/librustc_middle/mir/interpret/value.rs | 9 +++++++-- src/librustc_middle/ty/util.rs | 2 +- src/librustc_mir/interpret/intrinsics.rs | 4 ++-- src/librustc_typeck/check/intrinsic.rs | 2 +- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index d79b9a33b5aa8..6dbd4d435e408 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -415,7 +415,10 @@ impl dyn Any + Send + Sync { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct TypeId { + #[cfg(bootstrap)] t: u64, + #[cfg(not(bootstrap))] + t: u128, } impl TypeId { diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 25951e2f58235..542056c1dd5d7 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -808,8 +808,18 @@ extern "rust-intrinsic" { /// /// The stabilized version of this intrinsic is [`crate::any::TypeId::of`]. #[rustc_const_stable(feature = "const_type_id", since = "1.46.0")] + #[cfg(bootstrap)] pub fn type_id() -> u64; + /// Gets an identifier which is globally unique to the specified type. This + /// function will return the same value for a type regardless of whichever + /// crate it is invoked in. + /// + /// The stabilized version of this intrinsic is [`crate::any::TypeId::of`]. + #[rustc_const_stable(feature = "const_type_id", since = "1.46.0")] + #[cfg(not(bootstrap))] + pub fn type_id() -> u128; + /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: /// This will statically either panic, or do nothing. /// diff --git a/src/librustc_middle/mir/interpret/value.rs b/src/librustc_middle/mir/interpret/value.rs index 4c47f25105d0f..ac1dddcd51c18 100644 --- a/src/librustc_middle/mir/interpret/value.rs +++ b/src/librustc_middle/mir/interpret/value.rs @@ -95,8 +95,8 @@ impl<'tcx> ConstValue<'tcx> { ConstValue::Scalar(Scalar::from_bool(b)) } - pub fn from_u64(i: u64) -> Self { - ConstValue::Scalar(Scalar::from_u64(i)) + pub fn from_u128(i: u128) -> Self { + ConstValue::Scalar(Scalar::from_u128(i)) } pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self { @@ -324,6 +324,11 @@ impl<'tcx, Tag> Scalar { Scalar::Raw { data: i.into(), size: 8 } } + #[inline] + pub fn from_u128(i: u128) -> Self { + Scalar::Raw { data: i, size: 16 } + } + #[inline] pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self { Self::from_uint(i, cx.data_layout().pointer_size) diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index 63d4dcca0804a..d888218afe813 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -154,7 +154,7 @@ pub enum Representability { impl<'tcx> TyCtxt<'tcx> { /// Creates a hash of the type `Ty` which will be the same no matter what crate /// context it's calculated within. This is used by the `type_id` intrinsic. - pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 { + pub fn type_id_hash(self, ty: Ty<'tcx>) -> u128 { let mut hasher = StableHasher::new(); let mut hcx = self.create_stable_hashing_context(); diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index b37dcd42f4c71..6379bbb970dbb 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -73,7 +73,7 @@ crate fn eval_nullary_intrinsic<'tcx>( } sym::type_id => { ensure_monomorphic_enough(tcx, tp_ty)?; - ConstValue::from_u64(tcx.type_id_hash(tp_ty)) + ConstValue::from_u128(tcx.type_id_hash(tp_ty)) } sym::variant_count => { 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> { self.tcx.types.usize } sym::needs_drop => self.tcx.types.bool, - sym::type_id => self.tcx.types.u64, + sym::type_id => self.tcx.types.u128, sym::type_name => self.tcx.mk_static_str(), _ => bug!("already checked for nullary intrinsics"), }; diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 47cea8649ef3d..e2a10f4d8301d 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -194,7 +194,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { sym::needs_drop => (1, Vec::new(), tcx.types.bool), sym::type_name => (1, Vec::new(), tcx.mk_static_str()), - sym::type_id => (1, Vec::new(), tcx.types.u64), + sym::type_id => (1, Vec::new(), tcx.types.u128), sym::offset | sym::arith_offset => ( 1, vec![