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

MIR-borrowck: (unsound) fails to see error in borrowck-init-in-fru.rs #44833

Closed
pnkfelix opened this issue Sep 25, 2017 · 3 comments · Fixed by #45025
Closed

MIR-borrowck: (unsound) fails to see error in borrowck-init-in-fru.rs #44833

pnkfelix opened this issue Sep 25, 2017 · 3 comments · Fixed by #45025
Labels
A-borrow-checker Area: The borrow checker B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Sep 25, 2017

Many MIR-borrowck bugs have been categorized as either extra errors or poor diagnostics, but this is a case where MIR borrowck is simply failing to flag the main error in the code in question.

We see below that AST-borrowck is flagging the error while MIR-borrowck says nothing. (This is atop the mir-borrowck4 branch from #44736 )

% ./objdir-dbgopt/build/x86_64-unknown-linux-gnu/stage1/bin/rustc -Z emit-end-regions \
    -Z borrowck-mir ./src/test/compile-fail/borrowck/borrowck-init-in-fru.rs
error[E0381]: use of possibly uninitialized variable: `origin.y` (Ast)
  --> ./src/test/compile-fail/borrowck/borrowck-init-in-fru.rs:19:30
   |
19 |     origin = point {x: 10,.. origin}; //~ ERROR use of possibly uninitialized variable: `origin.y`
   |                              ^^^^^^ use of possibly uninitialized `origin.y`

error: aborting due to previous error
@TimNN TimNN added A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Sep 27, 2017
@bstrie bstrie added the B-unstable Blocker: Implemented in the nightly compiler and unstable. label Sep 27, 2017
@mikhail-m1
Copy link
Contributor

working on it

@mikhail-m1
Copy link
Contributor

mikhail-m1 commented Oct 3, 2017

simplified

struct Foo(isize);

fn main() {
    let mut a: Foo;
    let _ = a.0 + 1;
}

@pnkfelix
Copy link
Member Author

pnkfelix commented Oct 5, 2017

(I think I'm going to take the lead on this bug at this point; PR #45025 doesn't have the exact right solution yet, but I think the work there is part of the answer.)

pnkfelix added a commit to pnkfelix/rust that referenced this issue Oct 11, 2017
Fix rust-lang#44833 (a very specific instance of a very broad bug).

In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.

Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:

1. Looking solely at supporting prefixes does not suffice: it
   overlooks checking if the path was ever actually initialized in the
   first place. So you need to be willing to consider non-supporting
   prefixes.  Once you are looking at all prefixes, you *could* just
   look at the local that forms the base of the projection, but to
   handle partial initialization (which still needs to be formally
   specified), this code instead looks at the nearest prefix of L that
   has an associated MovePath (which, in the limit, will end up being
   a local).

2. You also need to consider the suffixes of the given Lvalue, due to
   how dataflow is representing partial moves of individual fields out
   of struct values.

3. (There was originally a third search, but ariel pointed out that
   the first and third could be folded into one.)

Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
bors added a commit that referenced this issue Oct 13, 2017
…ixes-invalidate-uses-too, r=arielb1

MIR-borrowck: moves of prefixes invalidate uses too

I overlooked the fact that when we check if a path is moved, we need to check for interference between the (shallow) prefixes and the use in question.

~~Long term, we may want to revise how this computation is done. For example, it might be better to represent the set of invalidated prefixes in the dataflow computation (the `maybe_uninitialized` dataflow), and thus avoid one of the loops in the code here.~~
 * Update: I was wrong in my original recollection of the dataflow code, which actually does the right thing, in terms of precisely tracking substructure initialization and movement.

Fix #44833

----

Update: The initial version of this PR's description (and the code as well) erroneously focused on supporting prefixes. ~~But the two main cases of interest are: 1. the *shallow* prefixes, and 2. the deref-free prefix built off a local (if the lvalue is indeed built off a local)~~

Update 2: The main cases of interest are in fact: 1. the nearest prefix with a MovePath, and 2. the suffixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants