Skip to content
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

Merged
merged 7 commits into from
Feb 3, 2018
Merged

Generator bugfixes #47845

merged 7 commits into from
Feb 3, 2018

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Jan 29, 2018

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 29, 2018
@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 29, 2018

I haven't reported this as an issue yet, but immovable generators can't be used in return/yield/break expressions due to static not being added to fn ident_can_begin_expr. Could you fix this as well?

@Zoxc Zoxc force-pushed the gen-fixes branch 2 times, most recently from 23addfb to e6ec6a5 Compare January 29, 2018 10:43
Copy link
Contributor

@nikomatsakis nikomatsakis left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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()) {
Copy link
Contributor

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...)

Copy link
Contributor Author

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.

Copy link
Contributor

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)]
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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

Copy link
Contributor Author

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)]
Copy link
Contributor

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 31, 2018

📌 Commit 6c66e11 has been approved by nikomatsakis

@nikomatsakis nikomatsakis added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 31, 2018
@bors
Copy link
Contributor

bors commented Feb 3, 2018

⌛ Testing commit 6c66e11 with merge 3d292b7...

bors added a commit that referenced this pull request Feb 3, 2018
@bors
Copy link
Contributor

bors commented Feb 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 3d292b7 to master...

@bors bors merged commit 6c66e11 into rust-lang:master Feb 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants