Skip to content

Commit 78f535a

Browse files
committed
Add ConstEq to many match cases
Where trivial, add ConstEq, otherwise defer to todos
1 parent 9586104 commit 78f535a

File tree

18 files changed

+107
-10
lines changed

18 files changed

+107
-10
lines changed

chalk-integration/src/db.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use chalk_ir::{
1414
};
1515
use chalk_solve::rust_ir::{
1616
AdtDatum, AdtRepr, AdtSizeAlign, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId,
17+
AssociatedConstDatum,
1718
ClosureKind, FnDefDatum, FnDefInputsAndOutputDatum, GeneratorDatum, GeneratorWitnessDatum,
1819
ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownTrait,
1920
};
@@ -91,6 +92,13 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
9192
self.program_ir().unwrap().associated_ty_data(ty)
9293
}
9394

95+
fn associated_const_data(
96+
&self,
97+
ct: AssocItemId<ChalkIr>,
98+
) -> Arc<AssociatedConstDatum<ChalkIr>> {
99+
self.program_ir().unwrap().associated_const_data(ct)
100+
}
101+
94102
fn trait_datum(&self, id: TraitId<ChalkIr>) -> Arc<TraitDatum<ChalkIr>> {
95103
self.program_ir().unwrap().trait_datum(id)
96104
}

chalk-integration/src/lowering.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ impl LowerWithEnv for WhereClause {
173173
],
174174
WhereClause::ConstProjectionEq { projection, val } => {
175175
vec![chalk_ir::WhereClause::ConstEq(chalk_ir::ConstEq {
176-
term: chalk_ir::AliasTy::Projection(projection.lower(env)?),
176+
// TODO maybe this should just be a projection term instead
177+
term: projection.lower(env)?.associated_term_id,
177178
ct: val.lower(env)?,
178179
})]
179180
}

chalk-integration/src/lowering/program_lowerer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl ProgramLowerer {
158158
let mut well_known_traits = BTreeMap::new();
159159
let mut impl_data = BTreeMap::new();
160160
let mut associated_const_values = BTreeMap::new();
161+
let mut associated_const_data = BTreeMap::new();
161162
let mut associated_ty_data = BTreeMap::new();
162163
let mut associated_ty_values = BTreeMap::new();
163164
let mut opaque_ty_data = BTreeMap::new();
@@ -317,6 +318,9 @@ impl ProgramLowerer {
317318
}),
318319
);
319320
}
321+
for assoc_ct_defn in &trait_defn.assoc_const_defns {
322+
todo!();
323+
}
320324
}
321325
Item::Impl(ref impl_defn) => {
322326
let impl_id = ImplId(raw_id);
@@ -522,6 +526,7 @@ impl ProgramLowerer {
522526
well_known_traits,
523527
impl_data,
524528
associated_const_values,
529+
associated_const_data,
525530
associated_ty_values,
526531
associated_ty_data,
527532
opaque_ty_ids: self.opaque_ty_ids,

chalk-integration/src/program.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use chalk_ir::{
1010
};
1111
use chalk_solve::rust_ir::{
1212
AdtDatum, AdtRepr, AdtSizeAlign, AssociatedConstValue, AssociatedConstValueId,
13+
AssociatedConstDatum,
1314
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ClosureKind, FnDefDatum,
1415
FnDefInputsAndOutputDatum, GeneratorDatum, GeneratorWitnessDatum, ImplDatum, ImplType,
1516
OpaqueTyDatum, TraitDatum, WellKnownTrait,
@@ -104,6 +105,9 @@ pub struct Program {
104105
/// For each associated ty declaration `type Foo` found in a trait:
105106
pub associated_ty_data: BTreeMap<AssocItemId<ChalkIr>, Arc<AssociatedTyDatum<ChalkIr>>>,
106107

108+
/// For each associated const declaration `const Foo` found in a trait:
109+
pub associated_const_data: BTreeMap<AssocItemId<ChalkIr>, Arc<AssociatedConstDatum<ChalkIr>>>,
110+
107111
/// For each user-specified clause
108112
pub custom_clauses: Vec<ProgramClause<ChalkIr>>,
109113

@@ -395,6 +399,10 @@ impl RustIrDatabase<ChalkIr> for Program {
395399
self.associated_ty_data[&ty].clone()
396400
}
397401

402+
fn associated_const_data(&self, ct: AssocItemId<ChalkIr>) -> Arc<AssociatedConstDatum<ChalkIr>> {
403+
self.associated_const_data[&ct].clone()
404+
}
405+
398406
fn trait_datum(&self, id: TraitId<ChalkIr>) -> Arc<TraitDatum<ChalkIr>> {
399407
self.trait_data[&id].clone()
400408
}

chalk-solve/src/clauses.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ pub fn program_clauses_that_could_match<I: Interner>(
570570
})
571571
});
572572
}
573+
DomainGoal::Holds(WhereClause::ConstEq(const_eq)) => {
574+
todo!()
575+
}
573576
DomainGoal::WellFormed(WellFormed::Trait(trait_ref))
574577
| DomainGoal::LocalImplAllowed(trait_ref) => {
575578
db.trait_datum(trait_ref.trait_id)
@@ -1071,6 +1074,7 @@ fn match_ty<I: Interner>(
10711074
vec![DomainGoal::WellFormed(WellFormed::Trait(trait_ref.clone()))]
10721075
}
10731076
WhereClause::AliasEq(_)
1077+
| WhereClause::ConstEq(_)
10741078
| WhereClause::LifetimeOutlives(_)
10751079
| WhereClause::TypeOutlives(_) => vec![],
10761080
}

chalk-solve/src/clauses/dyn_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(super) fn build_dyn_self_ty_clauses<I: Interner>(
7272
)
7373
}
7474
// FIXME: Associated item bindings are just taken as facts (?)
75-
WhereClause::AliasEq(_) => builder.push_fact(bound),
75+
WhereClause::AliasEq(_) | WhereClause::ConstEq(_) => builder.push_fact(bound),
7676
WhereClause::LifetimeOutlives(..) => {}
7777
WhereClause::TypeOutlives(..) => {}
7878
});

chalk-solve/src/clauses/program_clauses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<I: Interner> ToProgramClauses<I> for OpaqueTyDatum<I> {
206206
)
207207
}
208208
// FIXME: Associated item bindings are just taken as facts (?)
209-
WhereClause::AliasEq(_) => builder.push_fact(bound),
209+
WhereClause::AliasEq(_) | WhereClause::ConstEq(_) => builder.push_fact(bound),
210210
WhereClause::LifetimeOutlives(..) => {}
211211
WhereClause::TypeOutlives(..) => {}
212212
});

chalk-solve/src/clauses/super_traits.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ pub fn super_traits<I: Interner>(
9393
}
9494
Some(tr.clone())
9595
}
96-
WhereClause::AliasEq(_) => None,
97-
WhereClause::LifetimeOutlives(..) => None,
98-
WhereClause::TypeOutlives(..) => None,
96+
WhereClause::AliasEq(_)
97+
| WhereClause::LifetimeOutlives(..)
98+
| WhereClause::ConstEq(_)
99+
| WhereClause::TypeOutlives(..) => None,
99100
})
100101
})
101102
.collect::<Vec<_>>()

chalk-solve/src/coinductive_goal.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ impl<I: Interner> IsCoinductive<I> for Goal<I> {
2323
db.trait_datum(tr.trait_id).is_auto_trait()
2424
|| db.trait_datum(tr.trait_id).is_coinductive_trait()
2525
}
26-
WhereClause::AliasEq(..) => false,
27-
WhereClause::LifetimeOutlives(..) => false,
28-
WhereClause::TypeOutlives(..) => false,
26+
WhereClause::AliasEq(_)
27+
| WhereClause::LifetimeOutlives(..)
28+
| WhereClause::TypeOutlives(..)
29+
| WhereClause::ConstEq(_) => false,
2930
},
3031
GoalData::DomainGoal(DomainGoal::WellFormed(WellFormed::Trait(..))) => true,
3132
GoalData::Quantified(QuantifierKind::ForAll, goal) => {

chalk-solve/src/display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn display_self_where_clauses_as_bounds<'a, I: Interner>(
165165
}
166166
AliasTy::Opaque(opaque) => opaque.display(s).fmt(f),
167167
},
168+
WhereClause::ConstEq(_) => todo!(),
168169
WhereClause::LifetimeOutlives(lifetime) => lifetime.display(s).fmt(f),
169170
WhereClause::TypeOutlives(ty) => ty.display(s).fmt(f),
170171
}

0 commit comments

Comments
 (0)