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

Enum tag destructuring #1813

Merged
merged 4 commits into from
Feb 13, 2024
Merged

Enum tag destructuring #1813

merged 4 commits into from
Feb 13, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Feb 9, 2024

Follow-up of #1812. Prior to extending match expressions with full pattern matching, this PR adds support for bare enum tags, which will be needed to be able to handle the existing enum tags match expressions.

In the end, I tend to agree with @vkleen 's comment, and contrary to what the original description of #1812 said, enum tags shouldn't in fact be treated as constants but rather as special cases of enum variants. It'll also make the transition easier, if we decide to go with an explicit Unit type and really have them be the same thing.

There is a bit of fuss around lazyness for patterns. Right now, let 'Foo x = <exp> in <body> doesn't fire any check if <body> doesn't use x, which is in line with lazy contracts, but might be surprising. Then what should do a pattern that doesn't bind any variable? In this PR, I went with the answer that we should add an artificial dependency (basically, seq), otherwise let 'Foo = x in <body> would always succeed, whatever x is, which is unreasonable.

Thinking ahead toward pattern in match expression, patterns will have to evaluate arguments up to a point to decide which branch to take (and hence be more eager than current destructuring patterns). Although it's technically backward-incompatible, I think we should do the same with destructuring. Some programs that use to evaluate might suddenly break, but it's arguably a "should have broke earlier" case - adding eagerly error reporting isn't the same as breaking entirely fine programs. If we do so, we can just get rid of those lazyness shenanigans.

But we can discuss this question further.

Until now, only enum variants were supported within patterns (applied
enums). This commit adds support for bare enum tags as well.
Make `typeof` returns `'Enum` for enum variants as well, and update
`std.contract.Equal` to properly handle enum tags and enum variants.
@yannham yannham requested review from jneem and vkleen February 9, 2024 18:32
@github-actions github-actions bot temporarily deployed to pull request February 9, 2024 18:37 Inactive
@yannham yannham added this pull request to the merge queue Feb 13, 2024
Merged via the queue into master with commit 0768f05 Feb 13, 2024
5 checks passed
@yannham yannham deleted the feat/enum-tag-destructuring branch February 13, 2024 11:00
@yannham yannham mentioned this pull request Feb 14, 2024
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.

2 participants