diff options
author | Florian Diebold <[email protected]> | 2019-06-29 16:40:00 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-07-08 20:20:17 +0100 |
commit | 638100dc8bea69cc4093d15f1641ed39a8d27a43 (patch) | |
tree | bb7cf46f4095e9e427f7d4277f28693a3bd671a6 /crates/ra_hir/src/ty/traits | |
parent | 32100022010ecfefd1ea06caa71d1a508d2eb75d (diff) |
Refactor a bit & introduce Environment struct
Diffstat (limited to 'crates/ra_hir/src/ty/traits')
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 4c3744b44..bee35fa62 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -12,7 +12,7 @@ use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; | |||
12 | use ra_db::salsa::{InternId, InternKey}; | 12 | use ra_db::salsa::{InternId, InternKey}; |
13 | use test_utils::tested_by; | 13 | use test_utils::tested_by; |
14 | 14 | ||
15 | use super::ChalkContext; | 15 | use super::{Canonical, ChalkContext}; |
16 | use crate::{ | 16 | use crate::{ |
17 | db::HirDatabase, | 17 | db::HirDatabase, |
18 | generics::GenericDef, | 18 | generics::GenericDef, |
@@ -218,6 +218,60 @@ impl ToChalk for ProjectionTy { | |||
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | impl<T> ToChalk for Canonical<T> | ||
222 | where | ||
223 | T: ToChalk, | ||
224 | { | ||
225 | type Chalk = chalk_ir::Canonical<T::Chalk>; | ||
226 | |||
227 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> { | ||
228 | let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); | ||
229 | let value = self.value.to_chalk(db); | ||
230 | let canonical = chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }; | ||
231 | canonical | ||
232 | } | ||
233 | |||
234 | fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { | ||
235 | Canonical { num_vars: canonical.binders.len(), value: from_chalk(db, canonical.value) } | ||
236 | } | ||
237 | } | ||
238 | |||
239 | impl ToChalk for Arc<super::Environment> { | ||
240 | type Chalk = Arc<chalk_ir::Environment>; | ||
241 | |||
242 | fn to_chalk(self, _db: &impl HirDatabase) -> Arc<chalk_ir::Environment> { | ||
243 | chalk_ir::Environment::new() | ||
244 | } | ||
245 | |||
246 | fn from_chalk( | ||
247 | _db: &impl HirDatabase, | ||
248 | _env: Arc<chalk_ir::Environment>, | ||
249 | ) -> Arc<super::Environment> { | ||
250 | Arc::new(super::Environment) | ||
251 | } | ||
252 | } | ||
253 | |||
254 | impl<T: ToChalk> ToChalk for super::InEnvironment<T> { | ||
255 | type Chalk = chalk_ir::InEnvironment<T::Chalk>; | ||
256 | |||
257 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { | ||
258 | chalk_ir::InEnvironment { | ||
259 | environment: self.environment.to_chalk(db), | ||
260 | goal: self.value.to_chalk(db), | ||
261 | } | ||
262 | } | ||
263 | |||
264 | fn from_chalk( | ||
265 | db: &impl HirDatabase, | ||
266 | in_env: chalk_ir::InEnvironment<T::Chalk>, | ||
267 | ) -> super::InEnvironment<T> { | ||
268 | super::InEnvironment { | ||
269 | environment: from_chalk(db, in_env.environment), | ||
270 | value: from_chalk(db, in_env.goal), | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | |||
221 | fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> { | 275 | fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> { |
222 | chalk_ir::Binders { | 276 | chalk_ir::Binders { |
223 | value, | 277 | value, |