Widen TypeId from 64 bits to 128. · rust-lang/rust@3990fad (original) (raw)

6 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -415,7 +415,10 @@ impl dyn Any + Send + Sync {
415 415 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
416 416 #[stable(feature = "rust1", since = "1.0.0")]
417 417 pub struct TypeId {
418 +#[cfg(bootstrap)]
418 419 t: u64,
420 +#[cfg(not(bootstrap))]
421 +t: u128,
419 422 }
420 423
421 424 impl TypeId {
Original file line number Diff line number Diff line change
@@ -808,8 +808,18 @@ extern "rust-intrinsic" {
808 808 ///
809 809 /// The stabilized version of this intrinsic is [`crate::any::TypeId::of`].
810 810 #[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
811 +#[cfg(bootstrap)]
811 812 pub fn type_id<T: ?Sized + 'static>() -> u64;
812 813
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 +
813 823 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
814 824 /// This will statically either panic, or do nothing.
815 825 ///
Original file line number Diff line number Diff line change
@@ -95,8 +95,8 @@ impl<'tcx> ConstValue<'tcx> {
95 95 ConstValue::Scalar(Scalar::from_bool(b))
96 96 }
97 97
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))
100 100 }
101 101
102 102 pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self {
@@ -324,6 +324,11 @@ impl<'tcx, Tag> Scalar {
324 324 Scalar::Raw { data: i.into(), size: 8 }
325 325 }
326 326
327 +#[inline]
328 +pub fn from_u128(i: u128) -> Self {
329 +Scalar::Raw { data: i, size: 16 }
330 +}
331 +
327 332 #[inline]
328 333 pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self {
329 334 Self::from_uint(i, cx.data_layout().pointer_size)
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ pub enum Representability {
154 154 impl<'tcx> TyCtxt<'tcx> {
155 155 /// Creates a hash of the type `Ty` which will be the same no matter what crate
156 156 /// 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 {
158 158 let mut hasher = StableHasher::new();
159 159 let mut hcx = self.create_stable_hashing_context();
160 160
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
73 73 }
74 74 sym::type_id => {
75 75 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))
77 77 }
78 78 sym::variant_count => {
79 79 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> {
146 146 self.tcx.types.usize
147 147 }
148 148 sym::needs_drop => self.tcx.types.bool,
149 - sym::type_id => self.tcx.types.u64,
149 + sym::type_id => self.tcx.types.u128,
150 150 sym::type_name => self.tcx.mk_static_str(),
151 151 _ => bug!("already checked for nullary intrinsics"),
152 152 };
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
194 194 sym::needs_drop => (1, Vec::new(), tcx.types.bool),
195 195
196 196 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),
198 198 sym::offset | sym::arith_offset => (
199 199 1,
200 200 vec![