Skip to content

[Experiment] Split exhaustiveness logic into its own crate #89570

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

Closed

Conversation

Nadrieril
Copy link
Member

rust-analyzer currently maintains a patched copy of the exhaustiveness algorithm for their own analyses. That's too bad, so I factored out everything rustc-specific from the relevant files. If perf isn't killed, I'll move it into its own crate.

Until the type library gets librarified, there'll still be some nontrivial code that rust-analyzer will have to duplicate. But the core functionality will be shared and we should be able to implement cool features for the rust-analyzer side.

@Nadrieril Nadrieril added A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Oct 5, 2021
@rust-highfive
Copy link
Contributor

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 5, 2021
@Nadrieril
Copy link
Member Author

r? @ghost

@Nadrieril Nadrieril force-pushed the split-exhaustiveness-into-crate branch from edde94a to ec2324b Compare October 6, 2021 01:07
@Nadrieril
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
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 Oct 6, 2021
@bors
Copy link
Collaborator

bors commented Oct 6, 2021

⌛ Trying commit ec2324b with merge d333b4430fb1577f7c0f0e650ac2f49a6fd04048...

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 11600/12253
.................................................................................................... 11700/12253
.................................................................................................... 11800/12253
.................................................................................................... 11900/12253
.............................................................................................F...F.. 12000/12253
.........................................i.i........................................................ 12200/12253
.....................................................
failures:


---- [ui] ui/unsafe/union_destructure.rs#mir stdout ----
diff of stderr:

+ warning: unreachable pattern
+   --> $DIR/union_destructure.rs:22:33
+    |
+ LL |     let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u);
+    |
+    = note: `#[warn(unreachable_patterns)]` on by default
+ 
+ warning: unreachable pattern
+ warning: unreachable pattern
+   --> $DIR/union_destructure.rs:25:28
+    |
+ LL |         let (Foo { bar } | Foo { bar }) = u;
+ 
+ 
1 warning: unnecessary `unsafe` block
3    |

12 LL |     unsafe {
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
13    |     ^^^^^^ unnecessary `unsafe` block
- warning: 2 warnings emitted
+ warning: 4 warnings emitted
16 
17 
17 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.mir/union_destructure.mir.stderr
To only update this specific test, also pass `--test-args unsafe/union_destructure.rs`


error in revision `mir`: 1 errors occurred comparing output.
status: exit status: 0
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/unsafe/union_destructure.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "mir" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.mir/a" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.mir/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
warning: unreachable pattern
  --> /checkout/src/test/ui/unsafe/union_destructure.rs:22:33
   |
LL |     let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u);
   |
   = note: `#[warn(unreachable_patterns)]` on by default

warning: unreachable pattern
warning: unreachable pattern
  --> /checkout/src/test/ui/unsafe/union_destructure.rs:25:28
   |
LL |         let (Foo { bar } | Foo { bar }) = u;


warning: unnecessary `unsafe` block
   |
   |
LL |     unsafe { //[mir]~ WARNING unnecessary `unsafe` block
   |     ^^^^^^ unnecessary `unsafe` block
   = note: `#[warn(unused_unsafe)]` on by default


warning: unnecessary `unsafe` block
   |
   |
LL |     unsafe { //[mir]~ WARNING unnecessary `unsafe` block
   |     ^^^^^^ unnecessary `unsafe` block
warning: 4 warnings emitted


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


---- [ui] ui/unsafe/union_destructure.rs#thir stdout ----
normalized stderr:
warning: unreachable pattern
  --> $DIR/union_destructure.rs:22:33
   |
LL |     let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u);
   |
   = note: `#[warn(unreachable_patterns)]` on by default

warning: unreachable pattern
warning: unreachable pattern
  --> $DIR/union_destructure.rs:25:28
   |
LL |         let (Foo { bar } | Foo { bar }) = u;

warning: 2 warnings emitted





The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.thir/union_destructure.thir.stderr
To only update this specific test, also pass `--test-args unsafe/union_destructure.rs`


error in revision `thir`: 1 errors occurred comparing output.
status: exit status: 0
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/unsafe/union_destructure.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--cfg" "thir" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.thir/a" "-Crpath" "-O" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "thir-unsafeck" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unsafe/union_destructure.thir/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
warning: unreachable pattern
  --> /checkout/src/test/ui/unsafe/union_destructure.rs:22:33
   |
LL |     let (Some(Foo { bar: _ }) | Some(Foo { bar: _ }) | None) = Some(u);
   |
   = note: `#[warn(unreachable_patterns)]` on by default

warning: unreachable pattern
warning: unreachable pattern
  --> /checkout/src/test/ui/unsafe/union_destructure.rs:25:28
   |
LL |         let (Foo { bar } | Foo { bar }) = u;

warning: 2 warnings emitted


---
test result: FAILED. 12136 passed; 2 failed; 115 ignored; 0 measured; 0 filtered out; finished in 131.38s



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" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-10/bin/FileCheck" "--nodejs" "/usr/bin/node" "--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/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "10.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils 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 frontendopenmp fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo 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 orcerror orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils 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 x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--channel" "nightly" "--color" "always"


Build completed unsuccessfully in 0:13:42

@bors
Copy link
Collaborator

bors commented Oct 6, 2021

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

@rust-timer
Copy link
Collaborator

Queued d333b4430fb1577f7c0f0e650ac2f49a6fd04048 with parent 25ec827, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d333b4430fb1577f7c0f0e650ac2f49a6fd04048): comparison url.

Summary: This change led to moderate relevant regressions 😿 in compiler performance.

  • Moderate regression in instruction counts (up to 1.0% on incr-full builds of cranelift-codegen)

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 led 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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 6, 2021
@nikomatsakis
Copy link
Contributor

This is exciting!

use Constructor::*;
match pat.ctor() {
Wildcard => true,
Single => pat.iter_fields().all(|pat| pat_is_catchall(pat)),
Single | Tuple(_) | Ref(_) | BoxPat(_) => pat.iter_fields().all(|pat| pat_is_catchall(pat)),
Copy link
Member

Choose a reason for hiding this comment

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

Is this a bugfix?

This seems like it might be a source of performance impact.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is because I split the Single case into more specific subcases so that I could abstract it all in a trait. I suspected this could be the source of perf degradation but my local measurements don't show much impact from this.
The problem of course is that my local measurements don't match what rust-timer reports here so you could be right. When I get back to this I'll measure intermediate commits with rust-timer.

@Nadrieril
Copy link
Member Author

(I still intend get this done. Will get back to it whenever my work deadlines are done and motivation strikes)

@camelid camelid 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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2021
@Dylan-DPC
Copy link
Member

Closing this as it is inactive

@Dylan-DPC Dylan-DPC closed this Sep 22, 2022
@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 22, 2022
@Nadrieril Nadrieril deleted the split-exhaustiveness-into-crate branch December 11, 2023 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns perf-regression Performance regression. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.
Projects
None yet
Development

Successfully merging this pull request may close these issues.