Stream: t-compiler

Topic: non-tls Async/Await


bwb (Jul 26 2019 at 06:08, on Zulip):

@eddyb I'm here :)

bwb (Jul 26 2019 at 06:09, on Zulip):

@Zoxc

bwb (Jul 26 2019 at 06:09, on Zulip):

I'm currently hacking on removing the TLS dependency from async/await

bwb (Jul 26 2019 at 06:10, on Zulip):

also, cc @Taylor Cramer & @tmandry who gave me initial pointers

bwb (Jul 26 2019 at 06:16, on Zulip):

My understanding of this issue is that I need to do a few things.

1. Add arguments to resume()
2. change the lowering code to have a context = yield ... type pattern that mutates the shared context inside the expanded generator future
3. make yield actually return something other than the unit type

bwb (Jul 26 2019 at 06:24, on Zulip):

there is some question about how to get the initial state into the from_generator() though, since it needs to be a valid Context<'_> IIUC

https://gist.github.com/cavedweller/22ce62dc823defac5fc54e2160f084f8/a58abb06fe46f15515b9a4c77ed9d3f7f1a0e27e

bwb (Jul 26 2019 at 06:24, on Zulip):

although maybe a yield () would work right there as well

Zoxc (Jul 26 2019 at 06:30, on Zulip):

The first step would be to add generator arguments back. My original PR used gen arg as the syntax for it, but it probably make more sense to use the closure syntax for it |arg1, arg2| { ... }.

bwb (Jul 26 2019 at 06:30, on Zulip):

Are generator arguments really necessary? shouldn't args on resume be sufficient?

bwb (Jul 26 2019 at 06:31, on Zulip):

(context: I have no idea what I'm talking about. Just trying to understand :) )

Zoxc (Jul 26 2019 at 06:32, on Zulip):

Generator arguments would be the arguments you pass to resume.

bwb (Jul 26 2019 at 06:33, on Zulip):

ah, cool! I used the horrific rust-call abi hack to do that

extern "rust-call" fn resume(self: Pin<&mut Self>, args: Args) -> GeneratorState<Self::Yield, Self::Return>;

bwb (Jul 26 2019 at 06:33, on Zulip):

but I can do that differently if prefered

Zoxc (Jul 26 2019 at 06:36, on Zulip):

This is my branch with generators arguments: https://github.com/Zoxc/rust/commits/gen-body

Zoxc (Jul 26 2019 at 06:37, on Zulip):

It has bitrotted now, but it might be useful to look at. (last 2 commits)

bwb (Jul 26 2019 at 06:38, on Zulip):

This would have been very helpful a couple hours ago :D

Zoxc (Jul 26 2019 at 06:39, on Zulip):

You should not make yield return the arguments as that is a terrible solution (it requires you to yield to access the arguments).

bwb (Jul 26 2019 at 06:39, on Zulip):

ok :/ What would you prefer?

Zoxc (Jul 26 2019 at 06:41, on Zulip):

Using the same syntax as closures (with named arguments)

bwb (Jul 26 2019 at 06:42, on Zulip):

I'm not really following what that looks like unfortunately

Zoxc (Jul 26 2019 at 06:50, on Zulip):

Do you know how to declare and use arguments in closures?

bwb (Jul 26 2019 at 06:50, on Zulip):

yes

Zoxc (Jul 26 2019 at 06:50, on Zulip):

Exactly the same syntax could be used for generators =P

Zoxc (Jul 26 2019 at 06:51, on Zulip):

Currently generators have the same syntax as closures, but are required to have 0 arguments.

bwb (Jul 26 2019 at 06:52, on Zulip):

ooo. It's my unfamiliarity with the constraints on generators here that was throwing me off

Zoxc (Jul 26 2019 at 06:54, on Zulip):

It's probably not the easiest way to add arguments though, using a dedicated AST node like my branch might be easier.

Zoxc (Jul 26 2019 at 06:55, on Zulip):

You could use a gen_arg! macro to generate the AST node (like asm!)

Zoxc (Jul 26 2019 at 06:58, on Zulip):

I guess an intrinsic would also work instead of the custom AST node, and be less invasive

bwb (Jul 26 2019 at 07:01, on Zulip):

ok, this might be silly

bwb (Jul 26 2019 at 07:01, on Zulip):

why is getting the result from the yield bad?

bwb (Jul 26 2019 at 07:01, on Zulip):

I can't think of a scenario where you wouldn't be calling it

bwb (Jul 26 2019 at 07:02, on Zulip):

I also have practically no insight into the long term plans for Generators though

Zoxc (Jul 26 2019 at 07:14, on Zulip):

You may want to start an async operation using a context passed in the argument then yield to wait for it to complete.

bwb (Jul 26 2019 at 07:50, on Zulip):

which is kinda exactly what I need I guess as well

bwb (Jul 26 2019 at 07:51, on Zulip):

I'll do this with a specialized node tomorrow

Taylor Cramer (Jul 26 2019 at 16:02, on Zulip):

ou may want to start an async operation using a context passed in the argument then yield to wait for it to complete.

Taylor Cramer (Jul 26 2019 at 16:02, on Zulip):

that isn't how async works today

Taylor Cramer (Jul 26 2019 at 16:02, on Zulip):

no code is run until you .poll for the first time

Taylor Cramer (Jul 26 2019 at 16:02, on Zulip):

(.resume)

Taylor Cramer (Jul 26 2019 at 16:03, on Zulip):

on the very first poll, you enter the function, which is a generator. the very first .resume arguments translate to the arguments to that closure body

Taylor Cramer (Jul 26 2019 at 16:04, on Zulip):

store the results in a context variable, and update it every time yield is called

bwb (Jul 26 2019 at 16:06, on Zulip):

https://gist.github.com/cavedweller/22ce62dc823defac5fc54e2160f084f8

bwb (Jul 26 2019 at 16:06, on Zulip):

arguments translate to the arguments to that closure body

bwb (Jul 26 2019 at 16:06, on Zulip):

like that?

Taylor Cramer (Jul 26 2019 at 16:09, on Zulip):

without the rename of ctx to context, yes

Taylor Cramer (Jul 26 2019 at 16:09, on Zulip):

it needs to remain updated after the call to .await

Taylor Cramer (Jul 26 2019 at 16:10, on Zulip):

https://gist.github.com/cramertj/de3f16afe33c47cc814f3929cbe33a7a

bwb (Jul 26 2019 at 16:14, on Zulip):

cool, things make sense :)

tmandry (Jul 26 2019 at 20:03, on Zulip):

@Taylor Cramer interesting, I think that implies some sort of rule that our arg cx must _always_ be replaced by a yield (if it is, for example, a &mut Context), so it's not implicitly saved in the generator object

tmandry (Jul 26 2019 at 20:04, on Zulip):

although as I'm typing this I realize that typeck for generators might basically already do this

tmandry (Jul 26 2019 at 20:06, on Zulip):

there was mention in one of the pre-RFCs of yielding the context out of the generator, but I guess that isn't necessary if typeck can handle this

bwb (Jul 30 2019 at 19:10, on Zulip):

So I have the lowering working on this (finally)

bwb (Jul 30 2019 at 19:11, on Zulip):

currently investigating modifying the generator code to have yield return a value

bwb (Jul 30 2019 at 19:11, on Zulip):

if you have any insight @Zoxc, it'd be appreciated :)

Jake Goulding (Jul 30 2019 at 20:02, on Zulip):

oooh, is this the issue that will allow async fn and .await without libstd, and only libcore?

simulacrum (Jul 30 2019 at 20:05, on Zulip):

I believe so, or at least moves us much closer to that

bwb (Jul 30 2019 at 20:14, on Zulip):

yeah, that's what I'm working on unblocking right now

Jake Goulding (Jul 30 2019 at 20:49, on Zulip):

nice!

Benjamin Brittain (Jul 30 2019 at 21:13, on Zulip):

It'll be a while :P It's pretty gnarly

Jake Goulding (Jul 31 2019 at 01:05, on Zulip):

Are you done yet? /troll

Benjamin Brittain (Jul 31 2019 at 01:08, on Zulip):
thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /usr/local/google/home/bwb/rust/src/libcore/slice/mod.rs:2690:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: cat_expr Errd
 --> src/lib.rs:3:26
  |
3 |   pub async fn bar() -> u32{
  |  __________________________^
4 | |     3
5 | | }
  | |_^

error: internal compiler error: cat_expr Errd
 --> src/lib.rs:3:26
  |
3 |   pub async fn bar() -> u32{
  |  __________________________^
4 | |     3
5 | | }
  | |_^
Benjamin Brittain (Jul 31 2019 at 01:08, on Zulip):

not yet

Benjamin Brittain (Jul 31 2019 at 01:09, on Zulip):

teaching yield () that it can return something other than () is causing me to learn a lot about... well, all of the rustc internals

eddyb (Aug 12 2019 at 16:05, on Zulip):

hey

eddyb (Aug 12 2019 at 16:05, on Zulip):

@Benjamin Brittain just in case you didn't see my pings elsewhere: I should be more available now

eddyb (Aug 12 2019 at 16:06, on Zulip):

I disagree with making this anything like closures

eddyb (Aug 12 2019 at 16:06, on Zulip):

forcing it to always be one thing makes expression yield much easier

eddyb (Aug 12 2019 at 16:07, on Zulip):

Generator -> Generator<T>

Benjamin Brittain (Aug 12 2019 at 18:31, on Zulip):

Hey! I missed your pings because I've been on a train the last week :)

Benjamin Brittain (Aug 12 2019 at 18:32, on Zulip):

I'm back and I'd like to get working on this again

Benjamin Brittain (Aug 12 2019 at 18:32, on Zulip):

I don't have any particular investment in an implementation method (nor the context), just a desire to remove TLS

Benjamin Brittain (Aug 12 2019 at 18:33, on Zulip):

cc/ @Taylor Cramer ^

eddyb (Aug 13 2019 at 07:16, on Zulip):

@Benjamin Brittain btw unless I am actively talking, feel free to ping me because Zulip won't notify me otherwise :(

eddyb (Aug 13 2019 at 07:17, on Zulip):

@Benjamin Brittain what do you have so far? and what are you stuck on?

nikomatsakis (Aug 14 2019 at 19:21, on Zulip):

maybe move this discussion to #wg-async-foundations ?

Last update: Nov 22 2019 at 06:00UTC