aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-03 16:49:29 +0100
committerFlorian Diebold <[email protected]>2021-04-08 13:08:55 +0100
commit7e541e69b1eaab3c242c864a0930cb263d2cbaf5 (patch)
tree88fb29aa7e0b782efc9f91ec5676d93e4db4ffd7
parent926bfef0efc5caca2a04a50beaba9127338e21e0 (diff)
Add HasInterner bounds
-rw-r--r--crates/hir_ty/src/chalk_cast.rs8
-rw-r--r--crates/hir_ty/src/infer/unify.rs16
-rw-r--r--crates/hir_ty/src/lib.rs15
-rw-r--r--crates/hir_ty/src/lower.rs4
-rw-r--r--crates/hir_ty/src/traits/chalk.rs2
-rw-r--r--crates/hir_ty/src/walk.rs4
6 files changed, 35 insertions, 14 deletions
diff --git a/crates/hir_ty/src/chalk_cast.rs b/crates/hir_ty/src/chalk_cast.rs
index 1c3feabca..8bdd32ad6 100644
--- a/crates/hir_ty/src/chalk_cast.rs
+++ b/crates/hir_ty/src/chalk_cast.rs
@@ -5,7 +5,10 @@ use chalk_ir::{
5 interner::HasInterner, 5 interner::HasInterner,
6}; 6};
7 7
8use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause}; 8use crate::{
9 AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig,
10 ReturnTypeImplTraits, TraitRef, Ty, WhereClause,
11};
9 12
10macro_rules! has_interner { 13macro_rules! has_interner {
11 ($t:ty) => { 14 ($t:ty) => {
@@ -24,3 +27,6 @@ macro_rules! transitive_impl {
24 } 27 }
25 }; 28 };
26} 29}
30
31has_interner!(CallableSig);
32has_interner!(ReturnTypeImplTraits);
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 2ea9dd920..3732d8ebd 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -2,7 +2,9 @@
2 2
3use std::borrow::Cow; 3use std::borrow::Cow;
4 4
5use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind}; 5use chalk_ir::{
6 interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind,
7};
6use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; 8use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
7 9
8use super::{DomainGoal, InferenceContext}; 10use super::{DomainGoal, InferenceContext};
@@ -34,7 +36,10 @@ where
34} 36}
35 37
36#[derive(Debug)] 38#[derive(Debug)]
37pub(super) struct Canonicalized<T> { 39pub(super) struct Canonicalized<T>
40where
41 T: HasInterner<Interner = Interner>,
42{
38 pub(super) value: Canonical<T>, 43 pub(super) value: Canonical<T>,
39 free_vars: Vec<(InferenceVar, TyVariableKind)>, 44 free_vars: Vec<(InferenceVar, TyVariableKind)>,
40} 45}
@@ -76,7 +81,10 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
76 ) 81 )
77 } 82 }
78 83
79 fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { 84 fn into_canonicalized<T: HasInterner<Interner = Interner>>(
85 self,
86 result: T,
87 ) -> Canonicalized<T> {
80 let kinds = self 88 let kinds = self
81 .free_vars 89 .free_vars
82 .iter() 90 .iter()
@@ -108,7 +116,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
108 } 116 }
109} 117}
110 118
111impl<T> Canonicalized<T> { 119impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
112 pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty { 120 pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
113 ty.fold_binders( 121 ty.fold_binders(
114 &mut |ty, binders| { 122 &mut |ty, binders| {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 5fa8b3296..23dec7040 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -33,7 +33,11 @@ mod test_db;
33use std::sync::Arc; 33use std::sync::Arc;
34 34
35use base_db::salsa; 35use base_db::salsa;
36use chalk_ir::UintTy; 36use chalk_ir::{
37 cast::{CastTo, Caster},
38 interner::HasInterner,
39 UintTy,
40};
37use hir_def::{ 41use hir_def::{
38 expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId, 42 expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
39 TypeParamId, 43 TypeParamId,
@@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
115 119
116pub fn wrap_empty_binders<T>(value: T) -> Binders<T> 120pub fn wrap_empty_binders<T>(value: T) -> Binders<T>
117where 121where
118 T: TypeWalk, 122 T: TypeWalk + HasInterner<Interner = Interner>,
119{ 123{
120 Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) 124 Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
121} 125}
122 126
123pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> { 127pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
128 num_vars: usize,
129 value: T,
130) -> Binders<T> {
124 Binders::new( 131 Binders::new(
125 VariableKinds::from_iter( 132 VariableKinds::from_iter(
126 &Interner, 133 &Interner,
@@ -132,7 +139,7 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
132} 139}
133 140
134// FIXME: get rid of this 141// FIXME: get rid of this
135pub fn make_canonical<T>( 142pub fn make_canonical<T: HasInterner<Interner = Interner>>(
136 value: T, 143 value: T,
137 kinds: impl IntoIterator<Item = TyVariableKind>, 144 kinds: impl IntoIterator<Item = TyVariableKind>,
138) -> Canonical<T> { 145) -> Canonical<T> {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index e6903e189..d4ba707b4 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -8,7 +8,7 @@
8use std::{iter, sync::Arc}; 8use std::{iter, sync::Arc};
9 9
10use base_db::CrateId; 10use base_db::CrateId;
11use chalk_ir::{cast::Cast, Mutability, Safety}; 11use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety};
12use hir_def::{ 12use hir_def::{
13 adt::StructKind, 13 adt::StructKind,
14 builtin_type::BuiltinType, 14 builtin_type::BuiltinType,
@@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
1307 } 1307 }
1308} 1308}
1309 1309
1310fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> { 1310fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> {
1311 crate::make_only_type_binders(generics.len(), value) 1311 crate::make_only_type_binders(generics.len(), value)
1312} 1312}
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 090f6492b..a5aa40c10 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3 3
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{fold::shift::Shift, CanonicalVarKinds}; 6use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds};
7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; 7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
8 8
9use base_db::{salsa::InternKey, CrateId}; 9use base_db::{salsa::InternKey, CrateId};
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs
index 873d563c0..c1aecdafc 100644
--- a/crates/hir_ty/src/walk.rs
+++ b/crates/hir_ty/src/walk.rs
@@ -3,7 +3,7 @@
3 3
4use std::mem; 4use std::mem;
5 5
6use chalk_ir::DebruijnIndex; 6use chalk_ir::{interner::HasInterner, DebruijnIndex};
7 7
8use crate::{ 8use crate::{
9 utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, 9 utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg,
@@ -320,7 +320,7 @@ impl TypeWalk for Substitution {
320 } 320 }
321} 321}
322 322
323impl<T: TypeWalk> TypeWalk for Binders<T> { 323impl<T: TypeWalk + HasInterner<Interner = Interner>> TypeWalk for Binders<T> {
324 fn walk(&self, f: &mut impl FnMut(&Ty)) { 324 fn walk(&self, f: &mut impl FnMut(&Ty)) {
325 self.skip_binders().walk(f); 325 self.skip_binders().walk(f);
326 } 326 }