Initial fixes on top of type interner commit

This commit is contained in:
Michael Goulet 2022-05-22 12:57:46 -07:00
parent a7015fe816
commit a056a953f0
28 changed files with 171 additions and 134 deletions

View File

@ -3676,6 +3676,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"tracing",
]
@ -3969,6 +3970,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"tracing",
"unicode-security",
]
@ -4041,6 +4043,7 @@ dependencies = [
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_type_ir",
"smallvec",
"snap",
"tracing",
@ -4474,6 +4477,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"tracing",
]
@ -4512,6 +4516,7 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_ty_utils",
"rustc_type_ir",
"smallvec",
"tracing",
]

View File

@ -98,7 +98,9 @@ struct Upvar<'tcx> {
by_ref: bool,
}
const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref];
const fn deref_projection<'tcx>() -> &'tcx [PlaceElem<'tcx>; 1] {
&[ProjectionElem::Deref]
}
pub fn provide(providers: &mut Providers) {
*providers = Providers {
@ -1443,7 +1445,7 @@ fn check_for_invalidation_at_exit(
// Thread-locals might be dropped after the function exits
// We have to dereference the outer reference because
// borrows don't conflict behind shared references.
root_place.projection = DEREF_PROJECTION;
root_place.projection = deref_projection();
(true, true)
} else {
(false, self.locals_are_invalidated_at_exit)

View File

@ -33,7 +33,7 @@
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, AdtKind, Instance, ParamEnv, Ty, TyCtxt, COMMON_VTABLE_ENTRIES};
use rustc_middle::ty::{self, common_vtable_entries, AdtKind, Instance, ParamEnv, Ty, TyCtxt};
use rustc_session::config::{self, DebugInfo};
use rustc_span::symbol::Symbol;
use rustc_span::FileName;
@ -1392,7 +1392,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
tcx.vtable_entries(trait_ref)
} else {
COMMON_VTABLE_ENTRIES
common_vtable_entries()
};
// All function pointers are described as opaque pointers. This could be improved in the future

View File

@ -24,3 +24,4 @@ rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_span = { path = "../rustc_span" }
rustc_type_ir = { path = "../rustc_type_ir" }

View File

@ -2,7 +2,7 @@
use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic};
use rustc_middle::ty::{
self, Ty, COMMON_VTABLE_ENTRIES, COMMON_VTABLE_ENTRIES_ALIGN,
self, common_vtable_entries, Ty, COMMON_VTABLE_ENTRIES_ALIGN,
COMMON_VTABLE_ENTRIES_DROPINPLACE, COMMON_VTABLE_ENTRIES_SIZE,
};
use rustc_target::abi::{Align, Size};
@ -38,7 +38,7 @@ pub fn get_vtable(
}
/// Resolves the function at the specified slot in the provided
/// vtable. Currently an index of '3' (`COMMON_VTABLE_ENTRIES.len()`)
/// vtable. Currently an index of '3' (`common_vtable_entries().len()`)
/// corresponds to the first method declared in the trait of the provided vtable.
pub fn get_vtable_slot(
&self,
@ -64,7 +64,7 @@ pub fn read_drop_type_from_vtable(
let vtable = self
.get_ptr_alloc(
vtable,
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES.len()).unwrap(),
pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
self.tcx.data_layout.pointer_align.abi,
)?
.expect("cannot be a ZST");
@ -99,7 +99,7 @@ pub fn read_size_and_align_from_vtable(
let vtable = self
.get_ptr_alloc(
vtable,
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES.len()).unwrap(),
pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
self.tcx.data_layout.pointer_align.abi,
)?
.expect("cannot be a ZST");

View File

@ -21,3 +21,4 @@ rustc_session = { path = "../rustc_session" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_parse_format = { path = "../rustc_parse_format" }
rustc_infer = { path = "../rustc_infer" }
rustc_type_ir = { path = "../rustc_type_ir" }

View File

@ -27,3 +27,4 @@ rustc_ast = { path = "../rustc_ast" }
rustc_expand = { path = "../rustc_expand" }
rustc_span = { path = "../rustc_span" }
rustc_session = { path = "../rustc_session" }
rustc_type_ir = { path = "../rustc_type_ir" }

View File

@ -24,8 +24,8 @@
use rustc_middle::thir;
use rustc_middle::ty::codec::TyDecoder;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::GeneratorDiagnosticData;
use rustc_middle::ty::{self, ParameterizedOverTcx, Ty, TyCtxt, Visibility};
use rustc_middle::ty::{GeneratorDiagnosticData, TyInterner};
use rustc_serialize::{opaque, Decodable, Decoder};
use rustc_session::cstore::{
CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
@ -377,12 +377,13 @@ pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
}
}
impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true;
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx.expect("missing TyCtxt in DecodeContext")
type I = TyInterner<'tcx>;
fn interner(&self) -> Self::I {
TyInterner { tcx: self.tcx() }
}
#[inline]

View File

@ -26,7 +26,7 @@
use rustc_middle::ty::codec::TyEncoder;
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt, TyInterner};
use rustc_serialize::{opaque, Encodable, Encoder};
use rustc_session::config::CrateType;
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
@ -313,9 +313,11 @@ fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
}
}
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true;
type I = TyInterner<'tcx>;
fn position(&self) -> usize {
self.opaque.position()
}

