Skip to content

fix #9873: no longer use scala.Enum as parents of enums #9877

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

Closed

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Sep 25, 2020

fixes #9873

this also adds a new method to deriving.Mirror.Sum to access the enumLabel generically. no longer does this

Also removes the old unused enum helper classes from the non-bootstrapped library

…nums

this commit introduces the concept that some desugaring expansion
can occur after parents of the current class are known, i.e. methods
that contain no references like ordinal and enumLabel.
@bishabosha bishabosha force-pushed the topic/enum-remove-scala-enum branch from 77a53cf to 2351587 Compare September 25, 2020 16:19
@bishabosha bishabosha marked this pull request as ready for review September 25, 2020 16:19
Copy link
Contributor

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t have enough expertise to review the implementation but the test enum-mirror-sumOf.scala looks good to me!

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but it would be good to have confirmation from someone from the core dotty team on whether the new untpd tree is the right way to go.

@bishabosha bishabosha force-pushed the topic/enum-remove-scala-enum branch from dca2f45 to 489a1af Compare September 28, 2020 15:40
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to simplify this and reduce the scope. Let's discuss and possibly implement enumLabels separately. For dropping scala.Enum, the approach looks good, but I think it can be simplified.

no longer special case some definitions for indexing after the
parents of a class are discovered.

Extend invalidateIfClashingSynthetic to cover ordinal override
from java.lang.Enum
@bishabosha bishabosha force-pushed the topic/enum-remove-scala-enum branch from 9c341f4 to 4e3d6e4 Compare October 1, 2020 12:08
@bishabosha bishabosha requested a review from odersky October 1, 2020 12:13
@bishabosha
Copy link
Member Author

bishabosha commented Oct 1, 2020

@odersky I have revisited the implementation so that the only special case is to add ordinal to the cases invalidated in invalidateIfClashingSynthetic, and there is no change to either error messages, untpd, or deriving.Mirror.Sum.
The documentation still needs to be updated but I will do that if you are happy with the implementation

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good now, except for the suggested small change in SyntheticMembers.

@odersky odersky removed their assignment Oct 1, 2020
@bishabosha
Copy link
Member Author

Not really sure why the definitions are disappearing in the sconfig community build

@bishabosha
Copy link
Member Author

bishabosha commented Oct 1, 2020

so it looks like calling unlink is not enough, it will remove ordinal from the scope, but then it is still visible using findMember on the info of the enum class, and in some situations, like typedSelect when typing the sconfig example, the method is not chosen as it fails reallyExists

Edit: apparently delete does not stop downstream find member either

@odersky
Copy link
Contributor

odersky commented Oct 1, 2020

I think it's better not to remove ordinal. That's very tricky code, and we should use that only when absolutely necessary. As an alternative we could simply change the rhs of ordinal methods for cases of enums that extend java.lang Enum like this:

override def ordinal: Int = super.ordinal

I believe that's much easier to do. We could do this in SyntheticMethods, for instance, or anywhere else before RefChecks.

@bishabosha
Copy link
Member Author

Im not sure I understand, ordinal is a final method so we can't override it

@bishabosha bishabosha force-pushed the topic/enum-remove-scala-enum branch from d977a03 to be11253 Compare October 2, 2020 14:51
@bishabosha
Copy link
Member Author

bishabosha commented Oct 2, 2020

@odersky In addition to invalidation I also now do not enter the symbol for ordinal until after typing the parents - but the logic is all localised to the indexExpanded method, but this is far more minimal then running the whole index function after parents (as I did with the EnumGetters magic)

@bishabosha bishabosha requested a review from odersky October 2, 2020 15:00
@bishabosha bishabosha assigned odersky and unassigned bishabosha Oct 2, 2020
@odersky
Copy link
Contributor

odersky commented Oct 3, 2020

Im not sure I understand, ordinal is a final method so we can't override it

Ah. I did not consider that. Yes, scratch that idea then.

@odersky
Copy link
Contributor

odersky commented Oct 3, 2020

This is quite a heroic effort from @bishabosha's part. It needs some tricky logic in Namer which is already a class that is pushing the complexity budget. But I wonder whether it's worth it. Is it not simpler to just keep the Enum trait? If we are concerned about naming it could be scala.runtime.Enum. That way it won't shadow the Java trait.

@odersky
Copy link
Contributor

odersky commented Oct 3, 2020

I think it could be a valuable for a reflection framework to know that a class or value is an enum case. So having Enum as a marker trait might not be a bad idea after all.

@odersky odersky removed their assignment Oct 3, 2020
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current preference is to rename scala.Enum to scala.runtime.Enum and otherwise keep things as they are. I believe that's overall simplest.

@odersky
Copy link
Contributor

odersky commented Oct 3, 2020

In fact it could also be scala.reflect.Enum. The runtime package is reserved for classes that should not be mentioned in user code. So scala.runtime.Enum makes sense only if we say the class is an implementation detail. We should discuss this point.

Also, while we are at it, I believe the Enum class should be a super trait.

@bishabosha
Copy link
Member Author

close in favour of #9942

@bishabosha bishabosha closed this Oct 5, 2020
@bishabosha bishabosha deleted the topic/enum-remove-scala-enum branch September 10, 2021 14:17
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.

Should we remove scala.Enum trait as a parent of enums?
5 participants