Skip to content

Commit 9a64a35

Browse files
committed
Auto merge of #806 - mohe2015:rename-generator-to-coroutine, r=jackh726
Rename generator to coroutine Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
2 parents f068f5b + c9f0ad5 commit 9a64a35

Some content is hidden

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

46 files changed

+308
-308
lines changed

book/src/clauses/well_known_traits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Some common examples of auto traits are `Send` and `Sync`.
2828
[coinductive_section]: ../engine/logic/coinduction.html#coinduction-and-refinement-strands
2929

3030
# Current state
31-
| Type | Copy | Clone | Sized | Unsize | CoerceUnsized | Drop | FnOnce/FnMut/Fn | Unpin | Generator | auto traits |
31+
| Type | Copy | Clone | Sized | Unsize | CoerceUnsized | Drop | FnOnce/FnMut/Fn | Unpin | Coroutine | auto traits |
3232
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
3333
| tuple types |||||||||||
3434
| structs |||||||||||
@@ -44,7 +44,7 @@ Some common examples of auto traits are `Send` and `Sync`.
4444
| slices |||||||||||
4545
| arrays |||||||||||
4646
| closures |||||||||||
47-
| generators |||||||||||
47+
| coroutines |||||||||||
4848
| gen. witness |||||||||||
4949
| opaque |||||||||||
5050
| foreign |||||||||||

book/src/types/rust_types.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ types. The intention is that, at least when transitioning, rustc would
168168
implement the `Interner` trait and would map from the [`TyKind`][Rustc-TyKind]
169169
enum to chalk's [`TyKind`] on the fly, when `data()` is invoked.
170170

