Stream: t-compiler

Topic: #53834 await as a keyword and `await!` macro


Taylor Cramer (Sep 13 2018 at 20:16, on Zulip):

o/

nikomatsakis (Sep 13 2018 at 20:16, on Zulip):

woah weird

nikomatsakis (Sep 13 2018 at 20:16, on Zulip):

for some reason I saw my message twice

nikomatsakis (Sep 13 2018 at 20:17, on Zulip):

but I guess there was only one since when I deleted it we had nothing

nikomatsakis (Sep 13 2018 at 20:17, on Zulip):

ok, so ...

nikomatsakis (Sep 13 2018 at 20:17, on Zulip):

somebody was claiming I know something :P

nikomatsakis (Sep 13 2018 at 20:17, on Zulip):

actually, what I implemented was not quite the same as what you want to do

nikomatsakis (Sep 13 2018 at 20:18, on Zulip):

right now, what happens on 2018 if you use await? I'm guessing you get an error?

nikomatsakis (Sep 13 2018 at 20:19, on Zulip):

that..seems not to be true

nikomatsakis (Sep 13 2018 at 20:20, on Zulip):

uhh can you make an example today? I tried this but I get weird errors :)

nikomatsakis (Sep 13 2018 at 20:20, on Zulip):
#![feature(await_macro)]
#![feature(async_await)]
#![feature(generators)]

async fn foo() {
    let x = await!(bar());
}

async fn bar() -> impl Future<u32> {
    22
}

fn main() {

}
nikomatsakis (Sep 13 2018 at 20:20, on Zulip):

e.g. I don't know what future crate to import

Taylor Cramer (Sep 13 2018 at 20:22, on Zulip):

Right now you get no errors

Taylor Cramer (Sep 13 2018 at 20:22, on Zulip):

And you don't have to use futures at all

Taylor Cramer (Sep 13 2018 at 20:23, on Zulip):

it's just async fn bar() -> u32

Taylor Cramer (Sep 13 2018 at 20:23, on Zulip):

You also don't need feature(generators)

nikomatsakis (Sep 13 2018 at 20:24, on Zulip):

oh right

Taylor Cramer (Sep 13 2018 at 20:24, on Zulip):

https://play.rust-lang.org/?gist=73798a772604624f7afb651d3e885c0a&version=nightly&mode=debug&edition=2015

Taylor Cramer (Sep 13 2018 at 20:24, on Zulip):
#![feature(async_await, await_macro, futures_api)]

async fn foo() {
    let _ = await!(bar());
}

async fn bar() -> u32 { 5 }
nikomatsakis (Sep 13 2018 at 20:24, on Zulip):

it's just async fn bar() -> u32

I still have mixed feelings about that :P (not relevant, I know)

nikomatsakis (Sep 13 2018 at 20:24, on Zulip):

ok, so, this continues to work in Rust 2018

nikomatsakis (Sep 13 2018 at 20:24, on Zulip):

for...some reason

Taylor Cramer (Sep 13 2018 at 20:24, on Zulip):

async fn bar() -> impl Future<Output = u32> <- so noisy

Taylor Cramer (Sep 13 2018 at 20:25, on Zulip):

anyways

nikomatsakis (Sep 13 2018 at 20:25, on Zulip):

(man, I am always confused by how our parser handles keywords)

nikomatsakis (Sep 13 2018 at 20:25, on Zulip):

so one question that I don't know is: why does try error on Rust 2018?

nikomatsakis (Sep 13 2018 at 20:26, on Zulip):

it is kind of surprising to me that one works and one doesn't

nikomatsakis (Sep 13 2018 at 20:26, on Zulip):

async fn bar() -> impl Future<Output = u32> <- so noisy

yep...mixed feelings I said, and I meant it :)

Taylor Cramer (Sep 13 2018 at 20:27, on Zulip):

anyways, if you don't know what's going on, I'm happy to investigate more before bugging you ;)

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

oh

Taylor Cramer (Sep 13 2018 at 20:27, on Zulip):

centril just mentioned you might know what to do because you implemented this for try!

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

the reason is simple

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

await is not a keyword at all

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

in Rust 2018

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

only async is

Taylor Cramer (Sep 13 2018 at 20:27, on Zulip):

yup

nikomatsakis (Sep 13 2018 at 20:27, on Zulip):

ok ok

Taylor Cramer (Sep 13 2018 at 20:28, on Zulip):

and we want to make it a keyword

nikomatsakis (Sep 13 2018 at 20:28, on Zulip):

so

nikomatsakis (Sep 13 2018 at 20:28, on Zulip):

there are sort of two parts

Taylor Cramer (Sep 13 2018 at 20:28, on Zulip):

but allow it if await_macro is enabled

nikomatsakis (Sep 13 2018 at 20:28, on Zulip):

so I think what you want to do is probably this:

nikomatsakis (Sep 13 2018 at 20:28, on Zulip):
nikomatsakis (Sep 13 2018 at 20:28, on Zulip):
nikomatsakis (Sep 13 2018 at 20:28, on Zulip):
nikomatsakis (Sep 13 2018 at 20:28, on Zulip):
nikomatsakis (Sep 13 2018 at 20:29, on Zulip):

something roughly like that

nikomatsakis (Sep 13 2018 at 20:29, on Zulip):

(e.g., the parser doesn't know about the feature gates, so it can't check on its own)

Taylor Cramer (Sep 13 2018 at 20:29, on Zulip):

sg

nikomatsakis (Sep 13 2018 at 20:29, on Zulip):

at least I don't think it does

Taylor Cramer (Sep 13 2018 at 20:29, on Zulip):

it definitely didn't used to

nikomatsakis (Sep 13 2018 at 20:29, on Zulip):

besides, this will yield better errors I think

Taylor Cramer (Sep 13 2018 at 20:30, on Zulip):

cool, thanks for the pointer!

nikomatsakis (Sep 13 2018 at 20:30, on Zulip):

np

nikomatsakis (Sep 13 2018 at 20:30, on Zulip):

let me know if you hit any other problems...

Taylor Cramer (Sep 13 2018 at 22:53, on Zulip):

std::await!

Taylor Cramer (Sep 13 2018 at 22:54, on Zulip):

:(

Taylor Cramer (Sep 13 2018 at 22:54, on Zulip):

I guess we can just break it for now?

Taylor Cramer (Sep 13 2018 at 22:55, on Zulip):

also use std::await;

Taylor Cramer (Sep 13 2018 at 22:55, on Zulip):

use std::await as foo;

Taylor Cramer (Sep 13 2018 at 22:58, on Zulip):

ick, then we'd break https://github.com/tokio-rs/tokio/blob/master/tokio-async-await/src/lib.rs#L80

Taylor Cramer (Sep 13 2018 at 22:58, on Zulip):

so we can't do that :/

Taylor Cramer (Sep 13 2018 at 22:59, on Zulip):

One option would be to not treat it as a keyword at all

Taylor Cramer (Sep 13 2018 at 22:59, on Zulip):

and just error if we see it in the AST

Taylor Cramer (Sep 13 2018 at 22:59, on Zulip):

but then we won't get the edition transition lint

Taylor Cramer (Sep 13 2018 at 22:59, on Zulip):

:(

Taylor Cramer (Sep 13 2018 at 22:59, on Zulip):

@nikomatsakis ^

nikomatsakis (Sep 14 2018 at 14:31, on Zulip):

wait, @Taylor Cramer, what is std::await?

nikomatsakis (Sep 14 2018 at 14:31, on Zulip):

oic

nikomatsakis (Sep 14 2018 at 14:31, on Zulip):

@Taylor Cramer we could write our own lint tailored for await I guess

nikomatsakis (Sep 14 2018 at 14:31, on Zulip):

what a mess

nikomatsakis (Sep 14 2018 at 14:32, on Zulip):

can't we come up with some other name for the macro? :P

nikomatsakis (Sep 14 2018 at 14:32, on Zulip):

r#await..boom, done. :P

nikomatsakis (Sep 14 2018 at 19:04, on Zulip):

@Taylor Cramer did you ever decide how to proceed here?

nikomatsakis (Sep 14 2018 at 19:04, on Zulip):

@Taylor Cramer I imagine we could special case and permit await in paths as well

nikomatsakis (Sep 14 2018 at 19:05, on Zulip):

and filter for it

nikomatsakis (Sep 14 2018 at 19:05, on Zulip):

same way that we were talking about doing for macros

nikomatsakis (Sep 20 2018 at 21:28, on Zulip):

@Taylor Cramer are you going to be able to look into this after all?

Taylor Cramer (Sep 20 2018 at 21:56, on Zulip):

Sure, I can do this

Last update: Nov 16 2019 at 01:20UTC