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

Enable support for IndirectlyMutableLocals in rustc_peek #64980

Merged
merged 3 commits into from
Oct 2, 2019

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Oct 2, 2019

This PR allows rustc_peek tests to be written for the IndirectlyMutableLocals analysis implemented in #64470. See any of the tests in test/ui/mir-dataflow for an example.

Included in this PR is a major rewrite of the rustc_peek module. This was motivated by the differences between the IndirectlyMutableLocals analysis and the initialized places ones.

To properly test IndirectlyMutableLocals, we must pass locals by-value to rustc_peek, since any local that is not Freeze will be marked as indirectly mutable as soon as a reference to it is taken. Unfortunately, UnsafeCell is not Copy, so we can only do one rustc_peek on each value with interior mutability inside a test. I'm not sure how to deal with this restriction; perhaps I need to special case borrows preceding a call to rustc_peek in the analysis itself?

rustc_peek also assumed that the analysis was done on move paths and that its transfer function only needed to be applied at assignment statements. This PR removes both of those restrictions by adding a trait, RustcPeekAt, that controls how the peeked at Place maps to the current dataflow state and using a dataflow cursor to retrieve the state itself.

Finally, this PR adds a test which demonstrates some unsoundness in the IndirectlyMutableLocals analysis by converting a reference to a Freeze field to a reference to a !Freeze field by offsetting a pointer (or in this case transmuting a pointer to a ZST field with the same address as a !Freeze field). This does not represent a hole in the language proper, since this analysis is only used to validate const bodies, in which the unsound code will only compile with -Zunleash-the-miri-inside-of-you. Nevertheless, this should get fixed.

r? @oli-obk

