diff options
author | Florian Diebold <[email protected]> | 2019-05-05 15:04:31 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-05-07 12:45:29 +0100 |
commit | a78228a39c4786e67e5a94384388a04aa8d7b172 (patch) | |
tree | b7a22e89ff4fa3c28001794ae2414b423d0e0fec /crates/ra_hir/src | |
parent | ef782adc293deb287128f005dbab2038ba3ccdc1 (diff) |
Turn `implements` into a query again
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/db.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 6 |
5 files changed, 13 insertions, 8 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 8aaf0375a..689dd6225 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -161,6 +161,13 @@ pub trait HirDatabase: DefDatabase { | |||
161 | #[salsa::invoke(crate::ty::traits::solver)] | 161 | #[salsa::invoke(crate::ty::traits::solver)] |
162 | #[salsa::volatile] | 162 | #[salsa::volatile] |
163 | fn solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>; | 163 | fn solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>; |
164 | |||
165 | #[salsa::invoke(crate::ty::traits::implements)] | ||
166 | fn implements( | ||
167 | &self, | ||
168 | krate: Crate, | ||
169 | goal: crate::ty::Canonical<crate::ty::TraitRef>, | ||
170 | ) -> Option<crate::ty::traits::Solution>; | ||
164 | } | 171 | } |
165 | 172 | ||
166 | #[test] | 173 | #[test] |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index f4eee835f..24c45d728 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -240,7 +240,7 @@ impl TraitRef { | |||
240 | /// many there are. This is used to erase irrelevant differences between types | 240 | /// many there are. This is used to erase irrelevant differences between types |
241 | /// before using them in queries. | 241 | /// before using them in queries. |
242 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 242 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
243 | pub(crate) struct Canonical<T> { | 243 | pub struct Canonical<T> { |
244 | pub value: T, | 244 | pub value: T, |
245 | pub num_vars: usize, | 245 | pub num_vars: usize, |
246 | } | 246 | } |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index edce1afe7..1e7d97f51 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -328,8 +328,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
328 | Obligation::Trait(tr) => { | 328 | Obligation::Trait(tr) => { |
329 | let canonicalized = self.canonicalizer().canonicalize_trait_ref(tr.clone()); | 329 | let canonicalized = self.canonicalizer().canonicalize_trait_ref(tr.clone()); |
330 | ( | 330 | ( |
331 | super::traits::implements( | 331 | self.db.implements( |
332 | self.db, | ||
333 | self.resolver.krate().unwrap(), | 332 | self.resolver.krate().unwrap(), |
334 | canonicalized.value.clone(), | 333 | canonicalized.value.clone(), |
335 | ), | 334 | ), |
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 607e9ba79..d8b8c836c 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -196,8 +196,7 @@ fn iterate_trait_method_candidates<T>( | |||
196 | if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { | 196 | if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { |
197 | if !known_implemented { | 197 | if !known_implemented { |
198 | let trait_ref = canonical_trait_ref(db, t, ty.clone()); | 198 | let trait_ref = canonical_trait_ref(db, t, ty.clone()); |
199 | // FIXME cache this implements check (without solution) in a query? | 199 | if db.implements(krate, trait_ref).is_none() { |
200 | if super::traits::implements(db, krate, trait_ref).is_none() { | ||
201 | continue 'traits; | 200 | continue 'traits; |
202 | } | 201 | } |
203 | } | 202 | } |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index a1ed0c028..f70a32575 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -125,11 +125,11 @@ fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) - | |||
125 | } | 125 | } |
126 | 126 | ||
127 | #[derive(Clone, Debug, PartialEq, Eq)] | 127 | #[derive(Clone, Debug, PartialEq, Eq)] |
128 | pub(crate) struct SolutionVariables(pub Canonical<Vec<Ty>>); | 128 | pub struct SolutionVariables(pub Canonical<Vec<Ty>>); |
129 | 129 | ||
130 | #[derive(Clone, Debug, PartialEq, Eq)] | 130 | #[derive(Clone, Debug, PartialEq, Eq)] |
131 | /// A (possible) solution for a proposed goal. | 131 | /// A (possible) solution for a proposed goal. |
132 | pub(crate) enum Solution { | 132 | pub enum Solution { |
133 | /// The goal indeed holds, and there is a unique value for all existential | 133 | /// The goal indeed holds, and there is a unique value for all existential |
134 | /// variables. | 134 | /// variables. |
135 | Unique(SolutionVariables), | 135 | Unique(SolutionVariables), |
@@ -144,7 +144,7 @@ pub(crate) enum Solution { | |||
144 | #[derive(Clone, Debug, PartialEq, Eq)] | 144 | #[derive(Clone, Debug, PartialEq, Eq)] |
145 | /// When a goal holds ambiguously (e.g., because there are multiple possible | 145 | /// When a goal holds ambiguously (e.g., because there are multiple possible |
146 | /// solutions), we issue a set of *guidance* back to type inference. | 146 | /// solutions), we issue a set of *guidance* back to type inference. |
147 | pub(crate) enum Guidance { | 147 | pub enum Guidance { |
148 | /// The existential variables *must* have the given values if the goal is | 148 | /// The existential variables *must* have the given values if the goal is |
149 | /// ever to hold, but that alone isn't enough to guarantee the goal will | 149 | /// ever to hold, but that alone isn't enough to guarantee the goal will |
150 | /// actually hold. | 150 | /// actually hold. |