Stream: wg-async-foundations

Topic: mutuallly recursive async fn #62284


nikomatsakis (Jul 05 2019 at 17:58, on Zulip):

So @Taylor Cramer I'm looking at https://github.com/rust-lang/rust/issues/62284 a bit more closely

nikomatsakis (Jul 05 2019 at 18:04, on Zulip):

I'm a bit surprised by the example itself -- it is returning a boxed future from an async fn?

nikomatsakis (Jul 05 2019 at 18:04, on Zulip):

It seems like this cycles is tied to the way we implement impl Trait

nikomatsakis (Jul 05 2019 at 18:04, on Zulip):

i.e., auto trait leakage

nikomatsakis (Jul 05 2019 at 18:07, on Zulip):

this actually raises the issue of whether async fn should desugar to impl Future or impl Future + Send again, as the most obvious workaround is to desugar to something returning + Send

nikomatsakis (Jul 05 2019 at 18:28, on Zulip):

( cc @boats )

nikomatsakis (Jul 05 2019 at 19:57, on Zulip):

I left several comments on the issue itself. In general, recursive async functions are a bit of a pain right now, is roughly my conclusion, and the solutions are a bit tricky.

Taylor Cramer (Jul 08 2019 at 20:48, on Zulip):

This isn't an interesting issue with respect to cycles at all

Taylor Cramer (Jul 08 2019 at 20:49, on Zulip):

@nikomatsakis the issue is that it thinks there is a cycle, but it shouldn't, because the object returned by the async fn never gets stored into a local that is live across an await point

Taylor Cramer (Jul 08 2019 at 20:49, on Zulip):

It's just bad at determining which temporaries need to be analyzed

nikomatsakis (Jul 08 2019 at 20:51, on Zulip):

Yeah, but it seems more interesting when there are actual cycles

nikomatsakis (Jul 08 2019 at 20:52, on Zulip):

that's pretty painful right now

nikomatsakis (Jul 08 2019 at 20:52, on Zulip):

it's just not something I had on my radar

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

Sure, but the issue here is that there's a specific case that is pretty common, doesn't have cycles, and should be easily resolved

nikomatsakis (Jul 08 2019 at 20:54, on Zulip):

Why is this scenario common?

Taylor Cramer (Jul 08 2019 at 20:56, on Zulip):

it happens whenever you want to make a recursive async fn

Taylor Cramer (Jul 08 2019 at 20:56, on Zulip):

I've had a number of people at work try and do this and wound up repeating the steps that I showed in the issue

Taylor Cramer (Jul 08 2019 at 20:56, on Zulip):

(pull the call out into a separate function that does the boxing)

Taylor Cramer (Jul 08 2019 at 20:56, on Zulip):

which is silly boilerplate

nikomatsakis (Jul 08 2019 at 21:01, on Zulip):

Is it a common thing to have an async fn return a boxed future?

nikomatsakis (Jul 08 2019 at 21:01, on Zulip):

I guess it's a "stream-like" pattern

nikomatsakis (Jul 08 2019 at 21:01, on Zulip):

sort of analogous to a "one shot channel"

nikomatsakis (Jul 08 2019 at 21:02, on Zulip):

I wonder if the most logical fix is to make the "maybe lives across await" analysis more precise.

Taylor Cramer (Jul 08 2019 at 21:02, on Zulip):

it's certainly not uncommon, yes

Taylor Cramer (Jul 08 2019 at 21:03, on Zulip):

I wonder if the most logical fix is to make the "maybe lives across await" analysis more precise.

Yes, I think that's where the problem is here.

Last update: Nov 18 2019 at 00:40UTC