Skip to content

Commit

Permalink
Auto merge of #806 - mohe2015:rename-generator-to-coroutine, r=jackh726
Browse files Browse the repository at this point in the history
Rename generator to coroutine

Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
  • Loading branch information
bors committed Dec 31, 2023
2 parents f068f5b + c9f0ad5 commit 9a64a35
Show file tree
Hide file tree
Showing 46 changed files with 308 additions and 308 deletions.
4 changes: 2 additions & 2 deletions book/src/clauses/well_known_traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Some common examples of auto traits are `Send` and `Sync`.
[coinductive_section]: ../engine/logic/coinduction.html#coinduction-and-refinement-strands

# Current state
| Type | Copy | Clone | Sized | Unsize | CoerceUnsized | Drop | FnOnce/FnMut/Fn | Unpin | Generator | auto traits |
| Type | Copy | Clone | Sized | Unsize | CoerceUnsized | Drop | FnOnce/FnMut/Fn | Unpin | Coroutine | auto traits |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| tuple types |||||||||||
| structs |||||||||||
Expand All @@ -44,7 +44,7 @@ Some common examples of auto traits are `Send` and `Sync`.
| slices |||||||||||
| arrays |||||||||||
| closures |||||||||||
| generators |||||||||||
| coroutines |||||||||||
| gen. witness |||||||||||
| opaque |||||||||||
| foreign |||||||||||
Expand Down
6 changes: 3 additions & 3 deletions book/src/types/rust_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ types. The intention is that, at least when transitioning, rustc would
implement the `Interner` trait and would map from the [`TyKind`][Rustc-TyKind]
enum to chalk's [`TyKind`] on the fly, when `data()` is invoked.

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

| rustc type | chalk variant (and some notes) |
| ------------- | ------------------ |
Expand All @@ -188,8 +188,8 @@ enum to chalk's [`TyKind`] on the fly, when `data()` is invoked.
| `FnPtr` | `Function` |
| `Dynamic` | `Dyn` |
| `Closure` | `Closure` |
| `Generator` | `Generator` |
| `GeneratorWitness` | `GeneratorWitness` |
| `Coroutine` | `Coroutine` |
| `CoroutineWitness` | `CoroutineWitness` |
| `Never` | `Never` |
| `Tuple` | `Tuple` |
| `Projection` | `Alias` |
Expand Down
36 changes: 18 additions & 18 deletions book/src/types/rust_types/application_ty.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ but have since moved away from that; nevertheless, the term is still useful in d

## Notable application types

### Generator
### Coroutine

A `Generator` represents a Rust generator. There are three major components
to a generator:
A `Coroutine` represents a Rust coroutine. There are three major components
to a coroutine:

* Upvars - similar to closure upvars, they reference values outside of the generator,
* Upvars - similar to closure upvars, they reference values outside of the coroutine,
and are stored across all yield points.
* Resume/yield/return types - the types produced/consumed by various generator methods.
These are not stored in the generator across yield points - they are only
used when the generator is running.
* Generator witness - see the `Generator Witness` section below.

Of these types, only upvars and resume/yield/return are stored directly in `GeneratorDatum`
(which is accessed via `RustIrDatabase`). The generator witness is implicitly associated with
the generator by virtue of sharing the same `GeneratorId`. It is only used when determining
* Resume/yield/return types - the types produced/consumed by various coroutine methods.
These are not stored in the coroutine across yield points - they are only
used when the coroutine is running.
* Coroutine witness - see the `Coroutine Witness` section below.

Of these types, only upvars and resume/yield/return are stored directly in `CoroutineDatum`
(which is accessed via `RustIrDatabase`). The coroutine witness is implicitly associated with
the coroutine by virtue of sharing the same `CoroutineId`. It is only used when determining
auto trait impls, where it is considered a 'constituent type'.

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

### Generator witness types
### Coroutine witness types

The `GeneratorWitness` variant represents the generator witness of
the generator with id `GeneratorId`.
The `CoroutineWitness` variant represents the coroutine witness of
the coroutine with id `CoroutineId`.

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

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

