aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-21 18:51:53 +0100
committerGitHub <[email protected]>2021-05-21 18:51:53 +0100
commitedbde25ca2f13ffacfd006ada7b38618d36d97c6 (patch)
treeb1c5208c74ce56a36c8a9c454b9c479a3312ee94 /crates/hir
parentde403b10448e23f232804596538de92fc57203d6 (diff)
parentef558c97d09b0be8639c92f490e5ad380aa04288 (diff)
Merge #8856
8856: Use Chalk for unification r=flodiebold a=flodiebold - use Chalk's unification, get rid of our own `unify` - rewrite coercion to not use unification internals and to be more analogous to rustc - fix various coercion bugs - rewrite handling of obligations, since the old hacky optimization where we noted when an inference variable changes wasn't possible anymore - stop trying to deeply resolve types all the time during inference, instead only do it shallowly where necessary Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/lib.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index d443b124c..52d72c3c5 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1712,15 +1712,17 @@ impl Type {
1712 resolver: &Resolver, 1712 resolver: &Resolver,
1713 ty: Ty, 1713 ty: Ty,
1714 ) -> Type { 1714 ) -> Type {
1715 let environment = 1715 let environment = resolver
1716 resolver.generic_def().map_or_else(Default::default, |d| db.trait_environment(d)); 1716 .generic_def()
1717 .map_or_else(|| Arc::new(TraitEnvironment::empty(krate)), |d| db.trait_environment(d));
1717 Type { krate, env: environment, ty } 1718 Type { krate, env: environment, ty }
1718 } 1719 }
1719 1720
1720 fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { 1721 fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {
1721 let resolver = lexical_env.resolver(db.upcast()); 1722 let resolver = lexical_env.resolver(db.upcast());
1722 let environment = 1723 let environment = resolver
1723 resolver.generic_def().map_or_else(Default::default, |d| db.trait_environment(d)); 1724 .generic_def()
1725 .map_or_else(|| Arc::new(TraitEnvironment::empty(krate)), |d| db.trait_environment(d));
1724 Type { krate, env: environment, ty } 1726 Type { krate, env: environment, ty }
1725 } 1727 }
1726 1728
@@ -2051,11 +2053,7 @@ impl Type {
2051 name: Option<&Name>, 2053 name: Option<&Name>,
2052 mut callback: impl FnMut(&Ty, AssocItem) -> Option<T>, 2054 mut callback: impl FnMut(&Ty, AssocItem) -> Option<T>,
2053 ) -> Option<T> { 2055 ) -> Option<T> {
2054 // There should be no inference vars in types passed here 2056 let canonical = hir_ty::replace_errors_with_variables(self.ty.clone());
2055 // FIXME check that?
2056 // FIXME replace Unknown by bound vars here
2057 let canonical =
2058 Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(&Interner) };
2059 2057
2060 let env = self.env.clone(); 2058 let env = self.env.clone();
2061 let krate = krate.id; 2059 let krate = krate.id;
@@ -2223,8 +2221,9 @@ impl Type {
2223 walk_type(db, self, &mut cb); 2221 walk_type(db, self, &mut cb);
2224 } 2222 }
2225 2223
2226 pub fn could_unify_with(&self, other: &Type) -> bool { 2224 pub fn could_unify_with(&self, db: &dyn HirDatabase, other: &Type) -> bool {
2227 could_unify(&self.ty, &other.ty) 2225 let tys = hir_ty::replace_errors_with_variables((self.ty.clone(), other.ty.clone()));
2226 could_unify(db, self.env.clone(), &tys)
2228 } 2227 }
2229} 2228}
2230 2229