Skip to content

Commit 446edd1

Browse files
authored
Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2 parents 025a850 + e0d64b9 commit 446edd1

File tree

46 files changed

+818
-565
lines changed

Some content is hidden

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

46 files changed

+818
-565
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4345,6 +4345,7 @@ dependencies = [
43454345
"bitflags",
43464346
"rustc_data_structures",
43474347
"rustc_index",
4348+
"rustc_macros",
43484349
"rustc_serialize",
43494350
]
43504351

compiler/rustc_codegen_cranelift/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ mod vtable;
8383
mod prelude {
8484
pub(crate) use std::convert::{TryFrom, TryInto};
8585

86-
pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy};
8786
pub(crate) use rustc_span::Span;
8887

8988
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
9089
pub(crate) use rustc_middle::bug;
9190
pub(crate) use rustc_middle::mir::{self, *};
9291
pub(crate) use rustc_middle::ty::layout::{self, TyAndLayout};
9392
pub(crate) use rustc_middle::ty::{
94-
self, FnSig, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeAndMut, TypeFoldable,
93+
self, FloatTy, FnSig, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, TypeFoldable, UintTy,
9594
};
9695
pub(crate) use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx};
9796

compiler/rustc_codegen_llvm/src/builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
304304
lhs: Self::Value,
305305
rhs: Self::Value,
306306
) -> (Self::Value, Self::Value) {
307-
use rustc_ast::IntTy::*;
308-
use rustc_ast::UintTy::*;
309307
use rustc_middle::ty::{Int, Uint};
308+
use rustc_middle::ty::{IntTy::*, UintTy::*};
310309

311310
let new_kind = match ty.kind() {
312311
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::llvm::debuginfo::{
1818
};
1919
use crate::value::Value;
2020

21-
use rustc_ast as ast;
2221
use rustc_codegen_ssa::traits::*;
2322
use rustc_data_structures::const_cstr;
2423
use rustc_data_structures::fingerprint::Fingerprint;
@@ -830,37 +829,37 @@ trait MsvcBasicName {
830829
fn msvc_basic_name(self) -> &'static str;
831830
}
832831

833-
impl MsvcBasicName for ast::IntTy {
832+
impl MsvcBasicName for ty::IntTy {
834833
fn msvc_basic_name(self) -> &'static str {
835834
match self {
836-
ast::IntTy::Isize => "ptrdiff_t",
837-
ast::IntTy::I8 => "__int8",
838-
ast::IntTy::I16 => "__int16",
839-
ast::IntTy::I32 => "__int32",
840-
ast::IntTy::I64 => "__int64",
841-
ast::IntTy::I128 => "__int128",
835+
ty::IntTy::Isize => "ptrdiff_t",
836+
ty::IntTy::I8 => "__int8",
837+
ty::IntTy::I16 => "__int16",
838+
ty::IntTy::I32 => "__int32",
839+
ty::IntTy::I64 => "__int64",
840+
ty::IntTy::I128 => "__int128",
842841
}
843842
}
844843
}
845844

846-
impl MsvcBasicName for ast::UintTy {
845+
impl MsvcBasicName for ty::UintTy {
847846
fn msvc_basic_name(self) -> &'static str {
848847
match self {
849-
ast::UintTy::Usize => "size_t",
850-
ast::UintTy::U8 => "unsigned __int8",
851-
ast::UintTy::U16 => "unsigned __int16",
852-
ast::UintTy::U32 => "unsigned __int32",
853-
ast::UintTy::U64 => "unsigned __int64",
854-
ast::UintTy::U128 => "unsigned __int128",
848+
ty::UintTy::Usize => "size_t",
849+
ty::UintTy::U8 => "unsigned __int8",
850+
ty::UintTy::U16 => "unsigned __int16",
851+
ty::UintTy::U32 => "unsigned __int32",
852+
ty::UintTy::U64 => "unsigned __int64",
853+
ty::UintTy::U128 => "unsigned __int128",
855854
}
856855
}
857856
}
858857

859-
impl MsvcBasicName for ast::FloatTy {
858+
impl MsvcBasicName for ty::FloatTy {
860859
fn msvc_basic_name(self) -> &'static str {
861860
match self {
862-
ast::FloatTy::F32 => "float",
863-
ast::FloatTy::F64 => "double",
861+
ty::FloatTy::F32 => "float",
862+
ty::FloatTy::F64 => "double",
864863
}
865864
}
866865
}

compiler/rustc_codegen_llvm/src/type_.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ use crate::llvm;
77
use crate::llvm::{Bool, False, True};
88
use crate::type_of::LayoutLlvmExt;
99
use crate::value::Value;
10-
use rustc_ast as ast;
1110
use rustc_codegen_ssa::common::TypeKind;
1211
use rustc_codegen_ssa::traits::*;
1312
use rustc_data_structures::small_c_str::SmallCStr;
1413
use rustc_middle::bug;
1514
use rustc_middle::ty::layout::TyAndLayout;
16-
use rustc_middle::ty::Ty;
15+
use rustc_middle::ty::{self, Ty};
1716
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
1817
use rustc_target::abi::{AddressSpace, Align, Integer, Size};
1918

@@ -80,32 +79,32 @@ impl CodegenCx<'ll, 'tcx> {
8079
self.type_i8()
8180
}
8281

83-
crate fn type_int_from_ty(&self, t: ast::IntTy) -> &'ll Type {
82+
crate fn type_int_from_ty(&self, t: ty::IntTy) -> &'ll Type {
8483
match t {
85-
ast::IntTy::Isize => self.type_isize(),
86-
ast::IntTy::I8 => self.type_i8(),
87-
ast::IntTy::I16 => self.type_i16(),
88-
ast::IntTy::I32 => self.type_i32(),
89-
ast::IntTy::I64 => self.type_i64(),
90-
ast::IntTy::I128 => self.type_i128(),
84+
ty::IntTy::Isize => self.type_isize(),
85+
ty::IntTy::I8 => self.type_i8(),
86+
ty::IntTy::I16 => self.type_i16(),
87+
ty::IntTy::I32 => self.type_i32(),
88+
ty::IntTy::I64 => self.type_i64(),
89+
ty::IntTy::I128 => self.type_i128(),
9190
}
9291
}
9392

94-
crate fn type_uint_from_ty(&self, t: ast::UintTy) -> &'ll Type {
93+
crate fn type_uint_from_ty(&self, t: ty::UintTy) -> &'ll Type {
9594
match t {
96-
ast::UintTy::Usize => self.type_isize(),
97-
ast::UintTy::U8 => self.type_i8(),
98-
ast::UintTy::U16 => self.type_i16(),
99-
ast::UintTy::U32 => self.type_i32(),
100-
ast::UintTy::U64 => self.type_i64(),
101-
ast::UintTy::U128 => self.type_i128(),
95+
ty::UintTy::Usize => self.type_isize(),
96+
ty::UintTy::U8 => self.type_i8(),
97+
ty::UintTy::U16 => self.type_i16(),
98+
ty::UintTy::U32 => self.type_i32(),
99+
ty::UintTy::U64 => self.type_i64(),
100+
ty::UintTy::U128 => self.type_i128(),
102101
}
103102
}
104103

