提交 46389159 编写于 作者: M Michael Goulet

Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir

上级 f05a92d1
......@@ -8,7 +8,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
s.add_bounds(synstructure::AddBounds::Generics);
decodable_body(s, decoder_ty)
......@@ -95,7 +95,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
s.add_impl_generic(parse_quote! {'tcx});
}
let encoder_ty = quote! { __E };
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
s.add_bounds(synstructure::AddBounds::Generics);
encodable_body(s, encoder_ty, false)
......
......@@ -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,
......@@ -380,11 +380,11 @@ pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true;
type I = TyInterner<'tcx>;
type I = TyCtxt<'tcx>;
#[inline]
fn interner(&self) -> Self::I {
TyInterner { tcx: self.tcx() }
self.tcx()
}
#[inline]
......
......@@ -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, TyInterner};
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
use rustc_serialize::{opaque, Encodable, Encoder};
use rustc_session::config::CrateType;
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
......@@ -316,7 +316,7 @@ fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true;
type I = TyInterner<'tcx>;
type I = TyCtxt<'tcx>;
fn position(&self) -> usize {
self.opaque.position()
......
......@@ -115,7 +115,7 @@
use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::subst::GenericArgKind;
use crate::ty::{self, Instance, Ty, TyCtxt, TyInterner};
use crate::ty::{self, Instance, Ty, TyCtxt};
pub use self::error::{
struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
......@@ -203,7 +203,7 @@ enum AllocDiscriminant {
Static,
}
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyInterner<'tcx>>>(
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>>(
encoder: &mut E,
tcx: TyCtxt<'tcx>,
alloc_id: AllocId,
......@@ -277,7 +277,7 @@ impl<'s> AllocDecodingSession<'s> {
/// Decodes an `AllocId` in a thread-safe way.
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
where
D: TyDecoder<I = TyInterner<'tcx>>,
D: TyDecoder<I = TyCtxt<'tcx>>,
{
// Read the index of the allocation.
let idx = usize::try_from(decoder.read_u32()).unwrap();
......@@ -305,7 +305,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
AllocDiscriminant::Alloc => {
// If this is an allocation, we need to reserve an
// `AllocId` so we can decode cyclic graphs.
let alloc_id = decoder.interner().tcx.reserve_alloc_id();
let alloc_id = decoder.interner().reserve_alloc_id();
*entry =
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
Some(alloc_id)
......@@ -349,7 +349,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
// We already have a reserved `AllocId`.
let alloc_id = alloc_id.unwrap();
trace!("decoded alloc {:?}: {:#?}", alloc_id, alloc);
decoder.interner().tcx.set_alloc_id_same_memory(alloc_id, alloc);
decoder.interner().set_alloc_id_same_memory(alloc_id, alloc);
alloc_id
}
AllocDiscriminant::Fn => {
......@@ -357,7 +357,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
trace!("creating fn alloc ID");
let instance = ty::Instance::decode(decoder);
trace!("decoded fn alloc instance: {:?}", instance);
let alloc_id = decoder.interner().tcx.create_fn_alloc(instance);
let alloc_id = decoder.interner().create_fn_alloc(instance);
alloc_id
}
AllocDiscriminant::Static => {
......@@ -365,7 +365,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
trace!("creating extern static alloc ID");
let did = <DefId as Decodable<D>>::decode(decoder);
trace!("decoded static def-ID: {:?}", did);
let alloc_id = decoder.interner().tcx.create_static_alloc(did);
let alloc_id = decoder.interner().create_static_alloc(did);
alloc_id
}
}
......
......@@ -17,7 +17,7 @@
use crate::ty::subst::SubstsRef;
use crate::ty::{self, AdtDef, Ty};
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::TyInterner;
use rustc_middle::ty::TyCtxt;
use rustc_serialize::{Decodable, Encodable};
use rustc_span::Span;
pub use rustc_type_ir::{TyDecoder, TyEncoder};
......@@ -36,7 +36,7 @@ pub trait EncodableWithShorthand<E: TyEncoder>: Copy + Eq + Hash {
}
#[allow(rustc::usage_of_ty_tykind)]
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> EncodableWithShorthand<E> for Ty<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for Ty<'tcx> {
type Variant = ty::TyKind<'tcx>;
#[inline]
......@@ -45,9 +45,7 @@ fn variant(&self) -> &Self::Variant {
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> EncodableWithShorthand<E>
for ty::PredicateKind<'tcx>
{
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for ty::PredicateKind<'tcx> {
type Variant = ty::PredicateKind<'tcx>;
#[inline]
......@@ -66,7 +64,7 @@ fn variant(&self) -> &Self::Variant {
///
/// `Decodable` can still be implemented in cases where `Decodable` is required
/// by a trait bound.
pub trait RefDecodable<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> {
pub trait RefDecodable<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> {
fn decode(d: &mut D) -> &'tcx Self;
}
......@@ -77,7 +75,7 @@ pub fn encode_with_shorthand<'tcx, E, T, M>(
cache: M,
) -> Result<(), E::Error>
where
E: TyEncoder<I = TyInterner<'tcx>>,
E: TyEncoder<I = TyCtxt<'tcx>>,
M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>,
T: EncodableWithShorthand<E>,
// The discriminant and shorthand must have the same size.
......@@ -114,13 +112,13 @@ pub fn encode_with_shorthand<'tcx, E, T, M>(
Ok(())
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for Ty<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for Ty<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
encode_with_shorthand(e, self, TyEncoder::type_shorthands)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E>
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E>
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
{
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
......@@ -129,37 +127,37 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for ty::Predicate<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Predicate<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.kind().encode(e)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for ty::Region<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Region<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.kind().encode(e)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for ty::Const<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Const<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.0.0.encode(e)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for ConstAllocation<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ConstAllocation<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.inner().encode(e)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for AdtDef<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for AdtDef<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.0.0.encode(e)
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for AllocId {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for AllocId {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
e.encode_alloc_id(self)
}
......@@ -168,7 +166,7 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
#[inline]
fn decode_arena_allocable<
'tcx,
D: TyDecoder<I = TyInterner<'tcx>>,
D: TyDecoder<I = TyCtxt<'tcx>>,
T: ArenaAllocatable<'tcx> + Decodable<D>,
>(
decoder: &mut D,
......@@ -176,13 +174,13 @@ fn decode_arena_allocable<
where
D: TyDecoder,
{
decoder.interner().tcx.arena.alloc(Decodable::decode(decoder))
decoder.interner().arena.alloc(Decodable::decode(decoder))
}
#[inline]
fn decode_arena_allocable_slice<
'tcx,
D: TyDecoder<I = TyInterner<'tcx>>,
D: TyDecoder<I = TyCtxt<'tcx>>,
T: ArenaAllocatable<'tcx> + Decodable<D>,
>(
decoder: &mut D,
......@@ -190,10 +188,10 @@ fn decode_arena_allocable_slice<
where
D: TyDecoder,
{
decoder.interner().tcx.arena.alloc_from_iter(<Vec<T> as Decodable<D>>::decode(decoder))
decoder.interner().arena.alloc_from_iter(<Vec<T> as Decodable<D>>::decode(decoder))
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for Ty<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> {
#[allow(rustc::usage_of_ty_tykind)]
fn decode(decoder: &mut D) -> Ty<'tcx> {
// Handle shorthands first, if we have a usize > 0x80.
......@@ -206,13 +204,13 @@ fn decode(decoder: &mut D) -> Ty<'tcx> {
decoder.with_position(shorthand, Ty::decode)
})
} else {
let tcx = decoder.interner().tcx;
let tcx = decoder.interner();
tcx.mk_ty(rustc_type_ir::TyKind::decode(decoder))
}
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D>
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
{
fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
......@@ -233,64 +231,64 @@ fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Predicate<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Predicate<'tcx> {
fn decode(decoder: &mut D) -> ty::Predicate<'tcx> {
let predicate_kind = Decodable::decode(decoder);
decoder.interner().tcx.mk_predicate(predicate_kind)
decoder.interner().mk_predicate(predicate_kind)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for SubstsRef<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for SubstsRef<'tcx> {
fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize();
let tcx = decoder.interner().tcx;
let tcx = decoder.interner();
tcx.mk_substs(
(0..len).map::<ty::subst::GenericArg<'tcx>, _>(|_| Decodable::decode(decoder)),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for mir::Place<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for mir::Place<'tcx> {
fn decode(decoder: &mut D) -> Self {
let local: mir::Local = Decodable::decode(decoder);
let len = decoder.read_usize();
let projection = decoder.interner().tcx.mk_place_elems(
let projection = decoder.interner().mk_place_elems(
(0..len).map::<mir::PlaceElem<'tcx>, _>(|_| Decodable::decode(decoder)),
);
mir::Place { local, projection }
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Region<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> {
fn decode(decoder: &mut D) -> Self {
decoder.interner().tcx.mk_region(Decodable::decode(decoder))
decoder.interner().mk_region(Decodable::decode(decoder))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for CanonicalVarInfos<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for CanonicalVarInfos<'tcx> {
fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize();
let interned: Vec<CanonicalVarInfo<'tcx>> =
(0..len).map(|_| Decodable::decode(decoder)).collect();
decoder.interner().tcx.intern_canonical_var_infos(interned.as_slice())
decoder.interner().intern_canonical_var_infos(interned.as_slice())
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for AllocId {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for AllocId {
fn decode(decoder: &mut D) -> Self {
decoder.decode_alloc_id()
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::SymbolName<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::SymbolName<'tcx> {
fn decode(decoder: &mut D) -> Self {
ty::SymbolName::new(decoder.interner().tcx, &decoder.read_str())
ty::SymbolName::new(decoder.interner(), &decoder.read_str())
}
}
macro_rules! impl_decodable_via_ref {
($($t:ty),+) => {
$(impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for $t {
$(impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for $t {
fn decode(decoder: &mut D) -> Self {
RefDecodable::decode(decoder)
}
......@@ -298,89 +296,86 @@ fn decode(decoder: &mut D) -> Self {
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'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().mk_type_list((0..len).map::<Ty<'tcx>, _>(|_| Decodable::decode(decoder)))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
for ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
{
fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize();
decoder.interner().tcx.mk_poly_existential_predicates(
decoder.interner().mk_poly_existential_predicates(
(0..len).map::<ty::Binder<'tcx, _>, _>(|_| Decodable::decode(decoder)),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Const<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> {
fn decode(decoder: &mut D) -> Self {
decoder.interner().tcx.mk_const(Decodable::decode(decoder))
decoder.interner().mk_const(Decodable::decode(decoder))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [ty::ValTree<'tcx>] {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [ty::ValTree<'tcx>] {
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc_from_iter(
decoder.interner().arena.alloc_from_iter(
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ConstAllocation<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ConstAllocation<'tcx> {
fn decode(decoder: &mut D) -> Self {
decoder.interner().tcx.intern_const_alloc(Decodable::decode(decoder))
decoder.interner().intern_const_alloc(Decodable::decode(decoder))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for AdtDef<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for AdtDef<'tcx> {
fn decode(decoder: &mut D) -> Self {
decoder.interner().tcx.intern_adt_def(Decodable::decode(decoder))
decoder.interner().intern_adt_def(Decodable::decode(decoder))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
for [(ty::Predicate<'tcx>, Span)]
{
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc_from_iter(
decoder.interner().arena.alloc_from_iter(
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
for [thir::abstract_const::Node<'tcx>]
{
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc_from_iter(
decoder.interner().arena.alloc_from_iter(
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
for [thir::abstract_const::NodeId]
{
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc_from_iter(
decoder.interner().arena.alloc_from_iter(
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
impl<'tcx, D: TyDecoder<I = TyCtxt<'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(
decoder.interner().mk_bound_variable_kinds(
(0..len).map::<ty::BoundVariableKind, _>(|_| Decodable::decode(decoder)),
)
}
......@@ -414,14 +409,14 @@ fn $name(&mut self) -> $ty {
([]$args:tt) => {};
([decode $(, $attrs:ident)*]
[$name:ident: $ty:ty]) => {
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for $ty {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for $ty {
#[inline]
fn decode(decoder: &mut D) -> &'tcx Self {
decode_arena_allocable(decoder)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
#[inline]
fn decode(decoder: &mut D) -> &'tcx Self {
decode_arena_allocable_slice(decoder)
......@@ -443,17 +438,17 @@ fn decode(decoder: &mut D) -> &'tcx Self {
macro_rules! impl_arena_copy_decoder {
(<$tcx:tt> $($ty:ty,)*) => {
$(impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for $ty {
$(impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for $ty {
#[inline]
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc(Decodable::decode(decoder))
decoder.interner().arena.alloc(Decodable::decode(decoder))
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
#[inline]
fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().tcx.arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
decoder.interner().arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
}
})*
};
......@@ -512,13 +507,13 @@ fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
macro_rules! impl_binder_encode_decode {
($($t:ty),+ $(,)?) => {
$(
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for ty::Binder<'tcx, $t> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Binder<'tcx, $t> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.bound_vars().encode(e)?;
self.as_ref().skip_binder().encode(e)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Binder<'tcx, $t> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Binder<'tcx, $t> {
fn decode(decoder: &mut D) -> Self {
let bound_vars = Decodable::decode(decoder);
ty::Binder::bind_with_vars(Decodable::decode(decoder), bound_vars)
......
......@@ -90,12 +90,8 @@ fn new_empty(source_map: &'tcx SourceMap) -> Self
fn serialize(&self, tcx: TyCtxt<'tcx>, encoder: &mut FileEncoder) -> FileEncodeResult;
}
pub struct TyInterner<'tcx> {
pub tcx: TyCtxt<'tcx>,
}
#[allow(rustc::usage_of_ty_tykind)]
impl<'tcx> Interner for TyInterner<'tcx> {
impl<'tcx> Interner for TyCtxt<'tcx> {
type AdtDef = ty::AdtDef<'tcx>;
type SubstsRef = ty::SubstsRef<'tcx>;
type DefId = DefId;
......@@ -1103,11 +1099,6 @@ pub struct GlobalCtxt<'tcx> {
}
impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn interner(self) -> TyInterner<'tcx> {
TyInterner { tcx: self }
}
/// Expects a body and returns its codegen attributes.
///
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
......
......@@ -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, TypeckResults, UserType,
UserTypeAnnotationIndex,
};
pub use self::instance::{Instance, InstanceDef};
pub use self::list::List;
......@@ -463,30 +463,17 @@ pub(crate) struct TyS<'tcx> {
#[rustc_pass_by_value]
pub struct Ty<'tcx>(Interned<'tcx, WithStableHash<TyS<'tcx>>>);
static 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 {
impl<'tcx> TyCtxt<'tcx> {
/// A "bool" type used in rustc_mir_transform unit tests when we
/// have not spun up a TyCtxt.
pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> = Ty(Interned::new_unchecked(&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> {
......
......@@ -32,7 +32,7 @@
// Re-export the `TyKind` from `rustc_type_ir` here for convenience
#[rustc_diagnostic_item = "TyKind"]
pub type TyKind<'tcx> = IrTyKind<ty::TyInterner<'tcx>>;
pub type TyKind<'tcx> = IrTyKind<TyCtxt<'tcx>>;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable, Lift)]
......
......@@ -4,7 +4,7 @@
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt, TyInterner};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_data_structures::intern::{Interned, WithStableHash};
use rustc_hir::def_id::DefId;
......@@ -216,13 +216,13 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow
}
}
impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for GenericArg<'tcx> {
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for GenericArg<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
self.unpack().encode(e)
}
}
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for GenericArg<'tcx> {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArg<'tcx> {
fn decode(d: &mut D) -> GenericArg<'tcx> {
GenericArgKind::decode(d).pack()
}
......
......@@ -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, Ty};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{self, BytePos, Pos, Span, DUMMY_SP};
// All `TEMP_BLOCK` targets should be replaced before calling `to_body() -> mir::Body`.
......@@ -56,7 +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(),
bool_ty: TyCtxt::BOOL_TY_FOR_UNIT_TESTING,
}
}
......
......@@ -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, TyInterner};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_query_system::dep_graph::DepContext;
use rustc_query_system::query::{QueryCache, QueryContext, QuerySideEffects};
use rustc_serialize::{
......@@ -548,12 +548,12 @@ fn decode_tagged<D, T, V>(decoder: &mut D, expected_tag: T) -> V
}
impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
type I = TyInterner<'tcx>;
type I = TyCtxt<'tcx>;
const CLEAR_CROSS_CRATE: bool = false;
#[inline]
fn interner(&self) -> TyInterner<'tcx> {
TyInterner { tcx: self.tcx }
fn interner(&self) -> TyCtxt<'tcx> {
self.tcx
}
#[inline]
......@@ -932,7 +932,7 @@ impl<'a, 'tcx, E> TyEncoder for CacheEncoder<'a, 'tcx, E>
where
E: 'a + OpaqueEncoder,
{
type I = TyInterner<'tcx>;
type I = TyCtxt<'tcx>;
const CLEAR_CROSS_CRATE: bool = false;
fn position(&self) -> usize {
......
//! ICH - Incremental Compilation Hash
pub use self::hcx::StableHashingContext;
use rustc_data_structures::stable_hasher::HashStable;
use rustc_span::symbol::{sym, Symbol};
mod hcx;
......@@ -18,124 +17,3 @@
sym::rustc_partition_codegened,
sym::rustc_expected_cgu_reuse,
];
#[allow(rustc::usage_of_ty_tykind)]
impl<'__ctx, I: rustc_type_ir::Interner> HashStable<StableHashingContext<'__ctx>>
for rustc_type_ir::TyKind<I>
where
I::AdtDef: HashStable<StableHashingContext<'__ctx>>,
I::DefId: HashStable<StableHashingContext<'__ctx>>,
I::SubstsRef: HashStable<StableHashingContext<'__ctx>>,
I::Ty: HashStable<StableHashingContext<'__ctx>>,
I::Const: HashStable<StableHashingContext<'__ctx>>,
I::TypeAndMut: HashStable<StableHashingContext<'__ctx>>,
I::PolyFnSig: HashStable<StableHashingContext<'__ctx>>,
I::ListBinderExistentialPredicate: HashStable<StableHashingContext<'__ctx>>,
I::Region: HashStable<StableHashingContext<'__ctx>>,
I::Movability: HashStable<StableHashingContext<'__ctx>>,
I::Mutability: HashStable<StableHashingContext<'__ctx>>,
I::BinderListTy: HashStable<StableHashingContext<'__ctx>>,
I::ListTy: HashStable<StableHashingContext<'__ctx>>,
I::ProjectionTy: HashStable<StableHashingContext<'__ctx>>,
I::BoundTy: HashStable<StableHashingContext<'__ctx>>,
I::ParamTy: HashStable<StableHashingContext<'__ctx>>,
I::PlaceholderType: HashStable<StableHashingContext<'__ctx>>,
I::InferTy: HashStable<StableHashingContext<'__ctx>>,
I::DelaySpanBugEmitted: HashStable<StableHashingContext<'__ctx>>,
{
#[inline]
fn hash_stable(
&self,
__hcx: &mut crate::ich::StableHashingContext<'__ctx>,
__hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
) {
std::mem::discriminant(self).hash_stable(__hcx, __hasher);
use rustc_type_ir::TyKind::*;
match self {
Bool => {}
Char => {}
Int(i) => {
i.hash_stable(__hcx, __hasher);
}
Uint(u) => {
u.hash_stable(__hcx, __hasher);
}
Float(f) => {
f.hash_stable(__hcx, __hasher);
}
Adt(adt, substs) => {
adt.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Foreign(def_id) => {
def_id.hash_stable(__hcx, __hasher);
}
Str => {}
Array(t, c) => {
t.hash_stable(__hcx, __hasher);
c.hash_stable(__hcx, __hasher);
}
Slice(t) => {
t.hash_stable(__hcx, __hasher);
}
RawPtr(tam) => {
tam.hash_stable(__hcx, __hasher);
}
Ref(r, t, m) => {
r.hash_stable(__hcx, __hasher);
t.hash_stable(__hcx, __hasher);
m.hash_stable(__hcx, __hasher);
}
FnDef(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
FnPtr(polyfnsig) => {
polyfnsig.hash_stable(__hcx, __hasher);
}
Dynamic(l, r) => {
l.hash_stable(__hcx, __hasher);
r.hash_stable(__hcx, __hasher);
}
Closure(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Generator(def_id, substs, m) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
m.hash_stable(__hcx, __hasher);
}
GeneratorWitness(b) => {
b.hash_stable(__hcx, __hasher);
}
Never => {}
Tuple(substs) => {
substs.hash_stable(__hcx, __hasher);
}
Projection(p) => {
p.hash_stable(__hcx, __hasher);
}
Opaque(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Param(p) => {
p.hash_stable(__hcx, __hasher);
}
Bound(d, b) => {
d.hash_stable(__hcx, __hasher);
b.hash_stable(__hcx, __hasher);
}
Placeholder(p) => {
p.hash_stable(__hcx, __hasher);
}
Infer(i) => {
i.hash_stable(__hcx, __hasher);
}
Error(d) => {
d.hash_stable(__hcx, __hasher);
}
}
}
}
......@@ -8,7 +8,6 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::unify::{EqUnifyValue, UnifyKey};
//use rustc_serialize::{Decodable, Encodable};
use smallvec::SmallVec;
use std::fmt;
use std::fmt::Debug;
......
......@@ -13,6 +13,7 @@
use self::TyKind::*;
use rustc_data_structures::stable_hasher::HashStable;
use rustc_serialize::{Decodable, Encodable};
/// Defines the kinds of types used by the type system.
......@@ -198,7 +199,10 @@ pub fn is_primitive(&self) -> bool {
}
}
fn discriminant<I: Interner>(value: &TyKind<I>) -> usize {
// This is manually implemented for `TyKind` because `std::mem::discriminant`
// returns an opaque value that is `PartialEq` but not `PartialOrd`
#[inline]
const fn discriminant<I: Interner>(value: &TyKind<I>) -> usize {
match value {
Bool => 0,
Char => 1,
......@@ -230,6 +234,7 @@ fn discriminant<I: Interner>(value: &TyKind<I>) -> usize {
}
}
// This is manually implemented because a derive would require `I: Clone`
impl<I: Interner> Clone for TyKind<I> {
fn clone(&self) -> Self {
match self {
......@@ -264,6 +269,7 @@ fn clone(&self) -> Self {
}
}
// This is manually implemented because a derive would require `I: PartialEq`
impl<I: Interner> PartialEq for TyKind<I> {
#[inline]
fn eq(&self, other: &TyKind<I>) -> bool {
......@@ -324,8 +330,10 @@ fn eq(&self, other: &TyKind<I>) -> bool {
}
}
// This is manually implemented because a derive would require `I: Eq`
impl<I: Interner> Eq for TyKind<I> {}
// This is manually implemented because a derive would require `I: PartialOrd`
impl<I: Interner> PartialOrd for TyKind<I> {
#[inline]
fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> {
......@@ -333,6 +341,7 @@ fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> {
}
}
// This is manually implemented because a derive would require `I: Ord`
impl<I: Interner> Ord for TyKind<I> {
#[inline]
fn cmp(&self, other: &TyKind<I>) -> Ordering {
......@@ -430,6 +439,7 @@ fn cmp(&self, other: &TyKind<I>) -> Ordering {
}
}
// This is manually implemented because a derive would require `I: Hash`
impl<I: Interner> hash::Hash for TyKind<I> {
fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
......@@ -541,6 +551,7 @@ fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
}
}
// This is manually implemented because a derive would require `I: Debug`
impl<I: Interner> fmt::Debug for TyKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match (&*self,) {
......@@ -678,6 +689,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
// This is manually implemented because a derive would require `I: Encodable`
impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I>
where
I::DelaySpanBugEmitted: Encodable<E>,
......@@ -819,6 +831,7 @@ fn encode(&self, e: &mut E) -> Result<(), <E as rustc_serialize::Encoder>::Error
}
}
// This is manually implemented because a derive would require `I: Decodable`
impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I>
where
I::DelaySpanBugEmitted: Decodable<D>,
......@@ -905,3 +918,123 @@ fn decode(d: &mut D) -> Self {
}
}
}
// This is not a derived impl because a derive would require `I: HashStable`
#[allow(rustc::usage_of_ty_tykind)]
impl<CTX, I: Interner> HashStable<CTX> for TyKind<I>
where
I::AdtDef: HashStable<CTX>,
I::DefId: HashStable<CTX>,
I::SubstsRef: HashStable<CTX>,
I::Ty: HashStable<CTX>,
I::Const: HashStable<CTX>,
I::TypeAndMut: HashStable<CTX>,
I::PolyFnSig: HashStable<CTX>,
I::ListBinderExistentialPredicate: HashStable<CTX>,
I::Region: HashStable<CTX>,
I::Movability: HashStable<CTX>,
I::Mutability: HashStable<CTX>,
I::BinderListTy: HashStable<CTX>,
I::ListTy: HashStable<CTX>,
I::ProjectionTy: HashStable<CTX>,
I::BoundTy: HashStable<CTX>,
I::ParamTy: HashStable<CTX>,
I::PlaceholderType: HashStable<CTX>,
I::InferTy: HashStable<CTX>,
I::DelaySpanBugEmitted: HashStable<CTX>,
{
#[inline]
fn hash_stable(
&self,
__hcx: &mut CTX,
__hasher: &mut rustc_data_structures::stable_hasher::StableHasher,
) {
std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match self {
Bool => {}
Char => {}
Int(i) => {
i.hash_stable(__hcx, __hasher);
}
Uint(u) => {
u.hash_stable(__hcx, __hasher);
}
Float(f) => {
f.hash_stable(__hcx, __hasher);
}
Adt(adt, substs) => {
adt.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Foreign(def_id) => {
def_id.hash_stable(__hcx, __hasher);
}
Str => {}
Array(t, c) => {
t.hash_stable(__hcx, __hasher);
c.hash_stable(__hcx, __hasher);
}
Slice(t) => {
t.hash_stable(__hcx, __hasher);
}
RawPtr(tam) => {
tam.hash_stable(__hcx, __hasher);
}
Ref(r, t, m) => {
r.hash_stable(__hcx, __hasher);
t.hash_stable(__hcx, __hasher);
m.hash_stable(__hcx, __hasher);
}
FnDef(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
FnPtr(polyfnsig) => {
polyfnsig.hash_stable(__hcx, __hasher);
}
Dynamic(l, r) => {
l.hash_stable(__hcx, __hasher);
r.hash_stable(__hcx, __hasher);
}
Closure(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Generator(def_id, substs, m) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
m.hash_stable(__hcx, __hasher);
}
GeneratorWitness(b) => {
b.hash_stable(__hcx, __hasher);
}
Never => {}
Tuple(substs) => {
substs.hash_stable(__hcx, __hasher);
}
Projection(p) => {
p.hash_stable(__hcx, __hasher);
}
Opaque(def_id, substs) => {
def_id.hash_stable(__hcx, __hasher);
substs.hash_stable(__hcx, __hasher);
}
Param(p) => {
p.hash_stable(__hcx, __hasher);
}
Bound(d, b) => {
d.hash_stable(__hcx, __hasher);
b.hash_stable(__hcx, __hasher);
}
Placeholder(p) => {
p.hash_stable(__hcx, __hasher);
}
Infer(i) => {
i.hash_stable(__hcx, __hasher);
}
Error(d) => {
d.hash_stable(__hcx, __hasher);
}
}
}
}
......@@ -677,8 +677,6 @@ 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) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册