Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFixes to mir dataflow #33667
Conversation
pnkfelix
added some commits
Apr 28, 2016
rust-highfive
assigned
Aatch
May 16, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @Aatch (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
cc @arielb1 |
rust-highfive
assigned
nikomatsakis
and unassigned
Aatch
May 16, 2016
sanxiyn
reviewed
May 16, 2016
| /// attached to the function. | ||
| /// | ||
| /// For example, dataflow uses this to inject static assertions so | ||
| /// that `rustc_oeek(potentially_uninitialized)` would actually |
This comment has been minimized.
This comment has been minimized.
arielb1
reviewed
May 16, 2016
| // it will always appear like Lvalues are initialized; e.g. in | ||
| // a case like: | ||
| // | ||
| // <bitset maps var1 to 0> |
This comment has been minimized.
This comment has been minimized.
arielb1
May 16, 2016
Contributor
What is this talking about? rustc_peek(&var1) should be translated to
tmp1 = &var0;
tmp0 = rustc_peek(tmp1) -> bb1;
If it copies the lvalue before taking a reference, that would be totally broken (consider Cell). So it doesn't. Unless something funny is going on here.
This comment has been minimized.
This comment has been minimized.
pnkfelix
May 16, 2016
Author
Member
Oh you're right; I didn't update that comment correctly (it was originally authored for a different version of rustc_peek that looked like rustc_peek(var1) (instead of rustc_peek(&var1)), and I erroneously translated its content without thinking about what the actual translation of rustc_peek(&var1) is).
(The original version of rustc_peek had a more fragile API, where one would write rustc_peek(expr) (instead of rustc_peek(&expr)).)
The main point I'm trying to make is this: even with the corrected translation that you wrote:
tmp1 = &var0;
tmp0 = rustc_peek(tmp1) -> bb1;
The normal (naive) dataflow GEN/KILL sets are going to say that tmp1 is initialized. If the semantics of rustc_peek were a naive "look directly at your argument's dataflow bit state", then rustc_peek would query the state of tmp1, which would always indicate that it has been initialized under the naive rules.
So I had written a comment about a work-around I was using for the naive system.
With the new API the story is somewhat related, but the example I gave in the comment isn't helping explain things.
I will update it.
This comment has been minimized.
This comment has been minimized.
arielb1
May 16, 2016
Contributor
I guessed. Yeah, you want the state of var0, not of tmp1. I think you could just go to the initialization of tmp1 and use that.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 17, 2016
Contributor
(I also expected to find the definition of tmp1 when @pnkfelix and I discussed in the work week; but this solution works too.)
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 17, 2016
•
Contributor
I guess the reason not to do never mind, I see you are doing rustc_peek(&x) is that this code runs before borrowck anyway, so e.g. moves don't matter?&x
nikomatsakis
reviewed
May 17, 2016
| /// you if an l-value *might* be uninitialized at a given point in the | ||
| /// control flow. But `MovingOutStatements` also includes the added | ||
| /// data of *which* particular statement causing the deinitialization | ||
| /// that the borrow checker's error meessage may need to report. |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 17, 2016
•
Contributor
Intention is to compute this lazilly, right? Maybe note that?
nikomatsakis
reviewed
May 17, 2016
|
|
||
| These unit tests check the dataflow analysis by embedding calls to a | ||
| special `rustc_peek` intrinsic within the code, in tandem with an | ||
| attribute `#[rustc_mir(rustc_peek_maybe_init)]` (*). With that |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I gave this a brief review and it seems quite reasonable. I'll try to read a bit more in detail tomorrow though. |
pnkfelix
added some commits
May 17, 2016
pnkfelix
added some commits
May 24, 2016
This comment has been minimized.
This comment has been minimized.
|
@arielb1 @nikomatsakis The one thing I'd like someone to take a look at is the new My goal was to have a breakdown analogous to My analogous types in My problem is that I used a little bit of nasty unsafe code to accomplish this goal. :( (Namely, I did not see a way to turn a Maybe the right answer here is to not attempt to provide an unsized |
pnkfelix
reviewed
May 24, 2016
| /// "transfer-function" represnting the overall-effect of the | ||
| /// block, represented via GEN and KILL sets. | ||
| /// | ||
| /// The statement here is `idx_stmt.1`; `idx_stmt.0` is just |
This comment has been minimized.
This comment has been minimized.
pnkfelix
May 24, 2016
Author
Member
(note to self: this, like many comments, is out of date and needs to be fixed to reflect changes to the API here.)
pnkfelix
added some commits
May 25, 2016
nikomatsakis
reviewed
May 25, 2016
| // requires a transmute relying on representation guarantees that may | ||
| // not hold in the future. | ||
|
|
||
| pub struct IdxSet<T: Idx> { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
reviewed
May 25, 2016
| fn idx(&self) -> usize; | ||
| } | ||
|
|
||
| pub struct OwnIdxSet<T: Idx> { |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 25, 2016
Contributor
I would prefer the name IdxSetBuf, following the precedent of PathBuf and Path
This comment has been minimized.
This comment has been minimized.
nikomatsakis
reviewed
May 25, 2016
| } | ||
|
|
||
| pub struct OwnIdxSet<T: Idx> { | ||
| _pd: PhantomData<fn(&[T], usize) -> &T>, |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 25, 2016
Contributor
it'd be good to explain where this phantomdata comes from, since it's clearly quite deliberate...
This comment has been minimized.
This comment has been minimized.
nikomatsakis
May 25, 2016
Contributor
In terms of the intuition for phantdomdata, I think of this is basically being a more optimized version of a FnvHashSet<T>, hence I would expect PhantomData<T>, effectively. Not that this matters much in practice. :)
This comment has been minimized.
This comment has been minimized.
pnkfelix
May 25, 2016
•
Author
Member
Oh this PhantomData got things mixed up; you are right that PhantomData<T> would (probably) suffice here, (but I don't think its 100% accurate).
(I had originally attempted to put the actual represented type into the interface, e.g. make a connection from MovePathIndex to MovePath, and then the goal was to have a phantom data that would say Fn(&[MovePath], MovePathIndex) -> Option<&MovePath>. But as I reworked the API and removed references to the referenced data type, I didn't notice that I had mixed up the roles of T (the index type) and the referenced data type (now unnamed here).
I will replace with PhantomData<Fn(&T)> since that more properly reflects the relationship between the IdxSet and the Idx that each is fed.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
My feeling is that we should land this PR -- it seems like it contains many clear improvements and bug fixes, and it's big enough that we could keep iterating forever with nitpicks. I'd rather land it and then address further problems in follow-up PRs. @arielb1 -- thoughts? |
pnkfelix
added some commits
May 25, 2016
This comment has been minimized.
This comment has been minimized.
|
I'll go for that @bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
pnkfelix commentedMay 16, 2016
•
edited
Fixes to mir dataflow
This collects a bunch of changes to
rustc_borrowck::borrowck::dataflow(which others have pointed out should probably migrate to some crate that isn't tied to the borrow-checker -- but I have not attempted that here, especially since there are competing approaches to dataflow that we should also evaluate).These changes: