Skip to content

Commit 30f4a12

Browse files
committed
Auto merge of #628 - rust-lang:tykind, r=nathanwhit
Rename TyData to TyKind Part of #627
2 parents 8f88cdf + 21b44ab commit 30f4a12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+431
-401
lines changed

book/src/clauses/type_equality.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Placeholder associated types are never written directly by the user.
9393
They are used internally by the trait system only, as we will see
9494
shortly.
9595

96-
In rustc, they correspond to the `TyKind::UnnormalizedProjectionTy` enum
96+
In rustc, they correspond to the `TyVariableKind::UnnormalizedProjectionTy` enum
9797
variant, declared in [`compiler/rustc_middle/src/ty/sty.rs`][sty]. In chalk, we use an
9898
`ApplicationTy` with a name living in a special namespace dedicated to
9999
placeholder associated types (see the `TypeName` enum declared in

book/src/types/role_of_interner.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ used to intern all the types, as rustc does, or it could be used to
2222
The purpose of the [`Interner`] trait is to give control over how
2323
types and other bits of chalk-ir are represented in memory. This is
2424
done via an "indirection" strategy. We'll explain that strategy here
25-
in terms of [`Ty`] and [`TyData`], the two types used to represent
25+
in terms of [`Ty`] and [`TyKind`], the two types used to represent
2626
Rust types, but the same pattern is repeated for many other things.
2727

2828
[`Interner`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html
2929
[`Ty`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html
30-
[`TyData`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyData.html
30+
[`TyKind`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html
3131

32-
Types are represented by a [`Ty<I>`] type and the [`TyData<I>`] enum.
32+
Types are represented by a [`Ty<I>`] type and the [`TyKind<I>`] enum.
3333
There is no *direct* connection between them. The link is rather made
3434
by the [`Interner`] trait, via the [`InternedTy`] associated type:
3535

3636
[`Ty<I>`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html
37-
[`TyData<I>`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyData.html
37+
[`TyKind<I>`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html
3838
[`InternedTy`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html#associatedtype.InternedType
3939

4040
```rust,ignore
4141
struct Ty<I: Interner>(I::InternedTy);
42-
enum TyData<I: Interner> { .. }
42+
enum TyKind<I: Interner> { .. }
4343
```
4444

4545
The way this works is that the [`Interner`] trait has an associated
@@ -58,11 +58,11 @@ trait Interner {
5858
```
5959

6060
However, as a user you are not meant to use these directly. Rather,
61-
they are encapsulated in methods on the [`Ty`] and [`TyData`] types:
61+
they are encapsulated in methods on the [`Ty`] and [`TyKind`] types:
6262

6363
```rust,ignore
6464
impl<I: Interner> Ty<I> {
65-
fn data(&self) -> &TyData<I> {
65+
fn data(&self) -> &TyKind<I> {
6666
I::lookup_ty(self)
6767
}
6868
}
@@ -71,7 +71,7 @@ impl<I: Interner> Ty<I> {
7171
and
7272

7373
```rust,ignore
74-
impl<I: Interner> TyData<I> {
74+
impl<I: Interner> TyKind<I> {
7575
fn intern(&self, i: &I) -> Ty<I> {
7676
Ty(i.intern_ty(self))
7777
}

book/src/types/rust_types.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Rust types
22

3-
Rust types are represented by the [`Ty`] and [`TyData`] types.
3+
Rust types are represented by the [`Ty`] and [`TyKind`] types.
44
You use [`Ty`] to represent "some Rust type". But to actually inspect
55
what sort of type you have, you invoke the [`data`] method, which
6-
returns a [`TyData`]. As described earlier, the actual in-memory
6+
returns a [`TyKind`]. As described earlier, the actual in-memory
77
representation of types is controlled by the [`Interner`] trait.
88

99
[`Interner`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html
1010
[`Ty`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html
11-
[`TyData`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyData.html
11+
[`TyKind`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyKind.html
1212
[`data`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html#method.data
1313

14-
## The `TyData` variants and how they map to Rust syntax
14+
## The `TyKind` variants and how they map to Rust syntax
1515

1616
This section covers the variants we use to categorize types. We have
1717
endeavored to create a breakdown that simplifies the Rust "surface
@@ -31,7 +31,7 @@ differences in how they are handled.
3131

3232
## Justification for each variant
3333

34-
Each variant of `TyData` generally wraps a single struct, which
34+
Each variant of `TyKind` generally wraps a single struct, which
3535
represents a type known to be of that particular variant. This section
3636
goes through the variants in a bit more detail, and in particular
3737
describes why each variant exists.
@@ -169,7 +169,7 @@ The rustc [`TyKind`] enum has a lot more variants than chalk. This
169169
section describes how the rustc types can be mapped to chalk
170170
types. The intention is that, at least when transitioning, rustc would
171171
implement the `Interner` trait and would map from the [`TyKind`]
172-
enum to chalk's `TyData` on the fly, when `data()` is invoked.
172+
enum to chalk's `TyKind` on the fly, when `data()` is invoked.
173173

174174
[`TyKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
175175

chalk-engine/src/normalize_deep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
fn fold_inference_ty(
4747
&mut self,
4848
var: InferenceVar,
49-
kind: TyKind,
49+
kind: TyVariableKind,
5050
_outer_binder: DebruijnIndex,
5151
) -> Fallible<Ty<I>> {
5252
let interner = self.interner;

chalk-engine/src/slg.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ 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)) {
375-
(_, TyData::BoundVar(_)) => {
374+
match (new.kind(interner), current.kind(interner)) {
375+
(_, TyKind::BoundVar(_)) => {
376376
// If the aggregate solution already has an inference
377377
// variable here, then no matter what type we produce,
378378
// the aggregate cannot get 'more generalized' than it
@@ -384,7 +384,7 @@ impl<I: Interner> MayInvalidate<'_, I> {
384384
false
385385
}
386386

387-
(TyData::BoundVar(_), _) => {
387+
(TyKind::BoundVar(_), _) => {
388388
// If we see a type variable in the potential future
389389
// solution, we have to be conservative. We don't know
390390
// what type variable will wind up being! Remember
@@ -398,37 +398,37 @@ impl<I: Interner> MayInvalidate<'_, I> {
398398
true
399399
}
400400

401-
(TyData::InferenceVar(_, _), _) | (_, TyData::InferenceVar(_, _)) => {
401+
(TyKind::InferenceVar(_, _), _) | (_, TyKind::InferenceVar(_, _)) => {
402402
panic!(
403403
"unexpected free inference variable in may-invalidate: {:?} vs {:?}",
404404
new, current,
405405
);
406406
}
407407

408-
(TyData::Apply(apply1), TyData::Apply(apply2)) => {
408+
(TyKind::Apply(apply1), TyKind::Apply(apply2)) => {
409409
self.aggregate_application_tys(apply1, apply2)
410410
}
411411

412-
(TyData::Placeholder(p1), TyData::Placeholder(p2)) => {
412+
(TyKind::Placeholder(p1), TyKind::Placeholder(p2)) => {
413413
self.aggregate_placeholders(p1, p2)
414414
}
415415

416416
(
417-
TyData::Alias(AliasTy::Projection(proj1)),
418-
TyData::Alias(AliasTy::Projection(proj2)),
417+
TyKind::Alias(AliasTy::Projection(proj1)),
418+
TyKind::Alias(AliasTy::Projection(proj2)),
419419
) => self.aggregate_projection_tys(proj1, proj2),
420420

421421
(
422-
TyData::Alias(AliasTy::Opaque(opaque_ty1)),
423-
TyData::Alias(AliasTy::Opaque(opaque_ty2)),
422+
TyKind::Alias(AliasTy::Opaque(opaque_ty1)),
423+
TyKind::Alias(AliasTy::Opaque(opaque_ty2)),
424424
) => self.aggregate_opaque_ty_tys(opaque_ty1, opaque_ty2),
425425

426426
// For everything else, be conservative here and just say we may invalidate.
427-
(TyData::Function(_), _)
428-
| (TyData::Dyn(_), _)
429-
| (TyData::Apply(_), _)
430-
| (TyData::Placeholder(_), _)
431-
| (TyData::Alias(_), _) => true,
427+
(TyKind::Function(_), _)
428+
| (TyKind::Dyn(_), _)
429+
| (TyKind::Apply(_), _)
430+
| (TyKind::Placeholder(_), _)
431+
| (TyKind::Alias(_), _) => true,
432432
}
433433
}
434434

chalk-engine/src/slg/aggregate.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,48 +231,48 @@ 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
238238
// solutions that are both `(X, X)`, we just produce `(Y,
239239
// Z)` in all cases.
240-
(TyData::InferenceVar(_, _), TyData::InferenceVar(_, _)) => self.new_ty_variable(),
240+
(TyKind::InferenceVar(_, _), TyKind::InferenceVar(_, _)) => self.new_ty_variable(),
241241

242242
// Ugh. Aggregating two types like `for<'a> fn(&'a u32,
243243
// &'a u32)` and `for<'a, 'b> fn(&'a u32, &'b u32)` seems
244244
// kinda hard. Don't try to be smart for now, just plop a
245245
// variable in there and be done with it.
246-
(TyData::BoundVar(_), TyData::BoundVar(_))
247-
| (TyData::Function(_), TyData::Function(_))
248-
| (TyData::Dyn(_), TyData::Dyn(_)) => self.new_ty_variable(),
246+
(TyKind::BoundVar(_), TyKind::BoundVar(_))
247+
| (TyKind::Function(_), TyKind::Function(_))
248+
| (TyKind::Dyn(_), TyKind::Dyn(_)) => self.new_ty_variable(),
249249

250-
(TyData::Apply(apply1), TyData::Apply(apply2)) => {
250+
(TyKind::Apply(apply1), TyKind::Apply(apply2)) => {
251251
self.aggregate_application_tys(apply1, apply2)
252252
}
253253

254254
(
255-
TyData::Alias(AliasTy::Projection(proj1)),
256-
TyData::Alias(AliasTy::Projection(proj2)),
255+
TyKind::Alias(AliasTy::Projection(proj1)),
256+
TyKind::Alias(AliasTy::Projection(proj2)),
257257
) => self.aggregate_projection_tys(proj1, proj2),
258258

259259
(
260-
TyData::Alias(AliasTy::Opaque(opaque_ty1)),
261-
TyData::Alias(AliasTy::Opaque(opaque_ty2)),
260+
TyKind::Alias(AliasTy::Opaque(opaque_ty1)),
261+
TyKind::Alias(AliasTy::Opaque(opaque_ty2)),
262262
) => self.aggregate_opaque_ty_tys(opaque_ty1, opaque_ty2),
263263

264-
(TyData::Placeholder(placeholder1), TyData::Placeholder(placeholder2)) => {
264+
(TyKind::Placeholder(placeholder1), TyKind::Placeholder(placeholder2)) => {
265265
self.aggregate_placeholder_tys(placeholder1, placeholder2)
266266
}
267267

268268
// Mismatched base kinds.
269-
(TyData::InferenceVar(_, _), _)
270-
| (TyData::BoundVar(_), _)
271-
| (TyData::Dyn(_), _)
272-
| (TyData::Function(_), _)
273-
| (TyData::Apply(_), _)
274-
| (TyData::Alias(_), _)
275-
| (TyData::Placeholder(_), _) => self.new_ty_variable(),
269+
(TyKind::InferenceVar(_, _), _)
270+
| (TyKind::BoundVar(_), _)
271+
| (TyKind::Dyn(_), _)
272+
| (TyKind::Function(_), _)
273+
| (TyKind::Apply(_), _)
274+
| (TyKind::Alias(_), _)
275+
| (TyKind::Placeholder(_), _) => self.new_ty_variable(),
276276
}
277277
}
278278

@@ -293,7 +293,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
293293

294294
self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
295295
.map(|(&name, substitution)| {
296-
TyData::Apply(ApplicationTy { name, substitution }).intern(interner)
296+
TyKind::Apply(ApplicationTy { name, substitution }).intern(interner)
297297
})
298298
.unwrap_or_else(|| self.new_ty_variable())
299299
}
@@ -307,7 +307,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
307307
if index1 != index2 {
308308
self.new_ty_variable()
309309
} else {
310-
TyData::Placeholder(*index1).intern(interner)
310+
TyKind::Placeholder(*index1).intern(interner)
311311
}
312312
}
313313

@@ -328,7 +328,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
328328

329329
self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
330330
.map(|(&associated_ty_id, substitution)| {
331-
TyData::Alias(AliasTy::Projection(ProjectionTy {
331+
TyKind::Alias(AliasTy::Projection(ProjectionTy {
332332
associated_ty_id,
333333
substitution,
334334
}))
@@ -353,7 +353,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
353353

354354
self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
355355
.map(|(&opaque_ty_id, substitution)| {
356-
TyData::Alias(AliasTy::Opaque(OpaqueTy {
356+
TyKind::Alias(AliasTy::Opaque(OpaqueTy {
357357
opaque_ty_id,
358358
substitution,
359359
}))

chalk-engine/src/slg/resolvent.rs

Lines changed: 15 additions & 15 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 TyData::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,39 +385,39 @@ 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)) {
389-
(TyData::BoundVar(answer_depth), TyData::BoundVar(pending_depth)) => {
388+
match (answer.kind(interner), pending.kind(interner)) {
389+
(TyKind::BoundVar(answer_depth), TyKind::BoundVar(pending_depth)) => {
390390
self.assert_matching_vars(*answer_depth, *pending_depth)
391391
}
392392

393-
(TyData::Apply(answer), TyData::Apply(pending)) => Zip::zip_with(self, answer, pending),
393+
(TyKind::Apply(answer), TyKind::Apply(pending)) => Zip::zip_with(self, answer, pending),
394394

395-
(TyData::Dyn(answer), TyData::Dyn(pending)) => Zip::zip_with(self, answer, pending),
395+
(TyKind::Dyn(answer), TyKind::Dyn(pending)) => Zip::zip_with(self, answer, pending),
396396

397-
(TyData::Alias(answer), TyData::Alias(pending)) => Zip::zip_with(self, answer, pending),
397+
(TyKind::Alias(answer), TyKind::Alias(pending)) => Zip::zip_with(self, answer, pending),
398398

399-
(TyData::Placeholder(answer), TyData::Placeholder(pending)) => {
399+
(TyKind::Placeholder(answer), TyKind::Placeholder(pending)) => {
400400
Zip::zip_with(self, answer, pending)
401401
}
402402

403-
(TyData::Function(answer), TyData::Function(pending)) => {
403+
(TyKind::Function(answer), TyKind::Function(pending)) => {
404404
self.outer_binder.shift_in();
405405
Zip::zip_with(self, &answer.substitution, &pending.substitution)?;
406406
self.outer_binder.shift_out();
407407
Ok(())
408408
}
409409

410-
(TyData::InferenceVar(_, _), _) | (_, TyData::InferenceVar(_, _)) => panic!(
410+
(TyKind::InferenceVar(_, _), _) | (_, TyKind::InferenceVar(_, _)) => panic!(
411411
"unexpected inference var in answer `{:?}` or pending goal `{:?}`",
412412
answer, pending,
413413
),
414414

415-
(TyData::BoundVar(_), _)
416-
| (TyData::Apply(_), _)
417-
| (TyData::Dyn(_), _)
418-
| (TyData::Alias(_), _)
419-
| (TyData::Placeholder(_), _)
420-
| (TyData::Function(_), _) => panic!(
415+
(TyKind::BoundVar(_), _)
416+
| (TyKind::Apply(_), _)
417+
| (TyKind::Dyn(_), _)
418+
| (TyKind::Alias(_), _)
419+
| (TyKind::Placeholder(_), _)
420+
| (TyKind::Function(_), _) => panic!(
421421
"structural mismatch between answer `{:?}` and pending goal `{:?}`",
422422
answer, pending,
423423
),

chalk-integration/src/interner.rs

Lines changed: 2 additions & 2 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, TyData,
11+
QuantifiedWhereClause,
1212
};
1313
use std::fmt;
1414
use std::fmt::Debug;

0 commit comments

Comments
 (0)