Add a compiler pass for automatic generation of Generic instances for algebraic datatypes#466
Merged
Merged
Conversation
rodrigogribeiro
commented
Jun 15, 2026
Collaborator
- Add a compiler pass for generating Generic instance for datatypes.
- Add a pragma to disable Generic instance generation for datatypes.
8a45423 to
527cdd2
Compare
mbenke
reviewed
Jun 18, 2026
Comment on lines
+12
to
25
| // Only requirement: Generic instance using the primitive sum type. | ||
| // rep = sum((), uint256): inl(()) = None, inr(v) = Some(v) | ||
| instance Option(uint256) : Generic(sum((), uint256)) { | ||
| function from(x : Option(uint256)) -> sum((), uint256) { | ||
| match x { | ||
| | Option.None => return Sum.Inl(()); | ||
| | Option.Some(v) => return Sum.Inr(v); | ||
| | Option.None => return inl(()); | ||
| | Option.Some(v) => return inr(v); | ||
| } | ||
| } | ||
| function to(r : Sum((), uint256)) -> Option(uint256) { | ||
| function to(r : sum((), uint256)) -> Option(uint256) { | ||
| match r { | ||
| | Sum.Inl(_) => return Option.None; | ||
| | Sum.Inr(v) => return Option.Some(v); | ||
| | inl(_) => return Option.None; | ||
| | inr(v) => return Option.Some(v); | ||
| } |
Collaborator
There was a problem hiding this comment.
This instance should be derived, right? And similarly in generic_product?
Or perhaps there should be two sets of tests: one for explicit instance, and one for derived?
Collaborator
Author
There was a problem hiding this comment.
Fixed and added tests for the pragma that disable Generic instance generation.
mbenke
reviewed
Jun 19, 2026
| pragma no-coverage-condition ; | ||
| pragma no-bounded-variable-condition ; | ||
|
|
||
| infixl 70 (^^) => pow; |
Collaborator
There was a problem hiding this comment.
I don't think the operators have been merged yet:
test/examples/cases/user-op-lambda.solc
<input>:6:1:
|
6 | infixl 70 (^^) => pow;
| ^
unexpected 'i'
expecting "class", "constructor", "contract", "data", "default", "export", "fallback", "forall", "function", "import", "instance", "payable", "pragma", "public", "type", or end of input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.