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

ConstParamTy: require Eq as supertrait #116125

Merged
merged 2 commits into from Sep 26, 2023
Merged

Conversation

RalfJung
Copy link
Member

As discussed with @BoxyUwU on Zulip.

We want to say that valtree equality on const generic params agrees with ==, but that only makes sense if == actually exists, hence we should have an appropriate bound. Valtree equality is an equivalence relation, so such a type can always be Eq and not just PartialEq.

@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 24, 2023
@@ -986,11 +986,16 @@ pub trait Tuple {}
pub trait PointerLike {}

/// A marker for types which can be used as types of `const` generic parameters.
///
/// These types must have a proper equivalence relation (`Eq`) and it must be automatically
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 "just in case"? Like, there are no types that implement StructuralEq that don't also implement Eq, right, at least without a manual StructuralEq impl?

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice if you could add a test showing where possibly dubious code goes from pass -> err.

Copy link
Member Author

@RalfJung RalfJung Sep 24, 2023

Choose a reason for hiding this comment

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

Like, there are no types that implement StructuralEq that don't also implement Eq, right, at least without a manual StructuralEq impl?

Not quite.
A generic type with derive(Eq) will implement StructuralEq without any bounds on the generic parameters.

Is this "just in case"?

This is mostly to make the 2nd half of the comment coherent: we want to say that valtree equality agrees with ==. Without at least a PartialEq bound, that statement is ill-formed, since the type might not even have ==.

Copy link
Member Author

@RalfJung RalfJung Sep 24, 2023

Choose a reason for hiding this comment

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

Would be nice if you could add a test showing where possibly dubious code goes from pass -> err.

I don't know any such test (without a manual StructualEq impl), but currently the invariants that achieve that ConstParamTy implies Eq are rather subtle. This makes them a lot more obvious.

Copy link
Member

Choose a reason for hiding this comment

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

currently the invariants that achieve that ConstParamTy implies Eq are rather subtle. This makes them a lot more obvious.

Yeah, ok, that's all I wanted to really know. This isn't necessarily for "correctness" (but perhaps only by accident do we imply the right thing due to recursively checking fields for ConstParamTy in impls).

Copy link
Member Author

Choose a reason for hiding this comment

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

I also view this as preparation for removing the StructuralEq trait entirely (at which point only the StructuralPartialEq bound would be left otherwise).

I can do that all in the same PR if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I'll probably have more questions about behavioral changes on that PR anyways 😅

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 25, 2023

📌 Commit ad50963 has been approved by compiler-errors

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 25, 2023

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 Sep 25, 2023
@bors
Copy link
Contributor

bors commented Sep 26, 2023

⌛ Testing commit ad50963 with merge 27b4eb9...

@bors
Copy link
Contributor

bors commented Sep 26, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 27b4eb9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 26, 2023
@bors bors merged commit 27b4eb9 into rust-lang:master Sep 26, 2023
12 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 26, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (27b4eb9): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
-3.1% [-3.1%, -3.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.1% [-3.1%, -3.1%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 630.463s -> 632.394s (0.31%)
Artifact size: 317.25 MiB -> 317.19 MiB (-0.02%)

@RalfJung RalfJung deleted the const-param-ty-eq branch September 26, 2023 13:26
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants