Skip to content

[refactor] equal_tag => equal_constr#13467

Merged
gasche merged 2 commits intoocaml:trunkfrom
gasche:equal_constr
Sep 25, 2024
Merged

[refactor] equal_tag => equal_constr#13467
gasche merged 2 commits intoocaml:trunkfrom
gasche:equal_constr

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented Sep 23, 2024

(This PR is on top of #13466.)

The type-checker and pattern-matching compiler rely on a check that the "tags" of two constructors are equal. This check is hard to extend to new/funky sorts of constructors (extension constructor (existing), unboxed constructors (upcoming!)), and is also performance-sensitive ( #406 ).

Most uses in the codebase are not actually trying to check tag equality, but just whether two constructors are equal. We refactor the codebase to introduce a new equal_constr function and use it directly. This makes the intent clearer, it will be easier to extend with newer kinds of constructors, and it would probably help to make the check more efficient.

If two extension constructors have the same path, then they correspond
to the same declaration, and they must have the same constantness.
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Sep 25, 2024

I rebased this now that #13466 is merged. @Octachron remarked that I performed a slight simplification of the equality check in the extension-constructor case, and I added a commit that does this explicitly (rather than inside a refactoring commit) to clarify things.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

This is a clear simplification for all call sites.

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Sep 25, 2024

Thanks! Merging.

@gasche gasche merged commit e9bcdc5 into ocaml:trunk Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants