Stream: t-compiler/wg-nll

Topic: lifetime inference and yield


boats (Feb 11 2019 at 13:53, on Zulip):

A user posted an issue in which the lifetime of a reference was unnecessarily inferred to include a yield point. Since this can impact the auto traits of the resulting state machine, it'd be ideal if this didn't happen. I was just wondering if anyone is thinking about how yield points interact with region inference. https://internals.rust-lang.org/t/async-await-and-references-in-pattern-match/9409/2

Also this is my first time using Zulip so sorry if I've not done things properly somehow. :))

davidtwco (Feb 11 2019 at 13:53, on Zulip):

cc @WG-compiler-nll

pnkfelix (Feb 11 2019 at 14:02, on Zulip):

hmm there's definitely something funny happening there

pnkfelix (Feb 11 2019 at 14:04, on Zulip):

I want to double-check something: Is the claim here that this issue arises with and without AST-borrowck (which is non-trivial to check since one cannot run this example on the 2015 edition)?

pnkfelix (Feb 11 2019 at 14:04, on Zulip):

and that the reason NLL is relevant is because one might hope that the increased precision of NLL would allow sidestepping the problem?

pnkfelix (Feb 11 2019 at 14:05, on Zulip):

Or is the claim that this code works with AST-borrowck and NLL is somehow regressing it?

pnkfelix (Feb 11 2019 at 14:05, on Zulip):

@boats ^ ?

boats (Feb 11 2019 at 14:07, on Zulip):

I haven't investigated closely, but I don't have any reason to think its a regression.

pnkfelix (Feb 11 2019 at 14:08, on Zulip):

I find it fascinating that pulling the f.foo() expression out into its own local sidesteps the error. I'm more used to things going in the other direction. :smiley:

pnkfelix (Feb 11 2019 at 14:09, on Zulip):

(except of course for the cases where pulling it into a local is also introducing changes to evaluation order. But I do not think that is happening here. Then again I might be misunderstanding the generator desugaring.)

boats (Feb 11 2019 at 14:09, on Zulip):

Yea it was very surprising to me also that that code change made it compile.

boats (Feb 11 2019 at 14:13, on Zulip):

The most interesting thing to me in this thread was that this is a design goal that could be factored into future NLL/polonius work - reducing the number of live objects across yield points. This matters both for auto traits like in this example and also optimizing the size of the state machine.

pnkfelix (Feb 11 2019 at 14:16, on Zulip):

definitely

Last update: Nov 21 2019 at 14:45UTC