Add HasInterner bounds

This commit is contained in:
Florian Diebold 2021-04-03 17:49:29 +02:00
parent 926bfef0ef
commit 7e541e69b1
6 changed files with 35 additions and 14 deletions

View File

@ -5,7 +5,10 @@
interner::HasInterner,
};
use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause};
use crate::{
AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig,
ReturnTypeImplTraits, TraitRef, Ty, WhereClause,
};
macro_rules! has_interner {
($t:ty) => {
@ -24,3 +27,6 @@ fn cast_to(self, interner: &Interner) -> $c {
}
};
}
has_interner!(CallableSig);
has_interner!(ReturnTypeImplTraits);

View File

@ -2,7 +2,9 @@
use std::borrow::Cow;
use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind};
use chalk_ir::{
interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind,
};
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
use super::{DomainGoal, InferenceContext};
@ -34,7 +36,10 @@ pub(super) struct Canonicalizer<'a, 'b>
}
#[derive(Debug)]
pub(super) struct Canonicalized<T> {
pub(super) struct Canonicalized<T>
where
T: HasInterner<Interner = Interner>,
{
pub(super) value: Canonical<T>,
free_vars: Vec<(InferenceVar, TyVariableKind)>,
}
@ -76,7 +81,10 @@ fn do_canonicalize<T: TypeWalk>(&mut self, t: T, binders: DebruijnIndex) -> T {
)
}
fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> {
fn into_canonicalized<T: HasInterner<Interner = Interner>>(
self,
result: T,
) -> Canonicalized<T> {
let kinds = self
.free_vars
.iter()
@ -108,7 +116,7 @@ pub(crate) fn canonicalize_obligation(
}
}
impl<T> Canonicalized<T> {
impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
ty.fold_binders(
&mut |ty, binders| {

View File

@ -33,7 +33,11 @@ macro_rules! eprintln {
use std::sync::Arc;
use base_db::salsa;
use chalk_ir::UintTy;
use chalk_ir::{
cast::{CastTo, Caster},
interner::HasInterner,
UintTy,
};
use hir_def::{
expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
TypeParamId,
@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
pub fn wrap_empty_binders<T>(value: T) -> Binders<T>
where
T: TypeWalk,
T: TypeWalk + HasInterner<Interner = Interner>,
{
Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
}
pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
num_vars: usize,
value: T,
) -> Binders<T> {
Binders::new(
VariableKinds::from_iter(
&Interner,
@ -132,7 +139,7 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
}
// FIXME: get rid of this
pub fn make_canonical<T>(
pub fn make_canonical<T: HasInterner<Interner = Interner>>(
value: T,
kinds: impl IntoIterator<Item = TyVariableKind>,
) -> Canonical<T> {

View File

@ -8,7 +8,7 @@
use std::{iter, sync::Arc};
use base_db::CrateId;
use chalk_ir::{cast::Cast, Mutability, Safety};
use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety};
use hir_def::{
adt::StructKind,
builtin_type::BuiltinType,
@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
}
}
fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> {
fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> {
crate::make_only_type_binders(generics.len(), value)
}

View File

@ -3,7 +3,7 @@
use log::debug;
use chalk_ir::{fold::shift::Shift, CanonicalVarKinds};
use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds};
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
use base_db::{salsa::InternKey, CrateId};

View File

@ -3,7 +3,7 @@
use std::mem;
use chalk_ir::DebruijnIndex;
use chalk_ir::{interner::HasInterner, DebruijnIndex};
use crate::{
utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg,
@ -320,7 +320,7 @@ fn walk_mut_binders(
}
}
impl<T: TypeWalk> TypeWalk for Binders<T> {
impl<T: TypeWalk + HasInterner<Interner = Interner>> TypeWalk for Binders<T> {
fn walk(&self, f: &mut impl FnMut(&Ty)) {
self.skip_binders().walk(f);
}