Enhance constant-folding during inlining (second try)#25731
Enhance constant-folding during inlining (second try)#25731mbovel wants to merge 2 commits intoscala:mainfrom
Conversation
| if res eq subTree then tree else res | ||
|
|
||
| tree match | ||
| case Typed(expr, _) if expr.tpe frozen_<:< tree.tpe => recChild(expr) |
There was a problem hiding this comment.
This added guard is the single change compared to #24431.
|
Still failing (#25697): https://github.com/scala/scala3/actions/runs/24135304347/job/70429540306#step:5:2382 I'll investigate, but it seems this is just a missing case in the user macro code. |
|
The problem is that the library doesn't handle the case where |
When the compiler constant-folds `Pattern.CASE_INSENSITIVE | Pattern.COMMENTS` into a single IntConstant (e.g. 6), parseFlags failed to match. This adds a case to decompose the constant back into individual flag bits. See scala/scala3#25731 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
An ascription that doesn't pass that condition is an invalid ascription. How does it even get there? |
It turns out you can generate malformed trees with macros. See #25690 for more 😅 |
|
Right. Then the macro needs to be fixed. |
Sure, that's why I opened the PR on ZIO to enable In the meantime, and in case other codebases rely on broken macros, don't you think that defensively checking the assertion is valid would make sense? |
|
See also the internal Slack discussion about |
No, it really doesn't make sense. You can't pollute every other place of the compiler with dealing with bad stuff that macros generate. It's not sustainable. In this case it might run on the JVM because it inserts casts to heal things, but not on JS, whose backend is stricter. At most, you could have a postprocessing after a macro that turns bad ascriptions into casts. And emits a warning in the process. At least the blast radius of that hack would be limited to macros. |
|
I filled zio/zio#10721, let's see if I can get some help fixing this in ZIO directly. |
When the compiler constant-folds `Pattern.CASE_INSENSITIVE | Pattern.COMMENTS` into a single IntConstant (e.g. 6), parseFlags failed to match. This adds a case to decompose the constant back into individual flag bits. See scala/scala3#25731 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the compiler constant-folds `Pattern.CASE_INSENSITIVE | Pattern.COMMENTS` into a single IntConstant (e.g. 6), parseFlags failed to match. This adds a case to decompose the constant back into individual flag bits. See scala/scala3#25731 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the compiler constant-folds `Pattern.CASE_INSENSITIVE | Pattern.COMMENTS` into a single IntConstant (e.g. 6), parseFlags failed to match. This adds a case to decompose the constant back into individual flag bits. See scala/scala3#25731 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the compiler constant-folds `Pattern.CASE_INSENSITIVE | Pattern.COMMENTS` into a single IntConstant (e.g. 6), parseFlags failed to match. This adds a case to decompose the constant back into individual flag bits. See scala/scala3#25731 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
#24431 was reverted in #25703. This PR attempts to restore the changes from #24431, with a single twist: we now “see through” ascriptions on if the type of the ascribed tree is indeed a subtype of the target type. This is rules out cases where the ascription is semantically required, as in #25703.