We now use `DataflowResultsCursor` to get the dataflow state before
calls to `rustc_peek`. The original version used a custom implementation
that only looked at assignment statements. This also extends
`rustc_peek` to take arguments by-value as well as by-reference, and
allows *all* dataflow analyses, not just those dependent on `MoveData`,
to be inspected.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 2, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-02T03:49:03.0937013Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-02T03:49:03.1139704Z ##[command]git config gc.auto 0
2019-10-02T03:49:03.1214733Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-02T03:49:03.1267005Z ##[command]git config --get-all http.proxy
2019-10-02T03:49:03.1418872Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/64980/merge:refs/remotes/pull/64980/merge
---
2019-10-02T04:56:16.7034172Z .................................................................................................... 1500/9086
2019-10-02T04:56:23.8891480Z .................................................................................................... 1600/9086
2019-10-02T04:56:34.4002358Z ...................................................................................................i 1700/9086
2019-10-02T04:56:43.6439481Z ...............i.................................................................................... 1800/9086
2019-10-02T04:56:51.3111922Z ..........................................................................................iiiii..... 1900/9086
2019-10-02T04:57:15.7237246Z .................................................................................................... 2100/9086
2019-10-02T04:57:18.3999318Z .................................................................................................... 2200/9086
2019-10-02T04:57:21.2422064Z .................................................................................................... 2300/9086
2019-10-02T04:57:28.4121723Z .................................................................................................... 2400/9086
---
2019-10-02T05:00:41.0841271Z .............................................................................i...............i...... 4700/9086
2019-10-02T05:00:50.0628043Z .................................................................................................... 4800/9086
2019-10-02T05:01:00.8026354Z .................................................................................................... 4900/9086
2019-10-02T05:01:07.5454643Z .................................................................................................... 5000/9086
2019-10-02T05:01:19.4684741Z ....................................................................ii.ii........................... 5100/9086
2019-10-02T05:01:30.1141826Z .................................................................................................... 5300/9086
2019-10-02T05:01:40.4218213Z .................................................................................................... 5400/9086
2019-10-02T05:01:48.5888686Z ..................................i................................................................. 5500/9086
2019-10-02T05:01:55.3354844Z .................................................................................................... 5600/9086
2019-10-02T05:01:55.3354844Z .................................................................................................... 5600/9086
2019-10-02T05:02:07.9792004Z ...........................................F........................................................ 5700/9086
2019-10-02T05:02:19.5348496Z ...............................ii...i..ii...........i............................................... 5800/9086
2019-10-02T05:02:43.2274230Z .................................................................................................... 6000/9086
2019-10-02T05:02:53.0991291Z .................................................................................................... 6100/9086
2019-10-02T05:02:53.0991291Z .................................................................................................... 6100/9086
2019-10-02T05:03:11.0481451Z ..................................i..ii............................................................. 6200/9086
2019-10-02T05:03:32.7570315Z ..............................................................................................i..... 6400/9086
2019-10-02T05:03:35.2116855Z .................................................................................................... 6500/9086
2019-10-02T05:03:37.7075449Z ..................................................................i................................. 6600/9086
2019-10-02T05:03:40.9706982Z .................................................................................................... 6700/9086
---
2019-10-02T05:08:06.6217843Z 
2019-10-02T05:08:06.6218501Z ---- [ui] ui/mir-dataflow/indirect-mutation-offset.rs stdout ----
2019-10-02T05:08:06.6218574Z diff of stderr:
2019-10-02T05:08:06.6218612Z 
2019-10-02T05:08:06.6218680Z 1 error: rustc_peek: bit not set
2019-10-02T05:08:06.6219236Z +   --> $DIR/indirect-mutation-offset.rs:35:14
2019-10-02T05:08:06.6219306Z 3    |
2019-10-02T05:08:06.6219306Z 3    |
2019-10-02T05:08:06.6219356Z 4 LL |     unsafe { rustc_peek(x) };
2019-10-02T05:08:06.6219441Z 
2019-10-02T05:08:06.6219471Z 
2019-10-02T05:08:06.6219539Z The actual stderr differed from the expected stderr.
2019-10-02T05:08:06.6219929Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir-dataflow/indirect-mutation-offset/indirect-mutation-offset.stderr
2019-10-02T05:08:06.6219929Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir-dataflow/indirect-mutation-offset/indirect-mutation-offset.stderr
2019-10-02T05:08:06.6220221Z To update references, rerun the tests and pass the `--bless` flag
2019-10-02T05:08:06.6220569Z To only update this specific test, also pass `--test-args mir-dataflow/indirect-mutation-offset.rs`
2019-10-02T05:08:06.6220662Z error: 1 errors occurred comparing output.
2019-10-02T05:08:06.6220730Z status: exit code: 1
2019-10-02T05:08:06.6220730Z status: exit code: 1
2019-10-02T05:08:06.6221631Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/mir-dataflow/indirect-mutation-offset.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir-dataflow/indirect-mutation-offset" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Zunleash-the-miri-inside-of-you" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir-dataflow/indirect-mutation-offset/auxiliary" "-A" "unused"
2019-10-02T05:08:06.6222014Z ------------------------------------------
2019-10-02T05:08:06.6222055Z 
2019-10-02T05:08:06.6222321Z ------------------------------------------
2019-10-02T05:08:06.6222372Z stderr:
2019-10-02T05:08:06.6222372Z stderr:
2019-10-02T05:08:06.6222611Z ------------------------------------------
2019-10-02T05:08:06.6222683Z error: rustc_peek: bit not set
2019-10-02T05:08:06.6222968Z   --> /checkout/src/test/ui/mir-dataflow/indirect-mutation-offset.rs:35:14
2019-10-02T05:08:06.6223025Z    |
2019-10-02T05:08:06.6223100Z LL |     unsafe { rustc_peek(x) }; //~ ERROR rustc_peek: bit not set
2019-10-02T05:08:06.6223185Z 
2019-10-02T05:08:06.6223185Z 
2019-10-02T05:08:06.6223233Z error: stop_after_dataflow ended compilation
2019-10-02T05:08:06.6223547Z error: aborting due to 2 previous errors
2019-10-02T05:08:06.6223598Z 
2019-10-02T05:08:06.6223627Z 
2019-10-02T05:08:06.6223945Z ------------------------------------------
---
2019-10-02T05:08:06.6262932Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-10-02T05:08:06.6263037Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-10-02T05:08:06.6290670Z 
2019-10-02T05:08:06.6291119Z 
2019-10-02T05:08:06.6293403Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-10-02T05:08:06.6294257Z 
2019-10-02T05:08:06.6294414Z 
2019-10-02T05:08:06.6301287Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-10-02T05:08:06.6301527Z Build completed unsuccessfully in 1:11:38
2019-10-02T05:08:06.6301527Z Build completed unsuccessfully in 1:11:38
2019-10-02T05:08:06.6361195Z == clock drift check ==
2019-10-02T05:08:06.6378391Z   local time: Wed Oct  2 05:08:06 UTC 2019
2019-10-02T05:08:06.7900321Z   network time: Wed, 02 Oct 2019 05:08:06 GMT
2019-10-02T05:08:06.7900449Z == end clock drift check ==
2019-10-02T05:08:07.6430372Z ##[error]Bash exited with code '1'.
2019-10-02T05:08:07.6488522Z ##[section]Starting: Checkout
2019-10-02T05:08:07.6490702Z ==============================================================================
2019-10-02T05:08:07.6490765Z Task         : Get sources
2019-10-02T05:08:07.6490816Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@oli-obk
Copy link
Contributor

