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

Extend merge to enum variants #1862

Merged
merged 1 commit into from
Mar 26, 2024
Merged

Extend merge to enum variants #1862

merged 1 commit into from
Mar 26, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Mar 22, 2024

Enum variants (ADTs) were introduced in 1.5, but they currently can't be merged, which breaks the idempotency of merge on values. This commit extend merging to enum variants, by merging their content recursively if their tags are equal, or failing otherwise.

Semantics

Two different semantics have been discussed for enum variants:

  1. As for other primitive values, only merge variants that are strictly equal, including their arguments.
  2. Merge the arguments of variants if they have the same tag, that is 'Tag arg1 & 'Tag arg2 ~ 'Tag (arg1 & arg2).

The current statuos quo is lending toward 1., as this policy has been applied to other primitive values. However, there's no other reasonable semantics for constants (booleans, strings and numbers). So we should really compare variants to other datastructures, arrays and functions. For those two, we decided not to merge them to avoid silent and unwanted merging to happen (and because, for arrays, there are multiple possible reasonable semantics).

However, given the feedback of some users, it seems that merging enum variants with similar tags is both useful and natural. The risk of unwanted merging also seems to be limited, as when the tag differs, or the variant's argument is not a record (or only composed of variants of records), the merge will fail anyway. After consideration, we decided to go with semantics 2.

@yannham yannham requested review from jneem and vkleen March 22, 2024 11:14
@github-actions github-actions bot temporarily deployed to pull request March 22, 2024 11:17 Inactive
core/src/error/mod.rs Outdated Show resolved Hide resolved
doc/manual/merging.md Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request March 26, 2024 09:49 Inactive
Enum variants (ADTs) were introduced in 1.5, but they currently can't be
merged, which breaks the idempotency of merge on values. This commit
extend merging to enum variants, by merging their content recursively if
their tags are equal, or failing otherwise.

Co-authored-by: jneem <[email protected]>
@yannham yannham enabled auto-merge March 26, 2024 10:39
@github-actions github-actions bot temporarily deployed to pull request March 26, 2024 10:42 Inactive
@yannham yannham added this pull request to the merge queue Mar 26, 2024
Merged via the queue into master with commit a571507 Mar 26, 2024
5 checks passed
@yannham yannham deleted the fix/merging-adts branch March 26, 2024 11:06
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.

None yet

2 participants