View File

@ -17,8 +17,8 @@
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 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
}
}
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 @@ fn decode(decoder: &mut D) -> 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 @@ fn decode(decoder: &mut D) -> Self {
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 @@ fn decode(decoder: &mut D) -> Self {
}
}
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 @@ fn decode(decoder: &mut D) -> &'tcx Self {
}
}
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 @@ fn decode(decoder: &mut D) -> &'tcx Self {
}
}
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 @@ fn decode(decoder: &mut D) -> &'tcx Self {
}
}
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 @@ macro_rules! 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))
}
})*
};

View File

@ -2,7 +2,7 @@
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);

View File

@ -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) })

View File

@ -68,8 +68,8 @@
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::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]

View File

@ -954,9 +954,7 @@ pub fn projection_bounds<'a>(
}
#[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,

View File

@ -79,17 +79,17 @@ fn pack(self) -> GenericArg<'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)
}
};

View File

@ -5,9 +5,7 @@
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_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};

View File

@ -36,8 +36,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
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

View File

@ -37,7 +37,7 @@
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, BOOL_TY};
use rustc_middle::ty::{self, Ty};
use rustc_span::{self, BytePos, Pos, Span, DUMMY_SP};
// All `TEMP_BLOCK` targets should be replaced before calling `to_body() -> mir::Body`.
@ -47,6 +47,7 @@ struct MockBlocks<'tcx> {
blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
dummy_place: Place<'tcx>,
next_local: usize,
bool_ty: Ty<'tcx>,
}
impl<'tcx> MockBlocks<'tcx> {
@ -55,6 +56,7 @@ fn new() -> Self {
blocks: IndexVec::new(),
dummy_place: Place { local: RETURN_PLACE, projection: ty::List::empty() },
next_local: 0,
bool_ty: ty::leak_bool_ty_for_unit_testing(),
}
}
@ -155,7 +157,7 @@ fn goto(&mut self, some_from_block: Option<BasicBlock>) -> BasicBlock {
fn switchint(&mut self, some_from_block: Option<BasicBlock>) -> BasicBlock {
let switchint_kind = TerminatorKind::SwitchInt {
discr: Operand::Move(Place::from(self.new_temp())),
switch_ty: BOOL_TY, // just a dummy value
switch_ty: self.bool_ty, // just a dummy value
targets: SwitchTargets::static_if(0, TEMP_BLOCK, TEMP_BLOCK),
};
self.add_block_from(some_from_block, switchint_kind)

View File

@ -11,7 +11,7 @@
use rustc_middle::mir::{self, interpret};
use rustc_middle::thir;
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt, TyInterner};
use rustc_query_system::dep_graph::DepContext;
use rustc_query_system::query::{QueryCache, QueryContext, QuerySideEffects};
use rustc_serialize::{

View File

@ -33,7 +33,7 @@
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{
self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry, COMMON_VTABLE_ENTRIES,
self, common_vtable_entries, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry,
};
use rustc_span::{sym, Span};
use smallvec::SmallVec;
@ -695,7 +695,7 @@ fn vtable_entries<'tcx>(
let vtable_segment_callback = |segment| -> ControlFlow<()> {
match segment {
VtblSegment::MetadataDSA => {
entries.extend(COMMON_VTABLE_ENTRIES);
entries.extend(common_vtable_entries());
}
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
let existential_trait_ref = trait_ref
@ -785,7 +785,7 @@ fn vtable_trait_first_method_offset<'tcx>(
move |segment| {
match segment {
VtblSegment::MetadataDSA => {
vtable_base += COMMON_VTABLE_ENTRIES.len();
vtable_base += common_vtable_entries().len();
}
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
if tcx.erase_regions(trait_ref) == trait_to_be_found_erased {

View File

@ -834,7 +834,7 @@ fn confirm_trait_upcasting_unsize_candidate(
move |segment| {
match segment {
VtblSegment::MetadataDSA => {
vptr_offset += ty::COMMON_VTABLE_ENTRIES.len();
vptr_offset += ty::common_vtable_entries().len();
}
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
vptr_offset += util::count_own_vtable_entries(tcx, trait_ref);

View File

@ -14,3 +14,4 @@ rustc_span = { path = "../rustc_span" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }

View File

@ -47,7 +47,11 @@ pub trait TyDecoder: Decoder {
fn position(&self) -> usize;
fn cached_ty_for_shorthand<F>(&mut self, shorthand: usize, or_insert_with: F) -> <Self::I as Interner>::Ty
fn cached_ty_for_shorthand<F>(
&mut self,
shorthand: usize,
or_insert_with: F,
) -> <Self::I as Interner>::Ty
where
F: FnOnce(&mut Self) -> <Self::I as Interner>::Ty;
@ -60,4 +64,4 @@ fn positioned_at_shorthand(&self) -> bool {
}
fn decode_alloc_id(&mut self) -> <Self::I as Interner>::AllocId;
}
}

View File

@ -13,7 +13,7 @@
/// Types written by the user start out as [hir::TyKind](rustc_hir::TyKind) and get
/// converted to this representation using `AstConv::ast_ty_to_ty`.
#[allow(rustc::usage_of_ty_tykind)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
//#[derive(TyEncodable, TyDecodable)]
//#[derive(HashStable)]
#[rustc_diagnostic_item = "TyKind"]
@ -186,6 +186,42 @@ pub enum TyKind<I: Interner> {
Error(I::DelaySpanBugEmitted),
}
#[allow(rustc::usage_of_ty_tykind)]
impl<I: Interner> Clone for TyKind<I> {
fn clone(&self) -> Self {
use crate::TyKind::*;
match self {
Bool => Bool,
Char => Char,
Int(i) => Int(i.clone()),
Uint(u) => Uint(u.clone()),
Float(f) => Float(f.clone()),
Adt(d, s) => Adt(d.clone(), s.clone()),
Foreign(d) => Foreign(d.clone()),
Str => Str,
Array(t, c) => Array(t.clone(), c.clone()),
Slice(t) => Slice(t.clone()),
RawPtr(t) => RawPtr(t.clone()),
Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()),
FnDef(d, s) => FnDef(d.clone(), s.clone()),
FnPtr(s) => FnPtr(s.clone()),
Dynamic(p, r) => Dynamic(p.clone(), r.clone()),
Closure(d, s) => Closure(d.clone(), s.clone()),
Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()),
GeneratorWitness(g) => GeneratorWitness(g.clone()),
Never => Never,
Tuple(t) => Tuple(t.clone()),
Projection(p) => Projection(p.clone()),
Opaque(d, s) => Opaque(d.clone(), s.clone()),
Param(p) => Param(p.clone()),
Bound(d, b) => Bound(d.clone(), b.clone()),
Placeholder(p) => Placeholder(p.clone()),
Infer(t) => Infer(t.clone()),
Error(e) => Error(e.clone()),
}
}
}
#[allow(rustc::usage_of_ty_tykind)]
impl<I: Interner> TyKind<I> {
#[inline]
@ -383,9 +419,7 @@ fn decode(__decoder: &mut __D) -> Self {
rustc_serialize::Decodable::decode(__decoder),
),
9 => Slice(rustc_serialize::Decodable::decode(__decoder)),
10 => RawPtr(
rustc_serialize::Decodable::decode(__decoder),
),
10 => RawPtr(rustc_serialize::Decodable::decode(__decoder)),
11 => Ref(
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
@ -395,9 +429,7 @@ fn decode(__decoder: &mut __D) -> Self {
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
),
13 => FnPtr(
rustc_serialize::Decodable::decode(__decoder),
),
13 => FnPtr(rustc_serialize::Decodable::decode(__decoder)),
14 => Dynamic(
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
@ -411,44 +443,29 @@ fn decode(__decoder: &mut __D) -> Self {
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
),
17 => GeneratorWitness(
rustc_serialize::Decodable::decode(__decoder),
),
17 => GeneratorWitness(rustc_serialize::Decodable::decode(__decoder)),
18 => Never,
19 => Tuple(
rustc_serialize::Decodable::decode(__decoder),
),
20 => Projection(
rustc_serialize::Decodable::decode(__decoder),
),
19 => Tuple(rustc_serialize::Decodable::decode(__decoder)),
20 => Projection(rustc_serialize::Decodable::decode(__decoder)),
21 => Opaque(
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
),
22 => Param(
rustc_serialize::Decodable::decode(__decoder),
),
22 => Param(rustc_serialize::Decodable::decode(__decoder)),
23 => Bound(
rustc_serialize::Decodable::decode(__decoder),
rustc_serialize::Decodable::decode(__decoder),
),
24 => Placeholder(
rustc_serialize::Decodable::decode(__decoder),
24 => Placeholder(rustc_serialize::Decodable::decode(__decoder)),
25 => Infer(rustc_serialize::Decodable::decode(__decoder)),
26 => Error(rustc_serialize::Decodable::decode(__decoder)),
_ => panic!(
"{}",
format!(
"invalid enum variant tag while decoding `{}`, expected 0..{}",
"TyKind", 27,
)
),
25 => Infer(
rustc_serialize::Decodable::decode(__decoder),
),
26 => Error(
rustc_serialize::Decodable::decode(__decoder),
),
_ =>
panic!(
"{}",
format!(
"invalid enum variant tag while decoding `{}`, expected 0..{}",
"TyKind", 27,
)
),
}
}
}

View File

@ -29,3 +29,4 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
rustc_lint = { path = "../rustc_lint" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_type_ir = { path = "../rustc_type_ir" }

View File

@ -12,7 +12,7 @@
use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
use rustc_middle::ty::{self, Article, AssocItem, Ty, TypeAndMut};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{BytePos, Span};

View File

@ -4,7 +4,7 @@
use rustc_hir as hir;
use rustc_index::vec::Idx;
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TypeFoldable, UintTy};
use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TypeFoldable, UintTy, Article};
use rustc_session::lint;
use rustc_span::{Span, Symbol, DUMMY_SP};
use rustc_target::abi::{Pointer, VariantIdx};

View File

@ -10,7 +10,6 @@
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
};
use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{sym, Ident};
@ -18,6 +17,7 @@
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt as _;
use rustc_trait_selection::traits::{FulfillmentError, TraitEngine, TraitEngineExt};
use rustc_type_ir::sty::TyKind::*;
use std::ops::ControlFlow;
@ -677,6 +677,8 @@ pub fn check_user_unop(
operand_ty: Ty<'tcx>,
op: hir::UnOp,
) -> Ty<'tcx> {
use rustc_type_ir::sty::TyKind::*;
assert!(op.is_by_value());
match self.lookup_op_method(operand_ty, None, None, Op::Unary(op, ex.span)) {
Ok(method) => {