aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-03-27 13:50:08 +0000
committerFlorian Diebold <[email protected]>2020-04-05 18:23:18 +0100
commit3659502816134b45448799acf428055e40fdf4fc (patch)
tree4a6e1c8e489f5aa61361cc336f719b4d19739eac /crates
parent3431312418ea255e98d3f94536344d396b9b07d6 (diff)
Upgrade Chalk
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/Cargo.toml6
-rw-r--r--crates/ra_hir_ty/src/traits.rs6
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs123
3 files changed, 105 insertions, 30 deletions
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" }
23ra_syntax = { path = "../ra_syntax" } 23ra_syntax = { path = "../ra_syntax" }
24test_utils = { path = "../test_utils" } 24test_utils = { path = "../test_utils" }
25 25
26chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } 26chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
27chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } 27chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
28chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" } 28chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
29 29
30[dev-dependencies] 30[dev-dependencies]
31insta = "0.15.0" 31insta = "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(
153 } 153 }
154 } 154 }
155 155
156 let canonical = goal.to_chalk(db).cast(); 156 let canonical = goal.to_chalk(db).cast(&Interner);
157 157
158 // We currently don't deal with universes (I think / hope they're not yet 158 // We currently don't deal with universes (I think / hope they're not yet
159 // relevant for our use cases?) 159 // relevant for our use cases?)
@@ -194,8 +194,8 @@ fn solution_from_chalk(
194 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { 194 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| {
195 let value = subst 195 let value = subst
196 .value 196 .value
197 .into_iter() 197 .iter(&Interner)
198 .map(|p| match p.ty() { 198 .map(|p| match p.ty(&Interner) {
199 Some(ty) => from_chalk(db, ty.clone()), 199 Some(ty) => from_chalk(db, ty.clone()),
200 None => unimplemented!(), 200 None => unimplemented!(),
201 }) 201 })
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 {
59 None 59 None
60 } 60 }
61 61
62 fn debug_ty(_ty: &chalk_ir::Ty<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
63 None
64 }
65
66 fn debug_lifetime(
67 _lifetime: &chalk_ir::Lifetime<Self>,
68 _fmt: &mut fmt::Formatter<'_>,
69 ) -> Option<fmt::Result> {
70 None
71 }
72
73 fn debug_parameter(
74 _parameter: &Parameter<Self>,
75 _fmt: &mut fmt::Formatter<'_>,
76 ) -> Option<fmt::Result> {
77 None
78 }
79
80 fn debug_goal(_goal: &Goal<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
81 None
82 }
83
84 fn debug_goals(
85 _goals: &chalk_ir::Goals<Self>,
86 _fmt: &mut fmt::Formatter<'_>,
87 ) -> Option<fmt::Result> {
88 None
89 }
90
91 fn debug_program_clause_implication(
92 _pci: &chalk_ir::ProgramClauseImplication<Self>,
93 _fmt: &mut fmt::Formatter<'_>,
94 ) -> Option<fmt::Result> {
95 None
96 }
97
98 fn debug_application_ty(
99 _application_ty: &chalk_ir::ApplicationTy<Self>,
100 _fmt: &mut fmt::Formatter<'_>,
101 ) -> Option<fmt::Result> {
102 None
103 }
104
105 fn debug_substitution(
106 _substitution: &chalk_ir::Substitution<Self>,
107 _fmt: &mut fmt::Formatter<'_>,
108 ) -> Option<fmt::Result> {
109 None
110 }
111
112 fn debug_separator_trait_ref(
113 _separator_trait_ref: &chalk_ir::SeparatorTraitRef<Self>,
114 _fmt: &mut fmt::Formatter<'_>,
115 ) -> Option<fmt::Result> {
116 None
117 }
118
62 fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { 119 fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> {
63 Box::new(ty) 120 Box::new(ty)
64 } 121 }
65 122
66 fn ty_data(ty: &Box<chalk_ir::TyData<Self>>) -> &chalk_ir::TyData<Self> { 123 fn ty_data<'a>(&self, ty: &'a Box<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> {
67 ty 124 ty
68 } 125 }
69 126
70 fn intern_lifetime(lifetime: chalk_ir::LifetimeData<Self>) -> chalk_ir::LifetimeData<Self> { 127 fn intern_lifetime(
128 &self,
129 lifetime: chalk_ir::LifetimeData<Self>,
130 ) -> chalk_ir::LifetimeData<Self> {
71 lifetime 131 lifetime
72 } 132 }
73 133
74 fn lifetime_data(lifetime: &chalk_ir::LifetimeData<Self>) -> &chalk_ir::LifetimeData<Self> { 134 fn lifetime_data<'a>(
135 &self,
136 lifetime: &'a chalk_ir::LifetimeData<Self>,
137 ) -> &'a chalk_ir::LifetimeData<Self> {
75 lifetime 138 lifetime
76 } 139 }
77 140
78 fn intern_parameter(parameter: chalk_ir::ParameterData<Self>) -> chalk_ir::ParameterData<Self> { 141 fn intern_parameter(
142 &self,
143 parameter: chalk_ir::ParameterData<Self>,
144 ) -> chalk_ir::ParameterData<Self> {
79 parameter 145 parameter
80 } 146 }
81 147
82 fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> { 148 fn parameter_data<'a>(
149 &self,
150 parameter: &'a chalk_ir::ParameterData<Self>,
151 ) -> &'a chalk_ir::ParameterData<Self> {
83 parameter 152 parameter
84 } 153 }
85 154
86 fn intern_goal(goal: GoalData<Self>) -> Arc<GoalData<Self>> { 155 fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> {
87 Arc::new(goal) 156 Arc::new(goal)
88 } 157 }
89 158
90 fn intern_goals(data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals { 159 fn intern_goals(&self, data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals {
91 data.into_iter().collect() 160 data.into_iter().collect()
92 } 161 }
93 162
94 fn goal_data(goal: &Arc<GoalData<Self>>) -> &GoalData<Self> { 163 fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> {
95 goal 164 goal
96 } 165 }
97 166
98 fn goals_data(goals: &Vec<Goal<Interner>>) -> &[Goal<Interner>] { 167 fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] {
99 goals 168 goals
100 } 169 }
101 170
102 fn intern_substitution<E>( 171 fn intern_substitution<E>(
172 &self,
103 data: impl IntoIterator<Item = Result<Parameter<Self>, E>>, 173 data: impl IntoIterator<Item = Result<Parameter<Self>, E>>,
104 ) -> Result<Vec<Parameter<Self>>, E> { 174 ) -> Result<Vec<Parameter<Self>>, E> {
105 data.into_iter().collect() 175 data.into_iter().collect()
106 } 176 }
107 177
108 fn substitution_data(substitution: &Vec<Parameter<Self>>) -> &[Parameter<Self>] { 178 fn substitution_data<'a>(
179 &self,
180 substitution: &'a Vec<Parameter<Self>>,
181 ) -> &'a [Parameter<Self>] {
109 substitution 182 substitution
110 } 183 }
111} 184}
@@ -145,12 +218,14 @@ impl ToChalk for Ty {
145 Ty::Apply(apply_ty) => { 218 Ty::Apply(apply_ty) => {
146 let name = apply_ty.ctor.to_chalk(db); 219 let name = apply_ty.ctor.to_chalk(db);
147 let substitution = apply_ty.parameters.to_chalk(db); 220 let substitution = apply_ty.parameters.to_chalk(db);
148 chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) 221 chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner)
149 } 222 }
150 Ty::Projection(proj_ty) => { 223 Ty::Projection(proj_ty) => {
151 let associated_ty_id = proj_ty.associated_ty.to_chalk(db); 224 let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
152 let substitution = proj_ty.parameters.to_chalk(db); 225 let substitution = proj_ty.parameters.to_chalk(db);
153 chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern(&Interner) 226 chalk_ir::AliasTy { associated_ty_id, substitution }
227 .cast(&Interner)
228 .intern(&Interner)
154 } 229 }
155 Ty::Placeholder(id) => { 230 Ty::Placeholder(id) => {
156 let interned_id = db.intern_type_param_id(id); 231 let interned_id = db.intern_type_param_id(id);
@@ -173,14 +248,14 @@ impl ToChalk for Ty {
173 chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) 248 chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner)
174 } 249 }
175 Ty::Opaque(_) | Ty::Unknown => { 250 Ty::Opaque(_) | Ty::Unknown => {
176 let substitution = chalk_ir::Substitution::empty(); 251 let substitution = chalk_ir::Substitution::empty(&Interner);
177 let name = TypeName::Error; 252 let name = TypeName::Error;
178 chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner) 253 chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner)
179 } 254 }
180 } 255 }
181 } 256 }
182 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { 257 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
183 match chalk.data().clone() { 258 match chalk.data(&Interner).clone() {
184 chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { 259 chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name {
185 TypeName::Error => Ty::Unknown, 260 TypeName::Error => Ty::Unknown,
186 _ => { 261 _ => {
@@ -218,13 +293,13 @@ impl ToChalk for Substs {
218 type Chalk = chalk_ir::Substitution<Interner>; 293 type Chalk = chalk_ir::Substitution<Interner>;
219 294
220 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { 295 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
221 chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) 296 chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db)))
222 } 297 }
223 298
224 fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { 299 fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs {
225 let tys = parameters 300 let tys = parameters
226 .into_iter() 301 .iter(&Interner)
227 .map(|p| match p.ty() { 302 .map(|p| match p.ty(&Interner) {
228 Some(ty) => from_chalk(db, ty.clone()), 303 Some(ty) => from_chalk(db, ty.clone()),
229 None => unimplemented!(), 304 None => unimplemented!(),
230 }) 305 })
@@ -400,8 +475,8 @@ impl ToChalk for Obligation {
400 475
401 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> { 476 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
402 match self { 477 match self {
403 Obligation::Trait(tr) => tr.to_chalk(db).cast(), 478 Obligation::Trait(tr) => tr.to_chalk(db).cast(&Interner),
404 Obligation::Projection(pr) => pr.to_chalk(db).cast(), 479 Obligation::Projection(pr) => pr.to_chalk(db).cast(&Interner),
405 } 480 }
406 } 481 }
407 482
@@ -438,8 +513,8 @@ impl ToChalk for Arc<super::TraitEnvironment> {
438 continue; 513 continue;
439 } 514 }
440 let program_clause: chalk_ir::ProgramClause<Interner> = 515 let program_clause: chalk_ir::ProgramClause<Interner> =
441 pred.clone().to_chalk(db).cast(); 516 pred.clone().to_chalk(db).cast(&Interner);
442 clauses.push(program_clause.into_from_env_clause()); 517 clauses.push(program_clause.into_from_env_clause(&Interner));
443 } 518 }
444 chalk_ir::Environment::new().add_clauses(clauses) 519 chalk_ir::Environment::new().add_clauses(clauses)
445 } 520 }
@@ -578,9 +653,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
578 .map(|impl_| impl_.to_chalk(self.db)) 653 .map(|impl_| impl_.to_chalk(self.db))
579 .collect(); 654 .collect();
580 655
581 let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref().clone()); 656 let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone());
582 let arg: Option<Ty> = 657 let arg: Option<Ty> =
583 parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref().clone())); 658 parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref(&Interner).clone()));
584 659
585 builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| { 660 builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| {
586 result.push(i.to_chalk(self.db)) 661 result.push(i.to_chalk(self.db))