Use chalk_ir::FnSig

This commit is contained in:
Florian Diebold 2021-03-14 16:30:02 +01:00
parent 3411fe3e84
commit eea777c714
5 changed files with 22 additions and 21 deletions

View File

@ -84,7 +84,10 @@ fn deref_by_trait(
let projection = super::traits::ProjectionPredicate { let projection = super::traits::ProjectionPredicate {
ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len()))
.intern(&Interner), .intern(&Interner),
projection_ty: super::ProjectionTy { associated_ty_id: to_assoc_type_id(target), substitution: parameters }, projection_ty: super::ProjectionTy {
associated_ty_id: to_assoc_type_id(target),
substitution: parameters,
},
}; };
let obligation = super::Obligation::Projection(projection); let obligation = super::Obligation::Projection(projection);

View File

@ -261,7 +261,7 @@ impl<'a> InferenceContext<'a> {
sig_tys.push(ret_ty.clone()); sig_tys.push(ret_ty.clone());
let sig_ty = TyKind::Function(FnPointer { let sig_ty = TyKind::Function(FnPointer {
num_args: sig_tys.len() - 1, num_args: sig_tys.len() - 1,
sig: FnSig { variadic: false }, sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
substs: Substs(sig_tys.clone().into()), substs: Substs(sig_tys.clone().into()),
}) })
.intern(&Interner); .intern(&Interner);

View File

@ -46,7 +46,7 @@ pub use lower::{
}; };
pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind};
pub use crate::traits::chalk::Interner; pub use crate::traits::chalk::Interner;
@ -105,10 +105,7 @@ impl TypeWalk for ProjectionTy {
} }
} }
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub type FnSig = chalk_ir::FnSig<Interner>;
pub struct FnSig {
pub variadic: bool,
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct FnPointer { pub struct FnPointer {
@ -643,7 +640,7 @@ impl Ty {
pub fn fn_ptr(sig: CallableSig) -> Self { pub fn fn_ptr(sig: CallableSig) -> Self {
TyKind::Function(FnPointer { TyKind::Function(FnPointer {
num_args: sig.params().len(), num_args: sig.params().len(),
sig: FnSig { variadic: sig.is_varargs }, sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs },
substs: Substs(sig.params_and_return), substs: Substs(sig.params_and_return),
}) })
.intern(&Interner) .intern(&Interner)
@ -945,7 +942,9 @@ impl Ty {
} }
} }
TyKind::Alias(AliasTy::Projection(projection_ty)) => { TyKind::Alias(AliasTy::Projection(projection_ty)) => {
match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db.upcast()).container match from_assoc_type_id(projection_ty.associated_ty_id)
.lookup(db.upcast())
.container
{ {
AssocContainerId::TraitId(trait_id) => Some(trait_id), AssocContainerId::TraitId(trait_id) => Some(trait_id),
_ => None, _ => None,

View File

@ -8,7 +8,7 @@
use std::{iter, sync::Arc}; use std::{iter, sync::Arc};
use base_db::CrateId; use base_db::CrateId;
use chalk_ir::{cast::Cast, Mutability}; use chalk_ir::{cast::Cast, Mutability, Safety};
use hir_def::{ use hir_def::{
adt::StructKind, adt::StructKind,
builtin_type::BuiltinType, builtin_type::BuiltinType,
@ -181,7 +181,7 @@ impl<'a> TyLoweringContext<'a> {
let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect());
TyKind::Function(FnPointer { TyKind::Function(FnPointer {
num_args: substs.len() - 1, num_args: substs.len() - 1,
sig: FnSig { variadic: *is_varargs }, sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs },
substs, substs,
}) })
.intern(&Interner) .intern(&Interner)

View File

@ -14,7 +14,7 @@ use crate::{
from_assoc_type_id, from_assoc_type_id,
primitive::UintTy, primitive::UintTy,
traits::{Canonical, Obligation}, traits::{Canonical, Obligation},
AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy,
ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty,
}; };
@ -27,11 +27,11 @@ impl ToChalk for Ty {
match self.0 { match self.0 {
TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters),
TyKind::Array(parameters) => array_to_chalk(db, parameters), TyKind::Array(parameters) => array_to_chalk(db, parameters),
TyKind::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { TyKind::Function(FnPointer { sig, substs, .. }) => {
let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner));
chalk_ir::TyKind::Function(chalk_ir::FnPointer { chalk_ir::TyKind::Function(chalk_ir::FnPointer {
num_binders: 0, num_binders: 0,
sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, sig,
substitution, substitution,
}) })
.intern(&Interner) .intern(&Interner)
@ -121,7 +121,10 @@ impl ToChalk for Ty {
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
let associated_ty = proj.associated_ty_id; let associated_ty = proj.associated_ty_id;
let parameters = from_chalk(db, proj.substitution); let parameters = from_chalk(db, proj.substitution);
TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id: associated_ty, substitution: parameters })) TyKind::Alias(AliasTy::Projection(ProjectionTy {
associated_ty_id: associated_ty,
substitution: parameters,
}))
} }
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
let opaque_ty_id = opaque_ty.opaque_ty_id; let opaque_ty_id = opaque_ty.opaque_ty_id;
@ -130,7 +133,7 @@ impl ToChalk for Ty {
} }
chalk_ir::TyKind::Function(chalk_ir::FnPointer { chalk_ir::TyKind::Function(chalk_ir::FnPointer {
num_binders, num_binders,
sig: chalk_ir::FnSig { variadic, .. }, sig,
substitution, substitution,
.. ..
}) => { }) => {
@ -139,11 +142,7 @@ impl ToChalk for Ty {
db, db,
substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
); );
TyKind::Function(FnPointer { TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs })
num_args: (substs.len() - 1),
sig: FnSig { variadic },
substs,
})
} }
chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown,