-
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
Merged
Merged
Generator bugfixes #47845
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ad058cf
Make pattern visiting consistent
Zoxc dd3fa07
Make `yield_in_scope_for_expr` work with patterns. Fixes #47758
Zoxc 7a6f68c
Make error reporting work on generator upvars. Fixes #47793, #47805
Zoxc 77bc26f
Require yield types to be sized
Zoxc 4325c63
Allow access of the state field before the generator transform. Fixes…
Zoxc 5647356
Force locals to be live after they are borrowed for immovable generat…
Zoxc 6c66e11
The `static` keyword can now begin expressions
Zoxc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub use super::*; | ||
|
||
use rustc::mir::*; | ||
use rustc::mir::visit::Visitor; | ||
use dataflow::BitDenotation; | ||
|
||
/// This calculates if any part of a MIR local could have previously been borrowed. | ||
/// This means that once a local has been borrowed, its bit will always be set | ||
/// from that point and onwards, even if the borrow ends. You could also think of this | ||
/// as computing the lifetimes of infinite borrows. | ||
/// This is used to compute which locals are live during a yield expression for | ||
/// immovable generators. | ||
#[derive(Copy, Clone)] | ||
pub struct HaveBeenBorrowedLocals<'a, 'tcx: 'a> { | ||
mir: &'a Mir<'tcx>, | ||
} | ||
|
||
impl<'a, 'tcx: 'a> HaveBeenBorrowedLocals<'a, 'tcx> { | ||
pub fn new(mir: &'a Mir<'tcx>) | ||
-> Self { | ||
HaveBeenBorrowedLocals { mir: mir } | ||
} | ||
|
||
pub fn mir(&self) -> &Mir<'tcx> { | ||
self.mir | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> BitDenotation for HaveBeenBorrowedLocals<'a, 'tcx> { | ||
type Idx = Local; | ||
fn name() -> &'static str { "has_been_borrowed_locals" } | ||
fn bits_per_block(&self) -> usize { | ||
self.mir.local_decls.len() | ||
} | ||
|
||
fn start_block_effect(&self, _sets: &mut IdxSet<Local>) { | ||
// Nothing is borrowed on function entry | ||
} | ||
|
||
fn statement_effect(&self, | ||
sets: &mut BlockSets<Local>, | ||
loc: Location) { | ||
BorrowedLocalsVisitor { | ||
sets, | ||
}.visit_statement(loc.block, &self.mir[loc.block].statements[loc.statement_index], loc); | ||
} | ||
|
||
fn terminator_effect(&self, | ||
sets: &mut BlockSets<Local>, | ||
loc: Location) { | ||
BorrowedLocalsVisitor { | ||
sets, | ||
}.visit_terminator(loc.block, self.mir[loc.block].terminator(), loc); | ||
} | ||
|
||
fn propagate_call_return(&self, | ||
_in_out: &mut IdxSet<Local>, | ||
_call_bb: mir::BasicBlock, | ||
_dest_bb: mir::BasicBlock, | ||
_dest_place: &mir::Place) { | ||
// Nothing to do when a call returns successfully | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> BitwiseOperator for HaveBeenBorrowedLocals<'a, 'tcx> { | ||
#[inline] | ||
fn join(&self, pred1: usize, pred2: usize) -> usize { | ||
pred1 | pred2 // "maybe" means we union effects of both preds | ||
} | ||
} | ||
|
||
impl<'a, 'tcx> InitialFlow for HaveBeenBorrowedLocals<'a, 'tcx> { | ||
#[inline] | ||
fn bottom_value() -> bool { | ||
false // bottom = unborrowed | ||
} | ||
} | ||
|
||
struct BorrowedLocalsVisitor<'b, 'c: 'b> { | ||
sets: &'b mut BlockSets<'c, Local>, | ||
} | ||
|
||
fn find_local<'tcx>(place: &Place<'tcx>) -> Option<Local> { | ||
match *place { | ||
Place::Local(l) => Some(l), | ||
Place::Static(..) => None, | ||
Place::Projection(ref proj) => { | ||
match proj.elem { | ||
ProjectionElem::Deref => None, | ||
_ => find_local(&proj.base) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'tcx, 'b, 'c> Visitor<'tcx> for BorrowedLocalsVisitor<'b, 'c> { | ||
fn visit_rvalue(&mut self, | ||
rvalue: &Rvalue<'tcx>, | ||
location: Location) { | ||
if let Rvalue::Ref(_, _, ref place) = *rvalue { | ||
if let Some(local) = find_local(place) { | ||
self.sets.gen(&local); | ||
} | ||
} | ||
|
||
self.super_rvalue(rvalue, location) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.