Normalize handling of Scala 3 enums, remove allocations from reader#445
Merged
Normalize handling of Scala 3 enums, remove allocations from reader#445
Conversation
lefou
reviewed
Feb 28, 2023
Member
lefou
left a comment
There was a problem hiding this comment.
I glanced over these changes and they look good to me. This is a great PR. Thank you to all who helped! Yet, I don't fully understand all details and lack the time to do so in the near future, so I'd welcome additional reviews.
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.
Fixes #356
The Scala 3 code for handling enums was a parallel code path from that handling sealed hierarchies: going through separate
EnumReader/EnumWriters, raising separate error messages, and not supporting common use cases. This PR makes Scala 3 enums use the same sealed-trait-handling logic as far as possible, allowing them to support things like parametrized enums and parametrized enum cases. This also reduces the complexity of the code by ensuring bothenums andsealed traits go through a common code path, and should help avoid accidental divergence in futureOne notable point of divergence is the choice of type tag. Enums use the short name of the type
Foo, whereas sealed traits use the fully qualified namepkg.name.Foo. For now, I leave both behaviors in place, though ideally we should unify them at some pointI also took the opportunity to tweak the Scala 3
Reader.scalamacros, to move more logic to compile time to better mirror that behavior in Scala 2. This replaces a runtimeMapin each case class reader with a macro-generatedmatchstatement, and reduces the number of runtimeArrayswe need to allocate (though does not quite eliminate all of them, we still have two arrays forparamsandvisitors)All existing tests pass, and added new tests to verify the newly-working functionality.
I'll leave this up for a few days in case anyone wants to review it