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 support #43076

Merged
merged 128 commits into from
Aug 28, 2017
Merged
Changes from 1 commit
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
d861982
Generator literal support
Zoxc Dec 26, 2016
17c749f
Fix tidy warnings
alexcrichton Jul 5, 2017
8103017
std: Add forwarding impls of `Generator` trait
alexcrichton Jul 5, 2017
b5449b7
Ban explicit arguments on generators
Zoxc Jul 6, 2017
0b5b012
Consider all implementations of Generator, not just built in ones
Zoxc Jul 6, 2017
cc40f58
Added some tests
Zoxc Jul 7, 2017
51bb31a
Fix tests
alexcrichton Jul 7, 2017
5efb0cb
Add some generator pass/fail tests
alexcrichton Jul 7, 2017
bc9b4de
Make yield and gen arg outside generator literals an error and update…
Zoxc Jul 8, 2017
55bb1c0
Add documentation for generators
alexcrichton Jul 10, 2017
facabcb
Fill in generator tracking issue in a few more locations
alexcrichton Jul 10, 2017
075fd36
Ensure upvars are dropped when generators have never been resumed
Zoxc Jul 10, 2017
057b0ad
Don't print `gen` in HIR
Zoxc Jul 10, 2017
66fc6df
Update error codes
Zoxc Jul 10, 2017
df608e7
Rename suspend to yield
Zoxc Jul 10, 2017
8cd0595
Use FIXME instead of TODO
Zoxc Jul 10, 2017
2afd04c
Add some comments
Zoxc Jul 10, 2017
a88e750
Fix whitespace
Zoxc Jul 10, 2017
e62d9d5
Fix tests
Zoxc Jul 10, 2017
5d174f0
Clarifying documentation for generator
alexcrichton Jul 11, 2017
8bcafc5
Fix hash impl for SimplifiedType
Zoxc Jul 11, 2017
bfd71c5
Fix examples
Zoxc Jul 11, 2017
66b8a12
Fix upstream changes
Zoxc Jul 11, 2017
098d6f0
Move a FIXME around
Zoxc Jul 13, 2017
75eb598
Copy a comment
Zoxc Jul 13, 2017
21f2d25
Consider StorageDead and StorageLive as gens for liveness analysis
Zoxc Jul 13, 2017
05fcef0
Fix printing
Zoxc Jul 13, 2017
6e66dcc
Remove a FIXME
Zoxc Jul 13, 2017
7eae848
Touch up unstable docs for generators
alexcrichton Jul 13, 2017
77bf6e4
Add a test
Zoxc Jul 14, 2017
12bbcd3
Add a test case for conditional drop
alexcrichton Jul 14, 2017
8e82b19
Convert tabs to spaces
alexcrichton Jul 14, 2017
264c3f4
add some tests of yielding with outstanding borrows
nikomatsakis Jul 14, 2017
d71fa93
fix yields-in-args test and add a reverse one
nikomatsakis Jul 14, 2017
2ad0f89
Tweak docs
Zoxc Jul 14, 2017
10def9a
Revert borrowck changes
Zoxc Jul 14, 2017
a602fc0
Revert some whitespace changes
Zoxc Jul 14, 2017
dcddd80
Remove debug code
Zoxc Jul 15, 2017
9317204
Fix a bug with yielding subtypes of the yield type.
Zoxc Jul 15, 2017
09a5d31
Remove support for `gen arg`
alexcrichton Jul 11, 2017
eea290d
Convert to spaces
Zoxc Jul 15, 2017
cbdb186
Add some comments
Zoxc Jul 15, 2017
b744b1c
Convert to spaces
Zoxc Jul 15, 2017
e4fdbcb
Update FIXME
Zoxc Jul 15, 2017
14c7476
Fix a string literal
Zoxc Jul 15, 2017
5a6e069
Remove a FIXME and apply the same hack as closures
Zoxc Jul 15, 2017
188cdf4
combine `bckerr_to_diag` and `note_and_explain_bckerr`
nikomatsakis Jul 15, 2017
3fdc3fa
change how we report `err_out_of_scope` borrowck errors
nikomatsakis Jul 15, 2017
f5ec503
Fix tidy errors
Zoxc Jul 15, 2017
4628f85
Fix error message tests
Zoxc Jul 15, 2017
0a8b81a
Ignore drop check bools when testing for legal generator types
Zoxc Jul 15, 2017
6106f6c
Fix error message tests
Zoxc Jul 15, 2017
b2d931a
Fix error message tests again
Zoxc Jul 15, 2017
d32428b
Remove tabs
Zoxc Jul 16, 2017
39478e8
update references due to removing tabs
nikomatsakis Jul 16, 2017
62e210f
Derive traits for State.
Zoxc Jul 19, 2017
df0496a
Rename State to GeneratorState
Zoxc Jul 19, 2017
5da9a8a
Rename some variables in lowering.rs and add an error number for the …
Zoxc Jul 20, 2017
9a6a866
Remove visit_body from YieldFinder
Zoxc Jul 20, 2017
0f8897c
Fix error code
Zoxc Jul 20, 2017
9556fac
Fix error message string
Zoxc Jul 20, 2017
93b9b1a
Fix tests
Zoxc Jul 20, 2017
ae1856c
Update rename State in docs
Zoxc Jul 21, 2017
be0a9b8
Fix tests
Zoxc Jul 22, 2017
ff99685
Fix more tests with `GeneratorState` rename
alexcrichton Jul 22, 2017
416096d
Update comment
Zoxc Jul 25, 2017
06ce77c
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Jul 28, 2017
9285a61
Remove `IsGenerator` in favor of a boolean
alexcrichton Jul 28, 2017
cc4ff8f
Use a free error code
alexcrichton Jul 29, 2017
c25ddf2
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 8, 2017
352577f
Initial pass review comments
alexcrichton Aug 9, 2017
f72724e
Fix iterator over indexed sets
alexcrichton Aug 9, 2017
e181060
Add UI test outputs
alexcrichton Aug 9, 2017
be95ca4
Add a failing xcrate generator test
alexcrichton Aug 9, 2017
b8aa595
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 10, 2017
2d30e7e
Fix merge of scope.rs
Zoxc Aug 11, 2017
ffcd32c
Remove code related to the dropping of generator arguments
Zoxc Aug 11, 2017
bbe1552
Some tweaks and comments
Zoxc Aug 11, 2017
91dde3e
Typo
Zoxc Aug 11, 2017
be9c64b
Store generator interior in MIR literals
Zoxc Aug 11, 2017
6601ab9
Remove allocations
Zoxc Aug 11, 2017
54db165
Implement a cache for looking up yields
Zoxc Aug 11, 2017
2e3eaca
Please tidy
Zoxc Aug 11, 2017
2b04afb
Fix xcrate generator test
alexcrichton Aug 11, 2017
3971a3d
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 11, 2017
84af3d8
Fix an error in diagnostic codes
alexcrichton Aug 11, 2017
fa18aa3
Strip landing pads in the state transformation
Zoxc Aug 12, 2017
d020ff0
Merge branch 'master' of https://github.com/rust-lang/rust into gen
Zoxc Aug 12, 2017
1787d4e
Fix errors
Zoxc Aug 12, 2017
6eab1ca
Fix UI test
alexcrichton Aug 12, 2017
eff2884
Make generator interior types deterministic
Zoxc Aug 14, 2017
b045c20
Use a DepNode for the generator signature
Zoxc Aug 14, 2017
1413253
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 15, 2017
22ebcac
Choose another error code
alexcrichton Aug 15, 2017
b6b9690
Fix merge conflicts with `gen` branch
alexcrichton Aug 15, 2017
17197c6
Remove fixme
Zoxc Aug 15, 2017
1210ebf
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 16, 2017
0697e4b
Fix merge conflict
alexcrichton Aug 16, 2017
5f4a99f
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 16, 2017
63477fd
Fix merge conflicts
alexcrichton Aug 16, 2017
4b5f330
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 17, 2017
a47038f
Fix UI tests
alexcrichton Aug 17, 2017
9620d26
Fix more UI tests
alexcrichton Aug 18, 2017
e70cc27
Fix a diagnostic
alexcrichton Aug 18, 2017
bf3ebcc
Make gathering generator interior types O(n log n)
Zoxc Aug 20, 2017
b31998e
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 21, 2017
35b8dba
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 21, 2017
5dc9d71
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 21, 2017
04c66c3
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 22, 2017
c74ff32
More merge conflicts
alexcrichton Aug 22, 2017
0727ade
Avoid looking at `closure_kinds` for generators
alexcrichton Aug 24, 2017
b44e51c
Touch up a comment on `LocalDecl::internal`
alexcrichton Aug 24, 2017
c872f47
Merge remote-tracking branch 'origin/master' into gen
alexcrichton Aug 25, 2017
b28aeeb
Fix indentation
alexcrichton Aug 25, 2017
303a264
Reorder slightly in `visit_basic_block_data`
alexcrichton Aug 25, 2017
8c97ffa
Fix merge conflict
alexcrichton Aug 25, 2017
74b93f3
Add a `self_arg` convenience
alexcrichton Aug 25, 2017
ed5bc60
Remove unneeded FIXME for now
alexcrichton Aug 25, 2017
1917ffe
Add some suggested comments around drops
alexcrichton Aug 25, 2017
b4c5471
Comment about generators and drops
alexcrichton Aug 25, 2017
c711531
Add some comments and fix a typo
Zoxc Aug 24, 2017
5366135
Clean up YieldFinder
Zoxc Aug 25, 2017
7c5780b
Update rls
Zoxc Aug 28, 2017
d29af37
Merge branch 'master' of https://github.com/rust-lang/rust into gen
Zoxc Aug 28, 2017
8a9e32b
Update lock file
alexcrichton Aug 28, 2017
9eff522
Update the rls submodule again
alexcrichton Aug 28, 2017
876278f
Ignore a threaded test on emscripten
alexcrichton Aug 28, 2017
a996d5e
Tweak rls submodule again
alexcrichton Aug 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/master' into gen
  • Loading branch information