105-
crate fn type_float_from_ty(&self, t: ast::FloatTy) -> &'ll Type {
104+
crate fn type_float_from_ty(&self, t: ty::FloatTy) -> &'ll Type {
106105
match t {
107-
ast::FloatTy::F32 => self.type_f32(),
108-
ast::FloatTy::F64 => self.type_f64(),
106+
ty::FloatTy::F32 => self.type_f32(),
107+
ty::FloatTy::F64 => self.type_f64(),
109108
}
110109
}
111110

compiler/rustc_codegen_ssa/src/mir/block.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -875,20 +875,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
875875
ty::Uint(_) => value.to_string(),
876876
ty::Int(int_ty) => {
877877
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
878-
ast::IntTy::I8 => (value as i8).to_string(),
879-
ast::IntTy::I16 => (value as i16).to_string(),
880-
ast::IntTy::I32 => (value as i32).to_string(),
881-
ast::IntTy::I64 => (value as i64).to_string(),
882-
ast::IntTy::I128 => (value as i128).to_string(),
883-
ast::IntTy::Isize => unreachable!(),
878+
ty::IntTy::I8 => (value as i8).to_string(),
879+
ty::IntTy::I16 => (value as i16).to_string(),
880+
ty::IntTy::I32 => (value as i32).to_string(),
881+
ty::IntTy::I64 => (value as i64).to_string(),
882+
ty::IntTy::I128 => (value as i128).to_string(),
883+
ty::IntTy::Isize => unreachable!(),
884884
}
885885
}
886-
ty::Float(ast::FloatTy::F32) => {
887-
f32::from_bits(value as u32).to_string()
888-
}
889-
ty::Float(ast::FloatTy::F64) => {
890-
f64::from_bits(value as u64).to_string()
891-
}
886+
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
887+
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
892888
_ => span_bug!(span, "asm const has bad type {}", ty),
893889
};
894890
InlineAsmOperandRef::Const { string }

