Skip to content

Conversation

SuperRonan
Copy link
Contributor

Fixes #8439

When checked, generic type equality constraints types are now in a canonical order, allowing for a commutative type equality operator.

@SuperRonan SuperRonan requested a review from a team as a code owner September 15, 2025 19:59
@juliusikkala juliusikkala added the pr: non-breaking PRs without breaking changes label Sep 15, 2025
}
else if (!(subOk || supOk))
{
// None is qualified, the generic constraint is not valid anyway.
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we diagnose in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be diagnosed right after, but it will only point that sub is not valid.
To be more clear we could instead emit a diagnostic that at least one operarand must be valid, and that none were here.

auto ancestor = findDeclsLowestCommonAncestor(subAncestor, supAncestor);
if (!ancestor)
{
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we sort by mangled name if they belong to two different modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this case can present itself. To be valid, a type must depend on the parent generic decl, which is necessarily in the same module. So the if (subOk != supOk) // Only one is qualified logic should have already treated this case.

But if the case presents itself, yes we can compare the mangled name.

In the current implementation, if we fail to compare the two types and sub is not valid, a note is diagnosed to point that we failed to find the canonical order. This is because I am not sure all cases were handled properly without introducing a breaking change.

{
if (!validSub && !equalityCannon)
{
getSink()->diagnose(decl, Diagnostics::failedEqualityConstraintCanonicalOrder);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If !validSub, then we are already diagnosing an error during validateSybType. Why do we need another diagnostic here?

In principle there shouldn't be any cases where we cannot determine canonical order, and we should always be able to sort the types one way or the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In principle there shouldn't be any cases where we cannot determine canonical order, and we should always be able to sort the types one way or the other.

Yes, but if new cases arise in the future then we will be notified.

csyonghe
csyonghe previously approved these changes Sep 19, 2025
@csyonghe csyonghe enabled auto-merge September 19, 2025 06:58
@SuperRonan
Copy link
Contributor Author

Actually I was going to push some improvements based on your comments...

auto-merge was automatically disabled September 19, 2025 09:30

Head branch was pushed to by a user without write access

@SuperRonan SuperRonan force-pushed the ronan/feature/canonical-type-equality-constraint branch from 95f052b to b02b31f Compare September 19, 2025 09:30
@@ -0,0 +1,41 @@
//TEST:SIMPLE(filecheck=CHECK):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is better to have a test that computes something meaning out of it and make it an executable test (simplest form being //TEST:INTERPRET:.

csyonghe
csyonghe previously approved these changes Sep 23, 2025
Copy link
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

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

Looks good to me. Would be great if you can enhance the test into an executable one.

@SuperRonan
Copy link
Contributor Author

The CI failing tests pass when rebased / merged on master (locally for me)

auto-merge was automatically disabled September 26, 2025 12:01

Head branch was pushed to by a user without write access

@SuperRonan SuperRonan force-pushed the ronan/feature/canonical-type-equality-constraint branch from 6dd988a to af1810d Compare September 26, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic Type Equality Constraint commutativity
3 participants