Skip to content

Commit a056a95

Browse files
Initial fixes on top of type interner commit
1 parent a7015fe commit a056a95

File tree

28 files changed

+171
-134
lines changed

28 files changed

+171
-134
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,7 @@ dependencies = [
36763676
"rustc_span",
36773677
"rustc_target",
36783678
"rustc_trait_selection",
3679+
"rustc_type_ir",
36793680
"tracing",
36803681
]
36813682

@@ -3969,6 +3970,7 @@ dependencies = [
39693970
"rustc_span",
39703971
"rustc_target",
39713972
"rustc_trait_selection",
3973+
"rustc_type_ir",
39723974
"tracing",
39733975
"unicode-security",
39743976
]
@@ -4041,6 +4043,7 @@ dependencies = [
40414043
"rustc_session",
40424044
"rustc_span",
40434045
"rustc_target",
4046+
"rustc_type_ir",
40444047
"smallvec",
40454048
"snap",
40464049
"tracing",
@@ -4474,6 +4477,7 @@ dependencies = [
44744477
"rustc_span",
44754478
"rustc_target",
44764479
"rustc_trait_selection",
4480+
"rustc_type_ir",
44774481
"tracing",
44784482
]
44794483

@@ -4512,6 +4516,7 @@ dependencies = [
45124516
"rustc_target",
45134517
"rustc_trait_selection",
45144518
"rustc_ty_utils",
4519+
"rustc_type_ir",
45154520
"smallvec",
45164521
"tracing",
45174522
]

compiler/rustc_borrowck/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ struct Upvar<'tcx> {
9898
by_ref: bool,
9999
}
100100

101-
const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref];
101+
const fn deref_projection<'tcx>() -> &'tcx [PlaceElem<'tcx>; 1] {
102+
&[ProjectionElem::Deref]
103+
}
102104

103105
pub fn provide(providers: &mut Providers) {
104106
*providers = Providers {
@@ -1443,7 +1445,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14431445
// Thread-locals might be dropped after the function exits
14441446
// We have to dereference the outer reference because
14451447
// borrows don't conflict behind shared references.
1446-
root_place.projection = DEREF_PROJECTION;
1448+
root_place.projection = deref_projection();
14471449
(true, true)
14481450
} else {
14491451
(false, self.locals_are_invalidated_at_exit)

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_middle::mir::{self, GeneratorLayout};
3333
use rustc_middle::ty::layout::LayoutOf;
3434
use rustc_middle::ty::layout::TyAndLayout;
3535
use rustc_middle::ty::subst::GenericArgKind;
36-
use rustc_middle::ty::{self, AdtKind, Instance, ParamEnv, Ty, TyCtxt, COMMON_VTABLE_ENTRIES};
36+
use rustc_middle::ty::{self, common_vtable_entries, AdtKind, Instance, ParamEnv, Ty, TyCtxt};
3737
use rustc_session::config::{self, DebugInfo};
3838
use rustc_span::symbol::Symbol;
3939
use rustc_span::FileName;
@@ -1392,7 +1392,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
13921392

13931393
tcx.vtable_entries(trait_ref)
13941394
} else {
1395-
COMMON_VTABLE_ENTRIES
1395+
common_vtable_entries()
13961396
};
13971397

13981398
// All function pointers are described as opaque pointers. This could be improved in the future

compiler/rustc_const_eval/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ rustc_session = { path = "../rustc_session" }
2424
rustc_target = { path = "../rustc_target" }
2525
rustc_trait_selection = { path = "../rustc_trait_selection" }
2626
rustc_span = { path = "../rustc_span" }
27+
rustc_type_ir = { path = "../rustc_type_ir" }

compiler/rustc_const_eval/src/interpret/traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::convert::TryFrom;
22

33
use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic};
44
use rustc_middle::ty::{
5-
self, Ty, COMMON_VTABLE_ENTRIES, COMMON_VTABLE_ENTRIES_ALIGN,
5+
self, common_vtable_entries, Ty, COMMON_VTABLE_ENTRIES_ALIGN,
66
COMMON_VTABLE_ENTRIES_DROPINPLACE, COMMON_VTABLE_ENTRIES_SIZE,
77
};
88
use rustc_target::abi::{Align, Size};
@@ -38,7 +38,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3838
}
3939