compiler/rustc_infer/src/infer/combine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use super::{InferCtxt, MiscVariable, TypeTrace};
3434

3535
use crate::traits::{Obligation, PredicateObligations};
3636

37-
use rustc_ast as ast;
3837
use rustc_data_structures::sso::SsoHashMap;
3938
use rustc_hir::def_id::DefId;
4039
use rustc_middle::traits::ObligationCause;
@@ -281,7 +280,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
281280
&self,
282281
vid_is_expected: bool,
283282
vid: ty::FloatVid,
284-
val: ast::FloatTy,
283+
val: ty::FloatTy,
285284
) -> RelateResult<'tcx, Ty<'tcx>> {
286285
self.inner
287286
.borrow_mut()

compiler/rustc_lint/src/types.rs

+37-23
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,25 @@ fn lint_overflowing_range_endpoint<'tcx>(
168168

169169
// For `isize` & `usize`, be conservative with the warnings, so that the
170170
// warnings are consistent between 32- and 64-bit platforms.
171-
fn int_ty_range(int_ty: ast::IntTy) -> (i128, i128) {
171+
fn int_ty_range(int_ty: ty::IntTy) -> (i128, i128) {
172172
match int_ty {
173-
ast::IntTy::Isize => (i64::MIN.into(), i64::MAX.into()),
174-
ast::IntTy::I8 => (i8::MIN.into(), i8::MAX.into()),
175-
ast::IntTy::I16 => (i16::MIN.into(), i16::MAX.into()),
176-
ast::IntTy::I32 => (i32::MIN.into(), i32::MAX.into()),
177-
ast::IntTy::I64 => (i64::MIN.into(), i64::MAX.into()),
178-
ast::IntTy::I128 => (i128::MIN, i128::MAX),
173+
ty::IntTy::Isize => (i64::MIN.into(), i64::MAX.into()),
174+
ty::IntTy::I8 => (i8::MIN.into(), i8::MAX.into()),
175+
ty::IntTy::I16 => (i16::MIN.into(), i16::MAX.into()),
176+
ty::IntTy::I32 => (i32::MIN.into(), i32::MAX.into()),
177+
ty::IntTy::I64 => (i64::MIN.into(), i64::MAX.into()),
178+
ty::IntTy::I128 => (i128::MIN, i128::MAX),
179179
}
180180
}
181181

182-
fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) {
182+
fn uint_ty_range(uint_ty: ty::UintTy) -> (u128, u128) {
183183
let max = match uint_ty {
184-
ast::UintTy::Usize => u64::MAX.into(),
185-
ast::UintTy::U8 => u8::MAX.into(),
186-
ast::UintTy::U16 => u16::MAX.into(),
187-
ast::UintTy::U32 => u32::MAX.into(),
188-
ast::UintTy::U64 => u64::MAX.into(),
189-
ast::UintTy::U128 => u128::MAX,
184+
ty::UintTy::Usize => u64::MAX.into(),
185+
ty::UintTy::U8 => u8::MAX.into(),
186+
ty::UintTy::U16 => u16::MAX.into(),
187+
ty::UintTy::U32 => u32::MAX.into(),
188+
ty::UintTy::U64 => u64::MAX.into(),
189+
ty::UintTy::U128 => u128::MAX,
190190
};
191191
(0, max)
192192
}
@@ -258,8 +258,8 @@ fn report_bin_hex_error(
258258
//
259259
// No suggestion for: `isize`, `usize`.
260260
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static str> {
261-
use rustc_ast::IntTy::*;
262-
use rustc_ast::UintTy::*;
261+
use ty::IntTy::*;
262+
use ty::UintTy::*;
263263
macro_rules! find_fit {
264264
($ty:expr, $val:expr, $negative:expr,
265265
$($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => {
@@ -302,7 +302,7 @@ fn lint_int_literal<'tcx>(
302302
type_limits: &TypeLimits,
303303
e: &'tcx hir::Expr<'tcx>,
304304
lit: &hir::Lit,
305-
t: ast::IntTy,
305+
t: ty::IntTy,
306306
v: u128,
307307
) {
308308
let int_type = t.normalize(cx.sess().target.pointer_width);
@@ -314,7 +314,14 @@ fn lint_int_literal<'tcx>(
314314
// avoiding use of -min to prevent overflow/panic
315315
if (negative && v > max + 1) || (!negative && v > max) {
316316
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
317-
report_bin_hex_error(cx, e, attr::IntType::SignedInt(t), repr_str, v, negative);
317+
report_bin_hex_error(
318+
cx,
319+
e,
320+
attr::IntType::SignedInt(ty::ast_int_ty(t)),
321+
repr_str,
322+
v,
323+
negative,
324+
);
318325
return;
319326
}
320327

@@ -351,7 +358,7 @@ fn lint_uint_literal<'tcx>(
351358
cx: &LateContext<'tcx>,
352359
e: &'tcx hir::Expr<'tcx>,
353360
lit: &hir::Lit,
354-
t: ast::UintTy,
361+
t: ty::UintTy,
355362
) {
356363
let uint_type = t.normalize(cx.sess().target.pointer_width);
357364
let (min, max) = uint_ty_range(uint_type);
@@ -391,7 +398,14 @@ fn lint_uint_literal<'tcx>(
391398
}
392399
}
393400
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
394-
report_bin_hex_error(cx, e, attr::IntType::UnsignedInt(t), repr_str, lit_val, false);
401+
report_bin_hex_error(
402+
cx,
403+
e,
404+
attr::IntType::UnsignedInt(ty::ast_uint_ty(t)),
405+
repr_str,
406+
lit_val,
407+
false,
408+
);
395409
return;
396410
}
397411
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
@@ -430,8 +444,8 @@ fn lint_literal<'tcx>(
430444
ty::Float(t) => {
431445
let is_infinite = match lit.node {
432446
ast::LitKind::Float(v, _) => match t {
433-
ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
434-
ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
447+
ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
448+
ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
435449
},
436450
_ => bug!(),
437451
};
@@ -984,7 +998,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
984998
help: Some("consider using `u32` or `libc::wchar_t` instead".into()),
985999
},
9861000

987-
ty::Int(ast::IntTy::I128) | ty::Uint(ast::UintTy::U128) => FfiUnsafe {
1001+
ty::Int(ty::IntTy::I128) | ty::Uint(ty::UintTy::U128) => FfiUnsafe {
9881002
ty,
9891003
reason: "128-bit integers don't currently have a known stable ABI".into(),
9901004
help: None,

0 commit comments

Comments
 (0)