alexcrichton committed Aug 9, 2017

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit c25ddf21f18c3eeeaea2a4dffd70d2f6183068b5
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
ExprKind::Yield { value } => {
let value = unpack!(block = this.as_operand(block, scope, value));
let resume = this.cfg.start_new_block();
let cleanup = this.generator_drop_cleanup(expr_span);
let cleanup = this.generator_drop_cleanup();
this.cfg.terminate(block, source_info, TerminatorKind::Yield {
value: value,
resume: resume,
89 changes: 48 additions & 41 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
@@ -234,6 +234,15 @@ impl CachedBlock {
}
}

impl DropKind {
fn may_panic(&self) -> bool {
match *self {
DropKind::Value { .. } => true,
DropKind::Storage => false
}
}
}

impl<'tcx> Scope<'tcx> {
/// Invalidate all the cached blocks in the scope.
///
@@ -463,13 +472,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
///
/// This path terminates in GeneratorDrop. Returns the start of the path.
/// None indicates there’s no cleanup to do at this point.
pub fn generator_drop_cleanup(&mut self, span: Span) -> Option<BasicBlock> {
pub fn generator_drop_cleanup(&mut self) -> Option<BasicBlock> {
if !self.scopes.iter().any(|scope| scope.needs_cleanup) {
return None;
}

// Fill in the cache
self.diverge_cleanup_gen(span, true);
self.diverge_cleanup_gen(true);

let src_info = self.scopes[0].source_info(self.fn_span);
let tmp = self.get_unit_temp();
@@ -732,11 +741,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
/// This path terminates in Resume. Returns the start of the path.
/// See module comment for more details. None indicates there’s no
/// cleanup to do at this point.
pub fn diverge_cleanup(&mut self, span: Span) -> Option<BasicBlock> {
self.diverge_cleanup_gen(span, false)
pub fn diverge_cleanup(&mut self) -> Option<BasicBlock> {
self.diverge_cleanup_gen(false)
}

fn diverge_cleanup_gen(&mut self, span: Span, generator_drop: bool) -> Option<BasicBlock> {
fn diverge_cleanup_gen(&mut self, generator_drop: bool) -> Option<BasicBlock> {
if !self.scopes.iter().any(|scope| scope.needs_cleanup) {
return None;
}
@@ -773,7 +782,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
target = build_diverge_scope(hir.tcx(),
cfg,
&unit_temp,
span,
scope.extent_span,
scope,
target,
generator_drop);
@@ -856,45 +865,43 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
arg_count: usize,
generator_drop: bool)
-> BlockAnd<()> {

debug!("build_scope_drops({:?} -> {:?})", block, scope);
let mut iter = scope.drops.iter().rev().peekable();
while let Some(drop_data) = iter.next() {
let source_info = scope.source_info(drop_data.span);
if let DropKind::Value { .. } = drop_data.kind {
// Try to find the next block with its cached block
// for us to diverge into in case the drop panics.
let on_diverge = iter.peek().iter().filter_map(|dd| {
match dd.kind {
DropKind::Value { cached_block } => cached_block.get(generator_drop),
DropKind::Storage => None
}
}).next();
// If there’s no `cached_block`s within current scope,
// we must look for one in the enclosing scope.
let on_diverge = on_diverge.or_else(||{
earlier_scopes.iter().rev().flat_map(|s| s.cached_block(generator_drop)).next()
});
let next = cfg.start_new_block();
cfg.terminate(block, source_info, TerminatorKind::Drop {
location: drop_data.location.clone(),
target: next,
unwind: on_diverge
});
block = next;
}
match drop_data.kind {
DropKind::Value { .. } |
DropKind::Storage => {
// We do not need to emit these for generator drops
if generator_drop {
continue
}

// Only temps and vars need their storage dead.
match drop_data.location {
Lvalue::Local(index) if index.index() > arg_count => {}
_ => continue
}
DropKind::Value { .. } => {
// Try to find the next block with its cached block
// for us to diverge into in case the drop panics.
let on_diverge = iter.peek().iter().filter_map(|dd| {
match dd.kind {
DropKind::Value {
cached_block: CachedBlock {
unwind: None,
generator_drop: None,
}
} => {
span_bug!(drop_data.span, "cached block not present?")
}
DropKind::Value { cached_block } => cached_block.get(generator_drop),
DropKind::Storage => None
}
}).next();
// If there’s no `cached_block`s within current scope,
// we must look for one in the enclosing scope.
let on_diverge = on_diverge.or_else(|| {
earlier_scopes.iter().rev().flat_map(|s| s.cached_block(generator_drop)).next()
});
let next = cfg.start_new_block();
cfg.terminate(block, source_info, TerminatorKind::Drop {
location: drop_data.location.clone(),
target: next,
unwind: on_diverge
});
block = next;
}
DropKind::Storage => {}
}

// Drop the storage for both value and storage drops.
// Only temps and vars need their storage dead.
1 change: 1 addition & 0 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ impl<'tcx> Visitor<'tcx> for BlockInfoVisitor {

LvalueContext::Inspect |
LvalueContext::Consume |
LvalueContext::Validate |

// We consider drops to always be uses of locals.
// Drop eloboration should be run before this analysis otherwise
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
@@ -4011,7 +4011,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.check_expr_coercable_to_type(&value, ty);
}
None => {
struct_span_err!(self.tcx.sess, expr.span, E0624,
struct_span_err!(self.tcx.sess, expr.span, E0627,
"yield statement outside of generator literal").emit();
}
}
4 changes: 2 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -4649,7 +4649,7 @@ A private item was used outside of its scope.

Erroneous code example:

```compile_fail,E0624
```compile_fail,E0627
mod inner {
pub struct Foo;

@@ -4774,5 +4774,5 @@ register_diagnostics! {
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
E0592, // duplicate definitions with name `{}`
// E0613, // Removed (merged with E0609)
E0624, // yield statement outside of generator literal
E0627, // yield statement outside of generator literal
}
You are viewing a condensed version of this merge commit. You can view the full changes here.