-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generator bugfixes #47845
Generator bugfixes #47845
Conversation
I haven't reported this as an issue yet, but immovable generators can't be used in |
23addfb
to
e6ec6a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good. The last commit confused me a bit though. Left some requests for comments and other nits; let me know and will re-review.
@@ -467,9 +467,10 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor { | |||
} | |||
|
|||
fn visit_pat(&mut self, pat: &'tcx Pat) { | |||
intravisit::walk_pat(self, pat); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is motivating these changes? Presumably this is fixing a bug? If so, it'd be nice to have a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the visitation match the visitation in RegionResolutionVisitor
. I don't think this matters for patterns. It might mess up generators inside patterns somehow though.
@@ -533,15 +533,15 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { | |||
} | |||
} | |||
ty::TyGenerator(def_id, substs, _) => { | |||
// Try upvars first. `field_tys` requires final optimized MIR. | |||
if let Some(ty) = substs.upvar_tys(def_id, tcx).nth(field.index()) { | |||
// Try upvars first. `field_tys` requires the final optimized MIR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this comment seems slightly out of date, right? Maybe "Try pre-transform fields first (e.g., upvars, current state). The remaining fields (contained in field_tys
) require the final optimized MIR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the comment.
// Try upvars first. `field_tys` requires final optimized MIR. | ||
if let Some(ty) = substs.upvar_tys(def_id, tcx).nth(field.index()) { | ||
// Try upvars first. `field_tys` requires the final optimized MIR | ||
if let Some(ty) = substs.pre_transforms_tys(def_id, tcx).nth(field.index()) { | ||
return Ok(ty); | ||
} | ||
|
||
return match substs.field_tys(def_id, tcx).nth(field.index()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, this code is basically dead code, right? That is, we don't run the type-checker after optimization? I guess it's here just in case we do, as a kind of sanity check? (But in that case, i'm not sure that the full set of type checks would pass...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I wrote it, only the InstCombine
pass broke type checking. I disabled that and ran MIR type checking later anyway, for debugging purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K
use rustc::mir::visit::Visitor; | ||
use dataflow::BitDenotation; | ||
|
||
#[derive(Copy, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment explaining what this analysis does and its overall purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment here.
@@ -406,9 +418,9 @@ fn locals_live_across_suspend_points<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | |||
live_locals.union(&ignored.0); | |||
|
|||
if !movable { | |||
// For immovable generators we consider borrowed locals to always be live. | |||
// For immovable generators we consider locals to always be live once borrowed. | |||
// This effectively makes those locals use just the storage liveness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd appreciate a code example here, or somewhere =), explaining the meaning of these bits in a more intuitive way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some more comments. Let me know if that is good enough.
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(generators)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining what this test is testing? My guess is that it's a local variable that wouldn't have to be considered live (because it is borrowed only after the yield)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe I'm just confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment here.
@bors r+ |
📌 Commit 6c66e11 has been approved by |
Generator bugfixes r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
r? @nikomatsakis