4040
/// Resolves the function at the specified slot in the provided
41-
/// vtable. Currently an index of '3' (`COMMON_VTABLE_ENTRIES.len()`)
41+
/// vtable. Currently an index of '3' (`common_vtable_entries().len()`)
4242
/// corresponds to the first method declared in the trait of the provided vtable.
4343
pub fn get_vtable_slot(
4444
&self,
@@ -64,7 +64,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6464
let vtable = self
6565
.get_ptr_alloc(
6666
vtable,
67-
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES.len()).unwrap(),
67+
pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
6868
self.tcx.data_layout.pointer_align.abi,
6969
)?
7070
.expect("cannot be a ZST");
@@ -99,7 +99,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9999
let vtable = self
100100
.get_ptr_alloc(
101101
vtable,
102-
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES.len()).unwrap(),
102+
pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
103103
self.tcx.data_layout.pointer_align.abi,
104104
)?
105105
.expect("cannot be a ZST");

compiler/rustc_lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ rustc_session = { path = "../rustc_session" }
2121
rustc_trait_selection = { path = "../rustc_trait_selection" }
2222
rustc_parse_format = { path = "../rustc_parse_format" }
2323
rustc_infer = { path = "../rustc_infer" }
24+
rustc_type_ir = { path = "../rustc_type_ir" }

compiler/rustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ rustc_ast = { path = "../rustc_ast" }
2727
rustc_expand = { path = "../rustc_expand" }
2828
rustc_span = { path = "../rustc_span" }
2929
rustc_session = { path = "../rustc_session" }
30+
rustc_type_ir = { path = "../rustc_type_ir" }

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 6 additions & 5 deletions
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;
2827
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,
@@ -377,12 +377,13 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
377377
}
378378
}
379379

380-
impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
380+
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
381381
const CLEAR_CROSS_CRATE: bool = true;
382382

383-
#[inline]
384-
fn tcx(&self) -> TyCtxt<'tcx> {
385-
self.tcx.expect("missing TyCtxt in DecodeContext")
383+
type I = TyInterner<'tcx>;
384+
385+
fn interner(&self) -> Self::I {
386+
TyInterner { tcx: self.tcx() }
386387
}
387388

388389
#[inline]

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 2 deletions
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};
29+
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt, TyInterner};
3030
use rustc_serialize::{opaque, Encodable, Encoder};
3131
use rustc_session::config::CrateType;
3232
use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib};
@@ -313,9 +313,11 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
313313
}
314314
}
315315

316-
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
316+
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
317317
const CLEAR_CROSS_CRATE: bool = true;
318318

319+
type I = TyInterner<'tcx>;
320+
319321
fn position(&self) -> usize {
320322
self.opaque.position()
321323
}

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::traits;
1717
use crate::ty::subst::SubstsRef;
1818
use crate::ty::{self, AdtDef, Ty};
1919
use rustc_data_structures::fx::FxHashMap;
20-
use rustc_serialize::{Decodable, Encodable};
2120
use rustc_middle::ty::TyInterner;
21+
use rustc_serialize::{Decodable, Encodable};
2222
use rustc_span::Span;
2323
pub use rustc_type_ir::{TyDecoder, TyEncoder};
2424
use std::hash::Hash;
@@ -165,25 +165,6 @@ impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for AllocId {
165165
}
166166
}
167167

168-
macro_rules! encodable_via_deref {
169-
($($t:ty),+) => {
170-
$(impl<'tcx, E: TyEncoder<I = TyInterner<'tcx>>> Encodable<E> for $t {
171-
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
172-
(**self).encode(e)
173-
}
174-
})*
175-
}
176-
}
177-
178-
encodable_via_deref! {
179-
&'tcx ty::TypeckResults<'tcx>,
180-
&'tcx traits::ImplSource<'tcx, ()>,
181-
&'tcx mir::Body<'tcx>,
182-
&'tcx mir::UnsafetyCheckResult,
183-
&'tcx mir::BorrowCheckResult<'tcx>,
184-
&'tcx mir::coverage::CodeRegion
185-
}
186-
187168
#[inline]
188169
fn decode_arena_allocable<
189170
'tcx,
@@ -231,7 +212,9 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for Ty<'tcx> {
231212
}
232213
}
233214

