Fix #25728: remove wasteful transform(call) in PostTyper Inlined handler#25729
Draft
soronpo wants to merge 1 commit intoscala:mainfrom
Draft
Fix #25728: remove wasteful transform(call) in PostTyper Inlined handler#25729soronpo wants to merge 1 commit intoscala:mainfrom
soronpo wants to merge 1 commit intoscala:mainfrom
Conversation
… handler PostTyper's Inlined handler called `withMode(Mode.NoInline)(transform(call))` on every Inlined node, but the result was immediately discarded — the next line computes `callTrace` via `inlineCallTrace` (a minimal Ident) and uses that instead. When transparent inline operations are chained (e.g., `a + a + a + ...`), each Inlined node's `call` field contains the full expansion of all previous operations (because inline parameters carry the entire previous tree). The `call` tree size grows exponentially with chain length. Since `transform(call)` recursively traverses this entire tree — encountering nested Inlined nodes that each trigger their own `transform(call)` — the total work grows exponentially, causing compile times to double with each additional operation. The side-effecting check on the call (`CrossVersionChecks.checkRef`) is already performed on the line above and does not require full tree transformation. The expansion's contents are checked by `transform(expansion)`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25728
PostTyper's
Inlinedhandler calledwithMode(Mode.NoInline)(transform(call))on everyInlinednode, but the result was immediately discarded — the next line computescallTraceviainlineCallTrace(a minimalIdent) and uses that instead.When transparent inline operations are chained (e.g.,
a + a + a + ...), eachInlinednode'scallfield contains the full expansion of all previous operations (becauseinlineparameters carry the entire previous tree). Thecalltree size grows exponentially with chain length. Sincetransform(call)recursively traverses this entire tree — encountering nestedInlinednodes that each trigger their owntransform(call)— the total work grows exponentially, causing compile times to double with each additional operation.Measured PostTyper times for the reproducer (Scala 3.7.1, before fix):
The fix removes the
transform(call)line entirely. The side-effecting check (CrossVersionChecks.checkRef) is already performed on the preceding line and does not require full tree transformation. The expansion's contents are validated bytransform(expansion).How much have you relied on LLM-based tools in this contribution?
Extensively. Claude Code (Claude Opus) was used to investigate the root cause (instrumenting PostTyper, analyzing tree structures, measuring compile times), create the minimal reproducer, and draft this PR. The human contributor directed the investigation, validated findings against the DFHDL project (where this bug caused 33s compile times for 8 chained additions), and reviewed all changes.
How was the solution tested?
tests/posregression test (i25728/) is included: a multi-file test with a transparent inline macro and 20 chained operations that would previously time out or take minutes to compile.FlattenInlinedPhase.minimizeCall), which reduced 8-addition chains from 33s to 2s and enabled 20+ additions (previously impossible) to compile in 7s.transform(call)side effects.Additional notes
This is a draft PR to gauge CI reaction. If
transform(call)turns out to have necessary side effects beyondCrossVersionChecks.checkRef(e.g.,registerNeedsInliningon identifiers within the call tree), a more targeted fix could limit the transformation depth instead of removing it entirely.