oli-obk commented Oct 2, 2019

Please open an issue about the bug in the IndirectlyMutableLocals analysis so we don't lose track of it

@bors r+

@bors
Copy link
Contributor

bors commented Oct 2, 2019

📌 Commit 33aa5e8 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 2, 2019
…=oli-obk

Enable support for `IndirectlyMutableLocals` in `rustc_peek`

This PR allows `rustc_peek` tests to be written for the `IndirectlyMutableLocals` analysis implemented in rust-lang#64470. See any of the tests in [`test/ui/mir-dataflow`](https://github.com/rust-lang/rust/blob/master/src/test/ui/mir-dataflow/inits-1.rs) for an example.

Included in this PR is a major rewrite of the `rustc_peek` module. This was motivated by the differences between the `IndirectlyMutableLocals` analysis and the initialized places ones.

To properly test `IndirectlyMutableLocals`, we must pass locals by-value to `rustc_peek`, since any local that is not `Freeze` will be marked as indirectly mutable as soon as a reference to it is taken. Unfortunately, `UnsafeCell` is not `Copy`, so we can only do one `rustc_peek` on each value with interior mutability inside a test. I'm not sure how to deal with this restriction; perhaps I need to special case borrows preceding a call to `rustc_peek` in the analysis itself?

`rustc_peek` also assumed that the analysis was done on move paths and that its transfer function only needed to be applied at assignment statements. This PR removes both of those restrictions by adding a trait, `RustcPeekAt`, that controls how the peeked at `Place` maps to the current dataflow state and using a dataflow cursor to retrieve the state itself.

Finally, this PR adds a test which demonstrates some unsoundness in the `IndirectlyMutableLocals` analysis by converting a reference to a `Freeze` field to a reference to a `!Freeze` field by offsetting a pointer (or in this case transmuting a pointer to a ZST field with the same address as a `!Freeze` field). This does not represent a hole in the language proper, since this analysis is only used to validate `const` bodies, in which the unsound code will only compile with `-Zunleash-the-miri-inside-of-you`. Nevertheless, this should get fixed.

r? @oli-obk
bors added a commit that referenced this pull request Oct 2, 2019
Rollup of 13 pull requests

Successful merges:

 - #64581 (Fix unreachable_code warnings for try{} block ok-wrapped expressions)
 - #64850 (Remove inlines from DepNode code)
 - #64914 (regression test for 64453 borrow check error.)
 - #64922 (Use PlaceBuilder to avoid a lot of slice -> vec -> slice convertions)
 - #64948 (Improve sidebar styling to make its integration easier)
 - #64961 (Make comment about dummy type a bit more clear)
 - #64967 (Don't mark borrows of zero-sized arrays as indirectly mutable)
 - #64973 (Fix typo while setting `compile-flags` in test)
 - #64980 (Enable support for `IndirectlyMutableLocals` in `rustc_peek` )
 - #64989 (Fix ICE #64964)
 - #64991 ([const-prop] Correctly handle locals that can't be propagated)
 - #64995 (Remove rustdoc warning)
 - #64997 (rustc book: nitpick SLP vectorization)

Failed merges:

r? @ghost
@bors bors merged commit 33aa5e8 into rust-lang:master Oct 2, 2019
@ecstatic-morse ecstatic-morse deleted the better-rustc-peek branch October 6, 2020 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants