Skip to content

Commit ea532e0

Browse files
committed
Cleanups
1 parent 1ade318 commit ea532e0

File tree

6 files changed

+27
-46
lines changed

6 files changed

+27
-46
lines changed

book/src/clauses/type_equality.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ 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 `TyVariableKind::UnnormalizedProjectionTy` enum
96+
In rustc, they correspond to the `TyKind::UnnormalizedProjectionTy` enum
9797
variant, declared in [`compiler/rustc_middle/src/ty/sty.rs`][sty]. In chalk, we use an
98-
`Ty` with a name living in a special namespace dedicated to
99-
placeholder associated types.
98+
[`AssociatedType`].
10099

101100
[sty]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs
102101

book/src/types/rust_types.md

Lines changed: 8 additions & 7 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
5-
what sort of type you have, you invoke the [`data`] method, which
6-
returns a [`TyData`]. As described earlier, the actual in-memory
5+
what sort of type you have, you invoke the [`kind`] method, which
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
@@ -22,16 +22,17 @@ differences in how they are handled.
2222

2323
| Chalk variant | Example Rust types |
2424
| ------------- | ------------------ |
25-
| `Apply` | `Vec<u32>`, `f32` |
2625
| `Placeholder` | how we represent `T` when type checking `fn foo<T>() { .. }` |
2726
| `Dyn` | `dyn Trait` |
2827
| `Fn` | `fn(&u8)` |
2928
| `Alias` | `<T as Iterator>::Item`, or the `Foo` in `type Foo = impl Trait` and `type Foo = u32` |
3029
| `BoundVariable` | an uninstantiated generic parameter like the `T` in `struct Foo<T>` |
30+
| `Adt` | `struct Foo<T>` |
31+
| ... | ... |
3132

3233
## Justification for each variant
3334

34-
Each variant of `TyData` generally wraps a single struct, which
35+
Each variant of `TyKind` generally wraps a single struct, which
3536
represents a type known to be of that particular variant. This section
3637
goes through the variants in a bit more detail, and in particular
3738
describes why each variant exists.

chalk-integration/src/lowering/env.rs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,19 @@ impl Env<'_> {
9898
let interner = self.interner();
9999

100100
macro_rules! tykind {
101-
($k:expr, $type:expr) => {
101+
($k:expr, $tykind:ident, $id:expr) => {
102102
if $k.binders.len(interner) > 0 {
103103
Err(RustIrError::IncorrectNumberOfTypeParameters {
104104
identifier: name.clone(),
105105
expected: $k.binders.len(interner),
106106
actual: 0,
107107
})
108108
} else {
109-
$type.cast(interner)
109+
Ok(
110+
chalk_ir::TyKind::$tykind($id, chalk_ir::Substitution::empty(interner))
111+
.intern(interner),
112+
)
113+
.cast(interner)
110114
}
111115
};
112116
}
@@ -126,34 +130,10 @@ impl Env<'_> {
126130
}
127131
})
128132
}
129-
Ok(TypeLookup::Adt(id)) => tykind!(
130-
self.adt_kind(id),
131-
Ok(
132-
chalk_ir::TyKind::Adt(id, chalk_ir::Substitution::empty(interner))
133-
.intern(interner)
134-
)
135-
),
136-
Ok(TypeLookup::FnDef(id)) => tykind!(
137-
self.fn_def_kind(id),
138-
Ok(
139-
chalk_ir::TyKind::FnDef(id, chalk_ir::Substitution::empty(interner))
140-
.intern(interner)
141-
)
142-
),
143-
Ok(TypeLookup::Closure(id)) => tykind!(
144-
self.closure_kind(id),
145-
Ok(
146-
chalk_ir::TyKind::Closure(id, chalk_ir::Substitution::empty(interner))
147-
.intern(interner)
148-
)
149-
),
150-
Ok(TypeLookup::Generator(id)) => tykind!(
151-
self.generator_kind(id),
152-
Ok(
153-
chalk_ir::TyKind::Generator(id, chalk_ir::Substitution::empty(interner))
154-
.intern(interner)
155-
)
156-
),
133+
Ok(TypeLookup::Adt(id)) => tykind!(self.adt_kind(id), Adt, id),
134+
Ok(TypeLookup::FnDef(id)) => tykind!(self.fn_def_kind(id), FnDef, id),
135+
Ok(TypeLookup::Closure(id)) => tykind!(self.closure_kind(id), Closure, id),
136+
Ok(TypeLookup::Generator(id)) => tykind!(self.generator_kind(id), Generator, id),
157137
Ok(TypeLookup::Opaque(id)) => Ok(chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(
158138
chalk_ir::OpaqueTy {
159139
opaque_ty_id: id,

chalk-integration/src/query.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ fn environment(db: &dyn LoweringDatabase) -> Result<Arc<ProgramEnvironment>, Cha
225225
.filter(|(_, auto_trait)| auto_trait.is_auto_trait())
226226
{
227227
for &adt_id in program.adt_data.keys() {
228-
let ty = chalk_ir::TyKind::Adt(adt_id, Substitution::empty(builder.interner()))
229-
.intern(&ChalkIr);
230-
chalk_solve::clauses::push_auto_trait_impls(builder, auto_trait_id, &ty.kind(&ChalkIr))
228+
let ty = chalk_ir::TyKind::Adt(adt_id, Substitution::empty(builder.interner()));
229+
chalk_solve::clauses::push_auto_trait_impls(builder, auto_trait_id, &ty)
231230
.map_err(|_| ())
232231
.unwrap();
233232
}

chalk-solve/src/clauses.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ fn constituent_types<I: Interner>(db: &dyn RustIrDatabase<I>, ty: &TyKind<I>) ->
4343
.cloned()
4444
.collect(),
4545

46-
TyKind::Raw(_, ty) | TyKind::Ref(_, _, ty) | TyKind::Slice(ty) => vec![ty.clone()],
46+
TyKind::Array(ty, _) | TyKind::Slice(ty) | TyKind::Raw(_, ty) | TyKind::Ref(_, _, ty) => {
47+
vec![ty.clone()]
48+
}
4749

48-
TyKind::Array(_, _) | TyKind::Str | TyKind::Never | TyKind::Scalar(_) => Vec::new(),
50+
TyKind::Str | TyKind::Never | TyKind::Scalar(_) => Vec::new(),
4951

5052
TyKind::Generator(generator_id, substitution) => {
5153
let generator_datum = &db.generator_datum(*generator_id);

chalk-solve/src/clauses/env_elaborator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'me, I: Interner> Visitor<'me, I> for EnvElaborator<'me, I> {
7878
TyKind::Function(_) | TyKind::BoundVar(_) | TyKind::InferenceVar(_, _) => (),
7979

8080
_ => {
81-
// This should fail because of the above clauses
81+
// This shouldn't fail because of the above clauses
8282
match_ty(&mut self.builder, self.environment, &ty)
8383
.map_err(|_| ())
8484
.unwrap()

0 commit comments

Comments
 (0)