aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-07 18:37:47 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-07 18:37:47 +0100
commit70cd5ffbf5f2283fc4986c581d225987620b5335 (patch)
tree10d66df8729d3bd823ace808f3a05146a32d4ed4 /crates/ra_hir/src/ty
parentd3efedb752bb2198796603d8a479a5e3ee472a97 (diff)
parent530b3047ed19a6468fc75e5a5ec14763093a069d (diff)
Merge #1251
1251: Chalk integration improvements r=matklad a=flodiebold A few improvements that came up while working on where clause support: - turn `implements` into a query again to improve performance - allow skipping to a specific function with `analysis-stats`, e.g. `ra_cli analysis-stats --only world_symbols` - deduplicate impls in impls_for_trait -- previously many impls e.g. from std where repeated many times, this should help performance as well... - add a `HirDisplay` implementation for TraitRef (not used here anywhere, but useful for debugging) Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs3
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs3
-rw-r--r--crates/ra_hir/src/ty/traits.rs11
3 files changed, 8 insertions, 9 deletions
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..4bbc99f0e 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -1,6 +1,7 @@
1//! Trait solving using Chalk. 1//! Trait solving using Chalk.
2use std::sync::{Arc, Mutex}; 2use std::sync::{Arc, Mutex};
3 3
4use rustc_hash::FxHashSet;
4use log::debug; 5use log::debug;
5use chalk_ir::cast::Cast; 6use chalk_ir::cast::Cast;
6 7
@@ -31,7 +32,7 @@ pub(crate) fn impls_for_trait(
31 krate: Crate, 32 krate: Crate,
32 trait_: Trait, 33 trait_: Trait,
33) -> Arc<[ImplBlock]> { 34) -> Arc<[ImplBlock]> {
34 let mut impls = Vec::new(); 35 let mut impls = FxHashSet::default();
35 // We call the query recursively here. On the one hand, this means we can 36 // We call the query recursively here. On the one hand, this means we can
36 // reuse results from queries for different crates; on the other hand, this 37 // reuse results from queries for different crates; on the other hand, this
37 // will only ever get called for a few crates near the root of the tree (the 38 // will only ever get called for a few crates near the root of the tree (the
@@ -42,7 +43,7 @@ pub(crate) fn impls_for_trait(
42 } 43 }
43 let crate_impl_blocks = db.impls_in_crate(krate); 44 let crate_impl_blocks = db.impls_in_crate(krate);
44 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(&trait_)); 45 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(&trait_));
45 impls.into() 46 impls.into_iter().collect::<Vec<_>>().into()
46} 47}
47 48
48fn solve( 49fn solve(
@@ -125,11 +126,11 @@ fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -
125} 126}
126 127
127#[derive(Clone, Debug, PartialEq, Eq)] 128#[derive(Clone, Debug, PartialEq, Eq)]
128pub(crate) struct SolutionVariables(pub Canonical<Vec<Ty>>); 129pub struct SolutionVariables(pub Canonical<Vec<Ty>>);
129 130
130#[derive(Clone, Debug, PartialEq, Eq)] 131#[derive(Clone, Debug, PartialEq, Eq)]
131/// A (possible) solution for a proposed goal. 132/// A (possible) solution for a proposed goal.
132pub(crate) enum Solution { 133pub enum Solution {
133 /// The goal indeed holds, and there is a unique value for all existential 134 /// The goal indeed holds, and there is a unique value for all existential
134 /// variables. 135 /// variables.
135 Unique(SolutionVariables), 136 Unique(SolutionVariables),
@@ -144,7 +145,7 @@ pub(crate) enum Solution {
144#[derive(Clone, Debug, PartialEq, Eq)] 145#[derive(Clone, Debug, PartialEq, Eq)]
145/// When a goal holds ambiguously (e.g., because there are multiple possible 146/// When a goal holds ambiguously (e.g., because there are multiple possible
146/// solutions), we issue a set of *guidance* back to type inference. 147/// solutions), we issue a set of *guidance* back to type inference.
147pub(crate) enum Guidance { 148pub enum Guidance {
148 /// The existential variables *must* have the given values if the goal is 149 /// 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 150 /// ever to hold, but that alone isn't enough to guarantee the goal will
150 /// actually hold. 151 /// actually hold.