Initial fixes on top of type interner commit
This commit is contained in:
@@ -17,8 +17,8 @@ use crate::traits;
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{self, AdtDef, Ty};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_middle::ty::TyInterner;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::Span;
|
||||
pub use rustc_type_ir::{TyDecoder, TyEncoder};
|
||||
use std::hash::Hash;
|
||||
@@ -165,25 +165,6 @@ impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for AllocId {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! encodable_via_deref {
|
||||
($($t:ty),+) => {
|
||||
$(impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for $t {
|
||||
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||
(**self).encode(e)
|
||||
}
|
||||
})*
|
||||
}
|
||||
}
|
||||
|
||||
encodable_via_deref! {
|
||||
&'tcx ty::TypeckResults<'tcx>,
|
||||
&'tcx traits::ImplSource<'tcx, ()>,
|
||||
&'tcx mir::Body<'tcx>,
|
||||
&'tcx mir::UnsafetyCheckResult,
|
||||
&'tcx mir::BorrowCheckResult<'tcx>,
|
||||
&'tcx mir::coverage::CodeRegion
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn decode_arena_allocable<
|
||||
'tcx,
|
||||
@@ -231,7 +212,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for Ty<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D>
|
||||
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
|
||||
{
|
||||
fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
|
||||
let bound_vars = Decodable::decode(decoder);
|
||||
// Handle shorthands first, if we have a usize > 0x80.
|
||||
@@ -318,7 +301,10 @@ macro_rules! impl_decodable_via_ref {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
let len = decoder.read_usize();
|
||||
decoder.interner().tcx.mk_type_list((0..len).map::<Ty<'tcx>, _>(|_| Decodable::decode(decoder)))
|
||||
decoder
|
||||
.interner()
|
||||
.tcx
|
||||
.mk_type_list((0..len).map::<Ty<'tcx>, _>(|_| Decodable::decode(decoder)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +345,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for AdtDef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [(ty::Predicate<'tcx>, Span)] {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
|
||||
for [(ty::Predicate<'tcx>, Span)]
|
||||
{
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
decoder.interner().tcx.arena.alloc_from_iter(
|
||||
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
|
||||
@@ -367,7 +355,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [(ty::P
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::abstract_const::Node<'tcx>] {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
|
||||
for [thir::abstract_const::Node<'tcx>]
|
||||
{
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
decoder.interner().tcx.arena.alloc_from_iter(
|
||||
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
|
||||
@@ -375,7 +365,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::abstract_const::NodeId] {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
|
||||
for [thir::abstract_const::NodeId]
|
||||
{
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
decoder.interner().tcx.arena.alloc_from_iter(
|
||||
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
|
||||
@@ -383,7 +375,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
|
||||
for ty::List<ty::BoundVariableKind>
|
||||
{
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
let len = decoder.read_usize();
|
||||
decoder.interner().tcx.mk_bound_variable_kinds(
|
||||
@@ -449,17 +443,17 @@ arena_types!(impl_arena_allocatable_decoders);
|
||||
|
||||
macro_rules! impl_arena_copy_decoder {
|
||||
(<$tcx:tt> $($ty:ty,)*) => {
|
||||
$(impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for $ty {
|
||||
$(impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for $ty {
|
||||
#[inline]
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
decoder.tcx().arena.alloc(Decodable::decode(decoder))
|
||||
decoder.interner().tcx.arena.alloc(Decodable::decode(decoder))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [$ty] {
|
||||
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
|
||||
#[inline]
|
||||
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||
decoder.tcx().arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
|
||||
decoder.interner().tcx.arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
|
||||
}
|
||||
})*
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::mir::interpret::ConstValue;
|
||||
use crate::mir::interpret::{LitToConstInput, Scalar};
|
||||
use crate::ty::{
|
||||
self, InlineConstSubsts, InlineConstSubstsParts, InternalSubsts, ParamEnv, ParamEnvAnd, Ty,
|
||||
TyCtxt, TyInterner, TypeFoldable,
|
||||
TyCtxt, TypeFoldable,
|
||||
};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
@@ -40,14 +40,6 @@ pub struct ConstS<'tcx> {
|
||||
pub val: ConstKind<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx, S: rustc_type_ir::TyEncoder<I = TyInterner<'tcx>>> rustc_serialize::Encodable<S>
|
||||
for &'_ Const<'_>
|
||||
{
|
||||
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(*self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
static_assert_size!(ConstS<'_>, 48);
|
||||
|
||||
|
||||
@@ -1744,7 +1744,7 @@ macro_rules! nop_lift {
|
||||
impl<'a, 'tcx> Lift<'tcx> for $ty {
|
||||
type Lifted = $lifted;
|
||||
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
||||
if tcx.interners.$set.contains_pointer_to(&InternedInSet(self.0.0)) {
|
||||
if tcx.interners.$set.contains_pointer_to(&InternedInSet(&*self.0.0)) {
|
||||
// SAFETY: `self` is interned and therefore valid
|
||||
// for the entire lifetime of the `TyCtxt`.
|
||||
Some(unsafe { mem::transmute(self) })
|
||||
|
||||
@@ -68,8 +68,8 @@ pub use self::consts::{
|
||||
pub use self::context::{
|
||||
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
||||
CtxtInterners, DelaySpanBugEmitted, FreeRegionInfo, GeneratorDiagnosticData,
|
||||
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TyInterner, TypeckResults, UserType,
|
||||
UserTypeAnnotationIndex,
|
||||
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TyInterner, TypeckResults,
|
||||
UserType, UserTypeAnnotationIndex,
|
||||
};
|
||||
pub use self::instance::{Instance, InstanceDef};
|
||||
pub use self::list::List;
|
||||
@@ -78,13 +78,13 @@ pub use self::rvalue_scopes::RvalueScopes;
|
||||
pub use self::sty::BoundRegionKind::*;
|
||||
pub use self::sty::RegionKind::*;
|
||||
pub use self::sty::{
|
||||
Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind,
|
||||
CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBinder, EarlyBoundRegion,
|
||||
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig,
|
||||
GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, InlineConstSubstsParts, ParamConst,
|
||||
ParamTy, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig,
|
||||
PolyTraitRef, ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut,
|
||||
UpvarSubsts, VarianceDiagInfo,
|
||||
Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar,
|
||||
BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid,
|
||||
EarlyBinder, EarlyBoundRegion, ExistentialPredicate, ExistentialProjection,
|
||||
ExistentialTraitRef, FnSig, FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts,
|
||||
InlineConstSubsts, InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialProjection,
|
||||
PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind,
|
||||
RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo,
|
||||
};
|
||||
pub use self::trait_def::TraitDef;
|
||||
|
||||
@@ -463,16 +463,31 @@ pub(crate) struct TyS<'tcx> {
|
||||
#[rustc_pass_by_value]
|
||||
pub struct Ty<'tcx>(Interned<'tcx, WithStableHash<TyS<'tcx>>>);
|
||||
|
||||
// Statics only used for internal testing.
|
||||
pub static BOOL_TY: Ty<'static> = Ty(Interned::new_unchecked(&WithStableHash {
|
||||
internee: BOOL_TYS,
|
||||
stable_hash: Fingerprint::ZERO,
|
||||
}));
|
||||
const BOOL_TYS: TyS<'static> = TyS {
|
||||
kind: ty::Bool,
|
||||
flags: TypeFlags::empty(),
|
||||
outer_exclusive_binder: DebruijnIndex::from_usize(0),
|
||||
};
|
||||
const LEAKED_BOOL_TY_ALREADY: std::sync::atomic::AtomicBool =
|
||||
std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
/// "Static" bool only used for internal testing.
|
||||
///
|
||||
/// FIXME(rustc_type_ir): This really should be replaced with something that doesn't leak.
|
||||
/// however, since it's used for testing, it's not _that_ bad.
|
||||
pub fn leak_bool_ty_for_unit_testing<'tcx>() -> Ty<'tcx> {
|
||||
use std::sync::atomic::*;
|
||||
|
||||
if LEAKED_BOOL_TY_ALREADY.load(Ordering::Acquire) {
|
||||
panic!("Can only leak one bool type, since its equality depends on its address");
|
||||
} else {
|
||||
LEAKED_BOOL_TY_ALREADY.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
Ty(Interned::new_unchecked(Box::leak(Box::new(WithStableHash {
|
||||
internee: TyS {
|
||||
kind: ty::Bool,
|
||||
flags: TypeFlags::empty(),
|
||||
outer_exclusive_binder: DebruijnIndex::from_usize(0),
|
||||
},
|
||||
stable_hash: Fingerprint::ZERO,
|
||||
}))))
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> {
|
||||
#[inline]
|
||||
|
||||
@@ -954,9 +954,7 @@ impl<'tcx> List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn auto_traits<'a>(
|
||||
&'a self,
|
||||
) -> impl Iterator<Item = DefId> + rustc_data_structures::captures::Captures<'tcx> + 'a {
|
||||
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a {
|
||||
self.iter().filter_map(|predicate| match predicate.skip_binder() {
|
||||
ExistentialPredicate::AutoTrait(did) => Some(did),
|
||||
_ => None,
|
||||
|
||||
@@ -79,17 +79,17 @@ impl<'tcx> GenericArgKind<'tcx> {
|
||||
let (tag, ptr) = match self {
|
||||
GenericArgKind::Lifetime(lt) => {
|
||||
// Ensure we can use the tag bits.
|
||||
assert_eq!(mem::align_of_val(lt.0.0) & TAG_MASK, 0);
|
||||
assert_eq!(mem::align_of_val(&*lt.0.0) & TAG_MASK, 0);
|
||||
(REGION_TAG, lt.0.0 as *const ty::RegionKind as usize)
|
||||
}
|
||||
GenericArgKind::Type(ty) => {
|
||||
// Ensure we can use the tag bits.
|
||||
assert_eq!(mem::align_of_val(ty.0.0) & TAG_MASK, 0);
|
||||
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
|
||||
(TYPE_TAG, ty.0.0 as *const WithStableHash<ty::TyS<'tcx>> as usize)
|
||||
}
|
||||
GenericArgKind::Const(ct) => {
|
||||
// Ensure we can use the tag bits.
|
||||
assert_eq!(mem::align_of_val(ct.0.0) & TAG_MASK, 0);
|
||||
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
|
||||
(CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,9 +5,7 @@ use crate::ty::fold::{FallibleTypeFolder, TypeFolder};
|
||||
use crate::ty::layout::IntegerExt;
|
||||
use crate::ty::query::TyCtxtAt;
|
||||
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
|
||||
use crate::ty::{
|
||||
self, Const, DebruijnIndex, DefIdTree, List, ReEarlyBound, Ty, TyCtxt, TypeFoldable,
|
||||
};
|
||||
use crate::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_apfloat::Float as _;
|
||||
use rustc_ast as ast;
|
||||
use rustc_attr::{self as attr, SignedInt, UnsignedInt};
|
||||
@@ -22,7 +20,6 @@ use rustc_macros::HashStable;
|
||||
use rustc_span::{sym, DUMMY_SP};
|
||||
use rustc_target::abi::{Integer, Size, TargetDataLayout};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use smallvec::SmallVec;
|
||||
use std::{fmt, iter};
|
||||
|
||||
|
||||
@@ -36,8 +36,9 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub const COMMON_VTABLE_ENTRIES: &[VtblEntry<'_>] =
|
||||
&[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign];
|
||||
pub const fn common_vtable_entries<'tcx>() -> &'tcx [VtblEntry<'tcx>] {
|
||||
&[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign]
|
||||
}
|
||||
|
||||
pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0;
|
||||
pub const COMMON_VTABLE_ENTRIES_SIZE: usize = 1;
|
||||
@@ -57,7 +58,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
|
||||
|
||||
tcx.vtable_entries(trait_ref)
|
||||
} else {
|
||||
COMMON_VTABLE_ENTRIES
|
||||
common_vtable_entries()
|
||||
};
|
||||
|
||||
let layout = tcx
|
||||
|
||||
Reference in New Issue
Block a user