Repository navigation
DFG DOMJIT: fix attemptToMakeCallDOM predicates and restore typed-array/Int52 lowering #318
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
Open
robobun
wants to merge
2
commits into
main
Choose a base branch
from
robobun/domjit-fixup-and-dfg-lowering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
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.
🟡 The Int52 profitability mask at line 5343 tests
SpecInt32Only | SpecInt52Any, but at Fixup time a large integer argument (e.g.2**40) is profiled asSpecAnyIntAsDouble(bit 41) — neverSpecInt52Any(bits 39|40), which only appears onNodeResultInt52nodes after Fixup insertsInt52Rep. So a pure-large-int argument setsshouldConvertToCallDOM = falseand skips the DOMJIT fast path even thoughfixEdge<Int52RepUse>handlesSpecAnyIntAsDoublefine. Consider usingSpecIntAnyFormat(SpeculatedType.h:107) as the mask — the case-label list here already includesSpecAnyIntAsDouble, which suggests the body should accept it too.Extended reasoning...
What the issue is
Now that 1f1383b restructures the
doToChildrenlambda so++indexruns on every child, the profitability switch at DFGFixupPhase.cpp:5312 actually executes for the first time. The Int52 group (lines 5339-5346) tests:But at Fixup time the argument is still a raw
Call-node varargs child (aGetLocal/JSConstant/ etc.) whoseprediction()comes from bytecode value profiling. TheSpecInt52Anybits (39|40, SpeculatedType.h:92-94) only ever appear on nodes withNodeResultInt52— i.e. after Fixup has inserted anInt52Repconversion. Value profiles never produce them:speculationFromValue()(SpeculatedType.cpp:631-635) sees a large integer as a double-boxedJSValueand returnsSpecAnyIntAsDouble(bit 41), andSpecHeapTopexcludesSpecInt52Anyentirely.Step-by-step example
Take a bun:ffi reader whose argument was consistently observed as
2**40(a pointer-sized value):2**40is boxed as a doubleJSValue;speculationFromValue()returnsSpecAnyIntAsDouble(1ull << 41).attemptToMakeCallDOM, the argument edge points to aGetLocalwithprediction() == SpecAnyIntAsDouble.SpecInt32Only | SpecInt52Any= bits 34-40.SpecAnyIntAsDouble & (SpecInt32Only | SpecInt52Any)= 0.edge->prediction()is nonzero and the AND is zero →shouldConvertToCallDOM = false.false; the node stays a plainCalland never gets the DOMJIT fast path.Note that
fixEdge<Int52RepUse>infixupCallDOMhandlesSpecAnyIntAsDoublejust fine — it insertsInt52Rep(AnyIntUse), which converts an integral double to Int52 without a guaranteedBadTypeexit. So the profitability check is stricter than what the lowering actually requires. The case-label list itself already includesSpecAnyIntAsDouble(line 5342), which is a self-consistency signal that the mask should accept it.Why nothing else prevents it
SpecIntAnyFormat(SpeculatedType.h:107) =SpecInt52Any | SpecInt32Only | SpecAnyIntAsDoubleexists precisely for this "integer in any representation" test, andisIntAnyFormat()(line 417) is the corresponding predicate. The mask here just omits the third component. Mixed predictions that include anySpecInt32Onlybit (e.g. an argument observed as both small and large integers) still pass because the test is any-overlap, so this only bites the pure-large-int case — which is exactly the shape a bun:ffi pointer/offset argument would have.Impact
Not a correctness bug — the call falls back to a plain
Call, so behavior is identical, just slower. Not a runtime regression vs.maineither, since (a) this switch was dead code before 1f1383b, and (b) argument-bearing DOMJIT signatures are currently disabled in Bun. But the PR's stated purpose is to "unblock re-enabling argument-bearing DOMJIT signatures" and specifically calls outSpecInt52Any(bun:ffi readers); once those are re-enabled, this mask will keep the pure-large-int case on the slow path.Suggested fix
Replace the mask with
SpecIntAnyFormat:or equivalently gate on
!isIntAnyFormat(edge->prediction())/!edge->shouldSpeculateInt52(), matching whatInt52RepUsefixup can convert.