Witnesses have a binder for the erased lifetime(s), which must be
Expand Down
6 changes: 3 additions & 3 deletions chalk-engine/src/slg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ impl<I: Interner> MayInvalidate<I> {
(TyKind::Closure(id_a, substitution_a), TyKind::Closure(id_b, substitution_b)) => {
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
}
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
}
(
TyKind::GeneratorWitness(id_a, substitution_a),
TyKind::GeneratorWitness(id_b, substitution_b),
TyKind::CoroutineWitness(id_a, substitution_a),
TyKind::CoroutineWitness(id_b, substitution_b),
) => self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b),
(TyKind::Foreign(id_a), TyKind::Foreign(id_b)) => id_a != id_b,
(TyKind::Error, TyKind::Error) => false,
Expand Down
10 changes: 5 additions & 5 deletions chalk-engine/src/slg/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,20 @@ impl<I: Interner> AntiUnifier<'_, I> {
.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
.map(|(&name, substitution)| TyKind::Closure(name, substitution).intern(interner))
.unwrap_or_else(|| self.new_ty_variable()),
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
self.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
.map(|(&name, substitution)| {
TyKind::Generator(name, substitution).intern(interner)
TyKind::Coroutine(name, substitution).intern(interner)
})
.unwrap_or_else(|| self.new_ty_variable())
}
(
TyKind::GeneratorWitness(id_a, substitution_a),
TyKind::GeneratorWitness(id_b, substitution_b),
TyKind::CoroutineWitness(id_a, substitution_a),
TyKind::CoroutineWitness(id_b, substitution_b),
) => self
.aggregate_name_and_substs(id_a, substitution_a, id_b, substitution_b)
.map(|(&name, substitution)| {
TyKind::GeneratorWitness(name, substitution).intern(interner)
TyKind::CoroutineWitness(name, substitution).intern(interner)
})
.unwrap_or_else(|| self.new_ty_variable()),
(TyKind::Foreign(id_a), TyKind::Foreign(id_b)) => {
Expand Down
6 changes: 3 additions & 3 deletions chalk-engine/src/slg/resolvent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
substitution_b.as_slice(interner),
)
}
(TyKind::Generator(id_a, substitution_a), TyKind::Generator(id_b, substitution_b)) => {
(TyKind::Coroutine(id_a, substitution_a), TyKind::Coroutine(id_b, substitution_b)) => {
if id_a != id_b {
return Err(NoSolution);
}
Expand All @@ -559,8 +559,8 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
)
}
(
TyKind::GeneratorWitness(id_a, substitution_a),
TyKind::GeneratorWitness(id_b, substitution_b),
TyKind::CoroutineWitness(id_a, substitution_a),
TyKind::CoroutineWitness(id_b, substitution_b),
) => {
if id_a != id_b {
return Err(NoSolution);
Expand Down
16 changes: 8 additions & 8 deletions chalk-integration/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use crate::{
};
use chalk_ir::{
AdtId, AssocTypeId, Binders, Canonical, CanonicalVarKinds, ClosureId, ConstrainedSubst,
Environment, FnDefId, GeneratorId, GenericArg, Goal, ImplId, InEnvironment, OpaqueTyId,
CoroutineId, Environment, FnDefId, GenericArg, Goal, ImplId, InEnvironment, OpaqueTyId,
ProgramClause, ProgramClauses, Substitution, TraitId, Ty, TyKind, UCanonical,
UnificationDatabase, Variances,
};
use chalk_solve::rust_ir::{
AdtDatum, AdtRepr, AdtSizeAlign, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId,
ClosureKind, FnDefDatum, FnDefInputsAndOutputDatum, GeneratorDatum, GeneratorWitnessDatum,
ClosureKind, CoroutineDatum, CoroutineWitnessDatum, FnDefDatum, FnDefInputsAndOutputDatum,
ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownTrait,
};
use chalk_solve::{RustIrDatabase, Solution, SubstitutionResult};
Expand Down Expand Up @@ -118,15 +118,15 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
self.program_ir().unwrap().adt_datum(id)
}

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

fn generator_witness_datum(
fn coroutine_witness_datum(
&self,
id: GeneratorId<ChalkIr>,
) -> Arc<GeneratorWitnessDatum<ChalkIr>> {
self.program_ir().unwrap().generator_witness_datum(id)
id: CoroutineId<ChalkIr>,
) -> Arc<CoroutineWitnessDatum<ChalkIr>> {
self.program_ir().unwrap().coroutine_witness_datum(id)
}

fn adt_repr(&self, id: AdtId<ChalkIr>) -> Arc<AdtRepr<ChalkIr>> {
Expand Down
2 changes: 1 addition & 1 deletion chalk-integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum TypeSort {
Closure,
Trait,
Opaque,
Generator,
Coroutine,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
8 changes: 4 additions & 4 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ impl LowerWithEnv for Ty {
TypeLookup::FnDef(id) => tykind!(env.fn_def_kind(id), FnDef, id),
TypeLookup::Closure(id) => tykind!(env.closure_kind(id), Closure, id),
TypeLookup::Opaque(id) => tykind!(env.opaque_kind(id), OpaqueType, id),
TypeLookup::Generator(id) => tykind!(env.generator_kind(id), Generator, id),
TypeLookup::Coroutine(id) => tykind!(env.coroutine_kind(id), Coroutine, id),
TypeLookup::Foreign(_) | TypeLookup::Trait(_) => {
panic!("Unexpected apply type")
}
Expand Down Expand Up @@ -1047,8 +1047,8 @@ pub fn lower_goal(goal: &Goal, program: &LoweredProgram) -> LowerResult<chalk_ir
closure_ids: &program.closure_ids,
trait_ids: &program.trait_ids,
opaque_ty_ids: &program.opaque_ty_ids,
generator_ids: &program.generator_ids,
generator_kinds: &program.generator_kinds,
coroutine_ids: &program.coroutine_ids,
coroutine_kinds: &program.coroutine_kinds,
adt_kinds: &program.adt_kinds,
fn_def_kinds: &program.fn_def_kinds,
closure_kinds: &program.closure_kinds,
Expand Down Expand Up @@ -1137,7 +1137,7 @@ impl Lower for WellKnownTrait {
WellKnownTrait::Unpin => rust_ir::WellKnownTrait::Unpin,
WellKnownTrait::CoerceUnsized => rust_ir::WellKnownTrait::CoerceUnsized,
WellKnownTrait::DiscriminantKind => rust_ir::WellKnownTrait::DiscriminantKind,
WellKnownTrait::Generator => rust_ir::WellKnownTrait::Generator,
WellKnownTrait::Coroutine => rust_ir::WellKnownTrait::Coroutine,
WellKnownTrait::DispatchFromDyn => rust_ir::WellKnownTrait::DispatchFromDyn,
WellKnownTrait::Tuple => rust_ir::WellKnownTrait::Tuple,
WellKnownTrait::Pointee => rust_ir::WellKnownTrait::Pointee,
Expand Down
22 changes: 11 additions & 11 deletions chalk-integration/src/lowering/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chalk_ir::interner::HasInterner;
use chalk_ir::{
self, AdtId, BoundVar, ClosureId, DebruijnIndex, FnDefId, GeneratorId, OpaqueTyId, TraitId,
self, AdtId, BoundVar, ClosureId, CoroutineId, DebruijnIndex, FnDefId, OpaqueTyId, TraitId,
VariableKinds,
};
use chalk_ir::{cast::Cast, ForeignDefId, WithKind};
Expand All @@ -16,15 +16,15 @@ pub type AdtIds = BTreeMap<Ident, chalk_ir::AdtId<ChalkIr>>;
pub type FnDefIds = BTreeMap<Ident, chalk_ir::FnDefId<ChalkIr>>;
pub type ClosureIds = BTreeMap<Ident, chalk_ir::ClosureId<ChalkIr>>;
pub type TraitIds = BTreeMap<Ident, chalk_ir::TraitId<ChalkIr>>;
pub type GeneratorIds = BTreeMap<Ident, chalk_ir::GeneratorId<ChalkIr>>;
pub type CoroutineIds = BTreeMap<Ident, chalk_ir::CoroutineId<ChalkIr>>;
pub type OpaqueTyIds = BTreeMap<Ident, chalk_ir::OpaqueTyId<ChalkIr>>;
pub type AdtKinds = BTreeMap<chalk_ir::AdtId<ChalkIr>, TypeKind>;
pub type FnDefKinds = BTreeMap<chalk_ir::FnDefId<ChalkIr>, TypeKind>;
pub type ClosureKinds = BTreeMap<chalk_ir::ClosureId<ChalkIr>, TypeKind>;
pub type TraitKinds = BTreeMap<chalk_ir::TraitId<ChalkIr>, TypeKind>;
pub type AutoTraits = BTreeMap<chalk_ir::TraitId<ChalkIr>, bool>;
pub type OpaqueTyVariableKinds = BTreeMap<chalk_ir::OpaqueTyId<ChalkIr>, TypeKind>;
pub type GeneratorKinds = BTreeMap<chalk_ir::GeneratorId<ChalkIr>, TypeKind>;
pub type CoroutineKinds = BTreeMap<chalk_ir::CoroutineId<ChalkIr>, TypeKind>;
pub type AssociatedTyLookups = BTreeMap<(chalk_ir::TraitId<ChalkIr>, Ident), AssociatedTyLookup>;
pub type AssociatedTyValueIds =
BTreeMap<(chalk_ir::ImplId<ChalkIr>, Ident), AssociatedTyValueId<ChalkIr>>;
Expand All @@ -49,8 +49,8 @@ pub struct Env<'k> {
pub associated_ty_lookups: &'k AssociatedTyLookups,
pub auto_traits: &'k AutoTraits,
pub foreign_ty_ids: &'k ForeignIds,
pub generator_ids: &'k GeneratorIds,
pub generator_kinds: &'k GeneratorKinds,
pub coroutine_ids: &'k CoroutineIds,
pub coroutine_kinds: &'k CoroutineKinds,
/// GenericArg identifiers are used as keys, therefore
/// all identifiers in an environment must be unique (no shadowing).
pub parameter_map: ParameterMap,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum TypeLookup<'k> {
Opaque(OpaqueTyId<ChalkIr>),
Foreign(ForeignDefId<ChalkIr>),
Trait(TraitId<ChalkIr>),
Generator(GeneratorId<ChalkIr>),
Coroutine(CoroutineId<ChalkIr>),
}

impl Env<'_> {
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Env<'_> {
Ok(TypeLookup::Adt(id)) => tykind!(self.adt_kind(id), Adt, id),
Ok(TypeLookup::FnDef(id)) => tykind!(self.fn_def_kind(id), FnDef, id),
Ok(TypeLookup::Closure(id)) => tykind!(self.closure_kind(id), Closure, id),
Ok(TypeLookup::Generator(id)) => tykind!(self.generator_kind(id), Generator, id),
Ok(TypeLookup::Coroutine(id)) => tykind!(self.coroutine_kind(id), Coroutine, id),
Ok(TypeLookup::Opaque(id)) => Ok(chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(
chalk_ir::OpaqueTy {
opaque_ty_id: id,
Expand Down Expand Up @@ -165,8 +165,8 @@ impl Env<'_> {
Ok(TypeLookup::Foreign(*id))
} else if let Some(id) = self.trait_ids.get(&name.str) {
Ok(TypeLookup::Trait(*id))
} else if let Some(id) = self.generator_ids.get(&name.str) {
Ok(TypeLookup::Generator(*id))
} else if let Some(id) = self.coroutine_ids.get(&name.str) {
Ok(TypeLookup::Coroutine(*id))
} else {
Err(RustIrError::NotStruct(name.clone()))
}
Expand Down Expand Up @@ -208,8 +208,8 @@ impl Env<'_> {
&self.opaque_ty_kinds[&id]
}

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

pub fn lookup_associated_ty(
Expand Down
Loading

0 comments on commit 9a64a35

Please sign in to comment.