Skip to content

const generics support #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions chalk-integration/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl std::error::Error for ChalkError {}

#[derive(Debug)]
pub enum RustIrError {
InvalidTypeName(Identifier),
InvalidLifetimeName(Identifier),
InvalidParameterName(Identifier),
InvalidTraitName(Identifier),
NotTrait(Identifier),
NotStruct(Identifier),
DuplicateOrShadowedParameters,
Expand Down Expand Up @@ -96,8 +96,10 @@ pub enum RustIrError {
impl std::fmt::Display for RustIrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RustIrError::InvalidTypeName(name) => write!(f, "invalid type name `{}`", name),
RustIrError::InvalidLifetimeName(name) => write!(f, "invalid lifetime name `{}`", name),
RustIrError::InvalidParameterName(name) => {
write!(f, "invalid parameter name `{}`", name)
}
RustIrError::InvalidTraitName(name) => write!(f, "invalid trait name `{}`", name),
RustIrError::NotTrait(name) => write!(
f,
"expected a trait, found `{}`, which is not a trait",
Expand Down
18 changes: 16 additions & 2 deletions chalk-integration/src/interner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::tls;
use chalk_ir::interner::{HasInterner, Interner};
use chalk_ir::{
AdtId, AliasTy, ApplicationTy, AssocTypeId, CanonicalVarKind, CanonicalVarKinds, Goals,
Lifetime, OpaqueTy, OpaqueTyId, ProgramClauseImplication, ProgramClauses, ProjectionTy,
AdtId, AliasTy, ApplicationTy, AssocTypeId, CanonicalVarKind, CanonicalVarKinds, ConstData,
Goals, Lifetime, OpaqueTy, OpaqueTyId, ProgramClauseImplication, ProgramClauses, ProjectionTy,
QuantifiedWhereClauses, SeparatorTraitRef, Substitution, TraitId, Ty, VariableKind,
VariableKinds,
};
Expand Down Expand Up @@ -36,6 +36,8 @@ pub struct ChalkIr;
impl Interner for ChalkIr {
type InternedType = Arc<TyData<ChalkIr>>;
type InternedLifetime = LifetimeData<ChalkIr>;
type InternedConst = Arc<ConstData<ChalkIr>>;
type InternedConcreteConst = u32;
type InternedGenericArg = GenericArgData<ChalkIr>;
type InternedGoal = Arc<GoalData<ChalkIr>>;
type InternedGoals = Vec<Goal<ChalkIr>>;
Expand Down Expand Up @@ -214,6 +216,18 @@ impl Interner for ChalkIr {
lifetime
}

fn intern_const(&self, constant: ConstData<ChalkIr>) -> Arc<ConstData<ChalkIr>> {
Arc::new(constant)
}

fn const_data<'a>(&self, constant: &'a Arc<ConstData<ChalkIr>>) -> &'a ConstData<ChalkIr> {
constant
}

fn const_eq(&self, _ty: &Arc<TyData<ChalkIr>>, c1: &u32, c2: &u32) -> bool {
c1 == c2
}

fn intern_generic_arg(&self, generic_arg: GenericArgData<ChalkIr>) -> GenericArgData<ChalkIr> {
generic_arg
}
Expand Down
Loading