Skip to content

Always evaluate constant operands in const-prop#98426

Closed
b-naber wants to merge 5 commits into
rust-lang:masterfrom
b-naber:evaluate-const-operand-const-prop
Closed

Always evaluate constant operands in const-prop#98426
b-naber wants to merge 5 commits into
rust-lang:masterfrom
b-naber:evaluate-const-operand-const-prop

Conversation

@b-naber

@b-naber b-naber commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 23, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2022

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit, then r=me

Comment thread src/test/ui/consts/const-eval/issue-50814.rs Outdated
@lcnr lcnr added the A-const-generics Area: const generics (parameters and arguments) label Jun 24, 2022
@lcnr

lcnr commented Jun 24, 2022

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

this might actually impact perf, if unlikely

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 24, 2022
@bors

bors commented Jun 24, 2022

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 18e0d916581dc54ddd13e1643d25c81408ad1987 with merge 67ad21cde5ced3782151744e37f78e23af0e8b24...

@bors bors mentioned this pull request Jun 24, 2022
@bors

bors commented Jun 24, 2022

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 67ad21cde5ced3782151744e37f78e23af0e8b24 (67ad21cde5ced3782151744e37f78e23af0e8b24)

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued 67ad21cde5ced3782151744e37f78e23af0e8b24 with parent d017d59, future comparison URL.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (67ad21cde5ced3782151744e37f78e23af0e8b24): comparison url.

Instruction count

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
0.3% 0.4% 6
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-0.4% -0.4% 2
All 😿🎉 (primary) 0.3% 0.4% 6

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
1.3% 1.3% 1
Regressions 😿
(secondary)
9.6% 9.6% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 1.3% 1.3% 1

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.3% -3.3% 1
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 24, 2022
@lcnr

lcnr commented Jun 24, 2022

Copy link
Copy Markdown
Contributor

the way that mostly incr-unchanged is impacted and all perf impacts are really small I think this isn't too relevant.

I consider this a bug fix.

@bors r+

@bors

bors commented Jun 24, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 18e0d916581dc54ddd13e1643d25c81408ad1987 has been approved by lcnr

@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 Jun 24, 2022
@RalfJung

Copy link
Copy Markdown
Member

