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

feat(compiler): Support pattern matching "or" patterns #1173

Merged
merged 10 commits into from
Apr 20, 2022
Merged

Conversation

ospencer
Copy link
Member

This PR refactors the match compiler to properly support or-patterns. The two major changes are how bindings work and how constant patterns are compiled. Slots for each of the bindings needed in each of the branches are created, and during the branch selection process these slots are filled with the proper values. Constant patterns are now compiled the same way constructors are and should be more efficient now.

This opens the door for a number of optimizations we can write, but I left them out of this PR to keep it relatively simple.

You may notice that a fair number of snapshots are a bit bigger now; we need a few optimizations to remove the cruft, which will come after this PR.

Closes #264

@ospencer ospencer requested a review from a team March 20, 2022 22:11
@ospencer ospencer self-assigned this Mar 20, 2022
Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

Looks pretty good (matchcomp.re is definitely cleaner now), but I have a couple of questions before I hit approve.

compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Show resolved Hide resolved
@jozanza jozanza self-requested a review March 31, 2022 16:17
@marcusroberts
Copy link
Member

Does this need formatter support @ospencer

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Looking really good! We need to switch over to ocaml's Either since we upgraded to 4.12 and I had some other comments.

It looks like the snapshots are outdated so I didn't look at them.

compiler/src/utils/either.re Outdated Show resolved Hide resolved
compiler/src/middle_end/linearize.re Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
compiler/src/middle_end/matchcomp.re Outdated Show resolved Hide resolved
@ospencer
Copy link
Member Author

@phated @peblair this should be all set!

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

Awesome work!

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

🔥 Let's GOOOO!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pattern Matching: Support "or" patterns
5 participants