1
Fork 0

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`````
This commit is contained in:
Yuki Okushi 2021-01-28 15:09:02 +09:00 committed by GitHub
commit 446edd1e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 818 additions and 565 deletions

View file

@ -2059,9 +2059,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
match prim_ty {
hir::PrimTy::Bool => tcx.types.bool,
hir::PrimTy::Char => tcx.types.char,
hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)),
hir::PrimTy::Str => tcx.types.str_,
}
}

View file

@ -32,7 +32,6 @@ use super::FnCtxt;
use crate::hir::def_id::DefId;
use crate::type_error_struct;
use rustc_ast as ast;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
@ -660,7 +659,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
(_, Int(Bool)) => Err(CastError::CastToBool),
// * -> Char
(Int(U(ast::UintTy::U8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
(Int(U(ty::UintTy::U8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
(_, Int(Char)) => Err(CastError::CastToChar),
// prim -> float,ptr

View file

@ -372,13 +372,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// in C but we just error out instead and require explicit casts.
let arg_ty = self.structurally_resolved_type(arg.span, arg_ty);
match arg_ty.kind() {
ty::Float(ast::FloatTy::F32) => {
ty::Float(ty::FloatTy::F32) => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_double");
}
ty::Int(ast::IntTy::I8 | ast::IntTy::I16) | ty::Bool => {
ty::Int(ty::IntTy::I8 | ty::IntTy::I16) | ty::Bool => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_int");
}
ty::Uint(ast::UintTy::U8 | ast::UintTy::U16) => {
ty::Uint(ty::UintTy::U8 | ty::UintTy::U16) => {
variadic_error(tcx.sess, arg.span, arg_ty, "c_uint");
}
ty::FnDef(..) => {
@ -407,8 +407,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ast::LitKind::Byte(_) => tcx.types.u8,
ast::LitKind::Char(_) => tcx.types.char,
ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(t),
ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(t),
ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(ty::int_ty(t)),
ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(ty::uint_ty(t)),
ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => {
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
ty::Int(_) | ty::Uint(_) => Some(ty),
@ -419,7 +419,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
opt_ty.unwrap_or_else(|| self.next_int_var())
}
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => tcx.mk_mach_float(t),
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => {
tcx.mk_mach_float(ty::float_ty(t))
}
ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
ty::Float(_) => Some(ty),

View file

@ -8,7 +8,6 @@ use crate::errors::MethodCallOnUnknownType;
use crate::hir::def::DefKind;
use crate::hir::def_id::DefId;
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
@ -662,30 +661,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
ty::Int(i) => {
let lang_def_id = match i {
ast::IntTy::I8 => lang_items.i8_impl(),
ast::IntTy::I16 => lang_items.i16_impl(),
ast::IntTy::I32 => lang_items.i32_impl(),
ast::IntTy::I64 => lang_items.i64_impl(),
ast::IntTy::I128 => lang_items.i128_impl(),
ast::IntTy::Isize => lang_items.isize_impl(),
ty::IntTy::I8 => lang_items.i8_impl(),
ty::IntTy::I16 => lang_items.i16_impl(),
ty::IntTy::I32 => lang_items.i32_impl(),
ty::IntTy::I64 => lang_items.i64_impl(),
ty::IntTy::I128 => lang_items.i128_impl(),
ty::IntTy::Isize => lang_items.isize_impl(),
};
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::Uint(i) => {
let lang_def_id = match i {
ast::UintTy::U8 => lang_items.u8_impl(),
ast::UintTy::U16 => lang_items.u16_impl(),
ast::UintTy::U32 => lang_items.u32_impl(),
ast::UintTy::U64 => lang_items.u64_impl(),
ast::UintTy::U128 => lang_items.u128_impl(),
ast::UintTy::Usize => lang_items.usize_impl(),
ty::UintTy::U8 => lang_items.u8_impl(),
ty::UintTy::U16 => lang_items.u16_impl(),
ty::UintTy::U32 => lang_items.u32_impl(),
ty::UintTy::U64 => lang_items.u64_impl(),
ty::UintTy::U128 => lang_items.u128_impl(),
ty::UintTy::Usize => lang_items.usize_impl(),
};
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::Float(f) => {
let (lang_def_id1, lang_def_id2) = match f {
ast::FloatTy::F32 => (lang_items.f32_impl(), lang_items.f32_runtime_impl()),
ast::FloatTy::F64 => (lang_items.f64_impl(), lang_items.f64_runtime_impl()),
ty::FloatTy::F32 => (lang_items.f32_impl(), lang_items.f32_runtime_impl()),
ty::FloatTy::F64 => (lang_items.f64_impl(), lang_items.f64_runtime_impl()),
};
self.assemble_inherent_impl_for_primitive(lang_def_id1);
self.assemble_inherent_impl_for_primitive(lang_def_id2);

View file

@ -13,7 +13,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
use rustc_ast as ast;
use rustc_span::Span;
/// On-demand query: yields a map containing all types mapped to their inherent impls.
@ -178,7 +177,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::I8) => {
ty::Int(ty::IntTy::I8) => {
self.check_primitive_impl(
def_id,
lang_items.i8_impl(),
@ -189,7 +188,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::I16) => {
ty::Int(ty::IntTy::I16) => {
self.check_primitive_impl(
def_id,
lang_items.i16_impl(),
@ -200,7 +199,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::I32) => {
ty::Int(ty::IntTy::I32) => {
self.check_primitive_impl(
def_id,
lang_items.i32_impl(),
@ -211,7 +210,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::I64) => {
ty::Int(ty::IntTy::I64) => {
self.check_primitive_impl(
def_id,
lang_items.i64_impl(),
@ -222,7 +221,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::I128) => {
ty::Int(ty::IntTy::I128) => {
self.check_primitive_impl(
def_id,
lang_items.i128_impl(),
@ -233,7 +232,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Int(ast::IntTy::Isize) => {
ty::Int(ty::IntTy::Isize) => {
self.check_primitive_impl(
def_id,
lang_items.isize_impl(),
@ -244,7 +243,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::U8) => {
ty::Uint(ty::UintTy::U8) => {
self.check_primitive_impl(
def_id,
lang_items.u8_impl(),
@ -255,7 +254,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::U16) => {
ty::Uint(ty::UintTy::U16) => {
self.check_primitive_impl(
def_id,
lang_items.u16_impl(),
@ -266,7 +265,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::U32) => {
ty::Uint(ty::UintTy::U32) => {
self.check_primitive_impl(
def_id,
lang_items.u32_impl(),
@ -277,7 +276,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::U64) => {
ty::Uint(ty::UintTy::U64) => {
self.check_primitive_impl(
def_id,
lang_items.u64_impl(),
@ -288,7 +287,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::U128) => {
ty::Uint(ty::UintTy::U128) => {
self.check_primitive_impl(
def_id,
lang_items.u128_impl(),
@ -299,7 +298,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Uint(ast::UintTy::Usize) => {
ty::Uint(ty::UintTy::Usize) => {
self.check_primitive_impl(
def_id,
lang_items.usize_impl(),
@ -310,7 +309,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Float(ast::FloatTy::F32) => {
ty::Float(ty::FloatTy::F32) => {
self.check_primitive_impl(
def_id,
lang_items.f32_impl(),
@ -321,7 +320,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
assoc_items,
);
}
ty::Float(ast::FloatTy::F64) => {
ty::Float(ty::FloatTy::F64) => {
self.check_primitive_impl(
def_id,
lang_items.f64_impl(),