Do not CSE dynamic dispatch calls with a non-CSE-able callee#1271
Open
mbouaziz wants to merge 1 commit into
Open
Do not CSE dynamic dispatch calls with a non-CSE-able callee#1271mbouaziz wants to merge 1 commit into
mbouaziz wants to merge 1 commit into
Conversation
canCSECall's method branch used a deliberately lax per-callsite rule: CSE was allowed if any of the possible implementations could CSE. Two identical virtual calls were therefore merged even when the receiver could dispatch to a @debug (or untracked) implementation, silently deleting its second execution. A @debug implementation sharing a callsite with any CSE-able sibling implementation was enough to trigger it, at -O0 as well as -O2. Invert the rule: allow CSE only when every implementation the call might invoke passes funCanCSE. The allMethodImplementations iteration stops at the first implementation that cannot CSE, and the scan only runs for calls that already passed the deep-frozen gates, so there is no measurable compile-time impact (prelude release build: 17.7s before, 17.3s after). Fixes #1270 Co-Authored-By: Claude Fable 5 <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.
Summary
A dynamic dispatch call is no longer CSE'd when any of its possible callees cannot CSE (
@debugoruntracked).canCSECall's method branch used a deliberately lax per-callsite rule — "if any implementation can CSE we allow CSE" — so two identical virtual calls were merged even when the receiver could dispatch to a@debugimplementation, silently deleting its second execution:printed
kinstead ofkk(at-O0 --no-inlineas well as-O2) — the CSE-able sibling implementation (LinheritingB's trackedm) reaching the same callsite is what flipped the old rule to "allow".The fix inverts the rule: allow CSE only when every implementation the call might invoke passes
funCanCSE. TheallMethodImplementationsiteration stops at the first implementation that cannot CSE, and the scan only runs for calls that already passed the deep-frozen gates, so the cost is bounded by the concrete subtypes of the receiver's static type at eligible callsites.Fixes #1270.
Test plan
Runtime/DebugDispatchCsetest pins the repro (expectskk)@debug-only callsites behave as before🤖 Generated with Claude Code