234-
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
215+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D>
216+
for ty::Binder<'tcx, ty::PredicateKind<'tcx>>
217+
{
235218
fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
236219
let bound_vars = Decodable::decode(decoder);
237220
// Handle shorthands first, if we have a usize > 0x80.
@@ -318,7 +301,10 @@ macro_rules! impl_decodable_via_ref {
318301
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
319302
fn decode(decoder: &mut D) -> &'tcx Self {
320303
let len = decoder.read_usize();
321-
decoder.interner().tcx.mk_type_list((0..len).map::<Ty<'tcx>, _>(|_| Decodable::decode(decoder)))
304+
decoder
305+
.interner()
306+
.tcx
307+
.mk_type_list((0..len).map::<Ty<'tcx>, _>(|_| Decodable::decode(decoder)))
322308
}
323309
}
324310

@@ -359,31 +345,39 @@ impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> Decodable<D> for AdtDef<'tcx> {
359345
}
360346
}
361347

362-
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [(ty::Predicate<'tcx>, Span)] {
348+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
349+
for [(ty::Predicate<'tcx>, Span)]
350+
{
363351
fn decode(decoder: &mut D) -> &'tcx Self {
364352
decoder.interner().tcx.arena.alloc_from_iter(
365353
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
366354
)
367355
}
368356
}
369357

370-
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::abstract_const::Node<'tcx>] {
358+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
359+
for [thir::abstract_const::Node<'tcx>]
360+
{
371361
fn decode(decoder: &mut D) -> &'tcx Self {
372362
decoder.interner().tcx.arena.alloc_from_iter(
373363
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
374364
)
375365
}
376366
}
377367

378-
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [thir::abstract_const::NodeId] {
368+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
369+
for [thir::abstract_const::NodeId]
370+
{
379371
fn decode(decoder: &mut D) -> &'tcx Self {
380372
decoder.interner().tcx.arena.alloc_from_iter(
381373
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
382374
)
383375
}
384376
}
385377

386-
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
378+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D>
379+
for ty::List<ty::BoundVariableKind>
380+
{
387381
fn decode(decoder: &mut D) -> &'tcx Self {
388382
let len = decoder.read_usize();
389383
decoder.interner().tcx.mk_bound_variable_kinds(
@@ -449,17 +443,17 @@ arena_types!(impl_arena_allocatable_decoders);
449443

450444
macro_rules! impl_arena_copy_decoder {
451445
(<$tcx:tt> $($ty:ty,)*) => {
452-
$(impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for $ty {
446+
$(impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for $ty {
453447
#[inline]
454448
fn decode(decoder: &mut D) -> &'tcx Self {
455-
decoder.tcx().arena.alloc(Decodable::decode(decoder))
449+
decoder.interner().tcx.arena.alloc(Decodable::decode(decoder))
456450
}
457451
}
458452

459-
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [$ty] {
453+
impl<'tcx, D: TyDecoder<I = TyInterner<'tcx>>> RefDecodable<'tcx, D> for [$ty] {
460454
#[inline]
461455
fn decode(decoder: &mut D) -> &'tcx Self {
462-
decoder.tcx().arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
456+
decoder.interner().tcx.arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))
463457
}
464458
})*
465459
};

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::mir::interpret::ConstValue;
22
use crate::mir::interpret::{LitToConstInput, Scalar};
33
use crate::ty::{
44
self, InlineConstSubsts, InlineConstSubstsParts, InternalSubsts, ParamEnv, ParamEnvAnd, Ty,
5-
TyCtxt, TyInterner, TypeFoldable,
5+
TyCtxt, TypeFoldable,
66
};
77
use rustc_data_structures::intern::Interned;
88
use rustc_errors::ErrorGuaranteed;
@@ -40,14 +40,6 @@ pub struct ConstS<'tcx> {
4040
pub val: ConstKind<'tcx>,
4141
}
4242

43-
impl<'tcx, S: rustc_type_ir::TyEncoder<I = TyInterner<'tcx>>> rustc_serialize::Encodable<S>
44-
for &'_ Const<'_>
45-
{
46-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
47-
(*self).encode(s)
48-
}
49-
}
50-
5143
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
5244
static_assert_size!(ConstS<'_>, 48);
5345

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ macro_rules! nop_lift {
17441744
impl<'a, 'tcx> Lift<'tcx> for $ty {
17451745
type Lifted = $lifted;
17461746
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1747-
if tcx.interners.$set.contains_pointer_to(&InternedInSet(self.0.0)) {
1747+
if tcx.interners.$set.contains_pointer_to(&InternedInSet(&*self.0.0)) {
17481748
// SAFETY: `self` is interned and therefore valid
17491749
// for the entire lifetime of the `TyCtxt`.
17501750
Some(unsafe { mem::transmute(self) })

0 commit comments

Comments
 (0)