Skip to content

implement readResolve in terms of fromOrdinalDollar method #9612

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

Merged
merged 2 commits into from
Aug 24, 2020

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Aug 21, 2020

This adds a private $fromOrdinal method to an enum companion that is always generated if there are value enum cases and the enum does not derive from java.lang.Enum, for the purposes of replacing a serialized enum case.

This means that EnumValueSerializationProxy is no longer needed, and is moved to the non-bootstrapped library and deleted in the bootstrapped library. The proxy could remain but it makes it more complicated to call $fromOrdinal as the name can be mangled. The fields of the enum constants will be serialised perhaps unnecessarily.

This acts as a precursor to only generating .values when enum declares a pure enumeration: DesugarEnums.nextOrdinal collects the value enum cases and is aware of when the last case is reached, allowing to make decisions on what methods to generate based on collected constraints.

@bishabosha bishabosha requested review from smarter and sjrd August 21, 2020 11:28
@bishabosha
Copy link
Member Author

bishabosha commented Aug 21, 2020

failing CI because $fromOrdinal needs a default case resolved

@bishabosha bishabosha force-pushed the topic/enum-serialization-alt branch 5 times, most recently from 5a24a31 to b81b84c Compare August 21, 2020 14:02
@bishabosha
Copy link
Member Author

@nicolasstucki should it be safe to delete EnumValueSerializationProxy from the bootstrapped library?

@nicolasstucki
Copy link
Contributor

Yes, the EnumValueSerializationProxy is only needed for the non-bootstrapped.

value cases are collected in EnumCaseCount attachment during
nextOrdinal, and an attachment DefinesEnumLookupMethods determines
when the final case has been reached, at which point the methods
can be generated that depend on the cases.
@bishabosha bishabosha force-pushed the topic/enum-serialization-alt branch from b81b84c to 89d107c Compare August 24, 2020 11:44
@bishabosha bishabosha merged commit 5dbd4ed into scala:master Aug 24, 2020
@bishabosha bishabosha deleted the topic/enum-serialization-alt branch August 24, 2020 12:36
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.

3 participants