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

Clarify constructor splitting in exhaustiveness checking #80242

Merged
merged 13 commits into from
Dec 23, 2020

Conversation

Nadrieril
Copy link
Member

I reworked the explanation of the algorithm completely to make it properly account for the various extensions we've added. This includes constructor splitting, which was previously not clearly included in the algorithm. This makes wildcards less magical; I added some detailed examples; and this distinguishes clearly between constructors that only make sense in patterns (like ranges) and those that make sense for values (like Some). This reformulation had been floating around in my mind for a while, and I'm quite happy with how it turned out. Let me know how you feel about it.
I also factored out all three cases of splitting (wildcards, ranges and slices) into dedicated structs to encapsulate the complicated bits.
I measured no perf impact but I don't trust my local measurements for refactors since #79284.

r? @varkor
@rustbot modify labels: +A-exhaustiveness-checking

@rustbot rustbot added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Dec 20, 2020
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2020
@lqd
Copy link
Member

lqd commented Dec 20, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Dec 20, 2020

⌛ Trying commit ddc29bf59218179b7b829d9f7a99121d8e9932fb with merge 92e2d3444aa509193c1d1e464229151050a23df7...

@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
 Documenting rustc_typeck v0.0.0 (/checkout/compiler/rustc_typeck)
 Documenting rustc_mir v0.0.0 (/checkout/compiler/rustc_mir)
    Checking rustc_plugin_impl v0.0.0 (/checkout/compiler/rustc_plugin_impl)
 Documenting rustc_plugin_impl v0.0.0 (/checkout/compiler/rustc_plugin_impl)
error: unresolved link to `super::check_match::MatchVisitor::lower_pattern`
     |
     |
1014 |     /// [`super::check_match::MatchVisitor::lower_pattern`].
     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `MatchVisitor` in module `check_match`
     |
     = note: `-D broken-intra-doc-links` implied by `-D warnings`

error: unresolved link to `super::check_match::MatchVisitor::lower_pattern`
     |
     |
1033 | /// [`super::check_match::MatchVisitor::lower_pattern`].
     |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `MatchVisitor` in module `check_match`
error: aborting due to 2 previous errors

error: could not document `rustc_mir_build`


Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustdoc --edition=2018 --crate-type lib --crate-name rustc_mir_build compiler/rustc_mir_build/src/lib.rs --target x86_64-unknown-linux-gnu -o /checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/release/deps --extern rustc_apfloat=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_apfloat-e9bfb5f44b74579f.rmeta --extern rustc_arena=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_arena-e2f417d3f6c44169.rmeta --extern rustc_ast=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_ast-af8907c51d0619b2.rmeta --extern rustc_attr=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_attr-2f11728d63006441.rmeta --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-900d11de835d34e6.rmeta --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-1aabeb89ce38e926.rmeta --extern rustc_hir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_hir-782d95bf352570dd.rmeta --extern rustc_index=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_index-984047fbd60b0386.rmeta --extern rustc_infer=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_infer-01d356349ffa8afd.rmeta --extern rustc_middle=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_middle-fc5655365d5ee0f8.rmeta --extern rustc_serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_serialize-0f41645d10f64d62.rmeta --extern rustc_session=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_session-b88d46fe3041e688.rmeta --extern rustc_span=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_span-3f54fec704da7e59.rmeta --extern rustc_target=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_target-a7d4facd2979b981.rmeta --extern rustc_trait_selection=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_trait_selection-d813db1c1fb0c7e8.rmeta --extern smallvec=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/libsmallvec-e1ca8c1925105298.rmeta --extern tracing=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/deps/libtracing-166f52f5b1e92350.rmeta -Dwarnings -Winvalid_codeblock_attributes --crate-version '1.50.0-nightly
  (92e2d3444
  2020-12-20)' --document-private-items --enable-index-page -Zunstable-options -Znormalize-docs` (exit code: 1)
warning: could not parse code block as Rust code
   --> compiler/rustc_typeck/src/check/upvar.rs:350:9
    |
350 |       /// ```
---

error: build failed


