-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Try harder to get a constant rhs for inline vals
#24431
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
| val rhs = | ||
| typed(vdef.rhs) match | ||
| case ConstantValue(v) => Literal(Constant(v)) | ||
| case rhs => rhs |
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.
Should we directly report an error here?
This is wrong. It breaks separate compilation/tasty compatibility if you later change the body of
|
But that only works here because we are inside an Inside an |
|
No, |
|
Grateful I'm not trying to get something past sjrd right now. |
Why is it important that this is at That doesn't seem aligned with the implementation, which only checks that during And is this implied by the specification? Do spec definitions imply during |
|
Follow-up on the constant-folding part, independently from inlining: #24432. |
When should the result of calling a non-transparent inline method be visible?
Right now, it becomes visible when we reduce the condition of an
inline if:It is also visible for operations that can be constant-folded:
But it is not visible for a simple call:
The first two examples work because they rely on
ConstantValue, which always stripsTyped:scala3/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Lines 1217 to 1220 in 96b1b83
This PR makes the third example work as well by also calling
ConstantValuewhen typing the right-hand side of aninline valinside aninline def.