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

Revise dataflow to use middle::cfg flowgraph to drive analysis. #14873

Merged
merged 9 commits into from
Jun 18, 2014

Conversation

pnkfelix
Copy link
Member

Fix #6298. Fix #13767.

This also includes some drive by fixes for some other issues, noted in the commits.

I still need to integrate regression tests for some cases that I noticed were missing from our unit test suite (i.e. things that compiling rustc exposes that should have been exposed when doing make check-stage1). So do not land this yet, until I get the chance to add those tests.

I just wanted to get the review process started soon, since this has been long in the coming.

@pnkfelix
Copy link
Member Author

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

:)

@pcwalton
Copy link
Contributor

Will this effectively close #13767, given that most (all?) things are driven off dataflow now?

@pnkfelix
Copy link
Member Author

@pcwalton yes it would, IMO

@pcwalton
Copy link
Contributor

Great!

@pnkfelix
Copy link
Member Author

(updated description with @pcwalton's insight.)

@pnkfelix
Copy link
Member Author

Okay I have now added the tests that I think are reasonable to try to put in with this PR.

The main remaining thing to test is the control-flow graph and borrowck behavior associated with ExprInlineAsm; however, there are independent bugs that really should be fixed for asm! separately (see #14962), so I would prefer to rebase+land this now and then land the tests associated with asm! later.

@nikomatsakis
Copy link
Contributor

This looks good. r+.

Here are some suggested changes:

nikomatsakis@6f3c60a

@nikomatsakis
Copy link
Contributor

Ah, one more comment -- the change to introduce LpCopiedUpvar seems to apply equally to all upvars.

pnkfelix added 9 commits June 18, 2014 16:36
1. After recursively processing an ExprWhile, need to pop loop_scopes
   the same way we do for ExprLoop.

2. Proposed fix for flowgraph handling of ExprInlineAsm: we need to
   represent the flow into the subexpressions of an `asm!` block.
Fix rust-lang#6298.

This is instead of the prior approach of emulating cfg traversal
privately by traversing AST in same way).

Of special note, this removes a special case handling of `ExprParen`
that was actually injecting a bug (since it was acting like an
expression like `(*func)()` was consuming `*func` *twice*: once from
`(*func)` and again from `*func`).  nikomatsakis was the first one to
point out that it might suffice to simply have the outer `ExprParen`
do the consumption of the contents (alone).

(This version has been updated to incorporate feedback from Niko's
review of PR 14873.)
Namely:

 1. Now that cfg mod is used for dataflow, we do not need to turn on
    the `allow(deadcode)` to placate the linter.

 2. remove dead struct defn.
…ext.

Details: in a program like:
```
type T = proc(int) -> int; /* 4 */

pub fn outer(captured /* pat 16 */: T) -> T {
    (proc(x /* pat 23 */) {
        ((captured /* 29 */).foo((x /* 30 */)) /* 28 */)
    } /* block 27 */ /* 20 */)
} /* block 19 */ /* 12 */
```
the `captured` arg is moved from the outer fn into the inner proc (id=20).

The old dataflow analysis for flowed_move_data_moves, when looking at
the inner proc, would attempt to add a kill bit for `captured` at the
end of its scope; the problem is that it thought the end of the
`captured` arg's scope was the outer fn (id=12), even though at that
point in the analysis, the `captured` arg's scope should now be
restricted to the proc itself (id=20).

This patch fixes handling of upvars so that dataflow of a fn/proc
should never attempts to add a gen or kill bit to any NodeId outside
of the current fn/proc.  It accomplishes this by adding an `LpUpvar`
variant to `borrowck::LoanPath`, so for cases like `captured` above
will carry both their original `var_id`, as before, as well as the
`NodeId` for the closure that is capturing them.

As a drive-by fix to another occurrence of a similar bug that
nikomatsakis pointed out to me earlier, this also fixes
`gather_loans::compute_kill_scope` so that it computes the kill scope
of the `captured` arg to be block 27; that is, the block for the proc
itself (id=20).

(This is an updated version that generalizes the new loan path variant
to cover all upvars, and thus renamed the variant from `LpCopiedUpvar`
to just `LpUpvar`.)
thereof.)

PR 14739 injected the new message that this removes from one test
case: borrowck-vec-pattern-loan-from-mut.rs

When reviewing the test case, I was not able to convince myself that
the error message was a legitimate thing to start emitting.  Niko did
not see an obvious reason for it either, so I am going to remove it
and wait for someone (maybe Cameron Zwarich) to explain to me why we
should be emitting it.
bors added a commit that referenced this pull request Jun 18, 2014
…tsakis

Fix #6298.  Fix  #13767.

This also includes some drive by fixes for some other issues, noted in the commits.

I still need to integrate regression tests for some cases that I noticed were missing from our unit test suite (i.e. things that compiling rustc exposes that should have been exposed when doing `make check-stage1`).  So do not land this yet, until I get the chance to add those tests.

I just wanted to get the review process started soon, since this has been long in the coming.
@bors bors closed this Jun 18, 2014
@bors bors merged commit 4c2a8bb into rust-lang:master Jun 18, 2014
@pnkfelix
Copy link
Member Author

Filed followup issue #15019 that I decided not to attempt to address before getting this landed.

@pnkfelix
Copy link
Member Author

Filed followup issue #15020 that I did not want to attempt to address before getting this landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants