Skip to content

Commit 4638915

Browse files
Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir
1 parent f05a92d commit 4638915

File tree

15 files changed

+229
-248
lines changed

15 files changed

+229
-248
lines changed

compiler/rustc_macros/src/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
88
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
99
s.add_impl_generic(parse_quote! { 'tcx });
1010
}
11-
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
11+
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
1212
s.add_bounds(synstructure::AddBounds::Generics);
1313

1414
decodable_body(s, decoder_ty)
@@ -95,7 +95,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
9595
s.add_impl_generic(parse_quote! {'tcx});
9696
}
9797
let encoder_ty = quote! { __E };
98-
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyInterner<'tcx>>});
98+
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
9999
s.add_bounds(synstructure::AddBounds::Generics);
100100

101101
encodable_body(s, encoder_ty, false)

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
2424
use rustc_middle::thir;
2525
use rustc_middle::ty::codec::TyDecoder;
2626
use rustc_middle::ty::fast_reject::SimplifiedType;
27+
use rustc_middle::ty::GeneratorDiagnosticData;
2728
use rustc_middle::ty::{self, ParameterizedOverTcx, Ty, TyCtxt, Visibility};
28-
use rustc_middle::ty::{GeneratorDiagnosticData, TyInterner};
2929
use rustc_serialize::{opaque, Decodable, Decoder};
3030
use rustc_session::cstore::{
3131
CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
@@ -380,11 +380,11 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
380380
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
381381
const CLEAR_CROSS_CRATE: bool = true;
382382

383-
type I = TyInterner<'tcx>;
383+
type I = TyCtxt<'tcx>;
384384

385385
#[inline]
386386
fn interner(&self) -> Self::I {
387-
TyInterner { tcx: self.tcx() }
387+
self.tcx()
388388
}
389389

390390
#[inline]

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::traits::specialization_graph;
2626
use rustc_middle::ty::codec::TyEncoder;
2727
use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams};
2828
use rustc_middle::ty::query::Providers;
29-
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt, TyInterner};
29+
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
3030
use rustc_serialize::{opaque, Encodable, Encoder};
3131
use rustc_session::config::CrateType;
3232
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
@@ -316,7 +316,7 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
316316
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
317317
const CLEAR_CROSS_CRATE: bool = true;
318318

319-
type I = TyInterner<'tcx>;
319+
type I = TyCtxt<'tcx>;
320320

321321
fn position(&self) -> usize {
322322
self.opaque.position()

compiler/rustc_middle/src/mir/interpret/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ use rustc_target::abi::Endian;
115115
use crate::mir;
116116
use crate::ty::codec::{TyDecoder, TyEncoder};
117117
use crate::ty::subst::GenericArgKind;
118-
use crate::ty::{self, Instance, Ty, TyCtxt, TyInterner};
118+
use crate::ty::{self, Instance, Ty, TyCtxt};
119119

120120
pub use self::error::{
121121
struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
@@ -203,7 +203,7 @@ enum AllocDiscriminant {
203203
Static,
204204
}
205205

206-
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyInterner<'tcx>>>(
206+
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>>(
207207
encoder: &mut E,
208208
tcx: TyCtxt<'tcx>,
209209
alloc_id: AllocId,
@@ -277,7 +277,7 @@ impl<'s> AllocDecodingSession<'s> {
277277
/// Decodes an `AllocId` in a thread-safe way.
278278
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
279279
where
280-
D: TyDecoder<I = TyInterner<'tcx>>,
280+
D: TyDecoder<I = TyCtxt<'tcx>>,
281281
{
282282
// Read the index of the allocation.
283283
let idx = usize::try_from(decoder.read_u32()).unwrap();
@@ -305,7 +305,7 @@ impl<'s> AllocDecodingSession<'s> {
305305
AllocDiscriminant::Alloc => {
306306
// If this is an allocation, we need to reserve an
307307
// `AllocId` so we can decode cyclic graphs.
308-
let alloc_id = decoder.interner().tcx.reserve_alloc_id();
308+
let alloc_id = decoder.interner().reserve_alloc_id();
309309
*entry =
310310
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
311311
Some(alloc_id)
@@ -349,23 +349,23 @@ impl<'s> AllocDecodingSession<'s> {
349349
// We already have a reserved `AllocId`.
350350
let alloc_id = alloc_id.unwrap();
351351
trace!("decoded alloc {:?}: {:#?}", alloc_id, alloc);
352-
decoder.interner().tcx.set_alloc_id_same_memory(alloc_id, alloc);
352+
decoder.interner().set_alloc_id_same_memory(alloc_id, alloc);
353353
alloc_id
354354
}
355355
AllocDiscriminant::Fn => {
356356
assert!(alloc_id.is_none());
357357
trace!("creating fn alloc ID");
358358
let instance = ty::Instance::decode(decoder);
359359
trace!("decoded fn alloc instance: {:?}", instance);
360-
let alloc_id = decoder.interner().tcx.create_fn_alloc(instance);
360+
let alloc_id = decoder.interner().create_fn_alloc(instance);
361361
alloc_id
362362
}
363363
AllocDiscriminant::Static => {
364364
assert!(alloc_id.is_none());
365365
trace!("creating extern static alloc ID");
366366
let did = <DefId as Decodable<D>>::decode(decoder);
367367
trace!("decoded static def-ID: {:?}", did);
368-
let alloc_id = decoder.interner().tcx.create_static_alloc(did);
368+
let alloc_id = decoder.interner().create_static_alloc(did);
369369
alloc_id
370370
}
371371
}

0 commit comments

Comments
 (0)