Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TyInterner #86435

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4467,6 +4467,7 @@ dependencies = [
"rustc_index",
"rustc_macros",
"rustc_serialize",
"smallvec",
]

[[package]]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,10 @@ macro_rules! declare_arena {
self.dropless.alloc_slice(value)
}

pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, U>, U>(
&'a self,
iter: impl ::std::iter::IntoIterator<Item = T>,
) -> &'a mut [T] {
pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, U>, U, V: IntoIterator<Item = T>>(
&self,
iter: V,
) -> &mut [T] {
T::allocate_from_iter(self, iter)
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
ty: Ty<'tcx>,
init: InitKind,
) -> Option<InitError> {
use rustc_middle::ty::TyKind::*;
use rustc_type_ir::sty::TyKind::*;
match ty.kind() {
// Primitive types that don't like 0 as a value.
Ref(..) => Some(("references must be non-null".to_string(), None)),
Expand Down Expand Up @@ -2783,7 +2783,7 @@ impl ClashingExternDeclarations {
true
} else {
// Do a full, depth-first comparison between the two.
use rustc_middle::ty::TyKind::*;
use rustc_type_ir::sty::TyKind::*;
let a_kind = a.kind();
let b_kind = b.kind();

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_macros/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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_middle::ty::codec::TyDecoder<'tcx>});
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
s.add_bounds(synstructure::AddBounds::Generics);

decodable_body(s, decoder_ty)
Expand Down Expand Up @@ -136,7 +136,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_middle::ty::codec::TyEncoder<'tcx>});
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
s.add_bounds(synstructure::AddBounds::Generics);

encodable_body(s, encoder_ty, false)
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable<DecodeContext<'a, 'tcx>>> Lazy<[T]> {
}

impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx.expect("missing TyCtxt in DecodeContext")
}

fn cdata(&self) -> CrateMetadataRef<'a> {
self.cdata.expect("missing CrateMetadata in DecodeContext")
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ use rustc_target::abi::Endian;
use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::subst::GenericArgKind;
use crate::ty::{self, Instance, Ty, TyCtxt};
use crate::ty::{self, Instance, Ty, TyCtxt, TyInterner};

pub use self::error::{
struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
Expand Down Expand Up @@ -200,7 +200,7 @@ enum AllocDiscriminant {
Static,
}

pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyInterner<'tcx>>>(
encoder: &mut E,
tcx: TyCtxt<'tcx>,
alloc_id: AllocId,
Expand Down Expand Up @@ -270,11 +270,11 @@ pub struct AllocDecodingSession<'s> {
session_id: DecodingSessionId,
}

impl<'s> AllocDecodingSession<'s> {
impl<'s, 'tcx> AllocDecodingSession<'s> {
/// Decodes an `AllocId` in a thread-safe way.
pub fn decode_alloc_id<D>(&self, decoder: &mut D) -> Result<AllocId, D::Error>
where
D: TyDecoder<'tcx>,
D: TyDecoder<I = TyInterner<'tcx>>,
{
// Read the index of the allocation.
let idx = usize::try_from(decoder.read_u32()?).unwrap();
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<'s> AllocDecodingSession<'s> {
AllocDiscriminant::Alloc => {
// If this is an allocation, we need to reserve an
// `AllocId` so we can decode cyclic graphs.
let alloc_id = decoder.tcx().reserve_alloc_id();
let alloc_id = decoder.interner().tcx.reserve_alloc_id();
*entry =
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
Some(alloc_id)
Expand Down Expand Up @@ -346,23 +346,23 @@ impl<'s> AllocDecodingSession<'s> {
// We already have a reserved `AllocId`.
let alloc_id = alloc_id.unwrap();
trace!("decoded alloc {:?}: {:#?}", alloc_id, alloc);
decoder.tcx().set_alloc_id_same_memory(alloc_id, alloc);
decoder.interner().tcx.set_alloc_id_same_memory(alloc_id, alloc);
Ok(alloc_id)
}
AllocDiscriminant::Fn => {
assert!(alloc_id.is_none());
trace!("creating fn alloc ID");
let instance = ty::Instance::decode(decoder)?;
trace!("decoded fn alloc instance: {:?}", instance);
let alloc_id = decoder.tcx().create_fn_alloc(instance);
let alloc_id = decoder.interner().tcx.create_fn_alloc(instance);
Ok(alloc_id)
}
AllocDiscriminant::Static => {
assert!(alloc_id.is_none());
trace!("creating extern static alloc ID");
let did = <DefId as Decodable<D>>::decode(decoder)?;
trace!("decoded static def-ID: {:?}", did);
let alloc_id = decoder.tcx().create_static_alloc(did);
let alloc_id = decoder.interner().tcx.create_static_alloc(did);
Ok(alloc_id)
}
}
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ impl<'tcx> Body<'tcx> {

/// Returns an iterator over all user-declared mutable locals.
#[inline]
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
pub fn mut_vars_iter<'a>(
&'a self,
) -> impl Iterator<Item = Local> + rustc_data_structures::captures::Captures<'tcx> + 'a {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
Expand All @@ -395,7 +397,9 @@ impl<'tcx> Body<'tcx> {

/// Returns an iterator over all user-declared mutable arguments and locals.
#[inline]
pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
pub fn mut_vars_and_args_iter<'a>(
&'a self,
) -> impl Iterator<Item = Local> + rustc_data_structures::captures::Captures<'tcx> + 'a {
(1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
Expand Down Expand Up @@ -543,7 +547,7 @@ impl<T> ClearCrossCrate<T> {
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;

impl<'tcx, E: TyEncoder<'tcx>, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
#[inline]
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
if E::CLEAR_CROSS_CRATE {
Expand All @@ -559,7 +563,7 @@ impl<'tcx, E: TyEncoder<'tcx>, T: Encodable<E>> Encodable<E> for ClearCrossCrate
}
}
}
impl<'tcx, D: TyDecoder<'tcx>, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
impl<D: TyDecoder, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
#[inline]
fn decode(d: &mut D) -> Result<ClearCrossCrate<T>, D::Error> {
if D::CLEAR_CROSS_CRATE {
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ich::StableHashingContext;
use crate::mir::interpret::ErrorHandled;
use crate::ty;
use crate::ty::util::{Discr, IntTypeExt};
use crate::ty::TyInterner;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
Expand All @@ -10,10 +11,11 @@ use rustc_errors::ErrorReported;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_index::vec::{Idx, IndexVec};
use rustc_serialize::{self, Encodable, Encoder};
use rustc_serialize::{self, Encodable};
use rustc_session::DataTypeKind;
use rustc_span::symbol::sym;
use rustc_target::abi::VariantIdx;
use rustc_type_ir::codec::TyEncoder;

use std::cell::RefCell;
use std::cmp::Ordering;
Expand Down Expand Up @@ -105,7 +107,13 @@ impl Hash for AdtDef {
}
}

impl<S: Encoder> Encodable<S> for AdtDef {
impl<S: TyEncoder<I = TyInterner<'tcx>>> Encodable<S> for AdtDef {
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
self.did.encode(s)
}
}

impl<S: TyEncoder<I = TyInterner<'tcx>>> Encodable<S> for &AdtDef {
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
self.did.encode(s)
}
Expand Down
Loading