From 06ed140fc7672466bc090fadd95bcf60ed6e82a4 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 22 May 2020 16:40:42 +0200 Subject: Update Chalk As always, this just makes compilation work, we don't use the newly available functionality yet. --- Cargo.lock | 41 ++++------- crates/ra_hir_ty/Cargo.toml | 6 +- crates/ra_hir_ty/src/traits/chalk.rs | 119 +++++++++++++++++++------------ crates/ra_hir_ty/src/traits/chalk/tls.rs | 8 +-- 4 files changed, 94 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ce35c5b1..007f05b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,7 +114,7 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chalk-derive" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "proc-macro2", "quote", @@ -125,7 +125,7 @@ dependencies = [ [[package]] name = "chalk-engine" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "chalk-macros", "rustc-hash", @@ -134,7 +134,7 @@ dependencies = [ [[package]] name = "chalk-ir" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "chalk-derive", "chalk-engine", @@ -144,7 +144,7 @@ dependencies = [ [[package]] name = "chalk-macros" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "lazy_static", ] @@ -152,7 +152,7 @@ dependencies = [ [[package]] name = "chalk-rust-ir" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "chalk-derive", "chalk-engine", @@ -163,14 +163,14 @@ dependencies = [ [[package]] name = "chalk-solve" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3" +source = "git+https://github.com/rust-lang/chalk.git?rev=eaab84b394007d1bed15f5470409a6ea02900a96#eaab84b394007d1bed15f5470409a6ea02900a96" dependencies = [ "chalk-derive", "chalk-engine", "chalk-ir", "chalk-macros", "chalk-rust-ir", - "ena 0.13.1", + "ena", "itertools", "petgraph", "rustc-hash", @@ -307,15 +307,6 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" -[[package]] -name = "ena" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8944dc8fa28ce4a38f778bd46bf7d923fe73eed5a439398507246c8e017e6f36" -dependencies = [ - "log", -] - [[package]] name = "ena" version = "0.14.0" @@ -354,9 +345,9 @@ dependencies = [ [[package]] name = "fixedbitset" -version = "0.1.9" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" [[package]] name = "fnv" @@ -813,12 +804,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" -[[package]] -name = "ordermap" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" - [[package]] name = "parking_lot" version = "0.10.2" @@ -873,12 +858,12 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "petgraph" -version = "0.4.13" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" +checksum = "29c127eea4a29ec6c85d153c59dc1213f33ec74cead30fe4730aecc88cc1fd92" dependencies = [ "fixedbitset", - "ordermap", + "indexmap", ] [[package]] @@ -1053,7 +1038,7 @@ dependencies = [ "chalk-ir", "chalk-rust-ir", "chalk-solve", - "ena 0.14.0", + "ena", "insta", "itertools", "log", diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 5fc0ec5e3..b2de7fa34 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -27,9 +27,9 @@ test_utils = { path = "../test_utils" } scoped-tls = "1" -chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" } -chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" } +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" } [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 5870618a0..c2d7abd17 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -4,7 +4,7 @@ use std::{fmt, sync::Arc}; use log::debug; use chalk_ir::{ - cast::Cast, fold::shift::Shift, interner::HasInterner, Goal, GoalData, Parameter, + cast::Cast, fold::shift::Shift, interner::HasInterner, GenericArg, Goal, GoalData, PlaceholderIndex, TypeName, UniverseIndex, }; @@ -26,24 +26,24 @@ pub(super) mod tls; pub struct Interner; impl chalk_ir::interner::Interner for Interner { - type InternedType = Box>; + type InternedType = Box>; // FIXME use Arc? type InternedLifetime = chalk_ir::LifetimeData; - type InternedParameter = chalk_ir::ParameterData; + type InternedConst = Arc>; + type InternedConcreteConst = (); + type InternedGenericArg = chalk_ir::GenericArgData; type InternedGoal = Arc>; type InternedGoals = Vec>; - type InternedSubstitution = Vec>; + type InternedSubstitution = Vec>; type InternedProgramClause = chalk_ir::ProgramClauseData; type InternedProgramClauses = Arc<[chalk_ir::ProgramClause]>; type InternedQuantifiedWhereClauses = Vec>; - type InternedParameterKinds = Vec>; - type InternedCanonicalVarKinds = Vec>; - type Identifier = TypeAliasId; + type InternedVariableKinds = Vec>; + type InternedCanonicalVarKinds = Vec>; type DefId = InternId; + type InternedAdtId = InternId; + type Identifier = TypeAliasId; - fn debug_struct_id( - type_kind_id: StructId, - fmt: &mut fmt::Formatter<'_>, - ) -> Option { + fn debug_adt_id(type_kind_id: StructId, fmt: &mut fmt::Formatter<'_>) -> Option { tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) } @@ -94,11 +94,11 @@ impl chalk_ir::interner::Interner for Interner { tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt))) } - fn debug_parameter( - parameter: &Parameter, + fn debug_generic_arg( + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option { - tls::with_current_program(|prog| Some(prog?.debug_parameter(parameter, fmt))) + tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) } fn debug_goal(goal: &Goal, fmt: &mut fmt::Formatter<'_>) -> Option { @@ -164,17 +164,32 @@ impl chalk_ir::interner::Interner for Interner { lifetime } - fn intern_parameter( + fn intern_const(&self, constant: chalk_ir::ConstData) -> Arc> { + Arc::new(constant) + } + + fn const_data<'a>( + &self, + constant: &'a Arc>, + ) -> &'a chalk_ir::ConstData { + constant + } + + fn const_eq(&self, _ty: &Box>, _c1: &(), _c2: &()) -> bool { + true + } + + fn intern_generic_arg( &self, - parameter: chalk_ir::ParameterData, - ) -> chalk_ir::ParameterData { + parameter: chalk_ir::GenericArgData, + ) -> chalk_ir::GenericArgData { parameter } - fn parameter_data<'a>( + fn generic_arg_data<'a>( &self, - parameter: &'a chalk_ir::ParameterData, - ) -> &'a chalk_ir::ParameterData { + parameter: &'a chalk_ir::GenericArgData, + ) -> &'a chalk_ir::GenericArgData { parameter } @@ -199,15 +214,15 @@ impl chalk_ir::interner::Interner for Interner { fn intern_substitution( &self, - data: impl IntoIterator, E>>, - ) -> Result>, E> { + data: impl IntoIterator, E>>, + ) -> Result>, E> { data.into_iter().collect() } fn substitution_data<'a>( &self, - substitution: &'a Vec>, - ) -> &'a [Parameter] { + substitution: &'a Vec>, + ) -> &'a [GenericArg] { substitution } @@ -253,23 +268,23 @@ impl chalk_ir::interner::Interner for Interner { clauses } - fn intern_parameter_kinds( + fn intern_generic_arg_kinds( &self, - data: impl IntoIterator, E>>, - ) -> Result { + data: impl IntoIterator, E>>, + ) -> Result { data.into_iter().collect() } - fn parameter_kinds_data<'a>( + fn variable_kinds_data<'a>( &self, - parameter_kinds: &'a Self::InternedParameterKinds, - ) -> &'a [chalk_ir::ParameterKind<()>] { + parameter_kinds: &'a Self::InternedVariableKinds, + ) -> &'a [chalk_ir::VariableKind] { ¶meter_kinds } fn intern_canonical_var_kinds( &self, - data: impl IntoIterator, E>>, + data: impl IntoIterator, E>>, ) -> Result { data.into_iter().collect() } @@ -277,7 +292,7 @@ impl chalk_ir::interner::Interner for Interner { fn canonical_var_kinds_data<'a>( &self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, - ) -> &'a [chalk_ir::ParameterKind] { + ) -> &'a [chalk_ir::CanonicalVarKind] { &canonical_var_kinds } } @@ -290,8 +305,8 @@ pub type AssocTypeId = chalk_ir::AssocTypeId; pub type AssociatedTyDatum = chalk_rust_ir::AssociatedTyDatum; pub type TraitId = chalk_ir::TraitId; pub type TraitDatum = chalk_rust_ir::TraitDatum; -pub type StructId = chalk_ir::StructId; -pub type StructDatum = chalk_rust_ir::StructDatum; +pub type StructId = chalk_ir::AdtId; +pub type StructDatum = chalk_rust_ir::AdtDatum; pub type ImplId = chalk_ir::ImplId; pub type ImplDatum = chalk_rust_ir::ImplDatum; pub type AssociatedTyValueId = chalk_rust_ir::AssociatedTyValueId; @@ -453,14 +468,14 @@ impl ToChalk for TypeCtor { _ => { // other TypeCtors get interned and turned into a chalk StructId let struct_id = db.intern_type_ctor(self).into(); - TypeName::Struct(struct_id) + TypeName::Adt(struct_id) } } } fn from_chalk(db: &dyn HirDatabase, type_name: TypeName) -> TypeCtor { match type_name { - TypeName::Struct(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), + TypeName::Adt(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), TypeName::OpaqueType(_) => unreachable!(), @@ -471,6 +486,8 @@ impl ToChalk for TypeCtor { TypeName::Ref(_) => unreachable!(), TypeName::Str => unreachable!(), + TypeName::FnDef(_) => unreachable!(), + TypeName::Error => { // this should not be reached, since we don't represent TypeName::Error with TypeCtor unreachable!() @@ -622,7 +639,10 @@ where type Chalk = chalk_ir::Canonical; fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical { - let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); + let parameter = chalk_ir::CanonicalVarKind::new( + chalk_ir::VariableKind::Ty, + chalk_ir::UniverseIndex::ROOT, + ); let value = self.value.to_chalk(db); chalk_ir::Canonical { value, @@ -738,9 +758,9 @@ where T: HasInterner, { chalk_ir::Binders::new( - chalk_ir::ParameterKinds::from( + chalk_ir::VariableKinds::from( &Interner, - std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars), + std::iter::repeat(chalk_ir::VariableKind::Ty).take(num_vars), ), value, ) @@ -819,16 +839,25 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn trait_datum(&self, trait_id: TraitId) -> Arc { self.db.trait_datum(self.krate, trait_id) } - fn struct_datum(&self, struct_id: StructId) -> Arc { + fn adt_datum(&self, struct_id: StructId) -> Arc { self.db.struct_datum(self.krate, struct_id) } fn impl_datum(&self, impl_id: ImplId) -> Arc { self.db.impl_datum(self.krate, impl_id) } + + fn fn_def_datum( + &self, + _fn_def_id: chalk_ir::FnDefId, + ) -> Arc> { + // We don't yet provide any FnDefs to Chalk + unimplemented!() + } + fn impls_for_trait( &self, trait_id: TraitId, - parameters: &[Parameter], + parameters: &[GenericArg], ) -> Vec { debug!("impls_for_trait {:?}", trait_id); let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); @@ -1000,7 +1029,7 @@ pub(crate) fn struct_datum_query( struct_id: StructId, ) -> Arc { debug!("struct_datum {:?}", struct_id); - let type_ctor: TypeCtor = from_chalk(db, TypeName::Struct(struct_id)); + let type_ctor: TypeCtor = from_chalk(db, TypeName::Adt(struct_id)); debug!("struct {:?} = {:?}", struct_id, type_ctor); let num_params = type_ctor.num_ty_params(db); let upstream = type_ctor.krate(db) != Some(krate); @@ -1012,12 +1041,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::StructFlags { + let flags = chalk_rust_ir::AdtFlags { upstream, // FIXME set fundamental flag correctly fundamental: false, }; - let struct_datum_bound = chalk_rust_ir::StructDatumBound { + let struct_datum_bound = chalk_rust_ir::AdtDatumBound { fields: Vec::new(), // FIXME add fields (only relevant for auto traits) where_clauses, }; @@ -1153,7 +1182,7 @@ impl From for crate::TypeCtorId { impl From for StructId { fn from(type_ctor_id: crate::TypeCtorId) -> Self { - chalk_ir::StructId(type_ctor_id.as_intern_id()) + chalk_ir::AdtId(type_ctor_id.as_intern_id()) } } diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 4867cb17e..b7eb49d7b 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -1,7 +1,7 @@ //! Implementation of Chalk debug helper functions using TLS. use std::fmt; -use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplication, TypeName}; +use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName}; use itertools::Itertools; use super::{from_chalk, Interner}; @@ -18,7 +18,7 @@ impl DebugContext<'_> { id: super::StructId, f: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Struct(id)); + let type_ctor: TypeCtor = from_chalk(self.0, TypeName::Adt(id)); match type_ctor { TypeCtor::Bool => write!(f, "bool")?, TypeCtor::Char => write!(f, "char")?, @@ -188,9 +188,9 @@ impl DebugContext<'_> { write!(fmt, "{:?}", lifetime.data(&Interner)) } - pub fn debug_parameter( + pub fn debug_generic_arg( &self, - parameter: &Parameter, + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()) -- cgit v1.2.3