Skip to content

Commit 94e663f

Browse files
account for Generators being renamed to Coroutines
rust-lang/rust#116958
1 parent 9023ddc commit 94e663f

File tree

10 files changed

+98
-94
lines changed

10 files changed

+98
-94
lines changed

effing-macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use syn::{
1313
fn quote_do(e: &Expr) -> Expr {
1414
parse_quote! {
1515
{
16-
use ::core::ops::{Generator, GeneratorState};
16+
use ::core::ops::{Coroutine, CoroutineState};
1717
use ::effing_mad::frunk::Coproduct;
1818
let mut gen = #e;
1919
let mut injection = Coproduct::inject(::effing_mad::injection::Begin);
@@ -26,9 +26,9 @@ fn quote_do(e: &Expr) -> Expr {
2626
pinned.resume(injection)
2727
};
2828
match res {
29-
GeneratorState::Yielded(effs) =>
29+
CoroutineState::Yielded(effs) =>
3030
injection = (yield effs.embed()).subset().ok().unwrap(),
31-
GeneratorState::Complete(v) => break v,
31+
CoroutineState::Complete(v) => break v,
3232
}
3333
}
3434
}
@@ -146,7 +146,7 @@ pub fn effectful(args: TokenStream, item: TokenStream) -> TokenStream {
146146
#(#attrs)*
147147
#vis #constness #unsafety
148148
fn #ident #generics(#inputs)
149-
-> impl ::core::ops::Generator<
149+
-> impl ::core::ops::Coroutine<
150150
<#yield_type as ::effing_mad::injection::EffectList>::Injections,
151151
Yield = #yield_type,
152152
Return = #return_type

examples/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//! Note that the effect definitions are written out manually in this example. For usage of the
1010
//! effects! macro, which allows more ergonomic effect definitions, see effects_macro.rs
1111
12-
#![feature(generators)]
13-
#![feature(generator_trait)]
12+
#![feature(coroutines)]
13+
#![feature(coroutine_trait)]
1414

1515
use effing_mad::{effectful, handle, handler, Effect};
1616

examples/effects-macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//! Here we use State as a classic (and generic!) example of an effect. The same program could just
66
//! be written using a mutable variable, but that's no fun.
77
8-
#![feature(generators)]
9-
#![feature(generator_trait)]
8+
#![feature(coroutines)]
9+
#![feature(coroutine_trait)]
1010

1111
use effing_mad::{effectful, handle_group, handler, run};
1212

examples/higher-order.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! as `Option::map`) that take effectful functions instead of "pure" ones. This allows some pretty
33
//! freaky control flow, like what we see here where the mapper function fails.
44
5-
#![feature(generators)]
6-
#![feature(generator_trait)]
5+
#![feature(coroutines)]
6+
#![feature(coroutine_trait)]
77

88
use effing_mad::{effectful, handle, handler, higher_order::OptionExt, run, Effect, Never};
99

examples/nondet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//!
66
//! solve for s, e, n, d, m, o, r, y
77
8-
#![feature(generators)]
9-
#![feature(generator_trait)]
10-
#![feature(generator_clone)]
8+
#![feature(coroutines)]
9+
#![feature(coroutine_trait)]
10+
#![feature(coroutine_clone)]
1111

1212
use effing_mad::effectful;
1313
use effing_mad::effects::{run_nondet, Nondet};

examples/sync-and-async.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//! completes in roughly the same time even though it's doing two of The Thing, because it is I/O
1010
//! bound.
1111
12-
#![feature(generators)]
13-
#![feature(generator_trait)]
12+
#![feature(coroutines)]
13+
#![feature(coroutine_trait)]
1414

1515
use effing_mad::{effectful, handle_group, handle_group_async, handler, run};
1616

examples/transform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! known in effing_mad as "transforming" the effects. Print is then handled on its own and since it
33
//! is the only remaining effect the computation can then be run.
44
5-
#![feature(generators)]
6-
#![feature(generator_trait)]
5+
#![feature(coroutines)]
6+
#![feature(coroutine_trait)]
77

88
use core::ops::ControlFlow;
99

src/effects/future.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core::{
44
future::Future,
5-
ops::{Generator, GeneratorState},
5+
ops::{Coroutine, CoroutineState},
66
pin::Pin,
77
task::{Context, Poll, Waker},
88
};
@@ -51,9 +51,9 @@ pub struct Futurise<G> {
5151

5252
impl<G> Future for Futurise<G>
5353
where
54-
G: Generator<FInjs, Yield = FEffs>,
54+
G: Coroutine<FInjs, Yield = FEffs>,
5555
{
56-
type Output = <G as Generator<FInjs>>::Return;
56+
type Output = <G as Coroutine<FInjs>>::Return;
5757

5858
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
5959
// see the todo on has_begun
@@ -66,22 +66,22 @@ where
6666
let g = unsafe { Pin::new_unchecked(&mut self.as_mut().get_unchecked_mut().g) };
6767
let res = g.resume(inj);
6868
match res {
69-
GeneratorState::Yielded(eff) => match eff.uninject() {
69+
CoroutineState::Yielded(eff) => match eff.uninject() {
7070
Ok(GetContext) => inj = Coproduct::inject(Tagged::new(cx.waker() as *const Waker)),
7171
Err(Coproduct::Inl(Await)) => panic!("can't await without context"),
7272
Err(Coproduct::Inr(never)) => match never {},
7373
},
74-
GeneratorState::Complete(ret) => return Poll::Ready(ret),
74+
CoroutineState::Complete(ret) => return Poll::Ready(ret),
7575
}
7676
let g = unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().g) };
7777
let res = g.resume(inj);
7878
match res {
79-
GeneratorState::Yielded(eff) => match eff.uninject() {
79+
CoroutineState::Yielded(eff) => match eff.uninject() {
8080
Ok(Await) => Poll::Pending,
8181
Err(Coproduct::Inl(GetContext)) => panic!("no need to GetContext twice"),
8282
Err(Coproduct::Inr(never)) => match never {},
8383
},
84-
GeneratorState::Complete(ret) => Poll::Ready(ret),
84+
CoroutineState::Complete(ret) => Poll::Ready(ret),
8585
}
8686
}
8787
}
@@ -94,23 +94,23 @@ pub struct Effectfulise<F> {
9494
f: F,
9595
}
9696

97-
impl<F> Generator<FInjs> for Effectfulise<F>
97+
impl<F> Coroutine<FInjs> for Effectfulise<F>
9898
where
9999
F: Future,
100100
{
101101
type Yield = FEffs;
102102
type Return = F::Output;
103103

104-
fn resume(self: Pin<&mut Self>, injs: FInjs) -> GeneratorState<Self::Yield, Self::Return> {
104+
fn resume(self: Pin<&mut Self>, injs: FInjs) -> CoroutineState<Self::Yield, Self::Return> {
105105
// safety: project
106106
let f = unsafe { Pin::new_unchecked(&mut self.get_unchecked_mut().f) };
107107
match injs.uninject::<Tagged<*const Waker, _>, _>() {
108108
// safety: it's a pointer to something that the caller has a reference to.
109109
Ok(waker) => match f.poll(&mut Context::from_waker(unsafe { &*waker.untag() })) {
110-
Poll::Ready(ret) => GeneratorState::Complete(ret),
111-
Poll::Pending => GeneratorState::Yielded(Coproduct::inject(GetContext)),
110+
Poll::Ready(ret) => CoroutineState::Complete(ret),
111+
Poll::Pending => CoroutineState::Yielded(Coproduct::inject(GetContext)),
112112
},
113-
Err(_) => GeneratorState::Yielded(Coproduct::inject(GetContext)),
113+
Err(_) => CoroutineState::Yielded(Coproduct::inject(GetContext)),
114114
}
115115
}
116116
}
@@ -133,7 +133,7 @@ impl<F: Future> FutureExt for F {
133133
}
134134
impl<G> EffExt for G
135135
where
136-
G: Generator<FInjs, Yield = FEffs>,
136+
G: Coroutine<FInjs, Yield = FEffs>,
137137
{
138138
fn futurise(self) -> Futurise<Self> {
139139
Futurise {

src/higher_order.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core::{
44
marker::PhantomData,
5-
ops::{Generator, GeneratorState},
5+
ops::{Coroutine, CoroutineState},
66
pin::Pin,
77
};
88

@@ -15,25 +15,25 @@ pub struct OptionMapEff<G, Effs, U> {
1515
_u: PhantomData<fn() -> U>,
1616
}
1717

18-
impl<G, Effs, U> Generator<Effs::Injections> for OptionMapEff<G, Effs, U>
18+
impl<G, Effs, U> Coroutine<Effs::Injections> for OptionMapEff<G, Effs, U>
1919
where
2020
Effs: EffectList,
21-
G: Generator<Effs::Injections, Yield = Effs, Return = U>,
21+
G: Coroutine<Effs::Injections, Yield = Effs, Return = U>,
2222
{
2323
type Yield = Effs;
2424
type Return = Option<U>;
2525

2626
fn resume(
2727
self: Pin<&mut Self>,
2828
injs: Effs::Injections,
29-
) -> GeneratorState<Self::Yield, Self::Return> {
29+
) -> CoroutineState<Self::Yield, Self::Return> {
3030
unsafe {
3131
match &mut self.get_unchecked_mut().g {
3232
Some(g) => match Pin::new_unchecked(g).resume(injs) {
33-
GeneratorState::Yielded(effs) => GeneratorState::Yielded(effs),
34-
GeneratorState::Complete(ret) => GeneratorState::Complete(Some(ret)),
33+
CoroutineState::Yielded(effs) => CoroutineState::Yielded(effs),
34+
CoroutineState::Complete(ret) => CoroutineState::Complete(Some(ret)),
3535
},
36-
None => GeneratorState::Complete(None),
36+
None => CoroutineState::Complete(None),
3737
}
3838
}
3939
}
@@ -50,14 +50,14 @@ pub trait OptionExt<T>: Sized {
5050
fn map_eff<Effs, G>(self, g: impl FnOnce(T) -> G) -> OptionMapEff<G, Effs, G::Return>
5151
where
5252
Effs: EffectList,
53-
G: Generator<Effs::Injections, Yield = Effs>;
53+
G: Coroutine<Effs::Injections, Yield = Effs>;
5454
}
5555

5656
impl<T> OptionExt<T> for Option<T> {
5757
fn map_eff<Effs, G>(self, g: impl FnOnce(T) -> G) -> OptionMapEff<G, Effs, G::Return>
5858
where
5959
Effs: EffectList,
60-
G: Generator<Effs::Injections, Yield = Effs>,
60+
G: Coroutine<Effs::Injections, Yield = Effs>,
6161
{
6262
OptionMapEff {
6363
g: self.map(g),
@@ -74,29 +74,31 @@ pub struct ResultMapEff<G, E, Effs, U> {
7474
_u: PhantomData<fn() -> U>,
7575
}
7676

77-
impl<G, E, Effs, U> Generator<Effs::Injections> for ResultMapEff<G, E, Effs, U>
77+
impl<G, E, Effs, U> Coroutine<Effs::Injections> for ResultMapEff<G, E, Effs, U>
7878
where
7979
E: Unpin,
8080
Effs: EffectList,
81-
G: Generator<Effs::Injections, Yield = Effs, Return = U>,
81+
G: Coroutine<Effs::Injections, Yield = Effs, Return = U>,
8282
{
8383
type Yield = Effs;
8484
type Return = Result<U, E>;
8585

8686
fn resume(
8787
self: Pin<&mut Self>,
8888
injs: Effs::Injections,
89-
) -> GeneratorState<Self::Yield, Self::Return> {
89+
) -> CoroutineState<Self::Yield, Self::Return> {
9090
unsafe {
9191
let g = &mut self.get_unchecked_mut().g;
9292
match g {
9393
Some(Ok(g)) => match Pin::new_unchecked(g).resume(injs) {
94-
GeneratorState::Yielded(effs) => GeneratorState::Yielded(effs),
95-
GeneratorState::Complete(ret) => GeneratorState::Complete(Ok(ret)),
94+
CoroutineState::Yielded(effs) => CoroutineState::Yielded(effs),
95+
CoroutineState::Complete(ret) => CoroutineState::Complete(Ok(ret)),
9696
},
9797
Some(Err(_)) => {
98-
let Some(Err(e)) = core::mem::take(g) else { unreachable!() };
99-
GeneratorState::Complete(Err(e))
98+
let Some(Err(e)) = core::mem::take(g) else {
99+
unreachable!()
100+
};
101+
CoroutineState::Complete(Err(e))
100102
},
101103
None => panic!("resumed after completed"),
102104
}
@@ -111,29 +113,31 @@ pub struct ResultMapErrEff<G, T, Effs, U> {
111113
_u: PhantomData<fn() -> U>,
112114
}
113115

114-
impl<G, T, Effs, U> Generator<Effs::Injections> for ResultMapErrEff<G, T, Effs, U>
116+
impl<G, T, Effs, U> Coroutine<Effs::Injections> for ResultMapErrEff<G, T, Effs, U>
115117
where
116118
T: Unpin,
117119
Effs: EffectList,
118-
G: Generator<Effs::Injections, Yield = Effs, Return = U>,
120+
G: Coroutine<Effs::Injections, Yield = Effs, Return = U>,
119121
{
120122
type Yield = Effs;
121123
type Return = Result<T, U>;
122124

123125
fn resume(
124126
self: Pin<&mut Self>,
125127
injs: Effs::Injections,
126-
) -> GeneratorState<Self::Yield, Self::Return> {
128+
) -> CoroutineState<Self::Yield, Self::Return> {
127129
unsafe {
128130
let g = &mut self.get_unchecked_mut().g;
129131
match g {
130132
Some(Err(g)) => match Pin::new_unchecked(g).resume(injs) {
131-
GeneratorState::Yielded(effs) => GeneratorState::Yielded(effs),
132-
GeneratorState::Complete(ret) => GeneratorState::Complete(Err(ret)),
133+
CoroutineState::Yielded(effs) => CoroutineState::Yielded(effs),
134+
CoroutineState::Complete(ret) => CoroutineState::Complete(Err(ret)),
133135
},
134136
Some(Ok(_)) => {
135-
let Some(Ok(e)) = core::mem::take(g) else { unreachable!() };
136-
GeneratorState::Complete(Ok(e))
137+
let Some(Ok(e)) = core::mem::take(g) else {
138+
unreachable!()
139+
};
140+
CoroutineState::Complete(Ok(e))
137141
},
138142
None => panic!("resumed after completed"),
139143
}
@@ -149,22 +153,22 @@ pub trait ResultExt<T, E>: Sized {
149153
fn map_eff<Effs, G>(self, g: impl FnOnce(T) -> G) -> ResultMapEff<G, E, Effs, G::Return>
150154
where
151155
Effs: EffectList,
152-
G: Generator<Effs::Injections, Yield = Effs>;
156+
G: Coroutine<Effs::Injections, Yield = Effs>;
153157

154158
/// Transforms the value inside a [`Result::Err`] with some effects.
155159
///
156160
/// For more details, see [`OptionExt::map_eff`].
157161
fn map_err_eff<Effs, G>(self, g: impl FnOnce(E) -> G) -> ResultMapErrEff<G, T, Effs, G::Return>
158162
where
159163
Effs: EffectList,
160-
G: Generator<Effs::Injections, Yield = Effs>;
164+
G: Coroutine<Effs::Injections, Yield = Effs>;
161165
}
162166

163167
impl<T, E> ResultExt<T, E> for Result<T, E> {
164168
fn map_eff<Effs, G>(self, g: impl FnOnce(T) -> G) -> ResultMapEff<G, E, Effs, G::Return>
165169
where
166170
Effs: EffectList,
167-
G: Generator<Effs::Injections, Yield = Effs>,
171+
G: Coroutine<Effs::Injections, Yield = Effs>,
168172
{
169173
ResultMapEff {
170174
g: Some(self.map(g)),
@@ -176,7 +180,7 @@ impl<T, E> ResultExt<T, E> for Result<T, E> {
176180
fn map_err_eff<Effs, G>(self, g: impl FnOnce(E) -> G) -> ResultMapErrEff<G, T, Effs, G::Return>
177181
where
178182
Effs: EffectList,
179-
G: Generator<Effs::Injections, Yield = Effs>,
183+
G: Coroutine<Effs::Injections, Yield = Effs>,
180184
{
181185
ResultMapErrEff {
182186
g: Some(self.map_err(g)),

0 commit comments

Comments
 (0)