diff --git a/Cargo.lock b/Cargo.lock index 975c1aef86..506efdad02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,17 +114,18 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chalk-derive" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "proc-macro2", "quote", "syn", + "synstructure", ] [[package]] name = "chalk-engine" version = "0.9.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "chalk-macros", "rustc-hash", @@ -133,7 +134,7 @@ dependencies = [ [[package]] name = "chalk-ir" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "chalk-derive", "chalk-engine", @@ -143,7 +144,7 @@ dependencies = [ [[package]] name = "chalk-macros" version = "0.1.1" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "lazy_static", ] @@ -151,7 +152,7 @@ dependencies = [ [[package]] name = "chalk-rust-ir" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "chalk-derive", "chalk-engine", @@ -162,7 +163,7 @@ dependencies = [ [[package]] name = "chalk-solve" version = "0.1.0" -source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356" +source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea" dependencies = [ "chalk-derive", "chalk-engine", @@ -1564,6 +1565,18 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "synstructure" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + [[package]] name = "tempfile" version = "3.1.0" diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 59efc1c31d..aaee235d89 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -26,9 +26,9 @@ test_utils = { path = "../test_utils" } scoped-tls = "1" -chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" } -chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" } +chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" } +chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" } +chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" } [dev-dependencies] insta = "0.15.0" diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index e05fea8430..f6994a1f6f 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -32,6 +32,9 @@ impl chalk_ir::interner::Interner for Interner { type InternedGoal = Arc>; type InternedGoals = Vec>; type InternedSubstitution = Vec>; + type InternedProgramClause = chalk_ir::ProgramClauseData; + type InternedProgramClauses = Vec>; + type InternedQuantifiedWhereClauses = Vec>; type Identifier = TypeAliasId; type DefId = InternId; @@ -181,6 +184,48 @@ impl chalk_ir::interner::Interner for Interner { ) -> &'a [Parameter] { substitution } + + fn intern_program_clause( + &self, + data: chalk_ir::ProgramClauseData, + ) -> chalk_ir::ProgramClauseData { + data + } + + fn program_clause_data<'a>( + &self, + clause: &'a chalk_ir::ProgramClauseData, + ) -> &'a chalk_ir::ProgramClauseData { + clause + } + + fn intern_program_clauses( + &self, + data: impl IntoIterator>, + ) -> Vec> { + data.into_iter().collect() + } + + fn program_clauses_data<'a>( + &self, + clauses: &'a Vec>, + ) -> &'a [chalk_ir::ProgramClause] { + clauses + } + + fn intern_quantified_where_clauses( + &self, + data: impl IntoIterator>, + ) -> Self::InternedQuantifiedWhereClauses { + data.into_iter().collect() + } + + fn quantified_where_clauses_data<'a>( + &self, + clauses: &'a Self::InternedQuantifiedWhereClauses, + ) -> &'a [chalk_ir::QuantifiedWhereClause] { + clauses + } } impl chalk_ir::interner::HasInterner for Interner { @@ -238,12 +283,10 @@ impl ToChalk for Ty { Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner), Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), Ty::Dyn(predicates) => { - let where_clauses = predicates - .iter() - .filter(|p| !p.is_error()) - .cloned() - .map(|p| p.to_chalk(db)) - .collect(); + let where_clauses = chalk_ir::QuantifiedWhereClauses::from( + &Interner, + predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), + ); let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) }; chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) } @@ -281,8 +324,12 @@ impl ToChalk for Ty { chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown, chalk_ir::TyData::Dyn(where_clauses) => { assert_eq!(where_clauses.bounds.binders.len(), 1); - let predicates = - where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect(); + let predicates = where_clauses + .bounds + .skip_binders() + .iter(&Interner) + .map(|c| from_chalk(db, c.clone())) + .collect(); Ty::Dyn(predicates) } } @@ -426,7 +473,7 @@ impl ToChalk for GenericPredicate { ) -> GenericPredicate { // we don't produce any where clauses with binders and can't currently deal with them match where_clause - .value + .skip_binders() .shifted_out(&Interner) .expect("unexpected bound vars in where clause") { @@ -521,7 +568,7 @@ impl ToChalk for Arc { pred.clone().to_chalk(db).cast(&Interner); clauses.push(program_clause.into_from_env_clause(&Interner)); } - chalk_ir::Environment::new().add_clauses(clauses) + chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses) } fn from_chalk( @@ -603,10 +650,10 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData { } fn make_binders(value: T, num_vars: usize) -> chalk_ir::Binders { - chalk_ir::Binders { + chalk_ir::Binders::new( + std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars).collect(), value, - binders: std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars).collect(), - } + ) } fn convert_where_clauses( @@ -696,6 +743,12 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn interner(&self) -> &Interner { &Interner } + fn well_known_trait_id( + &self, + _well_known_trait: chalk_rust_ir::WellKnownTrait, + ) -> chalk_ir::TraitId { + unimplemented!() + } } pub(crate) fn associated_ty_data_query(