From c8a4bb1445e214dc7105de547bd999ad270e7b42 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 27 May 2020 21:05:21 +0200 Subject: Upgrade Chalk Chalk newly added TypeName::Never and Array; I implemented the conversion for Never, but not Array since that expects a const argument. --- Cargo.lock | 46 +++++++++--------------- Cargo.toml | 2 -- crates/ra_hir_ty/Cargo.toml | 5 ++- crates/ra_hir_ty/src/traits/chalk.rs | 50 +++++++++++++-------------- crates/ra_hir_ty/src/traits/chalk/interner.rs | 14 ++++---- crates/ra_hir_ty/src/traits/chalk/mapping.rs | 40 ++++++++++----------- 6 files changed, 71 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f3d1f564..1159d0f1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,10 +111,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chalk-base" +version = "0.10.1-dev" +source = "git+https://github.com/rust-lang/chalk.git?rev=5a3b871ca17529ab5aa5787594fabad1634936cb#5a3b871ca17529ab5aa5787594fabad1634936cb" +dependencies = [ + "lazy_static", +] + [[package]] name = "chalk-derive" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" +source = "git+https://github.com/rust-lang/chalk.git?rev=5a3b871ca17529ab5aa5787594fabad1634936cb#5a3b871ca17529ab5aa5787594fabad1634936cb" dependencies = [ "proc-macro2", "quote", @@ -125,51 +133,32 @@ dependencies = [ [[package]] name = "chalk-engine" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" +source = "git+https://github.com/rust-lang/chalk.git?rev=5a3b871ca17529ab5aa5787594fabad1634936cb#5a3b871ca17529ab5aa5787594fabad1634936cb" dependencies = [ - "chalk-macros", + "chalk-base", + "chalk-derive", + "chalk-ir", "rustc-hash", ] [[package]] name = "chalk-ir" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" +source = "git+https://github.com/rust-lang/chalk.git?rev=5a3b871ca17529ab5aa5787594fabad1634936cb#5a3b871ca17529ab5aa5787594fabad1634936cb" dependencies = [ + "chalk-base", "chalk-derive", - "chalk-engine", - "chalk-macros", -] - -[[package]] -name = "chalk-macros" -version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "chalk-rust-ir" -version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" -dependencies = [ - "chalk-derive", - "chalk-engine", - "chalk-ir", - "chalk-macros", ] [[package]] name = "chalk-solve" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" +source = "git+https://github.com/rust-lang/chalk.git?rev=5a3b871ca17529ab5aa5787594fabad1634936cb#5a3b871ca17529ab5aa5787594fabad1634936cb" dependencies = [ + "chalk-base", "chalk-derive", "chalk-engine", "chalk-ir", - "chalk-macros", - "chalk-rust-ir", "ena", "itertools", "petgraph", @@ -1036,7 +1025,6 @@ version = "0.1.0" dependencies = [ "arrayvec", "chalk-ir", - "chalk-rust-ir", "chalk-solve", "ena", "insta", diff --git a/Cargo.toml b/Cargo.toml index c034e2424..5278b5a16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,6 @@ opt-level = 0 opt-level = 0 [profile.release.package.chalk-derive] opt-level = 0 -[profile.release.package.chalk-macros] -opt-level = 0 [profile.release.package.salsa-macros] opt-level = 0 [profile.release.package.xtask] diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index b2de7fa34..6afed58a1 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -27,9 +27,8 @@ test_utils = { path = "../test_utils" } scoped-tls = "1" -chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "eaab84b394007d1bed15f5470409a6ea02900a96" } -chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "eaab84b394007d1bed15f5470409a6ea02900a96" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "eaab84b394007d1bed15f5470409a6ea02900a96" } +chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "5a3b871ca17529ab5aa5787594fabad1634936cb" } +chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "5a3b871ca17529ab5aa5787594fabad1634936cb" } [dev-dependencies] insta = "0.16.0" diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 5b0f12a3c..61de3cc30 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use log::debug; use chalk_ir::{fold::shift::Shift, GenericArg, TypeName}; +use chalk_solve::rust_ir::{self, WellKnownTrait}; use hir_def::{ lang_item::{lang_attr, LangItemTarget}, @@ -16,7 +17,6 @@ use crate::{ db::HirDatabase, display::HirDisplay, method_resolution::TyFingerprint, utils::generics, CallableDef, DebruijnIndex, GenericPredicate, Substs, Ty, TypeCtor, }; -use chalk_rust_ir::WellKnownTrait; use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, make_binders}; pub use self::interner::*; @@ -55,7 +55,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn fn_def_datum( &self, fn_def_id: chalk_ir::FnDefId, - ) -> Arc> { + ) -> Arc> { self.db.fn_def_datum(self.krate, fn_def_id) } @@ -112,7 +112,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { } fn well_known_trait_id( &self, - well_known_trait: chalk_rust_ir::WellKnownTrait, + well_known_trait: rust_ir::WellKnownTrait, ) -> Option> { let lang_attr = lang_attr_from_well_known_trait(well_known_trait); let lang_items = self.db.crate_lang_items(self.krate); @@ -133,13 +133,13 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn opaque_ty_data( &self, _id: chalk_ir::OpaqueTyId, - ) -> Arc> { + ) -> Arc> { unimplemented!() } fn force_impl_for( &self, - _well_known: chalk_rust_ir::WellKnownTrait, + _well_known: rust_ir::WellKnownTrait, _ty: &chalk_ir::TyData, ) -> Option { // this method is mostly for rustc @@ -150,6 +150,10 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { // FIXME: implement actual object safety true } + + fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId) -> chalk_ir::Ty { + Ty::Unknown.to_chalk(self.db) + } } pub(crate) fn program_clauses_for_chalk_env_query( @@ -188,7 +192,7 @@ pub(crate) fn associated_ty_data_query( .collect(); let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); - let bound_data = chalk_rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; + let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; let datum = AssociatedTyDatum { trait_id: trait_.to_chalk(db), id, @@ -209,7 +213,7 @@ pub(crate) fn trait_datum_query( debug!("trait {:?} = {:?}", trait_id, trait_data.name); let generic_params = generics(db.upcast(), trait_.into()); let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); - let flags = chalk_rust_ir::TraitFlags { + let flags = rust_ir::TraitFlags { auto: trait_data.auto, upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, non_enumerable: true, @@ -221,7 +225,7 @@ pub(crate) fn trait_datum_query( let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); let associated_ty_ids = trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect(); - let trait_datum_bound = chalk_rust_ir::TraitDatumBound { where_clauses }; + let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; let well_known = lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); let trait_datum = TraitDatum { @@ -271,12 +275,12 @@ pub(crate) fn struct_datum_query( convert_where_clauses(db, generic_def, &bound_vars) }) .unwrap_or_else(Vec::new); - let flags = chalk_rust_ir::AdtFlags { + let flags = rust_ir::AdtFlags { upstream, // FIXME set fundamental flag correctly fundamental: false, }; - let struct_datum_bound = chalk_rust_ir::AdtDatumBound { + let struct_datum_bound = rust_ir::AdtDatumBound { fields: Vec::new(), // FIXME add fields (only relevant for auto traits) where_clauses, }; @@ -316,9 +320,9 @@ fn impl_def_datum( let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let trait_ = trait_ref.trait_; let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate == krate { - chalk_rust_ir::ImplType::Local + rust_ir::ImplType::Local } else { - chalk_rust_ir::ImplType::External + rust_ir::ImplType::External }; let where_clauses = convert_where_clauses(db, impl_id.into(), &bound_vars); let negative = impl_data.is_negative; @@ -331,13 +335,9 @@ fn impl_def_datum( ); let trait_ref = trait_ref.to_chalk(db); - let polarity = if negative { - chalk_rust_ir::Polarity::Negative - } else { - chalk_rust_ir::Polarity::Positive - }; + let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive }; - let impl_datum_bound = chalk_rust_ir::ImplDatumBound { trait_ref, where_clauses }; + let impl_datum_bound = rust_ir::ImplDatumBound { trait_ref, where_clauses }; let trait_data = db.trait_data(trait_); let associated_ty_value_ids = impl_data .items @@ -395,8 +395,8 @@ fn type_alias_associated_ty_value( .associated_type_by_name(&type_alias_data.name) .expect("assoc ty value should not exist"); // validated when building the impl data as well let ty = db.ty(type_alias.into()); - let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; - let value = chalk_rust_ir::AssociatedTyValue { + let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; + let value = rust_ir::AssociatedTyValue { impl_id: Impl::ImplDef(impl_id).to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db), value: make_binders(value_bound, ty.num_binders), @@ -414,7 +414,7 @@ pub(crate) fn fn_def_datum_query( let sig = db.callable_item_signature(callable_def); let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); - let bound = chalk_rust_ir::FnDefDatumBound { + let bound = rust_ir::FnDefDatumBound { // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway argument_types: sig.value.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), return_type: sig.value.ret().clone().to_chalk(db), @@ -460,14 +460,14 @@ impl From for ImplId { } } -impl From> for crate::traits::AssocTyValueId { - fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { +impl From> for crate::traits::AssocTyValueId { + fn from(id: rust_ir::AssociatedTyValueId) -> Self { Self::from_intern_id(id.0) } } -impl From for chalk_rust_ir::AssociatedTyValueId { +impl From for rust_ir::AssociatedTyValueId { fn from(assoc_ty_value_id: crate::traits::AssocTyValueId) -> Self { - chalk_rust_ir::AssociatedTyValueId(assoc_ty_value_id.as_intern_id()) + rust_ir::AssociatedTyValueId(assoc_ty_value_id.as_intern_id()) } } diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 2a27f8ed8..e27074ba6 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs @@ -11,17 +11,17 @@ use std::{fmt, sync::Arc}; pub struct Interner; pub type AssocTypeId = chalk_ir::AssocTypeId; -pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum; +pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum; pub type TraitId = chalk_ir::TraitId; -pub type TraitDatum = chalk_rust_ir::TraitDatum; +pub type TraitDatum = chalk_solve::rust_ir::TraitDatum; pub type AdtId = chalk_ir::AdtId; -pub type StructDatum = chalk_rust_ir::AdtDatum; +pub type StructDatum = chalk_solve::rust_ir::AdtDatum; pub type ImplId = chalk_ir::ImplId; -pub type ImplDatum = chalk_rust_ir::ImplDatum; -pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId; -pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue; +pub type ImplDatum = chalk_solve::rust_ir::ImplDatum; +pub type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId; +pub type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue; pub type FnDefId = chalk_ir::FnDefId; -pub type FnDefDatum = chalk_rust_ir::FnDefDatum; +pub type FnDefDatum = chalk_solve::rust_ir::FnDefDatum; impl chalk_ir::interner::Interner for Interner { type InternedType = Box>; // FIXME use Arc? diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 7082cb095..5f6daf842 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -7,6 +7,7 @@ use chalk_ir::{ cast::Cast, fold::shift::Shift, interner::HasInterner, PlaceholderIndex, Scalar, TypeName, UniverseIndex, }; +use chalk_solve::rust_ir; use hir_def::{type_ref::Mutability, AssocContainerId, GenericDefId, Lookup, TypeAliasId}; use ra_db::salsa::InternKey; @@ -106,7 +107,7 @@ impl ToChalk for Ty { }) } chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx), - chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, + chalk_ir::TyData::InferenceVar(_iv, _kind) => Ty::Unknown, chalk_ir::TyData::Dyn(where_clauses) => { assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); let predicates = where_clauses @@ -232,12 +233,13 @@ impl ToChalk for TypeCtor { let id = callable_def.to_chalk(db); TypeName::FnDef(id) } + TypeCtor::Never => TypeName::Never, + TypeCtor::Int(Uncertain::Unknown) | TypeCtor::Float(Uncertain::Unknown) | TypeCtor::Adt(_) | TypeCtor::Array | TypeCtor::FnPtr { .. } - | TypeCtor::Never | TypeCtor::Closure { .. } => { // other TypeCtors get interned and turned into a chalk StructId let struct_id = db.intern_type_ctor(self).into(); @@ -273,13 +275,14 @@ impl ToChalk for TypeCtor { TypeName::Slice => TypeCtor::Slice, TypeName::Ref(mutability) => TypeCtor::Ref(from_chalk(db, mutability)), TypeName::Str => TypeCtor::Str, + TypeName::Never => TypeCtor::Never, TypeName::FnDef(fn_def_id) => { let callable_def = from_chalk(db, fn_def_id); TypeCtor::FnDef(callable_def) } - TypeName::Error => { + TypeName::Array | TypeName::Error => { // this should not be reached, since we don't represent TypeName::Error with TypeCtor unreachable!() } @@ -508,7 +511,7 @@ where fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical { let parameter = chalk_ir::CanonicalVarKind::new( - chalk_ir::VariableKind::Ty, + chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General), chalk_ir::UniverseIndex::ROOT, ); let value = self.value.to_chalk(db); @@ -579,17 +582,17 @@ impl ToChalk for builtin::BuiltinImplData { type Chalk = ImplDatum; fn to_chalk(self, db: &dyn HirDatabase) -> ImplDatum { - let impl_type = chalk_rust_ir::ImplType::External; + let impl_type = rust_ir::ImplType::External; let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect(); let impl_datum_bound = - chalk_rust_ir::ImplDatumBound { trait_ref: self.trait_ref.to_chalk(db), where_clauses }; + rust_ir::ImplDatumBound { trait_ref: self.trait_ref.to_chalk(db), where_clauses }; let associated_ty_value_ids = self.assoc_ty_values.into_iter().map(|v| v.to_chalk(db)).collect(); - chalk_rust_ir::ImplDatum { + rust_ir::ImplDatum { binders: make_binders(impl_datum_bound, self.num_vars), impl_type, - polarity: chalk_rust_ir::Polarity::Positive, + polarity: rust_ir::Polarity::Positive, associated_ty_value_ids, } } @@ -604,9 +607,9 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData { fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { let ty = self.value.to_chalk(db); - let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty }; + let value_bound = rust_ir::AssociatedTyValueBound { ty }; - chalk_rust_ir::AssociatedTyValue { + rust_ir::AssociatedTyValue { associated_ty_id: self.assoc_ty_id.to_chalk(db), impl_id: self.impl_.to_chalk(db), value: make_binders(value_bound, self.num_vars), @@ -628,7 +631,7 @@ where chalk_ir::Binders::new( chalk_ir::VariableKinds::from( &Interner, - std::iter::repeat(chalk_ir::VariableKind::Ty).take(num_vars), + std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)).take(num_vars), ), value, ) @@ -655,7 +658,7 @@ pub(super) fn generic_predicate_to_inline_bound( db: &dyn HirDatabase, pred: &GenericPredicate, self_ty: &Ty, -) -> Option> { +) -> Option> { // An InlineBound is like a GenericPredicate, except the self type is left out. // We don't have a special type for this, but Chalk does. match pred { @@ -670,8 +673,8 @@ pub(super) fn generic_predicate_to_inline_bound( .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) .collect(); let trait_bound = - chalk_rust_ir::TraitBound { trait_id: trait_ref.trait_.to_chalk(db), args_no_self }; - Some(chalk_rust_ir::InlineBound::TraitBound(trait_bound)) + rust_ir::TraitBound { trait_id: trait_ref.trait_.to_chalk(db), args_no_self }; + Some(rust_ir::InlineBound::TraitBound(trait_bound)) } GenericPredicate::Projection(proj) => { if &proj.projection_ty.parameters[0] != self_ty { @@ -685,16 +688,13 @@ pub(super) fn generic_predicate_to_inline_bound( .iter() .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) .collect(); - let alias_eq_bound = chalk_rust_ir::AliasEqBound { + let alias_eq_bound = rust_ir::AliasEqBound { value: proj.ty.clone().to_chalk(db), - trait_bound: chalk_rust_ir::TraitBound { - trait_id: trait_.to_chalk(db), - args_no_self, - }, + trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, associated_ty_id: proj.projection_ty.associated_ty.to_chalk(db), parameters: Vec::new(), // FIXME we don't support generic associated types yet }; - Some(chalk_rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) + Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) } GenericPredicate::Error => None, } -- cgit v1.2.3