-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow inline vals with alias to constant type #8840
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
Allow inline vals with alias to constant type #8840
Conversation
@nicolasstucki Can I have a couple of use cases: |
@plokhotnyuk that kind of computation is out of the scope of |
@plokhotnyuk you could use the following macro (or something simillar) private final val f64Pow5InvSplit: Array[Long] = ${ evalF64Pow5InvSplit }
// Put this in another file (not necessarily another project)
// Contents of Expr evaluated at compiletime and result lifted into the code to create that array
import scala.quoted._
def evalF64Pow5InvSplit(using QuoteContext): Expr[Array[Long]] = Expr {
val ss = new Array[Long](582)
var pow5 = BigInt(1)
var i = 0
while (i < 582) {
val inv = ((BigInt(1) << (pow5.bitLength + 121)) / pow5) + 1
ss(i) = inv.longValue & 0x3FFFFFFFFFFFFFFFL
ss(i + 1) = (inv >> 62).longValue & 0x3FFFFFFFFFFFFFFFL
pow5 *= 5
i += 2
}
ss
} |
f916747
to
8b23e2b
Compare
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
@@ -510,7 +510,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => | |||
*/ | |||
def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = { | |||
val tree1 = ConstFold(tree) | |||
tree1.tpe.widenTermRefExpr match { | |||
tree1.tpe.widenTermRefExpr.dealias 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.
For later: maybe we should call .normalized
, as dealias
is just one of many possible normalization operations on types.
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.
Yes, I have that in #8843. But when I tried to normalize it here it did not work. Maybe I need to deeply dealias and then normalize.
Allow inline vals with alias to constant type and make them constant fold