Skip to content

Commit

Permalink
Auto merge of #628 - rust-lang:tykind, r=nathanwhit
Browse files Browse the repository at this point in the history
Rename TyData to TyKind

Part of #627
  • Loading branch information
bors committed Oct 21, 2020
2 parents 8f88cdf + 21b44ab commit 30f4a12
Show file tree
Hide file tree
Showing 41 changed files with 431 additions and 401 deletions.
2 changes: 1 addition & 1 deletion book/src/clauses/type_equality.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Placeholder associated types are never written directly by the user.
They are used internally by the trait system only, as we will see
shortly.

In rustc, they correspond to the `TyKind::UnnormalizedProjectionTy` enum
In rustc, they correspond to the `TyVariableKind::UnnormalizedProjectionTy` enum
variant, declared in [`compiler/rustc_middle/src/ty/sty.rs`][sty]. In chalk, we use an
`ApplicationTy` with a name living in a special namespace dedicated to
placeholder associated types (see the `TypeName` enum declared in
Expand Down
16 changes: 8 additions & 8 deletions book/src/types/role_of_interner.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ used to intern all the types, as rustc does, or it could be used to
The purpose of the [`Interner`] trait is to give control over how
types and other bits of chalk-ir are represented in memory. This is
done via an "indirection" strategy. We'll explain that strategy here
in terms of [`Ty`] and [`TyData`], the two types used to represent
in terms of [`Ty`] and [`TyKind`], the two types used to represent
Rust types, but the same pattern is repeated for many other things.

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

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

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

```rust,ignore
struct Ty<I: Interner>(I::InternedTy);
enum TyData<I: Interner> { .. }
enum TyKind<I: Interner> { .. }
```

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

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

```rust,ignore
impl<I: Interner> Ty<I> {
fn data(&self) -> &TyData<I> {
fn data(&self) -> &TyKind<I> {
I::lookup_ty(self)
}
}
Expand All @@ -71,7 +71,7 @@ impl<I: Interner> Ty<I> {
and

```rust,ignore
impl<I: Interner> TyData<I> {
impl<I: Interner> TyKind<I> {
fn intern(&self, i: &I) -> Ty<I> {
Ty(i.intern_ty(self))
}
Expand Down
12 changes: 6 additions & 6 deletions book/src/types/rust_types.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Rust types

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

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

## The `TyData` variants and how they map to Rust syntax
## The `TyKind` variants and how they map to Rust syntax

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

## Justification for each variant

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

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

Expand Down
2 changes: 1 addition & 1 deletion chalk-engine/src/normalize_deep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
fn fold_inference_ty(
&mut self,
var: InferenceVar,
kind: TyKind,
kind: TyVariableKind,
_outer_binder: DebruijnIndex,
) -> Fallible<Ty<I>> {
let interner = self.interner;
Expand Down
30 changes: 15 additions & 15 deletions chalk-engine/src/slg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ impl<I: Interner> MayInvalidate<'_, I> {
/// Returns true if the two types could be unequal.
fn aggregate_tys(&mut self, new: &Ty<I>, current: &Ty<I>) -> bool {
let interner = self.interner;
match (new.data(interner), current.data(interner)) {
(_, TyData::BoundVar(_)) => {
match (new.kind(interner), current.kind(interner)) {
(_, TyKind::BoundVar(_)) => {
// If the aggregate solution already has an inference
// variable here, then no matter what type we produce,
// the aggregate cannot get 'more generalized' than it
Expand All @@ -384,7 +384,7 @@ impl<I: Interner> MayInvalidate<'_, I> {
false
}

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

(TyData::InferenceVar(_, _), _) | (_, TyData::InferenceVar(_, _)) => {
(TyKind::InferenceVar(_, _), _) | (_, TyKind::InferenceVar(_, _)) => {
panic!(
"unexpected free inference variable in may-invalidate: {:?} vs {:?}",
new, current,
);
}

(TyData::Apply(apply1), TyData::Apply(apply2)) => {
(TyKind::Apply(apply1), TyKind::Apply(apply2)) => {
self.aggregate_application_tys(apply1, apply2)
}

(TyData::Placeholder(p1), TyData::Placeholder(p2)) => {
(TyKind::Placeholder(p1), TyKind::Placeholder(p2)) => {
self.aggregate_placeholders(p1, p2)
}

(
TyData::Alias(AliasTy::Projection(proj1)),
TyData::Alias(AliasTy::Projection(proj2)),
TyKind::Alias(AliasTy::Projection(proj1)),
TyKind::Alias(AliasTy::Projection(proj2)),
) => self.aggregate_projection_tys(proj1, proj2),

(
TyData::Alias(AliasTy::Opaque(opaque_ty1)),
TyData::Alias(AliasTy::Opaque(opaque_ty2)),
TyKind::Alias(AliasTy::Opaque(opaque_ty1)),
TyKind::Alias(AliasTy::Opaque(opaque_ty2)),
) => self.aggregate_opaque_ty_tys(opaque_ty1, opaque_ty2),

// For everything else, be conservative here and just say we may invalidate.
(TyData::Function(_), _)
| (TyData::Dyn(_), _)
| (TyData::Apply(_), _)
| (TyData::Placeholder(_), _)
| (TyData::Alias(_), _) => true,
(TyKind::Function(_), _)
| (TyKind::Dyn(_), _)
| (TyKind::Apply(_), _)
| (TyKind::Placeholder(_), _)
| (TyKind::Alias(_), _) => true,
}
}

Expand Down
44 changes: 22 additions & 22 deletions chalk-engine/src/slg/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,48 +231,48 @@ struct AntiUnifier<'infer, 'intern, I: Interner> {
impl<I: Interner> AntiUnifier<'_, '_, I> {
fn aggregate_tys(&mut self, ty0: &Ty<I>, ty1: &Ty<I>) -> Ty<I> {
let interner = self.interner;
match (ty0.data(interner), ty1.data(interner)) {
match (ty0.kind(interner), ty1.kind(interner)) {
// If we see bound things on either side, just drop in a
// fresh variable. This means we will sometimes
// overgeneralize. So for example if we have two
// solutions that are both `(X, X)`, we just produce `(Y,
// Z)` in all cases.
(TyData::InferenceVar(_, _), TyData::InferenceVar(_, _)) => self.new_ty_variable(),
(TyKind::InferenceVar(_, _), TyKind::InferenceVar(_, _)) => self.new_ty_variable(),

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

(TyData::Apply(apply1), TyData::Apply(apply2)) => {
(TyKind::Apply(apply1), TyKind::Apply(apply2)) => {
self.aggregate_application_tys(apply1, apply2)
}

(
TyData::Alias(AliasTy::Projection(proj1)),
TyData::Alias(AliasTy::Projection(proj2)),
TyKind::Alias(AliasTy::Projection(proj1)),
TyKind::Alias(AliasTy::Projection(proj2)),
) => self.aggregate_projection_tys(proj1, proj2),

(
TyData::Alias(AliasTy::Opaque(opaque_ty1)),
TyData::Alias(AliasTy::Opaque(opaque_ty2)),
TyKind::Alias(AliasTy::Opaque(opaque_ty1)),
TyKind::Alias(AliasTy::Opaque(opaque_ty2)),
) => self.aggregate_opaque_ty_tys(opaque_ty1, opaque_ty2),

(TyData::Placeholder(placeholder1), TyData::Placeholder(placeholder2)) => {
(TyKind::Placeholder(placeholder1), TyKind::Placeholder(placeholder2)) => {
self.aggregate_placeholder_tys(placeholder1, placeholder2)
}

// Mismatched base kinds.
(TyData::InferenceVar(_, _), _)
| (TyData::BoundVar(_), _)
| (TyData::Dyn(_), _)
| (TyData::Function(_), _)
| (TyData::Apply(_), _)
| (TyData::Alias(_), _)
| (TyData::Placeholder(_), _) => self.new_ty_variable(),
(TyKind::InferenceVar(_, _), _)
| (TyKind::BoundVar(_), _)
| (TyKind::Dyn(_), _)
| (TyKind::Function(_), _)
| (TyKind::Apply(_), _)
| (TyKind::Alias(_), _)
| (TyKind::Placeholder(_), _) => self.new_ty_variable(),
}
}

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

self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
.map(|(&name, substitution)| {
TyData::Apply(ApplicationTy { name, substitution }).intern(interner)
TyKind::Apply(ApplicationTy { name, substitution }).intern(interner)
})
.unwrap_or_else(|| self.new_ty_variable())
}
Expand All @@ -307,7 +307,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
if index1 != index2 {
self.new_ty_variable()
} else {
TyData::Placeholder(*index1).intern(interner)
TyKind::Placeholder(*index1).intern(interner)
}
}

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

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

self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
.map(|(&opaque_ty_id, substitution)| {
TyData::Alias(AliasTy::Opaque(OpaqueTy {
TyKind::Alias(AliasTy::Opaque(OpaqueTy {
opaque_ty_id,
substitution,
}))
Expand Down
30 changes: 15 additions & 15 deletions chalk-engine/src/slg/resolvent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {
// "inputs" to the subgoal table. We need to extract the
// resulting answer that the subgoal found and unify it with
// the value from our "pending subgoal".
if let TyData::BoundVar(answer_depth) = answer.data(interner) {
if let TyKind::BoundVar(answer_depth) = answer.kind(interner) {
if self.unify_free_answer_var(
interner,
*answer_depth,
Expand All @@ -385,39 +385,39 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {

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

(TyData::Apply(answer), TyData::Apply(pending)) => Zip::zip_with(self, answer, pending),
(TyKind::Apply(answer), TyKind::Apply(pending)) => Zip::zip_with(self, answer, pending),

(TyData::Dyn(answer), TyData::Dyn(pending)) => Zip::zip_with(self, answer, pending),
(TyKind::Dyn(answer), TyKind::Dyn(pending)) => Zip::zip_with(self, answer, pending),

(TyData::Alias(answer), TyData::Alias(pending)) => Zip::zip_with(self, answer, pending),
(TyKind::Alias(answer), TyKind::Alias(pending)) => Zip::zip_with(self, answer, pending),

(TyData::Placeholder(answer), TyData::Placeholder(pending)) => {
(TyKind::Placeholder(answer), TyKind::Placeholder(pending)) => {
Zip::zip_with(self, answer, pending)
}

(TyData::Function(answer), TyData::Function(pending)) => {
(TyKind::Function(answer), TyKind::Function(pending)) => {
self.outer_binder.shift_in();
Zip::zip_with(self, &answer.substitution, &pending.substitution)?;
self.outer_binder.shift_out();
Ok(())
}

(TyData::InferenceVar(_, _), _) | (_, TyData::InferenceVar(_, _)) => panic!(
(TyKind::InferenceVar(_, _), _) | (_, TyKind::InferenceVar(_, _)) => panic!(
"unexpected inference var in answer `{:?}` or pending goal `{:?}`",
answer, pending,
),

(TyData::BoundVar(_), _)
| (TyData::Apply(_), _)
| (TyData::Dyn(_), _)
| (TyData::Alias(_), _)
| (TyData::Placeholder(_), _)
| (TyData::Function(_), _) => panic!(
(TyKind::BoundVar(_), _)
| (TyKind::Apply(_), _)
| (TyKind::Dyn(_), _)
| (TyKind::Alias(_), _)
| (TyKind::Placeholder(_), _)
| (TyKind::Function(_), _) => panic!(
"structural mismatch between answer `{:?}` and pending goal `{:?}`",
answer, pending,
),
Expand Down
4 changes: 2 additions & 2 deletions chalk-integration/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use chalk_ir::{
AdtId, AliasTy, ApplicationTy, AssocTypeId, CanonicalVarKind, CanonicalVarKinds, ConstData,
Constraint, FnDefId, Goals, InEnvironment, Lifetime, OpaqueTy, OpaqueTyId,
ProgramClauseImplication, ProgramClauses, ProjectionTy, QuantifiedWhereClauses,
SeparatorTraitRef, Substitution, TraitId, Ty, VariableKind, VariableKinds,
SeparatorTraitRef, Substitution, TraitId, Ty, TyData, VariableKind, VariableKinds,
};
use chalk_ir::{
GenericArg, GenericArgData, Goal, GoalData, LifetimeData, ProgramClause, ProgramClauseData,
QuantifiedWhereClause, TyData,
QuantifiedWhereClause,
};
use std::fmt;
use std::fmt::Debug;
Expand Down
Loading

0 comments on commit 30f4a12

Please sign in to comment.