-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove splice internal representation from public API #6073
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
Remove splice internal representation from public API #6073
Conversation
4674ae6
to
4fa9ada
Compare
bc9fd8f
to
a3c32a7
Compare
16c186c
to
a946148
Compare
fae3de1
to
1a22b7c
Compare
@@ -203,7 +203,7 @@ object StagedTuple { | |||
if (!specialize) '{dynamic_++[Self, That]($self, $that)} | |||
else { | |||
def genericConcat(xs: Expr[Tuple], ys: Expr[Tuple]): Expr[Tuple] = | |||
fromArrayStaged[Tuple]('{${ toArrayStaged(xs, None) } ++ ${ toArrayStaged(ys, None) }}, None) | |||
fromArrayStaged[Tuple]('{${ toArrayStaged(xs, None) } ++ (${ toArrayStaged(ys, None) }: Array[Object])}, None) |
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.
Why is the ascription needed here?
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.
From the desugaring of ${...}
to def exprSplice[T](x: Expr[T]): T
we get now need to infer T
as well as the types of ++
.
The acctual error is
[error] 206 | fromArrayStaged[Tuple]('{${ toArrayStaged(xs, None) } ++ ${ toArrayStaged(ys, None) }}, None)
[error] | ^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: quoted.Expr[Array[Object]]
[error] | Required: quoted.Expr[scala.collection.GenTraversableOnce[Object]]
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.
That's problematic. We should avoid type ascriptions that need to be added for obscure reasons. Should we change the desugaring instead?
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.
Actually, this is an instance of #6126 which is quite specific to ++
with Array
s. If fixed this would not be an issue.
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.
I'll have a look at #6126.
`scala.internal.Quoted.exprSplice` can be used for the same purpose by explicily setting the type parameter of `exprSplice` to a phase correct type alias.
Currently type inference for `Expr` of union types is not precise enough as reported in scala#4867. This implies that currently we cannot have macros of the form ```scala inline def foo(x: T) <: X | Y = ${ ... } ``` but we can always default back to the less informative alternative ```scala inline def foo(x: T) <: Any = ${ ... } ``` Both form will refine the type to the type of the expression returned by the macro.
d1b2bab
to
59a170e
Compare
This removes the
$splice
public member fromExpr
that was only for compiler internal representation.sealed abstract class Expr[+T] { - final def `$splice`: T = throw new Error("splice should have been compiled away") ... }
And remove the
asInstanceOf
s added around each splice to make pickling/unpickling retain phase consistency on types.With this change, we also start hitting an instance of #4867 that disallow us to write splices of expressions of union types. If #4867 is fixed we would not have this issue.