171-
[Rustc-TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html
171+
[Rustc-TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html
172172

173173
| rustc type | chalk variant (and some notes) |
174174
| ------------- | ------------------ |
@@ -188,8 +188,8 @@ enum to chalk's [`TyKind`] on the fly, when `data()` is invoked.
188188
| `FnPtr` | `Function` |
189189
| `Dynamic` | `Dyn` |
190190
| `Closure` | `Closure` |
191-
| `Generator` | `Generator` |
192-
| `GeneratorWitness` | `GeneratorWitness` |
191+
| `Coroutine` | `Coroutine` |
192+
| `CoroutineWitness` | `CoroutineWitness` |
193193
| `Never` | `Never` |
194194
| `Tuple` | `Tuple` |
195195
| `Projection` | `Alias` |

book/src/types/rust_types/application_ty.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ but have since moved away from that; nevertheless, the term is still useful in d
1717

1818
## Notable application types
1919

20-
### Generator
20+
### Coroutine
2121

22-
A `Generator` represents a Rust generator. There are three major components
23-
to a generator:
22+
A `Coroutine` represents a Rust coroutine. There are three major components
23+
to a coroutine:
2424

25-
* Upvars - similar to closure upvars, they reference values outside of the generator,
25+
* Upvars - similar to closure upvars, they reference values outside of the coroutine,
2626
and are stored across all yield points.
27-
* Resume/yield/return types - the types produced/consumed by various generator methods.
28-
These are not stored in the generator across yield points - they are only
29-
used when the generator is running.
30-
* Generator witness - see the `Generator Witness` section below.
31-
32-
Of these types, only upvars and resume/yield/return are stored directly in `GeneratorDatum`
33-
(which is accessed via `RustIrDatabase`). The generator witness is implicitly associated with
34-
the generator by virtue of sharing the same `GeneratorId`. It is only used when determining
27+
* Resume/yield/return types - the types produced/consumed by various coroutine methods.
28+
These are not stored in the coroutine across yield points - they are only
29+
used when the coroutine is running.
30+
* Coroutine witness - see the `Coroutine Witness` section below.
31+
32+
Of these types, only upvars and resume/yield/return are stored directly in `CoroutineDatum`
33+
(which is accessed via `RustIrDatabase`). The coroutine witness is implicitly associated with
34+
the coroutine by virtue of sharing the same `CoroutineId`. It is only used when determining
3535
auto trait impls, where it is considered a 'constituent type'.
3636

3737
For example:
@@ -49,20 +49,20 @@ fn use(_: usize) -> Bar {}
4949
The type of yield would be `usize`, the resume type would be the type of `a` and the return type
5050
would be `Bar`.
5151

52-
### Generator witness types
52+
### Coroutine witness types
5353

54-
The `GeneratorWitness` variant represents the generator witness of
55-
the generator with id `GeneratorId`.
54+
The `CoroutineWitness` variant represents the coroutine witness of
55+
the coroutine with id `CoroutineId`.
5656

57-
The generator witness contains multiple witness types,
58-
which represent the types that may be part of a generator
57+
The coroutine witness contains multiple witness types,
58+
which represent the types that may be part of a coroutine
5959
state - that is, the types of all variables that may be live across
6060
a `yield` point.
6161

6262
Unlike other types, witnesses include bound, existential
6363
lifetimes, which refer to lifetimes within the suspended stack frame.
6464
You can think of it as a type like `exists<'a> { (T...) }`.
65-
As an example, imagine that a type that isn't `Send` lives across a `yield`, then the generator
65+
As an example, imagine that a type that isn't `Send` lives across a `yield`, then the coroutine
6666
itself can't be `Send`.
6767

6868
Witnesses have a binder for the erased lifetime(s), which must be

chalk-engine/src/slg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ impl<I: Interner> MayInvalidate<I> {
230230
(TyKind::Closure(id_a, substitution_a), TyKind::Closure(id_b, substitution_b)) => {
231231
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
232232
}
233-
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
233+
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
234234
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
235235
}
236236
(
237-
TyKind::GeneratorWitness(id_a, substitution_a),
238-
TyKind::GeneratorWitness(id_b, substitution_b),
237+
TyKind::CoroutineWitness(id_a, substitution_a),
238+
TyKind::CoroutineWitness(id_b, substitution_b),
239239
) => self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b),
240240
(TyKind::Foreign(id_a), TyKind::Foreign(id_b)) => id_a != id_b,
241241
(TyKind::Error, TyKind::Error) => false,

chalk-engine/src/slg/aggregate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,20 @@ impl<I: Interner> AntiUnifier<'_, I> {
338338
.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
339339
.map(|(&name, substitution)| TyKind::Closure(name, substitution).intern(interner))
340340
.unwrap_or_else(|| self.new_ty_variable()),
341-
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
341+
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
342342
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
343343
.map(|(&name, substitution)| {
344-
TyKind::Generator(name, substitution).intern(interner)
344+
TyKind::Coroutine(name, substitution).intern(interner)
345345
})
346346
.unwrap_or_else(|| self.new_ty_variable())
347347
}
348348
(
349-
TyKind::GeneratorWitness(id_a, substitution_a),
350-
TyKind::GeneratorWitness(id_b, substitution_b),
349+
TyKind::CoroutineWitness(id_a, substitution_a),
350+
TyKind::CoroutineWitness(id_b, substitution_b),
351351
) => self
352352
.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
353353
.map(|(&name, substitution)| {
354-
TyKind::GeneratorWitness(name, substitution).intern(interner)
354+
TyKind::CoroutineWitness(name, substitution).intern(interner)
355355
})
356356
.unwrap_or_else(|| self.new_ty_variable()),
357357
(TyKind::Foreign(id_a), TyKind::Foreign(id_b)) => {

chalk-engine/src/slg/resolvent.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
547547
substitution_b.as_slice(interner),
548548
)
549549
}
550-
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
550+
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
551551
if id_a != id_b {
552552
return Err(NoSolution);
553553
}
@@ -559,8 +559,8 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
559559
)
560560
}
561561
(
562-
TyKind::GeneratorWitness(id_a, substitution_a),
563-
TyKind::GeneratorWitness(id_b, substitution_b),
562+
TyKind::CoroutineWitness(id_a, substitution_a),
563+
TyKind::CoroutineWitness(id_b, substitution_b),
564564
) => {
565565
if id_a != id_b {
566566
return Err(NoSolution);

chalk-integration/src/db.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use crate::{
88
};
99
use chalk_ir::{
1010
AdtId, AssocTypeId, Binders, Canonical, CanonicalVarKinds, ClosureId, ConstrainedSubst,
11-
Environment, FnDefId, GeneratorId, GenericArg, Goal, ImplId, InEnvironment, OpaqueTyId,
11+
CoroutineId, Environment, FnDefId, GenericArg, Goal, ImplId, InEnvironment, OpaqueTyId,
1212
ProgramClause, ProgramClauses, Substitution, TraitId, Ty, TyKind, UCanonical,
1313
UnificationDatabase, Variances,
1414
};
1515
use chalk_solve::rust_ir::{
1616
AdtDatum, AdtRepr, AdtSizeAlign, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId,
17-
ClosureKind, FnDefDatum, FnDefInputsAndOutputDatum, GeneratorDatum, GeneratorWitnessDatum,
17+
ClosureKind, CoroutineDatum, CoroutineWitnessDatum, FnDefDatum, FnDefInputsAndOutputDatum,
1818
ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownTrait,
1919
};
2020
use chalk_solve::{RustIrDatabase, Solution, SubstitutionResult};
@@ -118,15 +118,15 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
118118
self.program_ir().unwrap().adt_datum(id)
119119
}
120120

121-
fn generator_datum(&self, id: GeneratorId<ChalkIr>) -> Arc<GeneratorDatum<ChalkIr>> {
122-
self.program_ir().unwrap().generator_datum(id)
121+
fn coroutine_datum(&self, id: CoroutineId<ChalkIr>) -> Arc<CoroutineDatum<ChalkIr>> {
122+
self.program_ir().unwrap().coroutine_datum(id)
123123
}
124124

125-
fn generator_witness_datum(
125+
fn coroutine_witness_datum(
126126
&self,
127-
id: GeneratorId<ChalkIr>,
128-
) -> Arc<GeneratorWitnessDatum<ChalkIr>> {
129-
self.program_ir().unwrap().generator_witness_datum(id)
127+
id: CoroutineId<ChalkIr>,
128+
) -> Arc<CoroutineWitnessDatum<ChalkIr>> {
129+
self.program_ir().unwrap().coroutine_witness_datum(id)
130130
}
131131

132132
fn adt_repr(&self, id: AdtId<ChalkIr>) -> Arc<AdtRepr<ChalkIr>> {

chalk-integration/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum TypeSort {
2727
Closure,
2828
Trait,
2929
Opaque,
30-
Generator,
30+
Coroutine,
3131
}
3232

3333
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]

chalk-integration/src/lowering.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl LowerWithEnv for Ty {
752752
TypeLookup::FnDef(id) => tykind!(env.fn_def_kind(id), FnDef, id),
753753
TypeLookup::Closure(id) => tykind!(env.closure_kind(id), Closure, id),
754754
TypeLookup::Opaque(id) => tykind!(env.opaque_kind(id), OpaqueType, id),
755-
TypeLookup::Generator(id) => tykind!(env.generator_kind(id), Generator, id),
755+
TypeLookup::Coroutine(id) => tykind!(env.coroutine_kind(id), Coroutine, id),
756756
TypeLookup::Foreign(_) | TypeLookup::Trait(_) => {
757757
panic!("Unexpected apply type")
758758
}
@@ -1047,8 +1047,8 @@ pub fn lower_goal(goal: &Goal, program: &LoweredProgram) -> LowerResult<chalk_ir
10471047
closure_ids: &program.closure_ids,
10481048
trait_ids: &program.trait_ids,
10491049
opaque_ty_ids: &program.opaque_ty_ids,
1050-
generator_ids: &program.generator_ids,
1051-
generator_kinds: &program.generator_kinds,
1050+
coroutine_ids: &program.coroutine_ids,
1051+
coroutine_kinds: &program.coroutine_kinds,
10521052
adt_kinds: &program.adt_kinds,
10531053
fn_def_kinds: &program.fn_def_kinds,
10541054
closure_kinds: &program.closure_kinds,
@@ -1137,7 +1137,7 @@ impl Lower for WellKnownTrait {
11371137
WellKnownTrait::Unpin => rust_ir::WellKnownTrait::Unpin,
11381138
WellKnownTrait::CoerceUnsized => rust_ir::WellKnownTrait::CoerceUnsized,
11391139
WellKnownTrait::DiscriminantKind => rust_ir::WellKnownTrait::DiscriminantKind,
1140-
WellKnownTrait::Generator => rust_ir::WellKnownTrait::Generator,
1140+
WellKnownTrait::Coroutine => rust_ir::WellKnownTrait::Coroutine,
11411141
WellKnownTrait::DispatchFromDyn => rust_ir::WellKnownTrait::DispatchFromDyn,
11421142
WellKnownTrait::Tuple => rust_ir::WellKnownTrait::Tuple,
11431143
WellKnownTrait::Pointee => rust_ir::WellKnownTrait::Pointee,

chalk-integration/src/lowering/env.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chalk_ir::interner::HasInterner;
22
use chalk_ir::{
3-
self, AdtId, BoundVar, ClosureId, DebruijnIndex, FnDefId, GeneratorId, OpaqueTyId, TraitId,
3+
self, AdtId, BoundVar, ClosureId, CoroutineId, DebruijnIndex, FnDefId, OpaqueTyId, TraitId,
44
VariableKinds,
55
};
66
use chalk_ir::{cast::Cast, ForeignDefId, WithKind};
@@ -16,15 +16,15 @@ pub type AdtIds = BTreeMap<Ident, chalk_ir::AdtId<ChalkIr>>;
1616
pub type FnDefIds = BTreeMap<Ident, chalk_ir::FnDefId<ChalkIr>>;
1717
pub type ClosureIds = BTreeMap<Ident, chalk_ir::ClosureId<ChalkIr>>;
1818
pub type TraitIds = BTreeMap<Ident, chalk_ir::TraitId<ChalkIr>>;
19-
pub type GeneratorIds = BTreeMap<Ident, chalk_ir::GeneratorId<ChalkIr>>;
19+
pub type CoroutineIds = BTreeMap<Ident, chalk_ir::CoroutineId<ChalkIr>>;
2020
pub type OpaqueTyIds = BTreeMap<Ident, chalk_ir::OpaqueTyId<ChalkIr>>;
2121
pub type AdtKinds = BTreeMap<chalk_ir::AdtId<ChalkIr>, TypeKind>;
2222
pub type FnDefKinds = BTreeMap<chalk_ir::FnDefId<ChalkIr>, TypeKind>;
2323
pub type ClosureKinds = BTreeMap<chalk_ir::ClosureId<ChalkIr>, TypeKind>;
2424
pub type TraitKinds = BTreeMap<chalk_ir::TraitId<ChalkIr>, TypeKind>;
2525
pub type AutoTraits = BTreeMap<chalk_ir::TraitId<ChalkIr>, bool>;
2626
pub type OpaqueTyVariableKinds = BTreeMap<chalk_ir::OpaqueTyId<ChalkIr>, TypeKind>;
27-
pub type GeneratorKinds = BTreeMap<chalk_ir::GeneratorId<ChalkIr>, TypeKind>;
27+
pub type CoroutineKinds = BTreeMap<chalk_ir::CoroutineId<ChalkIr>, TypeKind>;
2828
pub type AssociatedTyLookups = BTreeMap<(chalk_ir::TraitId<ChalkIr>, Ident), AssociatedTyLookup>;
2929
pub type AssociatedTyValueIds =
3030
BTreeMap<(chalk_ir::ImplId<ChalkIr>, Ident), AssociatedTyValueId<ChalkIr>>;
@@ -49,8 +49,8 @@ pub struct Env<'k> {
4949
pub associated_ty_lookups: &'k AssociatedTyLookups,
5050
pub auto_traits: &'k AutoTraits,
5151
pub foreign_ty_ids: &'k ForeignIds,
52-
pub generator_ids: &'k GeneratorIds,
53-
pub generator_kinds: &'k GeneratorKinds,
52+
pub coroutine_ids: &'k CoroutineIds,
53+
pub coroutine_kinds: &'k CoroutineKinds,
5454
/// GenericArg identifiers are used as keys, therefore
5555
/// all identifiers in an environment must be unique (no shadowing).
5656
pub parameter_map: ParameterMap,
@@ -83,7 +83,7 @@ pub enum TypeLookup<'k> {
8383
Opaque(OpaqueTyId<ChalkIr>),
8484
Foreign(ForeignDefId<ChalkIr>),
8585
Trait(TraitId<ChalkIr>),
86-
Generator(GeneratorId<ChalkIr>),
86+
Coroutine(CoroutineId<ChalkIr>),
8787
}
8888

8989
impl Env<'_> {
@@ -133,7 +133,7 @@ impl Env<'_> {
133133
Ok(TypeLookup::Adt(id)) => tykind!(self.adt_kind(id), Adt, id),
134134
Ok(TypeLookup::FnDef(id)) => tykind!(self.fn_def_kind(id), FnDef, id),
135135
Ok(TypeLookup::Closure(id)) => tykind!(self.closure_kind(id), Closure, id),
136-
Ok(TypeLookup::Generator(id)) => tykind!(self.generator_kind(id), Generator, id),
136+
Ok(TypeLookup::Coroutine(id)) => tykind!(self.coroutine_kind(id), Coroutine, id),
137137
Ok(TypeLookup::Opaque(id)) => Ok(chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(
138138
chalk_ir::OpaqueTy {
139139
opaque_ty_id: id,
@@ -165,8 +165,8 @@ impl Env<'_> {
165165
Ok(TypeLookup::Foreign(*id))
166166
} else if let Some(id) = self.trait_ids.get(&name.str) {
167167
Ok(TypeLookup::Trait(*id))
168-
} else if let Some(id) = self.generator_ids.get(&name.str) {
169-
Ok(TypeLookup::Generator(*id))
168+
} else if let Some(id) = self.coroutine_ids.get(&name.str) {
169+
Ok(TypeLookup::Coroutine(*id))
170170
} else {
171171
Err(RustIrError::NotStruct(name.clone()))
172172
}
@@ -208,8 +208,8 @@ impl Env<'_> {
208208
&self.opaque_ty_kinds[&id]
209209
}
210210

211-
pub fn generator_kind(&self, id: chalk_ir::GeneratorId<ChalkIr>) -> &TypeKind {
212-
&self.generator_kinds[&id]
211+
pub fn coroutine_kind(&self, id: chalk_ir::CoroutineId<ChalkIr>) -> &TypeKind {
212+
&self.coroutine_kinds[&id]
213213
}
214214

215215
pub fn lookup_associated_ty(

0 commit comments

Comments
 (0)