diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/autoderef.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 15 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 11 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/types.rs | 10 |
7 files changed, 53 insertions, 33 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 8d00f7401..caa22dace 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -58,9 +58,8 @@ use hir_ty::{ | |||
58 | subst_prefix, | 58 | subst_prefix, |
59 | traits::FnTrait, | 59 | traits::FnTrait, |
60 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, | 60 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, |
61 | DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, | 61 | DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, Substitution, |
62 | SolutionVariables, Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyExt, TyKind, | 62 | TraitEnvironment, Ty, TyBuilder, TyDefId, TyExt, TyKind, TyVariableKind, WhereClause, |
63 | TyVariableKind, WhereClause, | ||
64 | }; | 63 | }; |
65 | use itertools::Itertools; | 64 | use itertools::Itertools; |
66 | use rustc_hash::FxHashSet; | 65 | use rustc_hash::FxHashSet; |
@@ -1822,8 +1821,9 @@ impl Type { | |||
1822 | ); | 1821 | ); |
1823 | 1822 | ||
1824 | match db.trait_solve(self.krate, goal)? { | 1823 | match db.trait_solve(self.krate, goal)? { |
1825 | Solution::Unique(SolutionVariables(subst)) => subst | 1824 | Solution::Unique(s) => s |
1826 | .value | 1825 | .value |
1826 | .subst | ||
1827 | .interned() | 1827 | .interned() |
1828 | .first() | 1828 | .first() |
1829 | .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())), | 1829 | .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())), |
diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index c5890e24d..80e192a57 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs | |||
@@ -120,8 +120,8 @@ fn deref_by_trait( | |||
120 | // assumptions will be broken. We would need to properly introduce | 120 | // assumptions will be broken. We would need to properly introduce |
121 | // new variables in that case | 121 | // new variables in that case |
122 | 122 | ||
123 | for i in 1..vars.0.binders.len(&Interner) { | 123 | for i in 1..vars.binders.len(&Interner) { |
124 | if vars.0.value.at(&Interner, i - 1).assert_ty_ref(&Interner).kind(&Interner) | 124 | if vars.value.subst.at(&Interner, i - 1).assert_ty_ref(&Interner).kind(&Interner) |
125 | != &TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1)) | 125 | != &TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1)) |
126 | { | 126 | { |
127 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.goal, solution); | 127 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.goal, solution); |
@@ -130,12 +130,12 @@ fn deref_by_trait( | |||
130 | } | 130 | } |
131 | Some(Canonical { | 131 | Some(Canonical { |
132 | value: vars | 132 | value: vars |
133 | .0 | ||
134 | .value | 133 | .value |
135 | .at(&Interner, vars.0.value.len(&Interner) - 1) | 134 | .subst |
135 | .at(&Interner, vars.value.subst.len(&Interner) - 1) | ||
136 | .assert_ty_ref(&Interner) | 136 | .assert_ty_ref(&Interner) |
137 | .clone(), | 137 | .clone(), |
138 | binders: vars.0.binders.clone(), | 138 | binders: vars.binders.clone(), |
139 | }) | 139 | }) |
140 | } | 140 | } |
141 | Solution::Ambig(_) => { | 141 | Solution::Ambig(_) => { |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 75d633c96..7c6c3600b 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -42,7 +42,7 @@ use super::{ | |||
42 | }; | 42 | }; |
43 | use crate::{ | 43 | use crate::{ |
44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, | 44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, |
45 | to_assoc_type_id, AliasEq, AliasTy, Interner, TyBuilder, TyExt, TyKind, | 45 | to_assoc_type_id, AliasEq, AliasTy, Canonical, Interner, TyBuilder, TyExt, TyKind, |
46 | }; | 46 | }; |
47 | 47 | ||
48 | // This lint has a false positive here. See the link below for details. | 48 | // This lint has a false positive here. See the link below for details. |
@@ -342,11 +342,18 @@ impl<'a> InferenceContext<'a> { | |||
342 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); | 342 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); |
343 | 343 | ||
344 | match solution { | 344 | match solution { |
345 | Some(Solution::Unique(substs)) => { | 345 | Some(Solution::Unique(canonical_subst)) => { |
346 | canonicalized.apply_solution(self, substs.0); | 346 | canonicalized.apply_solution( |
347 | self, | ||
348 | Canonical { | ||
349 | binders: canonical_subst.binders, | ||
350 | // FIXME: handle constraints | ||
351 | value: canonical_subst.value.subst, | ||
352 | }, | ||
353 | ); | ||
347 | } | 354 | } |
348 | Some(Solution::Ambig(Guidance::Definite(substs))) => { | 355 | Some(Solution::Ambig(Guidance::Definite(substs))) => { |
349 | canonicalized.apply_solution(self, substs.0); | 356 | canonicalized.apply_solution(self, substs); |
350 | self.obligations.push(obligation); | 357 | self.obligations.push(obligation); |
351 | } | 358 | } |
352 | Some(_) => { | 359 | Some(_) => { |
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 159a53a63..f1af2a0bd 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -7,7 +7,7 @@ | |||
7 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; | 7 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; |
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{autoderef, Interner, Solution, Ty, TyBuilder, TyExt, TyKind}; | 10 | use crate::{autoderef, Canonical, Interner, Solution, Ty, TyBuilder, TyExt, TyKind}; |
11 | 11 | ||
12 | use super::{InEnvironment, InferenceContext}; | 12 | use super::{InEnvironment, InferenceContext}; |
13 | 13 | ||
@@ -148,7 +148,14 @@ impl<'a> InferenceContext<'a> { | |||
148 | 148 | ||
149 | match solution { | 149 | match solution { |
150 | Solution::Unique(v) => { | 150 | Solution::Unique(v) => { |
151 | canonicalized.apply_solution(self, v.0); | 151 | canonicalized.apply_solution( |
152 | self, | ||
153 | Canonical { | ||
154 | binders: v.binders, | ||
155 | // FIXME handle constraints | ||
156 | value: v.value.subst, | ||
157 | }, | ||
158 | ); | ||
152 | } | 159 | } |
153 | _ => return None, | 160 | _ => return None, |
154 | }; | 161 | }; |
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index c8883485c..3374532c3 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -9,7 +9,7 @@ use stdx::panic_context; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment, | 11 | db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment, |
12 | Solution, SolutionVariables, Ty, TyKind, WhereClause, | 12 | Solution, Ty, TyKind, WhereClause, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use self::chalk::{from_chalk, Interner, ToChalk}; | 15 | use self::chalk::{from_chalk, Interner, ToChalk}; |
@@ -173,23 +173,15 @@ fn solution_from_chalk( | |||
173 | db: &dyn HirDatabase, | 173 | db: &dyn HirDatabase, |
174 | solution: chalk_solve::Solution<Interner>, | 174 | solution: chalk_solve::Solution<Interner>, |
175 | ) -> Solution { | 175 | ) -> Solution { |
176 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { | ||
177 | let result = from_chalk(db, subst); | ||
178 | SolutionVariables(result) | ||
179 | }; | ||
180 | match solution { | 176 | match solution { |
181 | chalk_solve::Solution::Unique(constr_subst) => { | 177 | chalk_solve::Solution::Unique(constr_subst) => { |
182 | let subst = chalk_ir::Canonical { | 178 | Solution::Unique(from_chalk(db, constr_subst)) |
183 | value: constr_subst.value.subst, | ||
184 | binders: constr_subst.binders, | ||
185 | }; | ||
186 | Solution::Unique(convert_subst(subst)) | ||
187 | } | 179 | } |
188 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Definite(subst)) => { | 180 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Definite(subst)) => { |
189 | Solution::Ambig(Guidance::Definite(convert_subst(subst))) | 181 | Solution::Ambig(Guidance::Definite(from_chalk(db, subst))) |
190 | } | 182 | } |
191 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Suggested(subst)) => { | 183 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Suggested(subst)) => { |
192 | Solution::Ambig(Guidance::Suggested(convert_subst(subst))) | 184 | Solution::Ambig(Guidance::Suggested(from_chalk(db, subst))) |
193 | } | 185 | } |
194 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Unknown) => { | 186 | chalk_solve::Solution::Ambig(chalk_solve::Guidance::Unknown) => { |
195 | Solution::Ambig(Guidance::Unknown) | 187 | Solution::Ambig(Guidance::Unknown) |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 0536b934e..84abd99b2 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -11,8 +11,8 @@ use hir_def::{GenericDefId, TypeAliasId}; | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | chalk_ext::ProjectionTyExt, db::HirDatabase, static_lifetime, AliasTy, CallableDefId, | 13 | chalk_ext::ProjectionTyExt, db::HirDatabase, static_lifetime, AliasTy, CallableDefId, |
14 | Canonical, DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, | 14 | Canonical, ConstrainedSubst, DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, |
15 | QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause, | 15 | ProjectionTy, QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | use super::interner::*; | 18 | use super::interner::*; |
@@ -459,6 +459,18 @@ where | |||
459 | } | 459 | } |
460 | } | 460 | } |
461 | 461 | ||
462 | impl ToChalk for crate::ConstrainedSubst { | ||
463 | type Chalk = chalk_ir::ConstrainedSubst<Interner>; | ||
464 | |||
465 | fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk { | ||
466 | unimplemented!() | ||
467 | } | ||
468 | |||
469 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { | ||
470 | ConstrainedSubst { subst: from_chalk(db, chalk.subst) } | ||
471 | } | ||
472 | } | ||
473 | |||
462 | pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> | 474 | pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> |
463 | where | 475 | where |
464 | T: HasInterner<Interner = Interner>, | 476 | T: HasInterner<Interner = Interner>, |
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index eac1b7900..c25bc2d6a 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -490,14 +490,16 @@ pub struct AliasEq { | |||
490 | } | 490 | } |
491 | 491 | ||
492 | #[derive(Clone, Debug, PartialEq, Eq)] | 492 | #[derive(Clone, Debug, PartialEq, Eq)] |
493 | pub struct SolutionVariables(pub Canonical<Substitution>); | 493 | pub struct ConstrainedSubst { |
494 | pub subst: Substitution, | ||
495 | } | ||
494 | 496 | ||
495 | #[derive(Clone, Debug, PartialEq, Eq)] | 497 | #[derive(Clone, Debug, PartialEq, Eq)] |
496 | /// A (possible) solution for a proposed goal. | 498 | /// A (possible) solution for a proposed goal. |
497 | pub enum Solution { | 499 | pub enum Solution { |
498 | /// The goal indeed holds, and there is a unique value for all existential | 500 | /// The goal indeed holds, and there is a unique value for all existential |
499 | /// variables. | 501 | /// variables. |
500 | Unique(SolutionVariables), | 502 | Unique(Canonical<ConstrainedSubst>), |
501 | 503 | ||
502 | /// The goal may be provable in multiple ways, but regardless we may have some guidance | 504 | /// The goal may be provable in multiple ways, but regardless we may have some guidance |
503 | /// for type inference. In this case, we don't return any lifetime | 505 | /// for type inference. In this case, we don't return any lifetime |
@@ -513,12 +515,12 @@ pub enum Guidance { | |||
513 | /// The existential variables *must* have the given values if the goal is | 515 | /// The existential variables *must* have the given values if the goal is |
514 | /// ever to hold, but that alone isn't enough to guarantee the goal will | 516 | /// ever to hold, but that alone isn't enough to guarantee the goal will |
515 | /// actually hold. | 517 | /// actually hold. |
516 | Definite(SolutionVariables), | 518 | Definite(Canonical<Substitution>), |
517 | 519 | ||
518 | /// There are multiple plausible values for the existentials, but the ones | 520 | /// There are multiple plausible values for the existentials, but the ones |
519 | /// here are suggested as the preferred choice heuristically. These should | 521 | /// here are suggested as the preferred choice heuristically. These should |
520 | /// be used for inference fallback only. | 522 | /// be used for inference fallback only. |
521 | Suggested(SolutionVariables), | 523 | Suggested(Canonical<Substitution>), |
522 | 524 | ||
523 | /// There's no useful information to feed back to type inference | 525 | /// There's no useful information to feed back to type inference |
524 | Unknown, | 526 | Unknown, |