Rollup merge of #78502 - matthewjasper:chalkup, r=nikomatsakis
Update Chalk to 0.36.0 This PR updates Chalk and fixes a number of bugs in the chalk integration code. cc `@rust-lang/wg-traits` r? `@nikomatsakis`
This commit is contained in:
commit
0aed74aa43
16
Cargo.lock
16
Cargo.lock
@ -460,9 +460,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chalk-derive"
|
||||
version = "0.32.0"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d072b2ba723f0bada7c515d8b3725224bc4f5052d2a92dcbeb0b118ff37084a"
|
||||
checksum = "9f88ce4deae1dace71e49b7611cfae2d5489de3530d6daba5758043c47ac3a10"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -472,9 +472,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-engine"
|
||||
version = "0.32.0"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fb5475f6083d6d6c509e1c335c4f69ad04144ac090faa1afb134a53c3695841"
|
||||
checksum = "0e34c9b1b10616782143d7f49490f91ae94afaf2202de3ab0b2835e78b4f0ccc"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
@ -485,9 +485,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-ir"
|
||||
version = "0.32.0"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f60cdb0e18c5455cb6a85e8464aad3622b70476018edfa8845691df66f7e9a05"
|
||||
checksum = "63362c629c2014ab639b04029070763fb8224df136d1363d30e9ece4c8877da3"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"lazy_static",
|
||||
@ -495,9 +495,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-solve"
|
||||
version = "0.32.0"
|
||||
version = "0.36.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "981534d499a8476ecc0b520be4d3864757f96211826a75360fbf2cb6fae362ab"
|
||||
checksum = "cac338a67af52a7f50bb2f8232e730a3518ce432dbe303246acfe525ddd838c7"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
|
@ -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.36.0"
|
||||
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
|
||||
measureme = "9.0.0"
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
|
@ -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<'_>,
|
||||
|
@ -63,7 +63,7 @@ thread_local! {
|
||||
/// Avoids running any queries during any prints that occur
|
||||
/// during the closure. This may alter the appearance of some
|
||||
/// types (e.g. forcing verbose printing for opaque types).
|
||||
/// This method is used during some queries (e.g. `predicates_of`
|
||||
/// This method is used during some queries (e.g. `explicit_item_bounds`
|
||||
/// for opaque types), to ensure that any debug printing that
|
||||
/// occurs during the query computation does not end up recursively
|
||||
/// calling the same query.
|
||||
|
@ -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.36.0"
|
||||
chalk-solve = "0.36.0"
|
||||
chalk-engine = "0.36.0"
|
||||
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
|
||||
rustc_infer = { path = "../rustc_infer" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
|
@ -37,7 +37,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
|
||||
def_id: DefId,
|
||||
bound_vars: SubstsRef<'tcx>,
|
||||
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
|
||||
let predicates = self.interner.tcx.predicates_of(def_id).predicates;
|
||||
let predicates = self.interner.tcx.predicates_defined_on(def_id).predicates;
|
||||
let mut regions_substitutor =
|
||||
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
|
||||
predicates
|
||||
@ -118,34 +118,27 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
.map(|i| chalk_ir::AssocTypeId(i.def_id))
|
||||
.collect();
|
||||
|
||||
let well_known = if self.interner.tcx.lang_items().sized_trait() == Some(def_id) {
|
||||
let lang_items = self.interner.tcx.lang_items();
|
||||
let well_known = if lang_items.sized_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Sized)
|
||||
} else if self.interner.tcx.lang_items().copy_trait() == Some(def_id) {
|
||||
} else if lang_items.copy_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Copy)
|
||||
} else if self.interner.tcx.lang_items().clone_trait() == Some(def_id) {
|
||||
} else if lang_items.clone_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Clone)
|
||||
} else if self.interner.tcx.lang_items().drop_trait() == Some(def_id) {
|
||||
} else if lang_items.drop_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Drop)
|
||||
} else if self.interner.tcx.lang_items().fn_trait() == Some(def_id) {
|
||||
} else if lang_items.fn_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Fn)
|
||||
} else if self
|
||||
.interner
|
||||
.tcx
|
||||
.lang_items()
|
||||
.fn_once_trait()
|
||||
.map(|t| def_id == t)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
} else if lang_items.fn_once_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::FnOnce)
|
||||
} else if self
|
||||
.interner
|
||||
.tcx
|
||||
.lang_items()
|
||||
.fn_mut_trait()
|
||||
.map(|t| def_id == t)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
} else if lang_items.fn_mut_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::FnMut)
|
||||
} else if lang_items.unsize_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Unsize)
|
||||
} else if lang_items.unpin_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::Unpin)
|
||||
} else if lang_items.coerce_unsized_trait() == Some(def_id) {
|
||||
Some(chalk_solve::rust_ir::WellKnownTrait::CoerceUnsized)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -281,11 +274,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
where_clauses,
|
||||
};
|
||||
|
||||
let associated_ty_value_ids: Vec<_> = self
|
||||
.interner
|
||||
.tcx
|
||||
.associated_items(def_id)
|
||||
.in_definition_order()
|
||||
.filter(|i| i.kind == AssocKind::Type)
|
||||
.map(|i| chalk_solve::rust_ir::AssociatedTyValueId(i.def_id))
|
||||
.collect();
|
||||
|
||||
Arc::new(chalk_solve::rust_ir::ImplDatum {
|
||||
polarity: chalk_solve::rust_ir::Polarity::Positive,
|
||||
polarity: self.interner.tcx.impl_polarity(def_id).lower_into(&self.interner),
|
||||
binders: chalk_ir::Binders::new(binders, value),
|
||||
impl_type: chalk_solve::rust_ir::ImplType::Local,
|
||||
associated_ty_value_ids: vec![],
|
||||
associated_ty_value_ids,
|
||||
})
|
||||
}
|
||||
|
||||
@ -324,19 +326,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 +367,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 +378,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,
|
||||
@ -404,24 +408,38 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
|
||||
let def_id = associated_ty_id.0;
|
||||
let assoc_item = self.interner.tcx.associated_item(def_id);
|
||||
let impl_id = match assoc_item.container {
|
||||
AssocItemContainer::TraitContainer(def_id) => def_id,
|
||||
_ => unimplemented!("Not possible??"),
|
||||
let (impl_id, trait_id) = match assoc_item.container {
|
||||
AssocItemContainer::TraitContainer(def_id) => (def_id, def_id),
|
||||
AssocItemContainer::ImplContainer(def_id) => {
|
||||
(def_id, self.interner.tcx.impl_trait_ref(def_id).unwrap().def_id)
|
||||
}
|
||||
};
|
||||
match assoc_item.kind {
|
||||
AssocKind::Type => {}
|
||||
_ => unimplemented!("Not possible??"),
|
||||
}
|
||||
|
||||
let trait_item = self
|
||||
.interner
|
||||
.tcx
|
||||
.associated_items(trait_id)
|
||||
.find_by_name_and_kind(self.interner.tcx, assoc_item.ident, assoc_item.kind, trait_id)
|
||||
.unwrap();
|
||||
let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
|
||||
let binders = binders_for(&self.interner, bound_vars);
|
||||
let ty = self.interner.tcx.type_of(def_id);
|
||||
let ty = self
|
||||
.interner
|
||||
.tcx
|
||||
.type_of(def_id)
|
||||
.subst(self.interner.tcx, bound_vars)
|
||||
.lower_into(&self.interner);
|
||||
|
||||
Arc::new(chalk_solve::rust_ir::AssociatedTyValue {
|
||||
impl_id: chalk_ir::ImplId(impl_id),
|
||||
associated_ty_id: chalk_ir::AssocTypeId(def_id),
|
||||
associated_ty_id: chalk_ir::AssocTypeId(trait_item.def_id),
|
||||
value: chalk_ir::Binders::new(
|
||||
binders,
|
||||
chalk_solve::rust_ir::AssociatedTyValueBound { ty: ty.lower_into(&self.interner) },
|
||||
chalk_solve::rust_ir::AssociatedTyValueBound { ty },
|
||||
),
|
||||
})
|
||||
}
|
||||
@ -441,19 +459,61 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
&self,
|
||||
opaque_ty_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
|
||||
) -> Arc<chalk_solve::rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> {
|
||||
let bound_vars = bound_vars_for_item(self.interner.tcx, opaque_ty_id.0);
|
||||
let binders = binders_for(&self.interner, bound_vars);
|
||||
let bound_vars = ty::fold::shift_vars(
|
||||
self.interner.tcx,
|
||||
&bound_vars_for_item(self.interner.tcx, opaque_ty_id.0),
|
||||
1,
|
||||
);
|
||||
let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars);
|
||||
let bounds = self.bounds_for(opaque_ty_id.0, bound_vars);
|
||||
|
||||
let identity_substs = InternalSubsts::identity_for_item(self.interner.tcx, opaque_ty_id.0);
|
||||
|
||||
let bounds =
|
||||
self.interner
|
||||
.tcx
|
||||
.explicit_item_bounds(opaque_ty_id.0)
|
||||
.iter()
|
||||
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
|
||||
.map(|bound| {
|
||||
bound.fold_with(&mut ty::fold::BottomUpFolder {
|
||||
tcx: self.interner.tcx,
|
||||
ty_op: |ty| {
|
||||
if let ty::Opaque(def_id, substs) = *ty.kind() {
|
||||
if def_id == opaque_ty_id.0 && substs == identity_substs {
|
||||
return self.interner.tcx.mk_ty(ty::Bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundTy::from(ty::BoundVar::from_u32(0)),
|
||||
));
|
||||
}
|
||||
}
|
||||
ty
|
||||
},
|
||||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
})
|
||||
})
|
||||
.filter_map(|bound| {
|
||||
LowerInto::<
|
||||
Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>
|
||||
>::lower_into(bound, &self.interner)
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Binder for the bound variable representing the concrete impl Trait type.
|
||||
let existential_binder = chalk_ir::VariableKinds::from1(
|
||||
&self.interner,
|
||||
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
|
||||
);
|
||||
|
||||
let value = chalk_solve::rust_ir::OpaqueTyDatumBound {
|
||||
bounds: chalk_ir::Binders::new(binders.clone(), bounds),
|
||||
where_clauses: chalk_ir::Binders::new(binders, where_clauses),
|
||||
bounds: chalk_ir::Binders::new(existential_binder.clone(), bounds),
|
||||
where_clauses: chalk_ir::Binders::new(existential_binder, where_clauses),
|
||||
};
|
||||
|
||||
let binders = binders_for(&self.interner, bound_vars);
|
||||
Arc::new(chalk_solve::rust_ir::OpaqueTyDatum {
|
||||
opaque_ty_id,
|
||||
bound: chalk_ir::Binders::empty(&self.interner, value),
|
||||
bound: chalk_ir::Binders::new(binders, value),
|
||||
})
|
||||
}
|
||||
|
||||
@ -506,17 +566,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 +584,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 +687,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))
|
||||
|
@ -31,11 +31,12 @@
|
||||
//! not. To lower anything wrapped in a `Binder`, we first deeply find any bound
|
||||
//! variables from the current `Binder`.
|
||||
|
||||
use rustc_ast::ast;
|
||||
use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
|
||||
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;
|
||||
|
||||
@ -240,24 +241,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),
|
||||
@ -265,7 +258,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),
|
||||
@ -273,80 +266,35 @@ 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) => {
|
||||
chalk_ir::TyKind::Raw(ptr.mutbl.lower_into(interner), ptr.ty.lower_into(interner))
|
||||
}
|
||||
ty::Ref(region, ty, mutability) => chalk_ir::TyKind::Ref(
|
||||
mutability.lower_into(interner),
|
||||
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)))
|
||||
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(
|
||||
@ -356,148 +304,115 @@ 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 rustc_ast::ast;
|
||||
use chalk_ir::TyKind;
|
||||
|
||||
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: mutbl.lower_into(interner),
|
||||
}),
|
||||
TyKind::Ref(mutbl, lifetime, ty) => ty::Ref(
|
||||
lifetime.lower_into(interner),
|
||||
ty.lower_into(interner),
|
||||
mutbl.lower_into(interner),
|
||||
),
|
||||
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),
|
||||
@ -506,16 +421,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)
|
||||
}
|
||||
@ -706,8 +621,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
|
||||
self,
|
||||
interner: &RustInterner<'tcx>,
|
||||
) -> chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>> {
|
||||
// `Self` has one binder:
|
||||
// Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>
|
||||
// The return type has two:
|
||||
// Binders<&[Binders<WhereClause<I>>]>
|
||||
// This means that any variables that are escaping `self` need to be
|
||||
// shifted in by one so that they are still escaping.
|
||||
let shifted_predicates = ty::fold::shift_vars(interner.tcx, &self, 1);
|
||||
|
||||
let (predicates, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, &self);
|
||||
collect_bound_vars(interner, interner.tcx, &shifted_predicates);
|
||||
let self_ty = interner.tcx.mk_ty(ty::Bound(
|
||||
// This is going to be wrapped in a binder
|
||||
ty::DebruijnIndex::from_usize(1),
|
||||
@ -716,7 +639,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
|
||||
let where_clauses = predicates.into_iter().map(|predicate| match predicate {
|
||||
ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef { def_id, substs }) => {
|
||||
chalk_ir::Binders::new(
|
||||
chalk_ir::VariableKinds::empty(interner),
|
||||
binders.clone(),
|
||||
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
|
||||
trait_id: chalk_ir::TraitId(def_id),
|
||||
substitution: interner
|
||||
@ -727,25 +650,34 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
|
||||
)
|
||||
}
|
||||
ty::ExistentialPredicate::Projection(predicate) => chalk_ir::Binders::new(
|
||||
chalk_ir::VariableKinds::empty(interner),
|
||||
binders.clone(),
|
||||
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
|
||||
alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
|
||||
associated_ty_id: chalk_ir::AssocTypeId(predicate.item_def_id),
|
||||
substitution: predicate.substs.lower_into(interner),
|
||||
substitution: interner
|
||||
.tcx
|
||||
.mk_substs_trait(self_ty, predicate.substs)
|
||||
.lower_into(interner),
|
||||
}),
|
||||
ty: predicate.ty.lower_into(interner),
|
||||
}),
|
||||
),
|
||||
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
|
||||
chalk_ir::VariableKinds::empty(interner),
|
||||
binders.clone(),
|
||||
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
|
||||
trait_id: chalk_ir::TraitId(def_id),
|
||||
substitution: interner.tcx.mk_substs_trait(self_ty, &[]).lower_into(interner),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
// Binder for the bound variable representing the concrete underlying type.
|
||||
let existential_binder = chalk_ir::VariableKinds::from1(
|
||||
interner,
|
||||
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
|
||||
);
|
||||
let value = chalk_ir::QuantifiedWhereClauses::from_iter(interner, where_clauses);
|
||||
chalk_ir::Binders::new(binders, value)
|
||||
chalk_ir::Binders::new(existential_binder, value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -818,6 +750,35 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, chalk_ir::Mutability> for ast::Mutability {
|
||||
fn lower_into(self, _interner: &RustInterner<'tcx>) -> chalk_ir::Mutability {
|
||||
match self {
|
||||
rustc_ast::Mutability::Mut => chalk_ir::Mutability::Mut,
|
||||
rustc_ast::Mutability::Not => chalk_ir::Mutability::Not,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, ast::Mutability> for chalk_ir::Mutability {
|
||||
fn lower_into(self, _interner: &RustInterner<'tcx>) -> ast::Mutability {
|
||||
match self {
|
||||
chalk_ir::Mutability::Mut => ast::Mutability::Mut,
|
||||
chalk_ir::Mutability::Not => ast::Mutability::Not,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::Polarity> for ty::ImplPolarity {
|
||||
fn lower_into(self, _interner: &RustInterner<'tcx>) -> chalk_solve::rust_ir::Polarity {
|
||||
match self {
|
||||
ty::ImplPolarity::Positive => chalk_solve::rust_ir::Polarity::Positive,
|
||||
ty::ImplPolarity::Negative => chalk_solve::rust_ir::Polarity::Negative,
|
||||
// FIXME(chalk) reservation impls
|
||||
ty::ImplPolarity::Reservation => chalk_solve::rust_ir::Polarity::Negative,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>>>
|
||||
for ty::ProjectionPredicate<'tcx>
|
||||
{
|
||||
@ -910,7 +871,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(_) => {}
|
||||
|
@ -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
|
||||
|
@ -61,23 +61,23 @@ fn opaque_type_bounds<'tcx>(
|
||||
bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
span: Span,
|
||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||
let item_ty =
|
||||
tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));
|
||||
ty::print::with_no_queries(|| {
|
||||
let item_ty =
|
||||
tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));
|
||||
|
||||
let bounds = ty::print::with_no_queries(|| {
|
||||
AstConv::compute_bounds(
|
||||
let bounds = AstConv::compute_bounds(
|
||||
&ItemCtxt::new(tcx, opaque_def_id),
|
||||
item_ty,
|
||||
bounds,
|
||||
SizedByDefault::Yes,
|
||||
span,
|
||||
)
|
||||
});
|
||||
.predicates(tcx, item_ty);
|
||||
|
||||
let bounds = bounds.predicates(tcx, item_ty);
|
||||
debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(opaque_def_id), bounds);
|
||||
debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(opaque_def_id), bounds);
|
||||
|
||||
tcx.arena.alloc_slice(&bounds)
|
||||
tcx.arena.alloc_slice(&bounds)
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn explicit_item_bounds(
|
||||
|
20
src/test/ui/chalkify/arithmetic.rs
Normal file
20
src/test/ui/chalkify/arithmetic.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// check-pass
|
||||
// compile-flags: -Z chalk
|
||||
|
||||
fn main() {
|
||||
1 + 2;
|
||||
3 * 6;
|
||||
2 - 5;
|
||||
17 / 6;
|
||||
23 % 11;
|
||||
4 & 6;
|
||||
7 | 15;
|
||||
4 << 7;
|
||||
123 >> 3;
|
||||
1 == 2;
|
||||
5 != 5;
|
||||
6 < 2;
|
||||
7 > 11;
|
||||
3 <= 1;
|
||||
9 >= 14;
|
||||
}
|
13
src/test/ui/chalkify/trait-objects.rs
Normal file
13
src/test/ui/chalkify/trait-objects.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// check-pass
|
||||
// compile-flags: -Z chalk
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
fn main() {
|
||||
let d: &dyn Display = &mut 3;
|
||||
// FIXME(chalk) should be able to call d.to_string() as well, but doing so
|
||||
// requires Chalk to be able to prove trait object well-formed goals.
|
||||
(&d).to_string();
|
||||
let f: &dyn Fn(i32) -> _ = &|x| x + x;
|
||||
f(2);
|
||||
}
|
Loading…
Reference in New Issue
Block a user