From 3659502816134b45448799acf428055e40fdf4fc Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 27 Mar 2020 14:50:08 +0100 Subject: Upgrade Chalk --- Cargo.lock | 35 ++++------ crates/ra_hir_ty/Cargo.toml | 6 +- crates/ra_hir_ty/src/traits.rs | 6 +- crates/ra_hir_ty/src/traits/chalk.rs | 123 ++++++++++++++++++++++++++++------- 4 files changed, 118 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3ca9684b..c46bf9448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,7 +114,7 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chalk-derive" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "proc-macro2", "quote", @@ -124,7 +124,7 @@ dependencies = [ [[package]] name = "chalk-engine" version = "0.9.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "chalk-macros", "rustc-hash", @@ -133,7 +133,7 @@ dependencies = [ [[package]] name = "chalk-ir" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "chalk-derive", "chalk-engine", @@ -143,7 +143,7 @@ dependencies = [ [[package]] name = "chalk-macros" version = "0.1.1" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "lazy_static", ] @@ -151,7 +151,7 @@ dependencies = [ [[package]] name = "chalk-rust-ir" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "chalk-derive", "chalk-engine", @@ -162,7 +162,7 @@ dependencies = [ [[package]] name = "chalk-solve" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=177d71340acc7a7204a33115fc63075d86452179#177d71340acc7a7204a33115fc63075d86452179" +source = "git+https://github.com/rust-lang/chalk.git?rev=d383af7333cc6014e9d9e3e77668b5d5b0a5b40e#d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" dependencies = [ "chalk-derive", "chalk-engine", @@ -170,7 +170,7 @@ dependencies = [ "chalk-macros", "chalk-rust-ir", "ena", - "itertools 0.8.2", + "itertools", "petgraph", "rustc-hash", ] @@ -505,15 +505,6 @@ dependencies = [ "libc", ] -[[package]] -name = "itertools" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.9.0" @@ -873,7 +864,7 @@ name = "ra_assists" version = "0.1.0" dependencies = [ "either", - "itertools 0.9.0", + "itertools", "ra_db", "ra_fmt", "ra_hir", @@ -927,7 +918,7 @@ dependencies = [ name = "ra_fmt" version = "0.1.0" dependencies = [ - "itertools 0.9.0", + "itertools", "ra_syntax", ] @@ -937,7 +928,7 @@ version = "0.1.0" dependencies = [ "arrayvec", "either", - "itertools 0.9.0", + "itertools", "log", "ra_db", "ra_hir_def", @@ -1015,7 +1006,7 @@ dependencies = [ "either", "indexmap", "insta", - "itertools 0.9.0", + "itertools", "log", "ra_assists", "ra_cfg", @@ -1127,7 +1118,7 @@ name = "ra_syntax" version = "0.1.0" dependencies = [ "arrayvec", - "itertools 0.9.0", + "itertools", "once_cell", "ra_parser", "ra_text_edit", @@ -1305,7 +1296,7 @@ dependencies = [ "crossbeam-channel", "env_logger", "globset", - "itertools 0.9.0", + "itertools", "jod-thread", "log", "lsp-server", diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 5a58d70cf..2cbab800d 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -23,9 +23,9 @@ ra_prof = { path = "../ra_prof" } ra_syntax = { path = "../ra_syntax" } test_utils = { path = "../test_utils" } -chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } -chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } +chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" } +chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" } +chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" } [dev-dependencies] insta = "0.15.0" diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index a1ca33c98..80eae4eca 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -153,7 +153,7 @@ pub(crate) fn trait_solve_query( } } - let canonical = goal.to_chalk(db).cast(); + let canonical = goal.to_chalk(db).cast(&Interner); // We currently don't deal with universes (I think / hope they're not yet // relevant for our use cases?) @@ -194,8 +194,8 @@ fn solution_from_chalk( let convert_subst = |subst: chalk_ir::Canonical>| { let value = subst .value - .into_iter() - .map(|p| match p.ty() { + .iter(&Interner) + .map(|p| match p.ty(&Interner) { Some(ty) => from_chalk(db, ty.clone()), None => unimplemented!(), }) diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 943d5f125..ab4cb33b4 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -59,53 +59,126 @@ impl chalk_ir::interner::Interner for Interner { None } + fn debug_ty(_ty: &chalk_ir::Ty, _fmt: &mut fmt::Formatter<'_>) -> Option { + None + } + + fn debug_lifetime( + _lifetime: &chalk_ir::Lifetime, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_parameter( + _parameter: &Parameter, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_goal(_goal: &Goal, _fmt: &mut fmt::Formatter<'_>) -> Option { + None + } + + fn debug_goals( + _goals: &chalk_ir::Goals, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_program_clause_implication( + _pci: &chalk_ir::ProgramClauseImplication, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_application_ty( + _application_ty: &chalk_ir::ApplicationTy, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_substitution( + _substitution: &chalk_ir::Substitution, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + + fn debug_separator_trait_ref( + _separator_trait_ref: &chalk_ir::SeparatorTraitRef, + _fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + fn intern_ty(&self, ty: chalk_ir::TyData) -> Box> { Box::new(ty) } - fn ty_data(ty: &Box>) -> &chalk_ir::TyData { + fn ty_data<'a>(&self, ty: &'a Box>) -> &'a chalk_ir::TyData { ty } - fn intern_lifetime(lifetime: chalk_ir::LifetimeData) -> chalk_ir::LifetimeData { + fn intern_lifetime( + &self, + lifetime: chalk_ir::LifetimeData, + ) -> chalk_ir::LifetimeData { lifetime } - fn lifetime_data(lifetime: &chalk_ir::LifetimeData) -> &chalk_ir::LifetimeData { + fn lifetime_data<'a>( + &self, + lifetime: &'a chalk_ir::LifetimeData, + ) -> &'a chalk_ir::LifetimeData { lifetime } - fn intern_parameter(parameter: chalk_ir::ParameterData) -> chalk_ir::ParameterData { + fn intern_parameter( + &self, + parameter: chalk_ir::ParameterData, + ) -> chalk_ir::ParameterData { parameter } - fn parameter_data(parameter: &chalk_ir::ParameterData) -> &chalk_ir::ParameterData { + fn parameter_data<'a>( + &self, + parameter: &'a chalk_ir::ParameterData, + ) -> &'a chalk_ir::ParameterData { parameter } - fn intern_goal(goal: GoalData) -> Arc> { + fn intern_goal(&self, goal: GoalData) -> Arc> { Arc::new(goal) } - fn intern_goals(data: impl IntoIterator>) -> Self::InternedGoals { + fn intern_goals(&self, data: impl IntoIterator>) -> Self::InternedGoals { data.into_iter().collect() } - fn goal_data(goal: &Arc>) -> &GoalData { + fn goal_data<'a>(&self, goal: &'a Arc>) -> &'a GoalData { goal } - fn goals_data(goals: &Vec>) -> &[Goal] { + fn goals_data<'a>(&self, goals: &'a Vec>) -> &'a [Goal] { goals } fn intern_substitution( + &self, data: impl IntoIterator, E>>, ) -> Result>, E> { data.into_iter().collect() } - fn substitution_data(substitution: &Vec>) -> &[Parameter] { + fn substitution_data<'a>( + &self, + substitution: &'a Vec>, + ) -> &'a [Parameter] { substitution } } @@ -145,12 +218,14 @@ impl ToChalk for Ty { Ty::Apply(apply_ty) => { let name = apply_ty.ctor.to_chalk(db); let substitution = apply_ty.parameters.to_chalk(db); - chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) + chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) } Ty::Projection(proj_ty) => { let associated_ty_id = proj_ty.associated_ty.to_chalk(db); let substitution = proj_ty.parameters.to_chalk(db); - chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern(&Interner) + chalk_ir::AliasTy { associated_ty_id, substitution } + .cast(&Interner) + .intern(&Interner) } Ty::Placeholder(id) => { let interned_id = db.intern_type_param_id(id); @@ -173,14 +248,14 @@ impl ToChalk for Ty { chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) } Ty::Opaque(_) | Ty::Unknown => { - let substitution = chalk_ir::Substitution::empty(); + let substitution = chalk_ir::Substitution::empty(&Interner); let name = TypeName::Error; - chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) + chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner) } } } fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty) -> Self { - match chalk.data().clone() { + match chalk.data(&Interner).clone() { chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { TypeName::Error => Ty::Unknown, _ => { @@ -218,13 +293,13 @@ impl ToChalk for Substs { type Chalk = chalk_ir::Substitution; fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution { - chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) + chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) } fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution) -> Substs { let tys = parameters - .into_iter() - .map(|p| match p.ty() { + .iter(&Interner) + .map(|p| match p.ty(&Interner) { Some(ty) => from_chalk(db, ty.clone()), None => unimplemented!(), }) @@ -400,8 +475,8 @@ impl ToChalk for Obligation { fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal { match self { - Obligation::Trait(tr) => tr.to_chalk(db).cast(), - Obligation::Projection(pr) => pr.to_chalk(db).cast(), + Obligation::Trait(tr) => tr.to_chalk(db).cast(&Interner), + Obligation::Projection(pr) => pr.to_chalk(db).cast(&Interner), } } @@ -438,8 +513,8 @@ impl ToChalk for Arc { continue; } let program_clause: chalk_ir::ProgramClause = - pred.clone().to_chalk(db).cast(); - clauses.push(program_clause.into_from_env_clause()); + pred.clone().to_chalk(db).cast(&Interner); + clauses.push(program_clause.into_from_env_clause(&Interner)); } chalk_ir::Environment::new().add_clauses(clauses) } @@ -578,9 +653,9 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { .map(|impl_| impl_.to_chalk(self.db)) .collect(); - let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref().clone()); + let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); let arg: Option = - parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref().clone())); + parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref(&Interner).clone())); builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| { result.push(i.to_chalk(self.db)) -- cgit v1.2.3