Update chalk 0.32.0 -> 0.35.0

This commit is contained in:
Matthew Jasper 2020-10-28 19:57:56 +00:00
parent 1f5c655d0c
commit 299a65ff71
7 changed files with 214 additions and 304 deletions

View File

@ -460,9 +460,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chalk-derive"
version = "0.32.0"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d072b2ba723f0bada7c515d8b3725224bc4f5052d2a92dcbeb0b118ff37084a"
checksum = "bc6d2895e93c0939074a7a0f525fd549b49da8362dea3def555e4aab95ff64cd"
dependencies = [
"proc-macro2",
"quote",
@ -472,9 +472,9 @@ dependencies = [
[[package]]
name = "chalk-engine"
version = "0.32.0"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb5475f6083d6d6c509e1c335c4f69ad04144ac090faa1afb134a53c3695841"
checksum = "93ed23c35d243ccc2caeae7ba4660a091e74b11c40e441d7849f07d8e71b5cb8"
dependencies = [
"chalk-derive",
"chalk-ir",
@ -485,9 +485,9 @@ dependencies = [
[[package]]
name = "chalk-ir"
version = "0.32.0"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60cdb0e18c5455cb6a85e8464aad3622b70476018edfa8845691df66f7e9a05"
checksum = "40d7f6140cccc889117e7372b6f9cfbc8103c86a1a0269ff6ab868f20ab414d6"
dependencies = [
"chalk-derive",
"lazy_static",
@ -495,9 +495,9 @@ dependencies = [
[[package]]
name = "chalk-solve"
version = "0.32.0"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "981534d499a8476ecc0b520be4d3864757f96211826a75360fbf2cb6fae362ab"
checksum = "fa65b636e64cbfcba31f053da97c32f3e15f2670b3cc620b84231a1656d754ec"
dependencies = [
"chalk-derive",
"chalk-ir",

View File

@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.32.0"
chalk-ir = "0.35.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "9.0.0"
rustc_session = { path = "../rustc_session" }

View File

@ -102,48 +102,6 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
Some(write())
}
fn debug_application_ty(
application_ty: &chalk_ir::ApplicationTy<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
match application_ty.name {
chalk_ir::TypeName::Ref(mutbl) => {
let data = application_ty.substitution.interned();
match (&**data[0].interned(), &**data[1].interned()) {
(
chalk_ir::GenericArgData::Lifetime(lifetime),
chalk_ir::GenericArgData::Ty(ty),
) => Some(match mutbl {
chalk_ir::Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty),
chalk_ir::Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty),
}),
_ => unreachable!(),
}
}
chalk_ir::TypeName::Array => {
let data = application_ty.substitution.interned();
match (&**data[0].interned(), &**data[1].interned()) {
(chalk_ir::GenericArgData::Ty(ty), chalk_ir::GenericArgData::Const(len)) => {
Some(write!(fmt, "[{:?}; {:?}]", ty, len))
}
_ => unreachable!(),
}
}
chalk_ir::TypeName::Slice => {
let data = application_ty.substitution.interned();
let ty = match &**data[0].interned() {
chalk_ir::GenericArgData::Ty(t) => t,
_ => unreachable!(),
};
Some(write!(fmt, "[{:?}]", ty))
}
_ => {
let chalk_ir::ApplicationTy { name, substitution } = application_ty;
Some(write!(fmt, "{:?}{:?}", name, chalk_ir::debug::Angle(substitution.interned())))
}
}
}
fn debug_substitution(
substitution: &chalk_ir::Substitution<Self>,
fmt: &mut fmt::Formatter<'_>,
@ -174,6 +132,32 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
Some(write!(fmt, "{:?}", clauses.interned()))
}
fn debug_ty(ty: &chalk_ir::Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
match &ty.interned().kind {
chalk_ir::TyKind::Ref(chalk_ir::Mutability::Not, lifetime, ty) => {
Some(write!(fmt, "(&{:?} {:?})", lifetime, ty))
}
chalk_ir::TyKind::Ref(chalk_ir::Mutability::Mut, lifetime, ty) => {
Some(write!(fmt, "(&{:?} mut {:?})", lifetime, ty))
}
chalk_ir::TyKind::Array(ty, len) => Some(write!(fmt, "[{:?}; {:?}]", ty, len)),
chalk_ir::TyKind::Slice(ty) => Some(write!(fmt, "[{:?}]", ty)),
chalk_ir::TyKind::Tuple(len, substs) => Some((|| {
write!(fmt, "(")?;
for (idx, substitution) in substs.interned().iter().enumerate() {
if idx == *len && *len != 1 {
// Don't add a trailing comma if the tuple has more than one element
write!(fmt, "{:?}", substitution)?;
} else {
write!(fmt, "{:?},", substitution)?;
}
}
write!(fmt, ")")
})()),
_ => None,
}
}
fn debug_alias(
alias_ty: &chalk_ir::AliasTy<Self>,
fmt: &mut fmt::Formatter<'_>,

View File

@ -12,9 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.32.0"
chalk-solve = "0.32.0"
chalk-engine = "0.32.0"
chalk-ir = "0.35.0"
chalk-solve = "0.35.0"
chalk-engine = "0.35.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../rustc_infer" }
rustc_trait_selection = { path = "../rustc_trait_selection" }

View File

@ -324,19 +324,19 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn impl_provided_for(
&self,
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
app_ty: &chalk_ir::ApplicationTy<RustInterner<'tcx>>,
chalk_ty: &chalk_ir::TyKind<RustInterner<'tcx>>,
) -> bool {
use chalk_ir::Scalar::*;
use chalk_ir::TypeName::*;
use chalk_ir::TyKind::*;
let trait_def_id = auto_trait_id.0;
let all_impls = self.interner.tcx.all_impls(trait_def_id);
for impl_def_id in all_impls {
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
let self_ty = trait_ref.self_ty();
let provides = match (self_ty.kind(), app_ty.name) {
(&ty::Adt(impl_adt_def, ..), Adt(id)) => impl_adt_def.did == id.0.did,
(_, AssociatedType(_ty_id)) => {
let provides = match (self_ty.kind(), chalk_ty) {
(&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did == id.0.did,
(_, AssociatedType(_ty_id, ..)) => {
// FIXME(chalk): See https://github.com/rust-lang/rust/pull/77152#discussion_r494484774
false
}
@ -365,10 +365,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
(ast::FloatTy::F32, chalk_ir::FloatTy::F32)
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64)
),
(&ty::Tuple(..), Tuple(..)) => true,
(&ty::Array(..), Array) => true,
(&ty::Slice(..), Slice) => true,
(&ty::RawPtr(type_and_mut), Raw(mutability)) => {
(&ty::Tuple(substs), Tuple(len, _)) => substs.len() == *len,
(&ty::Array(..), Array(..)) => true,
(&ty::Slice(..), Slice(..)) => true,
(&ty::RawPtr(type_and_mut), Raw(mutability, _)) => {
match (type_and_mut.mutbl, mutability) {
(ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
(ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
@ -376,17 +376,19 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
}
}
(&ty::Ref(.., mutability1), Ref(mutability2)) => match (mutability1, mutability2) {
(ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
(ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
(ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
},
(&ty::Opaque(def_id, ..), OpaqueType(opaque_ty_id)) => def_id == opaque_ty_id.0,
(&ty::FnDef(def_id, ..), FnDef(fn_def_id)) => def_id == fn_def_id.0,
(&ty::Ref(.., mutability1), Ref(mutability2, ..)) => {
match (mutability1, mutability2) {
(ast::Mutability::Mut, chalk_ir::Mutability::Mut) => true,
(ast::Mutability::Mut, chalk_ir::Mutability::Not) => false,
(ast::Mutability::Not, chalk_ir::Mutability::Mut) => false,
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
}
}
(&ty::Opaque(def_id, ..), OpaqueType(opaque_ty_id, ..)) => def_id == opaque_ty_id.0,
(&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0,
(&ty::Str, Str) => true,
(&ty::Never, Never) => true,
(&ty::Closure(def_id, ..), Closure(closure_id)) => def_id == closure_id.0,
(&ty::Closure(def_id, ..), Closure(closure_id, _)) => def_id == closure_id.0,
(&ty::Foreign(def_id), Foreign(foreign_def_id)) => def_id == foreign_def_id.0,
(&ty::Error(..), Error) => false,
_ => false,
@ -506,17 +508,11 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
substs: &chalk_ir::Substitution<RustInterner<'tcx>>,
) -> chalk_solve::rust_ir::ClosureKind {
let kind = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 3];
match kind.assert_ty_ref(&self.interner).data(&self.interner) {
chalk_ir::TyData::Apply(apply) => match apply.name {
chalk_ir::TypeName::Scalar(scalar) => match scalar {
chalk_ir::Scalar::Int(int_ty) => match int_ty {
chalk_ir::IntTy::I8 => chalk_solve::rust_ir::ClosureKind::Fn,
chalk_ir::IntTy::I16 => chalk_solve::rust_ir::ClosureKind::FnMut,
chalk_ir::IntTy::I32 => chalk_solve::rust_ir::ClosureKind::FnOnce,
_ => bug!("bad closure kind"),
},
_ => bug!("bad closure kind"),
},
match kind.assert_ty_ref(&self.interner).kind(&self.interner) {
chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(int_ty)) => match int_ty {
chalk_ir::IntTy::I8 => chalk_solve::rust_ir::ClosureKind::Fn,
chalk_ir::IntTy::I16 => chalk_solve::rust_ir::ClosureKind::FnMut,
chalk_ir::IntTy::I32 => chalk_solve::rust_ir::ClosureKind::FnOnce,
_ => bug!("bad closure kind"),
},
_ => bug!("bad closure kind"),
@ -530,23 +526,19 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
) -> chalk_ir::Binders<chalk_solve::rust_ir::FnDefInputsAndOutputDatum<RustInterner<'tcx>>>
{
let sig = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 2];
match sig.assert_ty_ref(&self.interner).data(&self.interner) {
chalk_ir::TyData::Function(f) => {
match sig.assert_ty_ref(&self.interner).kind(&self.interner) {
chalk_ir::TyKind::Function(f) => {
let substitution = f.substitution.as_slice(&self.interner);
let return_type =
substitution.last().unwrap().assert_ty_ref(&self.interner).clone();
// Closure arguments are tupled
let argument_tuple = substitution[0].assert_ty_ref(&self.interner);
let argument_types = match argument_tuple.data(&self.interner) {
chalk_ir::TyData::Apply(apply) => match apply.name {
chalk_ir::TypeName::Tuple(_) => apply
.substitution
.iter(&self.interner)
.map(|arg| arg.assert_ty_ref(&self.interner))
.cloned()
.collect(),
_ => bug!("Expecting closure FnSig args to be tupled."),
},
let argument_types = match argument_tuple.kind(&self.interner) {
chalk_ir::TyKind::Tuple(_len, substitution) => substitution
.iter(&self.interner)
.map(|arg| arg.assert_ty_ref(&self.interner))
.cloned()
.collect(),
_ => bug!("Expecting closure FnSig args to be tupled."),
};
@ -637,7 +629,7 @@ fn binders_for<'tcx>(
bound_vars.iter().map(|arg| match arg.unpack() {
ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::VariableKind::Lifetime,
ty::subst::GenericArgKind::Type(_ty) => {
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)
}
ty::subst::GenericArgKind::Const(c) => {
chalk_ir::VariableKind::Const(c.ty.lower_into(interner))

View File

@ -35,7 +35,7 @@ use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInt
use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{
self, Binder, BoundRegion, Region, RegionKind, Ty, TyCtxt, TyKind, TypeFoldable, TypeVisitor,
self, Binder, BoundRegion, Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor,
};
use rustc_span::def_id::DefId;
@ -239,24 +239,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::AliasEq<RustInterner<'tcx>>>
impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Ty<RustInterner<'tcx>> {
use chalk_ir::TyData;
use rustc_ast as ast;
use TyKind::*;
let empty = || chalk_ir::Substitution::empty(interner);
let struct_ty =
|def_id| chalk_ir::TypeName::Adt(chalk_ir::AdtId(interner.tcx.adt_def(def_id)));
let apply = |name, substitution| {
TyData::Apply(chalk_ir::ApplicationTy { name, substitution }).intern(interner)
};
let int = |i| apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Int(i)), empty());
let uint = |i| apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Uint(i)), empty());
let float = |f| apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Float(f)), empty());
let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i));
let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i));
let float = |f| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Float(f));
match *self.kind() {
Bool => apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Bool), empty()),
Char => apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Char), empty()),
Int(ty) => match ty {
ty::Bool => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Bool),
ty::Char => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Char),
ty::Int(ty) => match ty {
ast::IntTy::Isize => int(chalk_ir::IntTy::Isize),
ast::IntTy::I8 => int(chalk_ir::IntTy::I8),
ast::IntTy::I16 => int(chalk_ir::IntTy::I16),
@ -264,7 +256,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
ast::IntTy::I64 => int(chalk_ir::IntTy::I64),
ast::IntTy::I128 => int(chalk_ir::IntTy::I128),
},
Uint(ty) => match ty {
ty::Uint(ty) => match ty {
ast::UintTy::Usize => uint(chalk_ir::UintTy::Usize),
ast::UintTy::U8 => uint(chalk_ir::UintTy::U8),
ast::UintTy::U16 => uint(chalk_ir::UintTy::U16),
@ -272,80 +264,47 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
ast::UintTy::U64 => uint(chalk_ir::UintTy::U64),
ast::UintTy::U128 => uint(chalk_ir::UintTy::U128),
},
Float(ty) => match ty {
ty::Float(ty) => match ty {
ast::FloatTy::F32 => float(chalk_ir::FloatTy::F32),
ast::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
},
Adt(def, substs) => apply(struct_ty(def.did), substs.lower_into(interner)),
Foreign(def_id) => apply(chalk_ir::TypeName::Foreign(ForeignDefId(def_id)), empty()),
Str => apply(chalk_ir::TypeName::Str, empty()),
Array(ty, len) => {
let value = match len.val {
ty::ConstKind::Value(val) => {
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val })
}
ty::ConstKind::Bound(db, bound) => {
chalk_ir::ConstValue::BoundVar(chalk_ir::BoundVar::new(
chalk_ir::DebruijnIndex::new(db.as_u32()),
bound.index(),
))
}
_ => unimplemented!("Const not implemented. {:?}", len.val),
};
apply(
chalk_ir::TypeName::Array,
chalk_ir::Substitution::from_iter(
interner,
&[
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
chalk_ir::GenericArgData::Const(
chalk_ir::ConstData { ty: len.ty.lower_into(interner), value }
.intern(interner),
)
.intern(interner),
],
),
)
ty::Adt(def, substs) => {
chalk_ir::TyKind::Adt(chalk_ir::AdtId(def), substs.lower_into(interner))
}
Slice(ty) => apply(
chalk_ir::TypeName::Slice,
chalk_ir::Substitution::from1(
interner,
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
ty::Foreign(def_id) => chalk_ir::TyKind::Foreign(ForeignDefId(def_id)),
ty::Str => chalk_ir::TyKind::Str,
ty::Array(ty, len) => {
chalk_ir::TyKind::Array(ty.lower_into(interner), len.lower_into(interner))
}
ty::Slice(ty) => chalk_ir::TyKind::Slice(ty.lower_into(interner)),
ty::RawPtr(ptr) => match ptr.mutbl {
ast::Mutability::Mut => {
chalk_ir::TyKind::Raw(chalk_ir::Mutability::Mut, ptr.ty.lower_into(interner))
}
ast::Mutability::Not => {
chalk_ir::TyKind::Raw(chalk_ir::Mutability::Not, ptr.ty.lower_into(interner))
}
},
ty::Ref(region, ty, mutability) => match mutability {
ast::Mutability::Mut => chalk_ir::TyKind::Ref(
chalk_ir::Mutability::Mut,
region.lower_into(interner),
ty.lower_into(interner),
),
),
RawPtr(ptr) => {
let name = match ptr.mutbl {
ast::Mutability::Mut => chalk_ir::TypeName::Raw(chalk_ir::Mutability::Mut),
ast::Mutability::Not => chalk_ir::TypeName::Raw(chalk_ir::Mutability::Not),
};
apply(name, chalk_ir::Substitution::from1(interner, ptr.ty.lower_into(interner)))
ast::Mutability::Not => chalk_ir::TyKind::Ref(
chalk_ir::Mutability::Not,
region.lower_into(interner),
ty.lower_into(interner),
),
},
ty::FnDef(def_id, substs) => {
chalk_ir::TyKind::FnDef(chalk_ir::FnDefId(def_id), substs.lower_into(interner))
}
Ref(region, ty, mutability) => {
let name = match mutability {
ast::Mutability::Mut => chalk_ir::TypeName::Ref(chalk_ir::Mutability::Mut),
ast::Mutability::Not => chalk_ir::TypeName::Ref(chalk_ir::Mutability::Not),
};
apply(
name,
chalk_ir::Substitution::from_iter(
interner,
&[
chalk_ir::GenericArgData::Lifetime(region.lower_into(interner))
.intern(interner),
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
],
),
)
}
FnDef(def_id, substs) => apply(
chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(def_id)),
substs.lower_into(interner),
),
FnPtr(sig) => {
ty::FnPtr(sig) => {
let (inputs_and_outputs, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
TyData::Function(chalk_ir::FnPointer {
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
num_binders: binders.len(interner),
sig: sig.lower_into(interner),
substitution: chalk_ir::Substitution::from_iter(
@ -355,148 +314,122 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
}),
),
})
.intern(interner)
}
Dynamic(predicates, region) => TyData::Dyn(chalk_ir::DynTy {
ty::Dynamic(predicates, region) => chalk_ir::TyKind::Dyn(chalk_ir::DynTy {
bounds: predicates.lower_into(interner),
lifetime: region.lower_into(interner),
})
.intern(interner),
Closure(def_id, substs) => apply(
chalk_ir::TypeName::Closure(chalk_ir::ClosureId(def_id)),
substs.lower_into(interner),
),
Generator(_def_id, _substs, _) => unimplemented!(),
GeneratorWitness(_) => unimplemented!(),
Never => apply(chalk_ir::TypeName::Never, empty()),
Tuple(substs) => {
apply(chalk_ir::TypeName::Tuple(substs.len()), substs.lower_into(interner))
}),
ty::Closure(def_id, substs) => {
chalk_ir::TyKind::Closure(chalk_ir::ClosureId(def_id), substs.lower_into(interner))
}
Projection(proj) => TyData::Alias(proj.lower_into(interner)).intern(interner),
Opaque(def_id, substs) => {
TyData::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
ty::Generator(_def_id, _substs, _) => unimplemented!(),
ty::GeneratorWitness(_) => unimplemented!(),
ty::Never => chalk_ir::TyKind::Never,
ty::Tuple(substs) => chalk_ir::TyKind::Tuple(substs.len(), substs.lower_into(interner)),
ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)),
ty::Opaque(def_id, substs) => {
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
opaque_ty_id: chalk_ir::OpaqueTyId(def_id),
substitution: substs.lower_into(interner),
}))
.intern(interner)
}
// This should have been done eagerly prior to this, and all Params
// should have been substituted to placeholders
Param(_) => panic!("Lowering Param when not expected."),
Bound(db, bound) => TyData::BoundVar(chalk_ir::BoundVar::new(
ty::Param(_) => panic!("Lowering Param when not expected."),
ty::Bound(db, bound) => chalk_ir::TyKind::BoundVar(chalk_ir::BoundVar::new(
chalk_ir::DebruijnIndex::new(db.as_u32()),
bound.var.index(),
))
.intern(interner),
Placeholder(_placeholder) => TyData::Placeholder(chalk_ir::PlaceholderIndex {
ui: chalk_ir::UniverseIndex { counter: _placeholder.universe.as_usize() },
idx: _placeholder.name.as_usize(),
})
.intern(interner),
Infer(_infer) => unimplemented!(),
Error(_) => apply(chalk_ir::TypeName::Error, empty()),
)),
ty::Placeholder(_placeholder) => {
chalk_ir::TyKind::Placeholder(chalk_ir::PlaceholderIndex {
ui: chalk_ir::UniverseIndex { counter: _placeholder.universe.as_usize() },
idx: _placeholder.name.as_usize(),
})
}
ty::Infer(_infer) => unimplemented!(),
ty::Error(_) => chalk_ir::TyKind::Error,
}
.intern(interner)
}
}
impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> Ty<'tcx> {
use chalk_ir::TyData;
use chalk_ir::TyKind;
use rustc_ast::ast;
let kind = match self.data(interner) {
TyData::Apply(application_ty) => match application_ty.name {
chalk_ir::TypeName::Adt(struct_id) => {
ty::Adt(struct_id.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Scalar(scalar) => match scalar {
chalk_ir::Scalar::Bool => ty::Bool,
chalk_ir::Scalar::Char => ty::Char,
chalk_ir::Scalar::Int(int_ty) => match int_ty {
chalk_ir::IntTy::Isize => ty::Int(ast::IntTy::Isize),
chalk_ir::IntTy::I8 => ty::Int(ast::IntTy::I8),
chalk_ir::IntTy::I16 => ty::Int(ast::IntTy::I16),
chalk_ir::IntTy::I32 => ty::Int(ast::IntTy::I32),
chalk_ir::IntTy::I64 => ty::Int(ast::IntTy::I64),
chalk_ir::IntTy::I128 => ty::Int(ast::IntTy::I128),
},
chalk_ir::Scalar::Uint(int_ty) => match int_ty {
chalk_ir::UintTy::Usize => ty::Uint(ast::UintTy::Usize),
chalk_ir::UintTy::U8 => ty::Uint(ast::UintTy::U8),
chalk_ir::UintTy::U16 => ty::Uint(ast::UintTy::U16),
chalk_ir::UintTy::U32 => ty::Uint(ast::UintTy::U32),
chalk_ir::UintTy::U64 => ty::Uint(ast::UintTy::U64),
chalk_ir::UintTy::U128 => ty::Uint(ast::UintTy::U128),
},
chalk_ir::Scalar::Float(float_ty) => match float_ty {
chalk_ir::FloatTy::F32 => ty::Float(ast::FloatTy::F32),
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
},
let kind = match self.kind(interner) {
TyKind::Adt(struct_id, substitution) => {
ty::Adt(struct_id.0, substitution.lower_into(interner))
}
TyKind::Scalar(scalar) => match scalar {
chalk_ir::Scalar::Bool => ty::Bool,
chalk_ir::Scalar::Char => ty::Char,
chalk_ir::Scalar::Int(int_ty) => match int_ty {
chalk_ir::IntTy::Isize => ty::Int(ast::IntTy::Isize),
chalk_ir::IntTy::I8 => ty::Int(ast::IntTy::I8),
chalk_ir::IntTy::I16 => ty::Int(ast::IntTy::I16),
chalk_ir::IntTy::I32 => ty::Int(ast::IntTy::I32),
chalk_ir::IntTy::I64 => ty::Int(ast::IntTy::I64),
chalk_ir::IntTy::I128 => ty::Int(ast::IntTy::I128),
},
chalk_ir::Scalar::Uint(int_ty) => match int_ty {
chalk_ir::UintTy::Usize => ty::Uint(ast::UintTy::Usize),
chalk_ir::UintTy::U8 => ty::Uint(ast::UintTy::U8),
chalk_ir::UintTy::U16 => ty::Uint(ast::UintTy::U16),
chalk_ir::UintTy::U32 => ty::Uint(ast::UintTy::U32),
chalk_ir::UintTy::U64 => ty::Uint(ast::UintTy::U64),
chalk_ir::UintTy::U128 => ty::Uint(ast::UintTy::U128),
},
chalk_ir::Scalar::Float(float_ty) => match float_ty {
chalk_ir::FloatTy::F32 => ty::Float(ast::FloatTy::F32),
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
},
chalk_ir::TypeName::Array => {
let substs = application_ty.substitution.as_slice(interner);
let ty = substs[0].assert_ty_ref(interner).lower_into(interner);
let c = substs[1].assert_const_ref(interner).lower_into(interner);
ty::Array(ty, interner.tcx.mk_const(c))
}
chalk_ir::TypeName::FnDef(id) => {
ty::FnDef(id.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Closure(closure) => {
ty::Closure(closure.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Generator(_) => unimplemented!(),
chalk_ir::TypeName::GeneratorWitness(_) => unimplemented!(),
chalk_ir::TypeName::Never => ty::Never,
chalk_ir::TypeName::Tuple(_size) => {
ty::Tuple(application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Slice => ty::Slice(
application_ty.substitution.as_slice(interner)[0]
.ty(interner)
.unwrap()
.lower_into(interner),
),
chalk_ir::TypeName::Raw(mutbl) => ty::RawPtr(ty::TypeAndMut {
ty: application_ty.substitution.as_slice(interner)[0]
.ty(interner)
.unwrap()
.lower_into(interner),
mutbl: match mutbl {
chalk_ir::Mutability::Mut => ast::Mutability::Mut,
chalk_ir::Mutability::Not => ast::Mutability::Not,
},
}),
chalk_ir::TypeName::Ref(mutbl) => ty::Ref(
application_ty.substitution.as_slice(interner)[0]
.lifetime(interner)
.unwrap()
.lower_into(interner),
application_ty.substitution.as_slice(interner)[1]
.ty(interner)
.unwrap()
.lower_into(interner),
match mutbl {
chalk_ir::Mutability::Mut => ast::Mutability::Mut,
chalk_ir::Mutability::Not => ast::Mutability::Not,
},
),
chalk_ir::TypeName::Str => ty::Str,
chalk_ir::TypeName::OpaqueType(opaque_ty) => {
ty::Opaque(opaque_ty.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::AssociatedType(assoc_ty) => ty::Projection(ty::ProjectionTy {
substs: application_ty.substitution.lower_into(interner),
item_def_id: assoc_ty.0,
}),
chalk_ir::TypeName::Foreign(def_id) => ty::Foreign(def_id.0),
chalk_ir::TypeName::Error => unimplemented!(),
},
TyData::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
TyKind::Array(ty, c) => {
let ty = ty.lower_into(interner);
let c = c.lower_into(interner);
ty::Array(ty, interner.tcx.mk_const(c))
}
TyKind::FnDef(id, substitution) => ty::FnDef(id.0, substitution.lower_into(interner)),
TyKind::Closure(closure, substitution) => {
ty::Closure(closure.0, substitution.lower_into(interner))
}
TyKind::Generator(..) => unimplemented!(),
TyKind::GeneratorWitness(..) => unimplemented!(),
TyKind::Never => ty::Never,
TyKind::Tuple(_len, substitution) => ty::Tuple(substitution.lower_into(interner)),
TyKind::Slice(ty) => ty::Slice(ty.lower_into(interner)),
TyKind::Raw(mutbl, ty) => ty::RawPtr(ty::TypeAndMut {
ty: ty.lower_into(interner),
mutbl: match mutbl {
chalk_ir::Mutability::Mut => ast::Mutability::Mut,
chalk_ir::Mutability::Not => ast::Mutability::Not,
},
}),
TyKind::Ref(mutbl, lifetime, ty) => ty::Ref(
lifetime.lower_into(interner),
ty.lower_into(interner),
match mutbl {
chalk_ir::Mutability::Mut => ast::Mutability::Mut,
chalk_ir::Mutability::Not => ast::Mutability::Not,
},
),
TyKind::Str => ty::Str,
TyKind::OpaqueType(opaque_ty, substitution) => {
ty::Opaque(opaque_ty.0, substitution.lower_into(interner))
}
TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::ProjectionTy {
substs: substitution.lower_into(interner),
item_def_id: assoc_ty.0,
}),
TyKind::Foreign(def_id) => ty::Foreign(def_id.0),
TyKind::Error => return interner.tcx.ty_error(),
TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
name: ty::BoundVar::from_usize(placeholder.idx),
}),
chalk_ir::TyData::Alias(alias_ty) => match alias_ty {
TyKind::Alias(alias_ty) => match alias_ty {
chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy {
item_def_id: projection.associated_ty_id.0,
substs: projection.substitution.lower_into(interner),
@ -505,16 +438,16 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner))
}
},
TyData::Function(_quantified_ty) => unimplemented!(),
TyData::BoundVar(_bound) => ty::Bound(
TyKind::Function(_quantified_ty) => unimplemented!(),
TyKind::BoundVar(_bound) => ty::Bound(
ty::DebruijnIndex::from_usize(_bound.debruijn.depth() as usize),
ty::BoundTy {
var: ty::BoundVar::from_usize(_bound.index),
kind: ty::BoundTyKind::Anon,
},
),
TyData::InferenceVar(_, _) => unimplemented!(),
TyData::Dyn(_) => unimplemented!(),
TyKind::InferenceVar(_, _) => unimplemented!(),
TyKind::Dyn(_) => unimplemented!(),
};
interner.tcx.mk_ty(kind)
}
@ -909,7 +842,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
match self.parameters.entry(bound_ty.var.as_u32()) {
Entry::Vacant(entry) => {
entry.insert(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General));
entry.insert(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General));
}
Entry::Occupied(entry) => match entry.get() {
chalk_ir::VariableKind::Ty(_) => {}

View File

@ -69,15 +69,15 @@ crate fn evaluate_goal<'tcx>(
CanonicalVarKind::PlaceholderRegion(_ui) => unimplemented!(),
CanonicalVarKind::Ty(ty) => match ty {
CanonicalTyVarKind::General(ui) => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General),
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
chalk_ir::UniverseIndex { counter: ui.index() },
),
CanonicalTyVarKind::Int => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Integer),
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Integer),
chalk_ir::UniverseIndex::root(),
),
CanonicalTyVarKind::Float => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Float),
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Float),
chalk_ir::UniverseIndex::root(),
),
},
@ -97,7 +97,8 @@ crate fn evaluate_goal<'tcx>(
use chalk_solve::Solver;
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &lowered_goal));
let solution = solver.solve(&db, &lowered_goal);
debug!(?obligation, ?solution, "evaluatate goal");
// Ideally, the code to convert *back* to rustc types would live close to
// the code to convert *from* rustc types. Right now though, we don't