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

Run RemoveZsts pass at mir-opt-level=1 #83417

Merged
merged 1 commit into from
Aug 14, 2021

Conversation

erikdesjardins
Copy link
Contributor

@erikdesjardins erikdesjardins commented Mar 23, 2021

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 23, 2021
@camelid camelid added the A-mir-opt Area: MIR optimizations label Mar 23, 2021
@@ -8,9 +8,6 @@ pub struct RemoveZsts;

impl<'tcx> MirPass<'tcx> for RemoveZsts {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.mir_opt_level() < 3 {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be kept and use < 1 instead? I noticed that some const errors have changed, so I'm wondering if it's being triggered on mir-opt-level=0.

Copy link
Contributor Author

@erikdesjardins erikdesjardins Mar 23, 2021

Choose a reason for hiding this comment

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

It doesn't run at mir-opt-level=0.

See

&remove_zsts::RemoveZsts,
and
if mir_opt_level > 0 { optimizations } else { no_optimizations },

The error changes because it removes an assignment, so we hit a different error path due to a different use of the constant. The specific error messages changed in this PR are fine (see #83177 (comment)).

But this area seems undertested, I think I've found some cases where it's wrong. I'll open another PR to add tests, that we should merge before this one.

Copy link
Member

Choose a reason for hiding this comment

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

The error changes because it removes an assignment, so we hit a different error path due to a different use of the constant. The specific error messages changed in this PR are fine (see #83177 (comment)).

I see, does the mir-opt-level apply to const-eval as well?

Copy link
Contributor Author

@erikdesjardins erikdesjardins Mar 23, 2021

Choose a reason for hiding this comment

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

I believe so, because I believe the same MIR is used for const eval and codegen.

But I don't think that's relevant here--the error that changes is in main, not in const eval'd code.

There is a separate const eval error due to the panic (reported as a future compat warning):

const VOID: ! = panic!();
//~^ WARN any use of this value will cause an error
//~| WARN this was previously accepted by the compiler but is being phased out

Copy link
Contributor

Choose a reason for hiding this comment

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

Since #78407, CTFE uses unoptimized MIR to avoid situations where an undefined behaviour is hidden because of MIR optimizations.

Copy link
Member

Choose a reason for hiding this comment

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

But I don't think that's relevant here--the error that changes is in main, not in const eval'd code.

Ah, I didn't notice that. Thanks for clearing up my confusion :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for the change in diagnostics is that const propagation now doesn't see the constant anymore, but codegen will still evaluate it because it was used in the initial MIR body (see the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/required_consts/index.html field)

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to resolve that these tests get changed would be to eagerly evaluate all required_consts in const propagation

To stop depending on optimizations reporting these entirely, we could also evaluate the constant in

if let ConstKind::Unevaluated(_) = ct.val {
and only put it into required_consts if the evaluation did not succeed

@erikdesjardins
Copy link
Contributor Author

erikdesjardins commented Mar 23, 2021

Blocked on #83423

@rustbot labels: -S-waiting-on-review +S-blocked

Edit: are you not allowed to have any other text when mentioning rustbot? ah label not labels 😠

@erikdesjardins

This comment has been minimized.

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2021
@camelid
Copy link
Member

camelid commented Mar 23, 2021

Edit: are you not allowed to have any other text when mentioning rustbot? ah label not labels 😠

Note that in the future you can just edit your message to replace labels with label and triagebot should pick it up.

@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 30, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Mar 30, 2021

Blocked on #83423

I don't understand the reason for this PR. If we are breaking those tests, they are already in our test suite, so what is that PR adding?

I think we should avoid changing ui tests in this PR by doing what I mentioned in #83417 (comment) (that you can do in a separate PR though if you want :) )

@erikdesjardins
Copy link
Contributor Author

The existing tests aren't the same as #83423. For the existing tests, RemoveZsts just changes the error message. But for the tests in #83423, RemoveZsts removes the error entirely, allowing erroneous code to compile.

(I thought that was strange so I did some more testing...this seems to only happen with --emit=mir, I guess because it stops before codegen. Maybe that's fine? Is it okay if errors disappear when using --emit=mir?)

@oli-obk
Copy link
Contributor

oli-obk commented Apr 1, 2021

Right, these are only evaluated once we go into codegen, and for generic constants, this will always be true, we need to monomorphize in order to evaluate them. For the already monomorphic constants we can optimize a little by doing the second part in #83417 (comment) (meaning: only put constants into required_consts if their evaluation failed due to TooGeneric or Linted).

If we can keep errors in check builds instead of full builds, we should do so, even if it is imperfect.

@bors
Copy link
Contributor

bors commented May 31, 2021

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

Effectively reverts commit 6960bc9.
@erikdesjardins
Copy link
Contributor Author

erikdesjardins commented Aug 7, 2021

Rebased.

I made RequiredConstsVisitor attempt to evaluate consts (not pushed to this branch), but it made some errors disappear. You can see those changes here: erikdesjardins@c10bacf

@rustbot label: -S-waiting-on-author +S-waiting-on-review

@erikdesjardins erikdesjardins marked this pull request as ready for review August 7, 2021 17:43
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 7, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Aug 9, 2021

Let's merge as is then. Pointing to the use site of a broken constant isn't really necessary, and for associated constants of generics we still behave as previously, so that is good.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 9, 2021

📌 Commit 585e4ae 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 Aug 9, 2021
@bors
Copy link
Contributor

bors commented Aug 9, 2021

⌛ Testing commit 585e4ae with merge 5b243cdd288c0c43b89060c71cfc549ee02c04fb...

@bors
Copy link
Contributor

bors commented Aug 9, 2021

💔 Test failed - checks-actions

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Prepare workflow directory
Prepare all required actions
Getting action download info
Download action repository 'actions/checkout@v2'
##[warning]Failed to download action 'https://api.github.com/repos/actions/checkout/zipball/5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f'. Error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
##[warning]Back off 10.339 seconds before retry.
##[warning]Failed to download action 'https://api.github.com/repos/actions/checkout/zipball/5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f'. Error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
##[warning]Back off 17.939 seconds before retry.
##[error]A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 9, 2021

@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 Aug 9, 2021
@erikdesjardins
Copy link
Contributor Author

Maybe this should be rollup=never? (because perf implications)

@bors
Copy link
Contributor

bors commented Aug 12, 2021

⌛ Testing commit 585e4ae with merge 92d26e1859495c185896762086e495f4061de4fd...

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] ui/where-clauses/where-clause-early-bound-lifetimes.rs stdout ----

error: test run failed!
status: exit status: 101
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/remote-test-client" "run" "0" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/where-clauses/where-clause-early-bound-lifetimes/a"
------------------------------------------
uploaded "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/where-clauses/where-clause-early-bound-lifetimes/a", waiting for result

------------------------------------------
------------------------------------------
stderr:
------------------------------------------
thread 'main' panicked at 'client.read_exact(&mut header) failed with Connection reset by peer (os error 104)', src/tools/remote-test-client/src/main.rs:310:9

------------------------------------------


---

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=arm-unknown-linux-gnueabihf


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/arm-unknown-linux-gnueabihf/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-arm-unknown-linux-gnueabihf" "--suite" "ui" "--mode" "ui" "--target" "arm-unknown-linux-gnueabihf" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--linker" "arm-linux-gnueabihf-gcc" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/arm-unknown-linux-gnueabihf/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--llvm-version" "12.0.1-rust-1.56.0-nightly" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hellonew hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xray" "--cc" "" "--cxx" "" "--cflags" "" "--remote-test-client" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/remote-test-client" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--channel" "nightly" "--color" "always"


Build completed unsuccessfully in 0:29:44

@bors
Copy link
Contributor

bors commented Aug 12, 2021

💔 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 Aug 12, 2021
@erikdesjardins
Copy link
Contributor Author

^ looks like more network issues:

thread 'main' panicked at 'client.read_exact(&mut header) failed with Connection reset by peer (os error 104)', src/tools/remote-test-client/src/main.rs:310:9

@Aaron1011
Copy link
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 Aug 14, 2021
@bors
Copy link
Contributor

bors commented Aug 14, 2021

⌛ Testing commit 585e4ae with merge 8007b50...

@bors
Copy link
Contributor

bors commented Aug 14, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 8007b50 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 14, 2021
@bors bors merged commit 8007b50 into rust-lang:master Aug 14, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 14, 2021
@erikdesjardins erikdesjardins deleted the enableremovezsts branch August 14, 2021 23:01
erikdesjardins added a commit to erikdesjardins/rust that referenced this pull request Aug 16, 2021
…ts, r=oli-obk"

This reverts commit 8007b50, reversing
changes made to e55c13e.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 17, 2021
Revert "Auto merge of rust-lang#83417 - erikdesjardins:enableremovezsts, r=oli-obk"

This reverts commit 8007b50, reversing changes made to e55c13e.

Fixes rust-lang#88043

r? `@oli-obk`
erikdesjardins added a commit to erikdesjardins/rust that referenced this pull request Aug 20, 2021
…removezsts, r=oli-obk""

This reverts commit 8e11199.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2021
Reenable RemoveZsts

Now that the underlying issue has been fixed by rust-lang#88124, we can reland rust-lang#83417.

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations 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.

9 participants