fix(codegen): the Float64Array region guard reads the receiver's storage byte - #11819
Merged
Merged
Conversation
added 2 commits
October 3, 2026 17:48
…age byte #10516 removed the process-wide PERRY_TA_VIEW_GUARD in favour of the typed array header's own storage byte (header byte 10, TA_STORAGE_INLINE). The typed region guard added by #10741, merged after it, still loaded the removed global, so any module whose counted loop admitted a receiver not declared a plain Array (a Float64Array, but equally a Buffer) left @PERRY_TA_VIEW_GUARD undefined and failed LLVM IR parsing. Read the storage byte like the other #10516 sites. The existing #10741 test asserted on the IR text, which cannot see a reference to a symbol nothing declares; the new test also runs the module through LLVM.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (2)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Oct 3, 2026
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.
Symptom
Compiling OpenCode v1.18.30 on
main(Linux x86_64) fails four modules in codegen, all with the same LLVM IR parse error:The modules:
packages/opencode/src/id/id.ts,@jridgewell/resolve-uri's UMD bundle, and two@smithyCJS bundles. The build then aborts with "4 module(s) failed to compile".Cause
Two changes crossed on
main:748cefbb7f, "the header says where elements live, not a global view count") removed the process-widePERRY_TA_VIEW_GUARD— its runtime definition and itsruntime_declsdeclaration. Every reader was switched to the receiver's own storage byte: header byte 10,TA_STORAGE_INLINE= 0.63d69c9639) addedemit_typed_f64_region_guard, theFloat64Arraytwin of the dense-array region guard, and it still loads@PERRY_TA_VIEW_GUARD. It merged after perf: one ArrayBuffer-aliasing view anywhere, even a dead one, makes all typed-array access 81× slower than Node (process-global PERRY_TA_VIEW_GUARD) #10516, so it references a symbol that no longer exists anywhere.It is not limited to
Float64Arraycode. Any counted loop whose receiver is not declared a plainArraytakes this guard, so a plainBuffertriggers it —id.tshas no typed array at all, onlyBuffer.alloc(6)andrandomBytes(n)in twoforloops. At run time such a receiver fails the guard's kind check and takes the slow path, but the IR still names the missing global, so the module never compiles.Re-declaring the global would be wrong: the runtime no longer defines it, and a stub of 0 would tell the guard that every typed array uses inline storage, including views, whose elements are not at
header + 16.Fix
Read the receiver's storage byte, exactly as the other #10516 sites do (
inline_dyn_typed_array.rs,property_get.rs):load i8atheader + 10, inline storage when it is 0. The offset is the runtime's#[repr(C)] TypedArrayHeaderlayout (length@0, capacity@4, kind@8, elem_size@9, storage@10), which that struct documents as part of the codegen contract.Test
The existing #10741 test,
a_float64array_receiver_reads_canonicalise_nan, generates exactly this guard but asserts only on IR text, so it could not see a reference to an undeclared symbol. The newa_typed_region_guard_names_only_symbols_that_existbuilds the region loop for aFloat64Arrayand for aBufferreceiver. It first asserts that the loop really takes the typed guard (rloop.ta), so it cannot pass vacuously; then it asserts that the guard does not name the removed global; then it runs the module through LLVM (testing::verify_ir).guarded_array.rsreverted: fails at the global assertion, with the precondition holding.guarded_array.rsreverted and the text assertion removed: the LLVM check alone fails with the production error,use of undefined value '@PERRY_TA_VIEW_GUARD'. So the verifier covers the whole class — any symbol the generated code names but nothing defines — not just this one name.cargo fmt --all -- --checkis clean. This is independent of #11817; together the two take the OpenCode build through codegen. The changelog fragment follows once this PR has a number.