-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3866: Add support for typetags #3867
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
Conversation
test performance please |
performance test scheduled: 4 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3867/ to see the changes. Benchmarks is based on merging with master (79281da) |
- title: Symmetric Meta Programming | ||
url: docs/reference/symmetric-meta-programming.html | ||
- title: Meta Programming | ||
url: docs/reference/principled-meta-programming.html |
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.
The file name needs to be changed to principled-meta-programming.md
as well.
} | ||
def reflect[T, U](f: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[T => U] = | ||
’{ (x: ~t) => ~f(’(x)) | ||
|
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.
Missing }
at the end
library/src/scala/quoted/Type.scala
Outdated
@@ -9,6 +9,8 @@ abstract class Type[T] extends Quoted { | |||
/** Some basic type tags, currently incomplete */ | |||
object Type { | |||
|
|||
implicit def apply[T]: Type[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.
Are calls to this methods going to be replaced by the tags below when possible and replaced '[T]
if the type is statically known?
def unary_~: T // splice operation | ||
} | ||
class Type[T] { | ||
sealed abstract class Type[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.
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.
Otherwise LGTM
reference to a type `T` to a type-splice, by rewriting `T` to `~implicitly[Type[T]]`. | ||
For instance, the user-level definition of `reflect` | ||
|
||
def reflect[T: Type, U](f: Expr[T] => Expr[U]) Expr[T => U] = |
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.
Missing :
before result type.
|
||
would be rewritten to | ||
|
||
def reflect[T: Type, U](f: Expr[T] => Expr[U]) Expr[T => U] = |
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.
Missing :
before result type.
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.
Same here
} | ||
|
||
val tag = toTree(tpe) | ||
if (ok) ref(defn.typeQuoteMethod).appliedToTypeTrees(tag :: Nil) |
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.
In the future, we should optimize primitive types to return quoted.Type.XYZTag
. But we should do it in general for any '[XYZ]
that has a quoted.Type.XYZTag
. Probably as part of reification.
RefinedTypeTree(toTree(tpe), refinements, refineCls) | ||
} | ||
|
||
def toTree(tpe: Type): Tree = tpe.stripTypeVar match { |
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.
As discussed, we should try using the same trick to no need all these trees.
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.
LGTM, just missing a couple of details in the documentation.
reference to a type `T` to a type-splice, by rewriting `T` to `~implicitly[Type[T]]`. | ||
For instance, the user-level definition of `reflect`: | ||
|
||
def reflect[T: Type, U](f: Expr[T] => Expr[U]) Expr[T => U] = |
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.
Still missing a :
|
||
would be rewritten to | ||
|
||
def reflect[T: Type, U](f: Expr[T] => Expr[U]) Expr[T => U] = |
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.
Same here
Based on feedback with the early implementation, we found out that we need type lifting in the framework. This commit explains what needs to be done in the meta programming doc.
It's not so easy to see what is symmetric about it. "Principled" is bolder, but why not, since we do introduce a new principle?
This is intended as a stub. Calls to this method will be replaced by implicit type tag searches. Also, rework definition of quote and splice methods. This could also have contributed in the slowdown we were seeing in scala#3721.
We need to come back to the earlier scheme that a lifted type needs to refer to an implicit type tag.
Not sure this is the right way. It feels a bit roundabout to take the detour from types to type trees. But I am not sure we can correctly quote types without trees.
Generate a type with embedded quotes instead of a tree.
Based on feedback with the early implementation, we found out that we need type lifting
in the framework. The first commit explains what needs to be done in the meta programming doc.
The other commits are a first implementation. I am still not quite happy with it because we are lacking a way to do quoting and splicing directly on types. So for now we generate a type tree, but this cannot express all possible positions of typetags. For instance, we could not splice
a type tag in the position of a type parameter of a refined method since refined methods are
represented as types, not as type trees.
So maybe we need to take a step back and allow that. But that would upset quite a few core structures of the compiler.