Skip to content

Commit 0f06824

Browse files
committed
Auto merge of #97287 - compiler-errors:type-interner, r=jackh726,oli-obk
Move things to `rustc_type_ir` Finishes some work proposed in rust-lang/compiler-team#341. r? `@ghost`
2 parents 303d916 + 4638915 commit 0f06824

File tree

45 files changed

+1732
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1732
-630
lines changed

Cargo.lock

+8
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",
@@ -4262,6 +4265,7 @@ dependencies = [
42624265
"rustc_serialize",
42634266
"rustc_session",
42644267
"rustc_span",
4268+
"rustc_type_ir",
42654269
"tracing",
42664270
]
42674271

@@ -4283,6 +4287,7 @@ dependencies = [
42834287
"rustc_session",
42844288
"rustc_span",
42854289
"rustc_target",
4290+
"rustc_type_ir",
42864291
"smallvec",
42874292
"tracing",
42884293
]
@@ -4472,6 +4477,7 @@ dependencies = [
44724477
"rustc_span",
44734478
"rustc_target",
44744479
"rustc_trait_selection",
4480+
"rustc_type_ir",
44754481
"tracing",
44764482
]
44774483

@@ -4484,6 +4490,7 @@ dependencies = [
44844490
"rustc_index",
44854491
"rustc_macros",
44864492
"rustc_serialize",
4493+
"smallvec",
44874494
]
44884495

44894496
[[package]]
@@ -4509,6 +4516,7 @@ dependencies = [
45094516
"rustc_target",
45104517
"rustc_trait_selection",
45114518
"rustc_ty_utils",
4519+
"rustc_type_ir",
45124520
"smallvec",
45134521
"tracing",
45144522
]

compiler/rustc_borrowck/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ struct Upvar<'tcx> {
9898
by_ref: bool,
9999
}
100100

101-
const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref];
101+
/// Associate some local constants with the `'tcx` lifetime
102+
struct TyCtxtConsts<'tcx>(TyCtxt<'tcx>);
103+
impl<'tcx> TyCtxtConsts<'tcx> {
104+
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
105+
}
102106

103107
pub fn provide(providers: &mut Providers) {
104108
*providers = Providers {
@@ -1443,7 +1447,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14431447
// Thread-locals might be dropped after the function exits
14441448
// We have to dereference the outer reference because
14451449
// borrows don't conflict behind shared references.
1446-
root_place.projection = DEREF_PROJECTION;
1450+
root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
14471451
(true, true)
14481452
} else {
14491453
(false, self.locals_are_invalidated_at_exit)

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
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, 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+
TyCtxt::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

+1
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/cast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_middle::ty::adjustment::PointerCast;
88
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout};
99
use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut};
1010
use rustc_target::abi::{Integer, Variants};
11+
use rustc_type_ir::sty::TyKind::*;
1112

1213
use super::{
1314
util::ensure_monomorphic_enough, FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy,
@@ -102,7 +103,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
102103
src: &ImmTy<'tcx, M::PointerTag>,
103104
cast_ty: Ty<'tcx>,
104105
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
105-
use rustc_middle::ty::TyKind::*;
106+
use rustc_type_ir::sty::TyKind::*;
106107
trace!("Casting {:?}: {:?} to {:?}", *src, src.layout.ty, cast_ty);
107108

108109
match src.layout.ty.kind() {
@@ -205,7 +206,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
205206
let v = scalar.to_bits(src_layout.size)?;
206207
let v = if signed { self.sign_extend(v, src_layout) } else { v };
207208
trace!("cast_from_scalar: {}, {} -> {}", v, src_layout.ty, cast_ty);
208-
use rustc_middle::ty::TyKind::*;
209209

210210
Ok(match *cast_ty.kind() {
211211
Int(_) | Uint(_) => {
@@ -247,7 +247,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
247247
where
248248
F: Float + Into<Scalar<M::PointerTag>> + FloatConvert<Single> + FloatConvert<Double>,
249249
{
250-
use rustc_middle::ty::TyKind::*;
250+
use rustc_type_ir::sty::TyKind::*;
251251
match *dest_ty.kind() {
252252
// float -> uint
253253
Uint(t) => {

compiler/rustc_const_eval/src/interpret/traits.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ 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,
6-
COMMON_VTABLE_ENTRIES_DROPINPLACE, COMMON_VTABLE_ENTRIES_SIZE,
5+
self, Ty, TyCtxt, COMMON_VTABLE_ENTRIES_ALIGN, COMMON_VTABLE_ENTRIES_DROPINPLACE,
6+
COMMON_VTABLE_ENTRIES_SIZE,
77
};
88
use rustc_target::abi::{Align, Size};
99

@@ -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' (`TyCtxt::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(TyCtxt::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(TyCtxt::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

+1
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_lint/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24892489
ty: Ty<'tcx>,
24902490
init: InitKind,
24912491
) -> Option<InitError> {
2492-
use rustc_middle::ty::TyKind::*;
2492+
use rustc_type_ir::sty::TyKind::*;
24932493
match ty.kind() {
24942494
// Primitive types that don't like 0 as a value.
24952495
Ref(..) => Some(("references must be non-null".to_string(), None)),
@@ -2801,7 +2801,7 @@ impl ClashingExternDeclarations {
28012801
true
28022802
} else {
28032803
// Do a full, depth-first comparison between the two.
2804-
use rustc_middle::ty::TyKind::*;
2804+
use rustc_type_ir::sty::TyKind::*;
28052805
let a_kind = a.kind();
28062806
let b_kind = b.kind();
28072807

0 commit comments

Comments
 (0)