Update Chalk, clean up Chalk integration a bit

This commit is contained in:
Florian Diebold 2019-12-21 14:29:33 +01:00
parent 60aa4d12f9
commit 67a2555f6d
5 changed files with 131 additions and 153 deletions

56
Cargo.lock generated
View file

@ -128,7 +128,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "chalk-derive" name = "chalk-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -138,27 +138,27 @@ dependencies = [
[[package]] [[package]]
name = "chalk-engine" name = "chalk-engine"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "chalk-ir" name = "chalk-ir"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "chalk-macros" name = "chalk-macros"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -166,24 +166,24 @@ dependencies = [
[[package]] [[package]]
name = "chalk-rust-ir" name = "chalk-rust-ir"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
] ]
[[package]] [[package]]
name = "chalk-solve" name = "chalk-solve"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb#151949dece8117d180b5d197a7afa968c3ba14bb" source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
dependencies = [ dependencies = [
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -995,9 +995,9 @@ name = "ra_hir_ty"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)", "chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1782,12 +1782,12 @@ dependencies = [
"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202" "checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
"checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" "checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=151949dece8117d180b5d197a7afa968c3ba14bb)" = "<none>" "checksum chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
"checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e" "checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5d540c2d34ac9dd0deb5f3b5f54c36c79efa78f6b3ad19106a554d07a7b5d9f" "checksum console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5d540c2d34ac9dd0deb5f3b5f54c36c79efa78f6b3ad19106a554d07a7b5d9f"

View file

@ -21,10 +21,9 @@ ra_prof = { path = "../ra_prof" }
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
test_utils = { path = "../test_utils" } test_utils = { path = "../test_utils" }
# https://github.com/rust-lang/chalk/pull/294 chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" } chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" } chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "151949dece8117d180b5d197a7afa968c3ba14bb" }
lalrpop-intern = "0.15.1" lalrpop-intern = "0.15.1"

View file

@ -10,7 +10,7 @@ use ra_db::{salsa, CrateId};
use crate::{ use crate::{
method_resolution::CrateImplBlocks, method_resolution::CrateImplBlocks,
traits::{AssocTyValue, Impl}, traits::{chalk, AssocTyValue, Impl},
CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, TraitRef, Ty, TyDefId, TypeCtor, CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, TraitRef, Ty, TyDefId, TypeCtor,
ValueTyDefId, ValueTyDefId,
}; };
@ -77,39 +77,24 @@ pub trait HirDatabase: DefDatabase {
#[salsa::interned] #[salsa::interned]
fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId; fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> crate::traits::AssocTyValueId;
#[salsa::invoke(crate::traits::chalk::associated_ty_data_query)] #[salsa::invoke(chalk::associated_ty_data_query)]
fn associated_ty_data( fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>;
&self,
id: chalk_ir::TypeId,
) -> Arc<chalk_rust_ir::AssociatedTyDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::traits::chalk::trait_datum_query)] #[salsa::invoke(chalk::trait_datum_query)]
fn trait_datum( fn trait_datum(&self, krate: CrateId, trait_id: chalk::TraitId) -> Arc<chalk::TraitDatum>;
&self,
krate: CrateId,
trait_id: chalk_ir::TraitId,
) -> Arc<chalk_rust_ir::TraitDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::traits::chalk::struct_datum_query)] #[salsa::invoke(chalk::struct_datum_query)]
fn struct_datum( fn struct_datum(&self, krate: CrateId, struct_id: chalk::StructId) -> Arc<chalk::StructDatum>;
&self,
krate: CrateId,
struct_id: chalk_ir::StructId,
) -> Arc<chalk_rust_ir::StructDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::traits::chalk::impl_datum_query)] #[salsa::invoke(crate::traits::chalk::impl_datum_query)]
fn impl_datum( fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>;
&self,
krate: CrateId,
impl_id: chalk_ir::ImplId,
) -> Arc<chalk_rust_ir::ImplDatum<chalk_ir::family::ChalkIr>>;
#[salsa::invoke(crate::traits::chalk::associated_ty_value_query)] #[salsa::invoke(crate::traits::chalk::associated_ty_value_query)]
fn associated_ty_value( fn associated_ty_value(
&self, &self,
krate: CrateId, krate: CrateId,
id: chalk_rust_ir::AssociatedTyValueId, id: chalk::AssociatedTyValueId,
) -> Arc<chalk_rust_ir::AssociatedTyValue<chalk_ir::family::ChalkIr>>; ) -> Arc<chalk::AssociatedTyValue>;
#[salsa::invoke(crate::traits::trait_solve_query)] #[salsa::invoke(crate::traits::trait_solve_query)]
fn trait_solve( fn trait_solve(

View file

@ -209,9 +209,9 @@ fn solution_from_chalk(
.parameters .parameters
.into_iter() .into_iter()
.map(|p| { .map(|p| {
let ty = match p { let ty = match p.ty() {
chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), Some(ty) => from_chalk(db, ty.clone()),
chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), None => unimplemented!(),
}; };
ty ty
}) })

View file

@ -3,15 +3,9 @@ use std::sync::Arc;
use log::debug; use log::debug;
use chalk_ir::{ use chalk_ir::{cast::Cast, family::ChalkIr, Parameter, PlaceholderIndex, TypeName, UniverseIndex};
cast::Cast, family::ChalkIr, Identifier, Parameter, PlaceholderIndex, TypeId, TypeKindId,
TypeName, UniverseIndex,
};
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
use hir_def::{ use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId};
AssocContainerId, AssocItemId, GenericDefId, HasModule, ImplId, Lookup, TraitId, TypeAliasId,
};
use ra_db::{ use ra_db::{
salsa::{InternId, InternKey}, salsa::{InternId, InternKey},
CrateId, CrateId,
@ -23,9 +17,20 @@ use crate::{
ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
}; };
pub type TypeFamily = chalk_ir::family::ChalkIr; // TODO use everywhere
pub type AssocTypeId = chalk_ir::AssocTypeId<TypeFamily>;
pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum<TypeFamily>;
pub type TraitId = chalk_ir::TraitId<TypeFamily>;
pub type TraitDatum = chalk_rust_ir::TraitDatum<TypeFamily>;
pub type StructId = chalk_ir::StructId<TypeFamily>;
pub type StructDatum = chalk_rust_ir::StructDatum<TypeFamily>;
pub type ImplId = chalk_ir::ImplId<TypeFamily>;
pub type ImplDatum = chalk_rust_ir::ImplDatum<TypeFamily>;
pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId;
pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<TypeFamily>;
/// This represents a trait whose name we could not resolve. /// This represents a trait whose name we could not resolve.
const UNKNOWN_TRAIT: chalk_ir::TraitId = const UNKNOWN_TRAIT: TraitId = chalk_ir::TraitId(chalk_ir::RawId { index: u32::max_value() });
chalk_ir::TraitId(chalk_ir::RawId { index: u32::max_value() });
pub(super) trait ToChalk { pub(super) trait ToChalk {
type Chalk; type Chalk;
@ -53,7 +58,7 @@ impl ToChalk for Ty {
_ => { _ => {
// other TypeCtors get interned and turned into a chalk StructId // other TypeCtors get interned and turned into a chalk StructId
let struct_id = apply_ty.ctor.to_chalk(db); let struct_id = apply_ty.ctor.to_chalk(db);
TypeName::TypeKindId(struct_id.into()) TypeName::Struct(struct_id.into())
} }
}; };
let parameters = apply_ty.parameters.to_chalk(db); let parameters = apply_ty.parameters.to_chalk(db);
@ -71,11 +76,13 @@ impl ToChalk for Ty {
Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
Ty::Dyn(predicates) => { Ty::Dyn(predicates) => {
let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
chalk_ir::TyData::Dyn(make_binders(where_clauses, 1)).intern() let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
chalk_ir::TyData::Dyn(bounded_ty).intern()
} }
Ty::Opaque(predicates) => { Ty::Opaque(predicates) => {
let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect();
chalk_ir::TyData::Opaque(make_binders(where_clauses, 1)).intern() let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
chalk_ir::TyData::Opaque(bounded_ty).intern()
} }
Ty::Unknown => { Ty::Unknown => {
let parameters = Vec::new(); let parameters = Vec::new();
@ -87,10 +94,9 @@ impl ToChalk for Ty {
fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<ChalkIr>) -> Self { fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<ChalkIr>) -> Self {
match chalk.data().clone() { match chalk.data().clone() {
chalk_ir::TyData::Apply(apply_ty) => { chalk_ir::TyData::Apply(apply_ty) => {
// FIXME this is kind of hacky due to the fact that // TODO clean this up now that Placeholder isn't in TypeName anymore
// TypeName::Placeholder is a Ty::Param on our side
match apply_ty.name { match apply_ty.name {
TypeName::TypeKindId(TypeKindId::StructId(struct_id)) => { TypeName::Struct(struct_id) => {
let ctor = from_chalk(db, struct_id); let ctor = from_chalk(db, struct_id);
let parameters = from_chalk(db, apply_ty.parameters); let parameters = from_chalk(db, apply_ty.parameters);
Ty::Apply(ApplicationTy { ctor, parameters }) Ty::Apply(ApplicationTy { ctor, parameters })
@ -101,14 +107,12 @@ impl ToChalk for Ty {
Ty::Apply(ApplicationTy { ctor, parameters }) Ty::Apply(ApplicationTy { ctor, parameters })
} }
TypeName::Error => Ty::Unknown, TypeName::Error => Ty::Unknown,
// FIXME handle TypeKindId::Trait/Type here
TypeName::TypeKindId(_) => unimplemented!(),
TypeName::Placeholder(idx) => {
assert_eq!(idx.ui, UniverseIndex::ROOT);
Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() }
}
} }
} }
chalk_ir::TyData::Placeholder(idx) => {
assert_eq!(idx.ui, UniverseIndex::ROOT);
Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() }
}
chalk_ir::TyData::Projection(proj) => { chalk_ir::TyData::Projection(proj) => {
let associated_ty = from_chalk(db, proj.associated_ty_id); let associated_ty = from_chalk(db, proj.associated_ty_id);
let parameters = from_chalk(db, proj.parameters); let parameters = from_chalk(db, proj.parameters);
@ -118,15 +122,15 @@ impl ToChalk for Ty {
chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32), chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32),
chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
chalk_ir::TyData::Dyn(where_clauses) => { chalk_ir::TyData::Dyn(where_clauses) => {
assert_eq!(where_clauses.binders.len(), 1); assert_eq!(where_clauses.bounds.binders.len(), 1);
let predicates = let predicates =
where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect(); where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
Ty::Dyn(predicates) Ty::Dyn(predicates)
} }
chalk_ir::TyData::Opaque(where_clauses) => { chalk_ir::TyData::Opaque(where_clauses) => {
assert_eq!(where_clauses.binders.len(), 1); assert_eq!(where_clauses.bounds.binders.len(), 1);
let predicates = let predicates =
where_clauses.value.into_iter().map(|c| from_chalk(db, c)).collect(); where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
Ty::Opaque(predicates) Ty::Opaque(predicates)
} }
} }
@ -143,9 +147,9 @@ impl ToChalk for Substs {
fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter<ChalkIr>>) -> Substs { fn from_chalk(db: &impl HirDatabase, parameters: Vec<chalk_ir::Parameter<ChalkIr>>) -> Substs {
let tys = parameters let tys = parameters
.into_iter() .into_iter()
.map(|p| match p { .map(|p| match p.ty() {
chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), Some(ty) => from_chalk(db, ty.clone()),
chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), None => unimplemented!(),
}) })
.collect(); .collect();
Substs(tys) Substs(tys)
@ -168,65 +172,62 @@ impl ToChalk for TraitRef {
} }
} }
impl ToChalk for TraitId { impl ToChalk for hir_def::TraitId {
type Chalk = chalk_ir::TraitId; type Chalk = TraitId;
fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId { fn to_chalk(self, _db: &impl HirDatabase) -> TraitId {
chalk_ir::TraitId(id_to_chalk(self)) chalk_ir::TraitId(id_to_chalk(self))
} }
fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> TraitId { fn from_chalk(_db: &impl HirDatabase, trait_id: TraitId) -> hir_def::TraitId {
id_from_chalk(trait_id.0) id_from_chalk(trait_id.0)
} }
} }
impl ToChalk for TypeCtor { impl ToChalk for TypeCtor {
type Chalk = chalk_ir::StructId; type Chalk = StructId;
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::StructId { fn to_chalk(self, db: &impl HirDatabase) -> StructId {
db.intern_type_ctor(self).into() db.intern_type_ctor(self).into()
} }
fn from_chalk(db: &impl HirDatabase, struct_id: chalk_ir::StructId) -> TypeCtor { fn from_chalk(db: &impl HirDatabase, struct_id: StructId) -> TypeCtor {
db.lookup_intern_type_ctor(struct_id.into()) db.lookup_intern_type_ctor(struct_id.into())
} }
} }
impl ToChalk for Impl { impl ToChalk for Impl {
type Chalk = chalk_ir::ImplId; type Chalk = ImplId;
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::ImplId { fn to_chalk(self, db: &impl HirDatabase) -> ImplId {
db.intern_chalk_impl(self).into() db.intern_chalk_impl(self).into()
} }
fn from_chalk(db: &impl HirDatabase, impl_id: chalk_ir::ImplId) -> Impl { fn from_chalk(db: &impl HirDatabase, impl_id: ImplId) -> Impl {
db.lookup_intern_chalk_impl(impl_id.into()) db.lookup_intern_chalk_impl(impl_id.into())
} }
} }
impl ToChalk for TypeAliasId { impl ToChalk for TypeAliasId {
type Chalk = chalk_ir::TypeId; type Chalk = AssocTypeId;
fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId { fn to_chalk(self, _db: &impl HirDatabase) -> AssocTypeId {
chalk_ir::TypeId(id_to_chalk(self)) chalk_ir::AssocTypeId(id_to_chalk(self))
} }
fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAliasId { fn from_chalk(_db: &impl HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId {
id_from_chalk(type_alias_id.0) id_from_chalk(type_alias_id.0)
} }
} }
impl ToChalk for AssocTyValue { impl ToChalk for AssocTyValue {
type Chalk = chalk_rust_ir::AssociatedTyValueId; type Chalk = AssociatedTyValueId;
fn to_chalk(self, db: &impl HirDatabase) -> chalk_rust_ir::AssociatedTyValueId { fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValueId {
db.intern_assoc_ty_value(self).into() db.intern_assoc_ty_value(self).into()
} }
fn from_chalk( fn from_chalk(db: &impl HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue {
db: &impl HirDatabase,
assoc_ty_value_id: chalk_rust_ir::AssociatedTyValueId,
) -> AssocTyValue {
db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into())
} }
} }
@ -468,28 +469,28 @@ impl<'a, DB> chalk_solve::RustIrDatabase<ChalkIr> for ChalkContext<'a, DB>
where where
DB: HirDatabase, DB: HirDatabase,
{ {
fn associated_ty_data(&self, id: TypeId) -> Arc<AssociatedTyDatum<ChalkIr>> { fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
self.db.associated_ty_data(id) self.db.associated_ty_data(id)
} }
fn trait_datum(&self, trait_id: chalk_ir::TraitId) -> Arc<TraitDatum<ChalkIr>> { fn trait_datum(&self, trait_id: TraitId) -> Arc<TraitDatum> {
self.db.trait_datum(self.krate, trait_id) self.db.trait_datum(self.krate, trait_id)
} }
fn struct_datum(&self, struct_id: chalk_ir::StructId) -> Arc<StructDatum<ChalkIr>> { fn struct_datum(&self, struct_id: StructId) -> Arc<StructDatum> {
self.db.struct_datum(self.krate, struct_id) self.db.struct_datum(self.krate, struct_id)
} }
fn impl_datum(&self, impl_id: chalk_ir::ImplId) -> Arc<ImplDatum<ChalkIr>> { fn impl_datum(&self, impl_id: ImplId) -> Arc<ImplDatum> {
self.db.impl_datum(self.krate, impl_id) self.db.impl_datum(self.krate, impl_id)
} }
fn impls_for_trait( fn impls_for_trait(
&self, &self,
trait_id: chalk_ir::TraitId, trait_id: TraitId,
parameters: &[Parameter<ChalkIr>], parameters: &[Parameter<TypeFamily>],
) -> Vec<chalk_ir::ImplId> { ) -> Vec<ImplId> {
debug!("impls_for_trait {:?}", trait_id); debug!("impls_for_trait {:?}", trait_id);
if trait_id == UNKNOWN_TRAIT { if trait_id == UNKNOWN_TRAIT {
return Vec::new(); return Vec::new();
} }
let trait_: TraitId = from_chalk(self.db, trait_id); let trait_: hir_def::TraitId = from_chalk(self.db, trait_id);
let mut result: Vec<_> = self let mut result: Vec<_> = self
.db .db
.impls_for_trait(self.krate, trait_.into()) .impls_for_trait(self.krate, trait_.into())
@ -508,39 +509,32 @@ where
debug!("impls_for_trait returned {} impls", result.len()); debug!("impls_for_trait returned {} impls", result.len());
result result
} }
fn impl_provided_for( fn impl_provided_for(&self, auto_trait_id: TraitId, struct_id: StructId) -> bool {
&self,
auto_trait_id: chalk_ir::TraitId,
struct_id: chalk_ir::StructId,
) -> bool {
debug!("impl_provided_for {:?}, {:?}", auto_trait_id, struct_id); debug!("impl_provided_for {:?}, {:?}", auto_trait_id, struct_id);
false // FIXME false // FIXME
} }
fn type_name(&self, _id: TypeKindId) -> Identifier { fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> {
unimplemented!()
}
fn associated_ty_value(
&self,
id: chalk_rust_ir::AssociatedTyValueId,
) -> Arc<AssociatedTyValue<ChalkIr>> {
self.db.associated_ty_value(self.krate.into(), id) self.db.associated_ty_value(self.krate.into(), id)
} }
fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> { fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<ChalkIr>> {
vec![] vec![]
} }
fn local_impls_to_coherence_check( fn local_impls_to_coherence_check(&self, _trait_id: TraitId) -> Vec<ImplId> {
&self,
_trait_id: chalk_ir::TraitId,
) -> Vec<chalk_ir::ImplId> {
// We don't do coherence checking (yet) // We don't do coherence checking (yet)
unimplemented!() unimplemented!()
} }
fn as_struct_id(&self, id: &TypeName<TypeFamily>) -> Option<StructId> {
match id {
TypeName::Struct(struct_id) => Some(*struct_id),
_ => None,
}
}
} }
pub(crate) fn associated_ty_data_query( pub(crate) fn associated_ty_data_query(
db: &impl HirDatabase, db: &impl HirDatabase,
id: TypeId, id: AssocTypeId,
) -> Arc<AssociatedTyDatum<ChalkIr>> { ) -> Arc<AssociatedTyDatum> {
debug!("associated_ty_data {:?}", id); debug!("associated_ty_data {:?}", id);
let type_alias: TypeAliasId = from_chalk(db, id); let type_alias: TypeAliasId = from_chalk(db, id);
let trait_ = match type_alias.lookup(db).container { let trait_ = match type_alias.lookup(db).container {
@ -565,8 +559,8 @@ pub(crate) fn associated_ty_data_query(
pub(crate) fn trait_datum_query( pub(crate) fn trait_datum_query(
db: &impl HirDatabase, db: &impl HirDatabase,
krate: CrateId, krate: CrateId,
trait_id: chalk_ir::TraitId, trait_id: TraitId,
) -> Arc<TraitDatum<ChalkIr>> { ) -> Arc<TraitDatum> {
debug!("trait_datum {:?}", trait_id); debug!("trait_datum {:?}", trait_id);
if trait_id == UNKNOWN_TRAIT { if trait_id == UNKNOWN_TRAIT {
let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses: Vec::new() }; let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses: Vec::new() };
@ -586,7 +580,7 @@ pub(crate) fn trait_datum_query(
associated_ty_ids: vec![], associated_ty_ids: vec![],
}); });
} }
let trait_: TraitId = from_chalk(db, trait_id); let trait_: hir_def::TraitId = from_chalk(db, trait_id);
let trait_data = db.trait_data(trait_); let trait_data = db.trait_data(trait_);
debug!("trait {:?} = {:?}", trait_id, trait_data.name); debug!("trait {:?} = {:?}", trait_id, trait_data.name);
let generic_params = generics(db, trait_.into()); let generic_params = generics(db, trait_.into());
@ -616,8 +610,8 @@ pub(crate) fn trait_datum_query(
pub(crate) fn struct_datum_query( pub(crate) fn struct_datum_query(
db: &impl HirDatabase, db: &impl HirDatabase,
krate: CrateId, krate: CrateId,
struct_id: chalk_ir::StructId, struct_id: StructId,
) -> Arc<StructDatum<ChalkIr>> { ) -> Arc<StructDatum> {
debug!("struct_datum {:?}", struct_id); debug!("struct_datum {:?}", struct_id);
let type_ctor: TypeCtor = from_chalk(db, struct_id); let type_ctor: TypeCtor = from_chalk(db, struct_id);
debug!("struct {:?} = {:?}", struct_id, type_ctor); debug!("struct {:?} = {:?}", struct_id, type_ctor);
@ -648,8 +642,8 @@ pub(crate) fn struct_datum_query(
pub(crate) fn impl_datum_query( pub(crate) fn impl_datum_query(
db: &impl HirDatabase, db: &impl HirDatabase,
krate: CrateId, krate: CrateId,
impl_id: chalk_ir::ImplId, impl_id: ImplId,
) -> Arc<ImplDatum<ChalkIr>> { ) -> Arc<ImplDatum> {
let _p = ra_prof::profile("impl_datum"); let _p = ra_prof::profile("impl_datum");
debug!("impl_datum {:?}", impl_id); debug!("impl_datum {:?}", impl_id);
let impl_: Impl = from_chalk(db, impl_id); let impl_: Impl = from_chalk(db, impl_id);
@ -663,9 +657,9 @@ pub(crate) fn impl_datum_query(
fn impl_block_datum( fn impl_block_datum(
db: &impl HirDatabase, db: &impl HirDatabase,
krate: CrateId, krate: CrateId,
chalk_id: chalk_ir::ImplId, chalk_id: ImplId,
impl_id: ImplId, impl_id: hir_def::ImplId,
) -> Option<Arc<ImplDatum<ChalkIr>>> { ) -> Option<Arc<ImplDatum>> {
let trait_ref = db.impl_trait(impl_id)?; let trait_ref = db.impl_trait(impl_id)?;
let impl_data = db.impl_data(impl_id); let impl_data = db.impl_data(impl_id);
@ -721,7 +715,7 @@ fn impl_block_datum(
Some(Arc::new(impl_datum)) Some(Arc::new(impl_datum))
} }
fn invalid_impl_datum() -> Arc<ImplDatum<ChalkIr>> { fn invalid_impl_datum() -> Arc<ImplDatum> {
let trait_ref = chalk_ir::TraitRef { let trait_ref = chalk_ir::TraitRef {
trait_id: UNKNOWN_TRAIT, trait_id: UNKNOWN_TRAIT,
parameters: vec![chalk_ir::TyData::BoundVar(0).cast().intern().cast()], parameters: vec![chalk_ir::TyData::BoundVar(0).cast().intern().cast()],
@ -754,7 +748,7 @@ fn type_alias_associated_ty_value(
db: &impl HirDatabase, db: &impl HirDatabase,
_krate: CrateId, _krate: CrateId,
type_alias: TypeAliasId, type_alias: TypeAliasId,
) -> Arc<AssociatedTyValue<ChalkIr>> { ) -> Arc<AssociatedTyValue> {
let type_alias_data = db.type_alias_data(type_alias); let type_alias_data = db.type_alias_data(type_alias);
let impl_id = match type_alias.lookup(db).container { let impl_id = match type_alias.lookup(db).container {
AssocContainerId::ImplId(it) => it, AssocContainerId::ImplId(it) => it,
@ -786,25 +780,25 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId {
chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() }
} }
impl From<chalk_ir::StructId> for crate::TypeCtorId { impl From<StructId> for crate::TypeCtorId {
fn from(struct_id: chalk_ir::StructId) -> Self { fn from(struct_id: StructId) -> Self {
id_from_chalk(struct_id.0) id_from_chalk(struct_id.0)
} }
} }
impl From<crate::TypeCtorId> for chalk_ir::StructId { impl From<crate::TypeCtorId> for StructId {
fn from(type_ctor_id: crate::TypeCtorId) -> Self { fn from(type_ctor_id: crate::TypeCtorId) -> Self {
chalk_ir::StructId(id_to_chalk(type_ctor_id)) chalk_ir::StructId(id_to_chalk(type_ctor_id))
} }
} }
impl From<chalk_ir::ImplId> for crate::traits::GlobalImplId { impl From<ImplId> for crate::traits::GlobalImplId {
fn from(impl_id: chalk_ir::ImplId) -> Self { fn from(impl_id: ImplId) -> Self {
id_from_chalk(impl_id.0) id_from_chalk(impl_id.0)
} }
} }
impl From<crate::traits::GlobalImplId> for chalk_ir::ImplId { impl From<crate::traits::GlobalImplId> for ImplId {
fn from(impl_id: crate::traits::GlobalImplId) -> Self { fn from(impl_id: crate::traits::GlobalImplId) -> Self {
chalk_ir::ImplId(id_to_chalk(impl_id)) chalk_ir::ImplId(id_to_chalk(impl_id))
} }