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

rustc_mir: double-check const-promotion candidates for sanity. #63812

Merged
merged 2 commits into from
Oct 26, 2019

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Aug 22, 2019

Previously, const promotion involved tracking information about the value in a MIR local (or any part of the computation leading up to that value), aka "qualifs", in a quite stateful manner, which is hard to extend to arbitrary CFGs without a dataflow pass.

However, the nature of the promotion we do is that it's effectively an SSA-like "tree" (or DAG, really), of assigned-once locals - which is how we can take them from the original MIR in the first place.
This structure means that the subset of the MIR responsible for computing any given part of a const-promoted value is readily analyzable by walking that tree/DAG.

This PR implements such an analysis in promote_consts, reusing the HasMutInterior / NeedsDrop computation from qualify_consts, but reimplementing the equivalent of IsNotPromotable / IsNotImplicitlyPromotable.

Eventually we should be able to remove IsNotPromotable / IsNotImplicitlyPromotable from qualify_consts, which will simplify @ecstatic-morse's dataflow-based const-checking efforts.

But currently this is mainly for a crater check-only run - it will compare the results from the old promotion collection and the new promotion validation and ICE if they don't match.

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2019
@eddyb
Copy link
Member Author

eddyb commented Aug 22, 2019

@bors try

@bors
Copy link
Contributor

bors commented Aug 22, 2019

⌛ Trying commit 0229fb0 with merge 28d741e...

bors added a commit that referenced this pull request Aug 22, 2019
[WIP] rustc_mir: double-check const-promotion candidates for sanity.

Previously, const promotion involved tracking information about the value in a MIR local (or any part of the computation leading up to that value), aka "qualifs", in a quite stateful manner, which is hard to extend to arbitrary CFGs without a dataflow pass.

However, the nature of the promotion we do is that it's effectively an SSA-like "tree" (or DAG, really), of assigned-once locals - which is how we can take them from the original MIR in the first place.
This structure means that the subset of the MIR responsible for computing any given part of a const-promoted value is readily analyzable by walking that tree/DAG.

This PR implements such an analysis in `promote_consts`, reusing the `HasMutInterior` / `NeedsDrop` computation from `qualify_consts`, but reimplementing the equivalent of `IsNotPromotable` / `IsNotImplicitlyPromotable`.

Eventually we should be able to remove `IsNotPromotable` / `IsNotImplicitlyPromotable` from `qualify_consts`, which will simplify @ecstatic-morse's dataflow-based const-checking efforts.

But currently this is mainly for a crater check-only run - it will compare the results from the old promotion collection and the new promotion validation and ICE if they don't match.

r? @oli-obk
@bors
Copy link
Contributor

bors commented Aug 22, 2019

☀️ Try build successful - checks-azure
Build commit: 28d741e

@eddyb
Copy link
Member Author

eddyb commented Aug 23, 2019

@craterbot run mode=check-only

@craterbot
Copy link
Collaborator

👌 Experiment pr-63812 created and queued.
🤖 Automatically detected try build 28d741e
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2019
@eddyb
Copy link
Member Author

eddyb commented Aug 23, 2019

@rust-timer build 28d741e

@rust-timer
Copy link
Collaborator

Success: Queued 28d741e with parent 201e52e, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 28d741e, comparison URL.

@eddyb
Copy link
Member Author

eddyb commented Aug 23, 2019

Doesn't look like this is significant-enough perf regression, so we could probably even land it in compare mode.

@pietroalbini
Copy link
Member

@craterbot crates=full

@craterbot
Copy link
Collaborator

📝 Configuration of the pr-63812 experiment changed.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

bors added a commit that referenced this pull request Sep 8, 2019
…oli-obk

Refactor the `MirPass for QualifyAndPromoteConstants`

This is an accumulation of drive-by commits while working on `Vec::new` as a stable `const fn`.
The PR is probably easiest read commit-by-commit.

r? @oli-obk

