-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add SIP 23 ValueOf #5647
Add SIP 23 ValueOf #5647
Conversation
Added an implementation of SIP 23 ValueOf and copied over the corresponding Scala 2 tests.
case ConstantType(c: Constant) => | ||
success(Literal(c)) | ||
case TypeRef(_, sym) if sym == defn.UnitClass => | ||
success(Literal(Constant(()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't Unit
handled by the ContantType
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it isn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it should be, but currently Unit
isn't classified as a singleton type in either Scala 2 or Dotty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should certainly be, at least conceptually. Isn't Unit
the singleton type par excellence?
There is already a package object typelevel {
inline def constValueOpt[T]: Option[T] = ???
inline def constValue[T]: T = ???
type S[X <: Int] <: Int
} The main difference between I don't have a strong opinion whether we should have a typeclass or a macro, but we should certainly not have both. So if we go for the typeclass, we should replace all occurrences of |
Specifically, the question would be: Can we formulate
One question for my understanding: Why does |
Typically I'd be more than happy to see |
OK, I see the case for
|
It's worth noting for this discussion that once we switch to using the 2.13 library we'll have to use their version of the ValueOf class, or at least a binary-compatible one. |
I see now that the Could we have an intrinsified implementation of If that produces the same bytecode in all the cases that |
That would be good, yes. I think
Should it not be the other way around? If there is a contextual ValueOf instance, pick that. If not there is a fallback instance that can be based on
Sure. The biggest use case we have right now is Tuple.scala. It would be interesting to see whether we can use ValueOf there. On the other hand, since things are pretty much in flux now, we can also accept some duplication, as long as we plan to come back to try to eliminate it once our toolbox has stabilized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milessabin I happy to have this go in now and we sort out the duplication afterwards. Alternatively, if you want to try to do some harmonization first let me know and I'll hold back with merging.
@odersky let's merge this now and deal with the duplication as part of firming up the content of the |
Added an implementation of SIP 23
ValueOf
and copied over the corresponding Scala 2 tests.Fixes #2616.