Skip to content

Commit 5452311

Browse files
committed
Make ty_data return TyData and add ty_kind
1 parent e4b9f46 commit 5452311

File tree

26 files changed

+100
-70
lines changed

26 files changed

+100
-70
lines changed

book/src/types/role_of_interner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ type [`InternedTy`] and two related methods, [`intern_ty`] and [`ty_data`]:
5252
trait Interner {
5353
type InternedTy;
5454
55-
fn intern_ty(&self, data: &TyKind<Self>) -> Self::InternedTy;
56-
fn ty_data(data: &Self::InternedTy) -> &TyKind<Self>;
55+
fn intern_ty(&self, data: &TyData<Self>) -> Self::InternedTy;
56+
fn ty_data(data: &Self::InternedTy) -> &TyData<Self>;
5757
}
5858
```
5959

chalk-engine/src/slg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<I: Interner> MayInvalidate<'_, I> {
371371
/// Returns true if the two types could be unequal.
372372
fn aggregate_tys(&mut self, new: &Ty<I>, current: &Ty<I>) -> bool {
373373
let interner = self.interner;
374-
match (new.data(interner), current.data(interner)) {
374+
match (new.kind(interner), current.kind(interner)) {
375375
(_, TyKind::BoundVar(_)) => {
376376
// If the aggregate solution already has an inference
377377
// variable here, then no matter what type we produce,

chalk-engine/src/slg/aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct AntiUnifier<'infer, 'intern, I: Interner> {
231231
impl<I: Interner> AntiUnifier<'_, '_, I> {
232232
fn aggregate_tys(&mut self, ty0: &Ty<I>, ty1: &Ty<I>) -> Ty<I> {
233233
let interner = self.interner;
234-
match (ty0.data(interner), ty1.data(interner)) {
234+
match (ty0.kind(interner), ty1.kind(interner)) {
235235
// If we see bound things on either side, just drop in a
236236
// fresh variable. This means we will sometimes
237237
// overgeneralize. So for example if we have two

chalk-engine/src/slg/resolvent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {
373373
// "inputs" to the subgoal table. We need to extract the
374374
// resulting answer that the subgoal found and unify it with
375375
// the value from our "pending subgoal".
376-
if let TyKind::BoundVar(answer_depth) = answer.data(interner) {
376+
if let TyKind::BoundVar(answer_depth) = answer.kind(interner) {
377377
if self.unify_free_answer_var(
378378
interner,
379379
*answer_depth,
@@ -385,7 +385,7 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {
385385

386386
// Otherwise, the answer and the selected subgoal ought to be a perfect match for
387387
// one another.
388-
match (answer.data(interner), pending.data(interner)) {
388+
match (answer.kind(interner), pending.kind(interner)) {
389389
(TyKind::BoundVar(answer_depth), TyKind::BoundVar(pending_depth)) => {
390390
self.assert_matching_vars(*answer_depth, *pending_depth)
391391
}

chalk-integration/src/interner.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use chalk_ir::{
44
AdtId, AliasTy, ApplicationTy, AssocTypeId, CanonicalVarKind, CanonicalVarKinds, ConstData,
55
Constraint, FnDefId, Goals, InEnvironment, Lifetime, OpaqueTy, OpaqueTyId,
66
ProgramClauseImplication, ProgramClauses, ProjectionTy, QuantifiedWhereClauses,
7-
SeparatorTraitRef, Substitution, TraitId, Ty, VariableKind, VariableKinds,
7+
SeparatorTraitRef, Substitution, TraitId, Ty, TyData, VariableKind, VariableKinds,
88
};
99
use chalk_ir::{
1010
GenericArg, GenericArgData, Goal, GoalData, LifetimeData, ProgramClause, ProgramClauseData,
11-
QuantifiedWhereClause, TyKind,
11+
QuantifiedWhereClause,
1212
};
1313
use std::fmt;
1414
use std::fmt::Debug;
@@ -40,7 +40,7 @@ pub enum ChalkFnAbi {
4040
pub struct ChalkIr;
4141

4242
impl Interner for ChalkIr {
43-
type InternedType = Arc<TyKind<ChalkIr>>;
43+
type InternedType = Arc<TyData<ChalkIr>>;
4444
type InternedLifetime = LifetimeData<ChalkIr>;
4545
type InternedConst = Arc<ConstData<ChalkIr>>;
4646
type InternedConcreteConst = u32;
@@ -212,11 +212,11 @@ impl Interner for ChalkIr {
212212
tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt)))
213213
}
214214

215-
fn intern_ty(&self, ty: TyKind<ChalkIr>) -> Arc<TyKind<ChalkIr>> {
215+
fn intern_ty(&self, ty: TyData<ChalkIr>) -> Arc<TyData<ChalkIr>> {
216216
Arc::new(ty)
217217
}
218218

219-
fn ty_data<'a>(&self, ty: &'a Arc<TyKind<ChalkIr>>) -> &'a TyKind<Self> {
219+
fn ty_data<'a>(&self, ty: &'a Arc<TyData<ChalkIr>>) -> &'a TyData<Self> {
220220
ty
221221
}
222222

@@ -236,7 +236,7 @@ impl Interner for ChalkIr {
236236
constant
237237
}
238238

239-
fn const_eq(&self, _ty: &Arc<TyKind<ChalkIr>>, c1: &u32, c2: &u32) -> bool {
239+
fn const_eq(&self, _ty: &Arc<TyData<ChalkIr>>, c1: &u32, c2: &u32) -> bool {
240240
c1 == c2
241241
}
242242

chalk-integration/src/lowering.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,18 @@ impl Lower for VariableKind {
120120
type Lowered = chalk_ir::WithKind<ChalkIr, Ident>;
121121
fn lower(&self) -> Self::Lowered {
122122
let (kind, n) = match self {
123-
VariableKind::Ty(n) => (chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General), n),
124-
VariableKind::IntegerTy(n) => {
125-
(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Integer), n)
126-
}
127-
VariableKind::FloatTy(n) => (chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Float), n),
123+
VariableKind::Ty(n) => (
124+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
125+
n,
126+
),
127+
VariableKind::IntegerTy(n) => (
128+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Integer),
129+
n,
130+
),
131+
VariableKind::FloatTy(n) => (
132+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Float),
133+
n,
134+
),
128135
VariableKind::Lifetime(n) => (chalk_ir::VariableKind::Lifetime, n),
129136
VariableKind::Const(ref n) => (chalk_ir::VariableKind::Const(get_type_of_u32()), n),
130137
};

chalk-integration/src/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl RustIrDatabase<ChalkIr> for Program {
460460
.skip_binders()
461461
.trait_ref
462462
.self_type_parameter(interner);
463-
match ty.data(interner) {
463+
match ty.kind(interner) {
464464
TyKind::Apply(app) => Some(app.clone()),
465465
_ => None,
466466
}

chalk-ir/src/could_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ where
2626
impl<'i, I: Interner> Zipper<'i, I> for MatchZipper<'i, I> {
2727
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()> {
2828
let interner = self.interner;
29-
let could_match = match (a.data(interner), b.data(interner)) {
30-
(&TyKind::Apply(ref a), &TyKind::Apply(ref b)) => {
29+
let could_match = match (a.kind(interner), b.kind(interner)) {
30+
(TyKind::Apply(ref a), TyKind::Apply(ref b)) => {
3131
let names_could_match = a.name == b.name;
3232

3333
names_could_match

chalk-ir/src/debug.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ impl<I: Interner> Debug for TypeName<I> {
220220
}
221221
}
222222

223+
impl<I: Interner> Debug for TyData<I> {
224+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
225+
self.kind.fmt(fmt)
226+
}
227+
}
228+
223229
impl<I: Interner> Debug for TyKind<I> {
224230
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
225231
match self {
@@ -871,8 +877,12 @@ impl<I: Interner, T: Debug> Debug for WithKind<I, T> {
871877
let value = self.skip_kind();
872878
match &self.kind {
873879
VariableKind::Ty(TyVariableKind::General) => write!(fmt, "{:?} with kind type", value),
874-
VariableKind::Ty(TyVariableKind::Integer) => write!(fmt, "{:?} with kind integer type", value),
875-
VariableKind::Ty(TyVariableKind::Float) => write!(fmt, "{:?} with kind float type", value),
880+
VariableKind::Ty(TyVariableKind::Integer) => {
881+
write!(fmt, "{:?} with kind integer type", value)
882+
}
883+
VariableKind::Ty(TyVariableKind::Float) => {
884+
write!(fmt, "{:?} with kind float type", value)
885+
}
876886
VariableKind::Lifetime => write!(fmt, "{:?} with kind lifetime", value),
877887
VariableKind::Const(ty) => write!(fmt, "{:?} with kind {:?}", value, ty),
878888
}

chalk-ir/src/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ where
407407
TI: 'i,
408408
{
409409
let interner = folder.interner();
410-
match self.data(interner) {
410+
match self.kind(interner) {
411411
TyKind::BoundVar(bound_var) => {
412412
if let Some(bound_var1) = bound_var.shifted_out_to(outer_binder) {
413413
// This variable was bound outside of the binders

0 commit comments

Comments
 (0)