cc @eddyb @ecstatic-morse -- your two PRs #63812 and #63860 respectively will conflict with this a tiny bit but it should be trivial to reintegrate your changes atop of this.
@eddyb
Copy link
Member Author

eddyb commented Sep 12, 2019

@craterbot abort
(in favor of #64398)

@craterbot
Copy link
Collaborator

🗑️ Experiment pr-63812 deleted!

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Sep 12, 2019
@bors
Copy link
Contributor

bors commented Sep 13, 2019

☔ The latest upstream changes (presumably #63420) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-highfive
Copy link
Collaborator

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-24T13:46:15.1577143Z do so (now or later) by using -b with the checkout command again. Example:
2019-10-24T13:46:15.1577522Z 
2019-10-24T13:46:15.1578067Z   git checkout -b <new-branch-name>
2019-10-24T13:46:15.1578232Z 
2019-10-24T13:46:15.1578954Z HEAD is now at eda87bac0 Auto merge of #63812 - eddyb:promo-sanity, r=oli-obk
2019-10-24T13:46:15.1978792Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-10-24T13:46:15.2091140Z ==============================================================================
2019-10-24T13:46:15.2091242Z Task         : Bash
2019-10-24T13:46:15.2091307Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-24T13:50:46.7917962Z resolving dependencies...
2019-10-24T13:50:46.7918161Z skipping target: mingw-w64-i686-gcc
2019-10-24T13:50:46.8111131Z looking for conflicting packages...
2019-10-24T13:50:46.8200812Z 
2019-10-24T13:50:46.8204631Z Packages (64) mingw-w64-i686-brotli-1.0.7-1  mingw-w64-i686-bzip2-1.0.8-1  mingw-w64-i686-c-ares-1.15.0-1  mingw-w64-i686-ca-certificates-20180409-3  mingw-w64-i686-curl-7.66.0-1  mingw-w64-i686-expat-2.2.9-1  mingw-w64-i686-gettext-0.19.8.1-8  mingw-w64-i686-gmp-6.1.2-1  mingw-w64-i686-isl-0.21-1  mingw-w64-i686-jansson-2.12-1  mingw-w64-i686-jemalloc-5.2.1-1  mingw-w64-i686-jsoncpp-1.9.1-1  mingw-w64-i686-libarchive-3.4.0-2  mingw-w64-i686-libffi-3.2.1-4  mingw-w64-i686-libiconv-1.16-1  mingw-w64-i686-libidn2-2.2.0-1  mingw-w64-i686-libmetalink-0.1.3-3  mingw-w64-i686-libpsl-0.21.0-1  mingw-w64-i686-libssh2-1.9.0-1  mingw-w64-i686-libsystre-1.0.1-4  mingw-w64-i686-libtasn1-4.14-1  mingw-w64-i686-libtre-git-r128.6fb7206-2  mingw-w64-i686-libunistring-0.9.10-1  mingw-w64-i686-libuv-1.33.0-1  mingw-w64-i686-lz4-1.9.2-1  mingw-w64-i686-lzo2-2.10-1  mingw-w64-i686-mpc-1.1.0-1  mingw-w64-i686-mpdecimal-2.4.2-1  mingw-w64-i686-mpfr-4.0.2-2  mingw-w64-i686-ncurses-6.1.20190630-1  mingw-w64-i686-nettle-3.5.1-1  mingw-w64-i686-nghttp2-1.39.2-1  mingw-w64-i686-openssl-1.1.1.d-1  mingw-w64-i686-p11-kit-0.23.16.1-1  mingw-w64-i686-python3-3.8.0-1  mingw-w64-i686-readline-8.0.001-2  mingw-w64-i686-rhash-1.3.8-1  mingw-w64-i686-sqlite3-3.30.1-1  mingw-w64-i686-tcl-8.6.9-2  mingw-w64-i686-termcap-1.3.1-5  mingw-w64-i686-tk-8.6.9.1-1  mingw-w64-i686-windows-default-manifest-6.4-3  mingw-w64-i686-xz-5.2.4-1  mingw-w64-i686-zlib-1.2.11-7  mingw-w64-i686-zstd-1.4.3-1  mingw-w64-i686-binutils-2.33.1-1  mingw-w64-i686-cmake-3.15.4-1  mingw-w64-i686-crt-git-7.0.0.5553.e922460c-1  mingw-w64-i686-gcc-9.2.0-2  mingw-w64-i686-gcc-ada-9.2.0-2  mingw-w64-i686-gcc-fortran-9.2.0-2  mingw-w64-i686-gcc-libgfortran-9.2.0-2  mingw-w64-i686-gcc-libs-9.2.0-2  mingw-w64-i686-gcc-objc-9.2.0-2  mingw-w64-i686-gdb-8.3.1-2  mingw-w64-i686-headers-git-7.0.0.5553.e922460c-1  mingw-w64-i686-libmangle-git-7.0.0.5230.69c8fad6-1  mingw-w64-i686-libwinpthread-git-7.0.0.5544.15da3ce2-1  mingw-w64-i686-make-4.2.1-4  mingw-w64-i686-pkg-config-0.29.2-1  mingw-w64-i686-python2-2.7.17-1  mingw-w64-i686-tools-git-7.0.0.5479.8db8dd5a-1  mingw-w64-i686-winpthreads-git-7.0.0.5544.15da3ce2-1  mingw-w64-i686-winstorecompat-git-7.0.0.5479.8db8dd5a-1
2019-10-24T13:50:46.8206220Z Total Download Size:    168.33 MiB
2019-10-24T13:50:46.8206361Z Total Installed Size:  1047.78 MiB
2019-10-24T13:50:46.8206493Z 
2019-10-24T13:50:46.8206661Z :: Proceed with installation? [Y/n] 
---
2019-10-24T13:52:19.8738688Z                                  Dload  Upload   Total   Spent    Left  Speed
2019-10-24T13:52:19.8745440Z 
2019-10-24T13:52:20.2956641Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2019-10-24T13:52:20.2966864Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2019-10-24T13:52:20.2967157Z curl: (60) SSL certificate problem: unable to get local issuer certificate
2019-10-24T13:52:20.2967324Z More details here: https://curl.haxx.se/docs/sslcerts.html
2019-10-24T13:52:20.2967466Z 
2019-10-24T13:52:20.2967606Z curl failed to verify the legitimacy of the server and therefore could not
2019-10-24T13:52:20.2967956Z establish a secure connection to it. To learn more about this situation and
2019-10-24T13:52:20.2968149Z how to fix it, please visit the web page mentioned above.
2019-10-24T13:52:20.2998084Z 
2019-10-24T13:52:20.3117133Z ##[error]Bash exited with code '60'.
2019-10-24T13:52:20.3316527Z ##[section]Starting: Upload CPU usage statistics
2019-10-24T13:52:20.3435001Z ==============================================================================
2019-10-24T13:52:20.3435092Z Task         : Bash
2019-10-24T13:52:20.3435160Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-10-24T13:52:20.6344277Z ========================== Starting Command Output ===========================
2019-10-24T13:52:20.6348348Z [command]D:\a\msys2\usr\bin\bash.exe --noprofile --norc /d/a/_temp/fa24fe0b-3e12-4e8b-a8e0-57263e84ecbb.sh
2019-10-24T13:52:20.6698703Z /d/a/_temp/fa24fe0b-3e12-4e8b-a8e0-57263e84ecbb.sh: line 1: aws: command not found
2019-10-24T13:52:20.6707293Z 
2019-10-24T13:52:20.6740333Z ##[error]Bash exited with code '127'.
2019-10-24T13:52:20.6813228Z ##[section]Starting: Checkout
2019-10-24T13:52:20.6919428Z ==============================================================================
2019-10-24T13:52:20.6919712Z Task         : Get sources
2019-10-24T13:52:20.6919825Z 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)

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 24, 2019
@RalfJung
Copy link
Member

2019-10-24T13:52:20.2967157Z curl: (60) SSL certificate problem: unable to get local issuer certificate
2019-10-24T13:52:20.2967324Z More details here: https://curl.haxx.se/docs/sslcerts.html
2019-10-24T13:52:20.2967466Z 
2019-10-24T13:52:20.2967606Z curl failed to verify the legitimacy of the server and therefore could not
2019-10-24T13:52:20.2967956Z establish a secure connection to it. To learn more about this situation and
2019-10-24T13:52:20.2968149Z how to fix it, please visit the web page mentioned above.

Same as in another PR...

@bors retry

@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 24, 2019
@bors

This comment has been minimized.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 25, 2019
@eddyb
Copy link
Member Author

eddyb commented Oct 25, 2019

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Oct 25, 2019

📌 Commit f2c8628 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2019
@bors
Copy link
Contributor

bors commented Oct 26, 2019

⌛ Testing commit f2c8628 with merge 084edc4...

bors added a commit that referenced this pull request Oct 26, 2019
rustc_mir: double-check const-promotion candidates for sanity.

Previously, const promotion involved tracking information about the value in a MIR local (or any part of the computation leading up to that value), aka "qualifs", in a quite stateful manner, which is hard to extend to arbitrary CFGs without a dataflow pass.

However, the nature of the promotion we do is that it's effectively an SSA-like "tree" (or DAG, really), of assigned-once locals - which is how we can take them from the original MIR in the first place.
This structure means that the subset of the MIR responsible for computing any given part of a const-promoted value is readily analyzable by walking that tree/DAG.

This PR implements such an analysis in `promote_consts`, reusing the `HasMutInterior` / `NeedsDrop` computation from `qualify_consts`, but reimplementing the equivalent of `IsNotPromotable` / `IsNotImplicitlyPromotable`.

Eventually we should be able to remove `IsNotPromotable` / `IsNotImplicitlyPromotable` from `qualify_consts`, which will simplify @ecstatic-morse's dataflow-based const-checking efforts.

But currently this is mainly for a crater check-only run - it will compare the results from the old promotion collection and the new promotion validation and ICE if they don't match.

r? @oli-obk
@bors
Copy link
Contributor

bors commented Oct 26, 2019

☀️ Test successful - checks-azure
Approved by: oli-obk
Pushing 084edc4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 26, 2019
@bors bors merged commit f2c8628 into rust-lang:master Oct 26, 2019
ecstatic-morse added a commit to ecstatic-morse/rust that referenced this pull request Oct 26, 2019
This is a relic from earlier attempts at dataflow-based const validation
that attempted to do promotion at the same time. rust-lang#63812 takes a
different approach: `IsNotPromotable` is no longer a `Qualif` and is
computed lazily instead of eagerly. As a result, there's no need for an
eager `TempPromotionResolver`, and we can use the only implementer of
`QualifResolver` directly instead of through a trait.
@eddyb eddyb deleted the promo-sanity branch October 26, 2019 07:18
Centril added a commit to Centril/rust that referenced this pull request Oct 27, 2019
…r=eddyb

Clean up `check_consts` now that new promotion pass is implemented

`check_consts::resolver` contained a layer of abstraction (`QualifResolver`) to allow the existing, eager style of qualif propagation to work with either a dataflow results cursor or by applying the transfer function directly (if dataflow was not needed e.g. for promotion). However, rust-lang#63812 uses a different, lazy paradigm for checking promotability, which makes this unnecessary. This PR cleans up `check_consts::validation` to use `FlowSensitiveResolver` directly, instead of through the now obselete `QualifResolver` API.

Also, this contains a few commits (the first four) that address some FIXMEs in rust-lang#63812 regarding code duplication. They could be split out, but I think they will be relatively noncontroversial? Notably, `validation::Mode` is renamed to `ConstKind` and used in `promote_consts` to denote what kind of item we are in.

This is best reviewed commit-by-commit and is low priority.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.