Stream: wg-async-foundations

Topic: the `?` operator


nikomatsakis (Jul 10 2019 at 20:36, on Zulip):

I am writing a first pass at reference material for the book. Along the way, I noticed that the async-await RFC says that the ? operator's behavior has not yet been determined. And yet it seems to work fine in an async block (playground). Should we move that to a separate feature gate?

cc @WG-async-foundations

Taylor Cramer (Jul 10 2019 at 20:44, on Zulip):

responded on the issue

Taylor Cramer (Jul 10 2019 at 20:44, on Zulip):

this was initially a point of discussion

Taylor Cramer (Jul 10 2019 at 20:45, on Zulip):

but we discussed it in further lang team meetings and decided that we were all okay with return/break/continue/? all working as they did in closures, which is really the only possible option

Taylor Cramer (Jul 10 2019 at 20:45, on Zulip):

separately feature-gating ? would essentially make async/await dead-on-arrival given that almost all futures return Result types.

Taylor Cramer (Jul 10 2019 at 20:46, on Zulip):

i don't know if that decision was ever recorded anywhere, given that discussion over this has spread across so many issues and meetings over time.

centril (Jul 10 2019 at 20:51, on Zulip):

but we discussed it in further lang team meetings and decided that we were all okay with return/break/continue/? all working as they did in closures, which is really the only possible option

I don't recall this, but I also don't think there's anything strange going on here so I'm fine with shipping it.

That said, looking over the "existing tests" list I see no mention of ?

Taylor Cramer (Jul 10 2019 at 20:53, on Zulip):

I mean, I don't think ? is "anything special" here-- its behavior falls out as an obvious consequence of async blocks being a kind of closure.

Taylor Cramer (Jul 10 2019 at 20:54, on Zulip):

but it seems fine to me to add tests for that, break, continue, return, etc.

boats (Jul 10 2019 at 20:54, on Zulip):

Frankly, that comment should not have been allowed to be added to the RFC

boats (Jul 10 2019 at 20:55, on Zulip):

There has never been any serious doubt about the behavior of ?

centril (Jul 10 2019 at 20:58, on Zulip):

I mean, I don't think ? is "anything special" here-- its behavior falls out as an obvious consequence of async blocks being a kind of closure.

That presumes a sane compiler and a sane implementation

centril (Jul 10 2019 at 20:58, on Zulip):

I assume the implementation is wrong when thinking of tests

centril (Jul 10 2019 at 20:59, on Zulip):

and it's also important in terms of avoiding regressions

boats (Jul 10 2019 at 21:00, on Zulip):

seems like tests for all control flow operatos would be fine

centril (Jul 10 2019 at 21:03, on Zulip):

(I tested quickly at playground... seems nothing strange is going on, but the one bit that stood out is that https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=42f1c7732a5623674481654189f517ee gives subpar diagnostics that leaks the fact that it behaves like a function)

centril (Jul 10 2019 at 21:03, on Zulip):

(That doesn't seem blocking, but it would be good to improve diagnostics here)

centril (Jul 10 2019 at 21:08, on Zulip):

(Filed as: https://github.com/rust-lang/rust/issues/62570)

nikomatsakis (Jul 10 2019 at 22:02, on Zulip):

I agree we should just stabilize existing behavior of ?

nikomatsakis (Jul 10 2019 at 22:03, on Zulip):

I also agree we should write some tests :)

nikomatsakis (Jul 10 2019 at 22:04, on Zulip):

@Taylor Cramer do we permit return to "return" from the block?

nikomatsakis (Jul 10 2019 at 22:04, on Zulip):

it...seems we do.

nagisa (Jul 10 2019 at 22:18, on Zulip):

Into where does it return?

nikomatsakis (Jul 10 2019 at 22:44, on Zulip):

Into the result of the future, as with a closure.

nikomatsakis (Jul 10 2019 at 22:44, on Zulip):

And yes this connects to your other topic :)

rpjohnst (Jul 10 2019 at 22:44, on Zulip):

otoh this makes async blocks into implicit try blocks, in a sense- they're intentionally not like closures in a lot of ways so it seems strange and unnecessary to allow return/? just because the implementation is straightforward

nikomatsakis (Jul 10 2019 at 22:44, on Zulip):

/me not inclined to revist a basic question like this at this stage

nikomatsakis (Jul 10 2019 at 22:45, on Zulip):

(although I agree that return in particular feels surprising to me)

nikomatsakis (Jul 10 2019 at 22:45, on Zulip):

although convenient!

kennytm (Jul 12 2019 at 10:31, on Zulip):

i too find it very awkward that return has closure semantic without the closure syntax (the ||) :(

Last update: Nov 18 2019 at 00:45UTC