command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "doc" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--locked" "--color" "always" "--features" "jemalloc llvm max_level_info" "--manifest-path" "/checkout/compiler/rustc/Cargo.toml" "--no-deps" "-p" "rustc_typeck" "-p" "rustc_symbol_mangling" "-p" "rustc_query_system" "-p" "rustc_ty_utils" "-p" "rustc_session" "-p" "rustc_hir_pretty" "-p" "rustc_ast_passes" "-p" "rustc_error_codes" "-p" "rustc_expand" "-p" "coverage_test_macros" "-p" "rustc_mir_build" "-p" "rustc_codegen_llvm" "-p" "rustc_index" "-p" "rustc_ast_lowering" "-p" "rustc_middle" "-p" "rustc_feature" "-p" "rustc_errors" "-p" "rustc_plugin_impl" "-p" "rustc_target" "-p" "rustc_llvm" "-p" "rustc_ast" "-p" "rustc_arena" "-p" "rustc_save_analysis" "-p" "rustc_type_ir" "-p" "rustc_lexer" "-p" "rustc_graphviz" "-p" "rustc_mir" "-p" "rustc_privacy" "-p" "rustc_parse_format" "-p" "rustc_interface" "-p" "rustc_driver" "-p" "rustc_apfloat" "-p" "rustc_builtin_macros" "-p" "rustc_incremental" "-p" "rustc_traits" "-p" "rustc_span" "-p" "rustc_macros" "-p" "rustc_trait_selection" "-p" "rustc_resolve" "-p" "rustc_hir" "-p" "rustc_codegen_ssa" "-p" "rustc_infer" "-p" "rustc_fs_util" "-p" "rustc_lint_defs" "-p" "rustc_passes" "-p" "rustc_lint" "-p" "rustc_parse" "-p" "rustc_attr" "-p" "rustc_serialize" "-p" "rustc_metadata" "-p" "rustc_data_structures" "-p" "rustc_ast_pretty"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu --include-default-paths src/tools/build-manifest
Build completed unsuccessfully in 0:24:06

@bors
Copy link
Contributor

bors commented Dec 20, 2020

💔 Test failed - checks-actions

@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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2020
@lqd
Copy link
Member

lqd commented Dec 20, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Dec 20, 2020

⌛ Trying commit 6d885fb79cc8105204f03736a4b5cc13da4377ec with merge 63732d777c405f4a8e36687aaee37dadf67b14bc...

@bors
Copy link
Contributor

bors commented Dec 20, 2020

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

@rust-timer
Copy link
Collaborator

Queued 63732d777c405f4a8e36687aaee37dadf67b14bc with parent b0e5c7d, future comparison URL.

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

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 20, 2020
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (63732d777c405f4a8e36687aaee37dadf67b14bc): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 21, 2020
@bjorn3
Copy link
Member

bjorn3 commented Dec 21, 2020

This is a slight regression.

Copy link
Member

@varkor varkor left a comment

Choose a reason for hiding this comment

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

I'm happy with the changes after the few minor comments, but maybe you have an idea about how to avoid the regression, @Nadrieril? I think it's negligible enough not to worry, but perhaps an #[inline] in the right place could do the trick.

/// [..] => {}
/// }
/// ```
/// Here are the results of specialization for the first few lengths:
Copy link
Member

Choose a reason for hiding this comment

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

This example is nice and clear :)

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/usefulness.rs Outdated Show resolved Hide resolved
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 

@Nadrieril
Copy link
Member Author

Thanks for spotting all my typos! I've stared at it for too long I can't see them myself anymore ^^.
The perf regression seems to come from 17d9a5f where I add the Missing constructor. I've noticed that match-stress-enum gets consistently affected when I add or remove variants to the Constructor enum, so it makes sense. Not much I can do about that one.
#78242 will cause a conflict. I'll have a rebase ready for when it gets merged.

@bors
Copy link
Contributor

bors commented Dec 22, 2020

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

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@varkor
Copy link
Member

varkor commented Dec 22, 2020

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 22, 2020

📌 Commit be23694 has been approved by varkor

@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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 22, 2020
@bors
Copy link
Contributor

bors commented Dec 22, 2020

⌛ Testing commit be23694 with merge 969b42d...

@bors
Copy link
Contributor

bors commented Dec 23, 2020

☀️ Test successful - checks-actions
Approved by: varkor
Pushing 969b42d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 23, 2020
@bors bors merged commit 969b42d into rust-lang:master Dec 23, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 23, 2020
@Nadrieril Nadrieril deleted the explain-and-factor-splitting branch December 23, 2020 04:08
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 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