Skip to content

Commit 72e1bd0

Browse files
wackbyterosefromthedead
authored andcommitted
Replace all mentions of "generator" with "coroutine"
Also fixes the compilation of the crate when the `alloc` feature flag is enabled.
1 parent 6da8bf5 commit 72e1bd0

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ I wanted to see what would happen.
4444

4545
## how cool is it?
4646
effing-mad is cool. Rad, even. Check out all these cool things it has:
47-
* unstable compiler features (generators, generator_trait)
47+
* unstable compiler features (coroutines, coroutine_trait)
4848
* a function with 22 type arguments
4949
* `#![no_std]`
5050
* scary category theory words (coproduct! 👻)
@@ -70,10 +70,10 @@ On the other hand, I do understand algebraic effects, and therefore they are goo
7070
far more easily and in my opinion are more intuitive. Download effing-mad today!
7171

7272
## more facts - to do with rust this time
73-
effing-mad uses generators. The implementation of it was made far easier by the lang team already
74-
needing functions that can be suspended and resumed, because that caused them to invent generators.
73+
effing-mad uses coroutines. The implementation of it was made far easier by the lang team already
74+
needing functions that can be suspended and resumed, because that caused them to invent coroutines.
7575
Even though they were made for the compiler to be able to compile async fns, they're way more
7676
general than async fns are.
7777

78-
Generators are used by the compiler, but directly using them has not been stabilised yet because no
78+
Coroutines are used by the compiler, but directly using them has not been stabilised yet because no
7979
one really needs it to be. That's why you need to use a nightly compiler to use effing-mad.

effing-macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn quote_do(e: &Expr) -> Expr {
1919
let mut injection = Coproduct::inject(::effing_mad::injection::Begin);
2020
loop {
2121
// interesting hack to trick the borrow checker
22-
// allows cloneable generators
22+
// allows cloneable coroutines
2323
let res = {
2424
// safety: same as in `handle_group`
2525
let pinned = unsafe { ::core::pin::Pin::new_unchecked(&mut gen) };
@@ -107,7 +107,7 @@ impl syn::visit_mut::VisitMut for Effectful {
107107
/// It is possible to create effectful functions whose computations can be cloned. This requires
108108
/// marking the function as `#[effectful::cloneable]` after the `#[effectful(...)]` invocation,
109109
/// the function to have only `Clone` and `Unpin` locals, and the function to never hold a
110-
/// reference to a local across a yield point. In other words, the underlying generator must be
110+
/// reference to a local across a yield point. In other words, the underlying coroutine must be
111111
/// `Clone` and `Unpin`.
112112
#[proc_macro_attribute]
113113
pub fn effectful(args: TokenStream, item: TokenStream) -> TokenStream {

src/effects/nondet.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use frunk::{Coprod, Coproduct};
44

5-
use core::ops::{Generator, GeneratorState};
5+
use core::ops::{Coroutine, CoroutineState};
66

77
use alloc::vec::Vec;
88

@@ -26,7 +26,7 @@ impl<T> Effect for Nondet<T> {
2626
/// Run a nondeterministic computation, collecting all the resulting return values into a `Vec`.
2727
pub fn run_nondet<G, T>(g: G) -> Vec<G::Return>
2828
where
29-
G: Generator<Coprod!(Tagged<T, Nondet<T>>, Begin), Yield = Coprod!(Nondet<T>)> + Clone,
29+
G: Coroutine<Coprod!(Tagged<T, Nondet<T>>, Begin), Yield = Coprod!(Nondet<T>)> + Clone,
3030
{
3131
let mut rets = Vec::new();
3232
run_nondet_inner(g, Coproduct::inject(Begin), &mut rets);
@@ -38,11 +38,11 @@ fn run_nondet_inner<G, T>(
3838
injs: Coprod!(Tagged<T, Nondet<T>>, Begin),
3939
rets: &mut Vec<G::Return>,
4040
) where
41-
G: Generator<Coprod!(Tagged<T, Nondet<T>>, Begin), Yield = Coprod!(Nondet<T>)> + Clone,
41+
G: Coroutine<Coprod!(Tagged<T, Nondet<T>>, Begin), Yield = Coprod!(Nondet<T>)> + Clone,
4242
{
4343
let mut pinned = core::pin::pin!(g);
4444
match pinned.as_mut().resume(injs) {
45-
GeneratorState::Yielded(effs) => {
45+
CoroutineState::Yielded(effs) => {
4646
let Nondet(xs) = match effs {
4747
Coproduct::Inl(v) => v,
4848
Coproduct::Inr(never) => match never {},
@@ -52,6 +52,6 @@ fn run_nondet_inner<G, T>(
5252
run_nondet_inner(g2, Coproduct::inject(Tagged::new(x)), rets);
5353
}
5454
},
55-
GeneratorState::Complete(ret) => rets.push(ret),
55+
CoroutineState::Complete(ret) => rets.push(ret),
5656
}
5757
}

src/injection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::Effect;
88

99
/// Before an effectful computation has started, there is no injection to pass in, because no
1010
/// effects have been run yet. However, due to the signature of
11-
/// [`Generator::resume`](core::ops::Generator::resume), it is necessary to pass one in anyway.
11+
/// [`Coroutine::resume`](core::ops::Coroutine::resume), it is necessary to pass one in anyway.
1212
/// This type is used as a first injection for all effectful computations.
1313
#[derive(Clone, Copy)]
1414
pub struct Begin;

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub enum Never {}
7070

7171
/// Run an effectful computation that has no effects.
7272
///
73-
/// Effectful computations are generators, but if they have no effects, it is guaranteed that they
73+
/// Effectful computations are coroutines, but if they have no effects, it is guaranteed that they
7474
/// will never yield. Therefore they can be run by resuming them once. This function does that.
7575
pub fn run<F, R>(mut f: F) -> R
7676
where
@@ -247,7 +247,7 @@ where
247247
let mut injs = Coproduct::inject(Begin);
248248
loop {
249249
// safety: see handle_group() - remember that futures are pinned in the same way as
250-
// generators
250+
// coroutines
251251
let pinned = unsafe { Pin::new_unchecked(&mut g) };
252252
match pinned.resume(injs) {
253253
CoroutineState::Yielded(effs) => {
@@ -287,7 +287,7 @@ where
287287
let mut injs = Is::inject(Begin);
288288
loop {
289289
// safety: see handle_group() - remember that futures are pinned in the same way as
290-
// generators
290+
// coroutines
291291
let pinned = unsafe { Pin::new_unchecked(&mut g) };
292292
match pinned.resume(injs) {
293293
CoroutineState::Yielded(effs) => match handler(effs).await {

0 commit comments

Comments
 (0)