Const-prop does not run in the body of a const/static, does it?
Those items contain promoteds that might fail to evaluate, so it is crucial that we only evaluate those nested constants that are actually needed to compute the const/static initializer. I tried to fix this but too much code out there has such potentially failing promoteds. :( See #80619.

I am fairly sure I added a test for this so it's probably fine, just double-checking. :)

@bors

bors commented Jun 28, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 18e0d916581dc54ddd13e1643d25c81408ad1987 with merge efa8ecf1ad8601a2b9aa8549d40052761450cc9d...

@bors

bors commented Jun 28, 2022

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@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 Jun 28, 2022
@Dylan-DPC

Copy link
Copy Markdown
Member

@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 Jun 28, 2022
@b-naber

b-naber commented Jun 28, 2022

Copy link
Copy Markdown
Contributor Author

@Dylan-DPC this doesn't look spurious. Can you r- this, please?

@RalfJung

Copy link
Copy Markdown
Member

@bors r-

@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 Jun 28, 2022
@rust-log-analyzer

This comment has been minimized.

@JohnCSimon

Copy link
Copy Markdown
Member

Triage:
@b-naber can you post the status of this PR?

@b-naber

b-naber commented Jul 28, 2022

Copy link
Copy Markdown
Contributor Author

I don't know why these lints are output on that machine (which seems to be a 64-bit machine):

Future incompatibility report: Future breakage diagnostic:
error: any use of this value will cause an error
  --> /checkout/src/test/ui/consts/const-eval/issue-50814.rs:15:21
   |
LL |     const MAX: u8 = A::MAX + B::MAX;
   |     ----------------^^^^^^^^^^^^^^^-
   |                     |
   |                     attempt to compute `u8::MAX + u8::MAX`, which would overflow
   |
   = note: `#[deny(const_err)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

Future breakage diagnostic:
error: any use of this value will cause an error
  --> /checkout/src/test/ui/consts/const-eval/issue-50814.rs:15:21
   |
LL |     const MAX: u8 = A::MAX + B::MAX;
   |     ----------------^^^^^^^^^^^^^^^-
   |                     |
   |                     attempt to compute `u8::MAX + u8::MAX`, which would overflow
   |
   = note: `#[deny(const_err)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

This looks like a miri-related lint, @RalfJung do you have any idea why we get those lints on that machine, but not on the ones in the PR CI?

@RalfJung

Copy link
Copy Markdown
Member

Maybe different flags? Debug vs release mode can make a difference.
Also the lints are emitted by const-prop-lint, which uses Miri but then also does a lot of other stuff, and I'm not much involved with that. Maybe @oli-obk knows more.

@RalfJung

Copy link
Copy Markdown
Member

Also make sure you rebase, there have been some changes wrt binop overflow checking a few weeks ago.

Comment thread compiler/rustc_mir_transform/src/const_prop.rs Outdated
@b-naber b-naber force-pushed the evaluate-const-operand-const-prop branch from 18e0d91 to 5726ed7 Compare August 4, 2022 09:14
@rustbot rustbot added the T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. label Aug 4, 2022
@rustbot

rustbot commented Aug 4, 2022

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [mir-opt] src/test/mir-opt/remove-never-const.rs stdout ----

error: compilation failed!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/mir-opt/remove-never-const.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "-O" "-Copt-level=1" "-Zdump-mir=all" "-Zvalidate-mir" "-Zdump-mir-exclude-pass-number" "-Zmir-pretty-relative-line-numbers=yes" "-Zmir-opt-level=4" "-Zdump-mir-dir=/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/remove-never-const" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/remove-never-const" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--emit" "mir,link" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt/remove-never-const/auxiliary"
stdout: none
--- stderr -------------------------------
  --> /checkout/src/test/mir-opt/remove-never-const.rs:11:8
   |
   |
11 | struct PrintName<T>(T);
   |
   = note: `#[warn(dead_code)]` on by default

warning: function `no_codegen` is never used
warning: function `no_codegen` is never used
  --> /checkout/src/test/mir-opt/remove-never-const.rs:18:4
   |
18 | fn no_codegen<T>() {

warning: associated constant `VOID` is never used
  --> /checkout/src/test/mir-opt/remove-never-const.rs:14:11
   |

@b-naber

b-naber commented Aug 4, 2022

Copy link
Copy Markdown
Contributor Author

The error we get in the failing mir-opt test looks wrong.

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the failing mir opt test shows that we fail to add some constants to https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#structfield.required_consts though I don't know why, how or where.

Comment thread .github/workflows/ci.yml
Comment on lines +49 to +51
- name: dist-i586-gnu-i586-i686-musl
os: ubuntu-20.04-xl
env: {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this accidentally get added during a rebase?

Comment on lines -289 to +292


- name: dist-i586-gnu-i586-i686-musl
<<: *job-linux-xl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@RalfJung

Copy link
Copy Markdown
Member

I guess the failing mir opt test shows that we fail to add some constants to https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#structfield.required_consts though I don't know why, how or where.

Promoteds don't get added there. That is by design since their evaluation cannot fail (in fn), or must only be attempted if they are in live code (in const/static).

Not sure if that's the issue here, though.

@bors

bors commented Aug 29, 2022

Copy link
Copy Markdown
Collaborator

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

@b-naber

b-naber commented Aug 30, 2022

Copy link
Copy Markdown
Contributor Author

I'm going to close this, not familiar enough with const prop to tell what's really going on here.

@b-naber b-naber closed this Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-generics Area: const generics (parameters and arguments) perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.