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

Const qualification for StructuralEq #67343

Merged
merged 10 commits into from
Apr 29, 2020

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Dec 16, 2019

Furthers #62411. Resolves #62614.

The goal of this PR is to implement the logic in #67088 on the MIR instead of the HIR. It uses the Qualif trait to track StructuralPartialEq/StructuralEq in the final value of a const. Then, if we encounter a constant during HAIR lowering whose value may not be structurally matchable, we emit the indirect_structural_match lint.

This PR contains all the tests present in #67088 and emits the proper warnings for the corner cases. This PR does not handle #65466, which would require that we be more aggressive when checking matched types for PartialEq. I think that should be done separately.

Because this works on MIR and uses dataflow, this PR should accept more cases than #67088. Notably, the qualifs in the final value of a const are encoded cross-crate, so matching on a constant whose value is defined in another crate to be Option::<TyWithCustomEqImpl>::None should work. Additionally, if a const has branching/looping, we will only emit the warning if any possible control flow path could result in a type with a custom PartialEq impl ending up as the final value of a const. I'm not sure how #67088 handled this.

AFAIK, it's not settled that these are the semantics we actually want: it's just how the Qualif framework happens to work. If the cross-crate part is undesirable, it would be quite easy to change the result of mir_const_qualif().custom_eq to true before encoding it in the crate metadata. This way, other crates would have to assume that all publicly exported constants may not be safe for matching.

r? @pnkfelix
cc @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 16, 2019
@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@JohnCSimon JohnCSimon 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 Jan 18, 2020
@Dylan-DPC-zz

This comment has been minimized.

@Dylan-DPC-zz

This comment has been minimized.

@Dylan-DPC-zz Dylan-DPC-zz added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2020
@mark-i-m

This comment has been minimized.

@ecstatic-morse ecstatic-morse 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: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Mar 16, 2020
@ecstatic-morse
Copy link
Contributor Author

This handles #62614 properly, but still ICEs on #65466.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@ecstatic-morse ecstatic-morse changed the title [WIP] Const qualification for StructuralEq Const qualification for StructuralEq Apr 7, 2020
@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Apr 7, 2020

@pnkfelix I've updated the PR description and this is now ready for review.

LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
Copy link
Contributor Author

@ecstatic-morse ecstatic-morse Apr 7, 2020

Choose a reason for hiding this comment

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

Note that these error messages are repeated for some reason. This does not happen on nightly, or when I run the test using rustc +stage1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we don't deduplicate errors when running compiletest? Tests like ui/consts/match_ice.rs also have repeated output on master.

@ecstatic-morse
Copy link
Contributor Author

@bors r=pnkfelix

I believe I've addressed everything above that needed immediate attention. One warn is now a bug and the other is a debug, since it is relatively common.

@bors
Copy link
Contributor

bors commented Apr 29, 2020

📌 Commit e4c650c has been approved by pnkfelix

@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 Apr 29, 2020
@bors
Copy link
Contributor

bors commented Apr 29, 2020

⌛ Testing commit e4c650c with merge 36d13cb...

@bors
Copy link
Contributor

bors commented Apr 29, 2020

☀️ Test successful - checks-azure
Approved by: pnkfelix
Pushing 36d13cb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 29, 2020
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #67343!

Tested on commit 36d13cb.
Direct link to PR: #67343

🎉 rustc-dev-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m).

@bors bors merged commit 36d13cb into rust-lang:master Apr 29, 2020
rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Apr 29, 2020
Tested on commit rust-lang/rust@36d13cb.
Direct link to PR: <rust-lang/rust#67343>

🎉 rustc-dev-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m).
@nnethercote
Copy link
Contributor

As expected, this was a perf regression of up to 6% on many-assoc-items and up to 2% on a few others, mostly html5ever.

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.

indirect_structural_match lint misfiring on enum variant unused in const item