Skip to content

fix(codegen): the Float64Array region guard reads the receiver's storage byte - #11819

Merged
proggeramlug merged 2 commits into
mainfrom
fix/typed-region-guard-storage-byte
Oct 3, 2026
Merged

proggeramlug merged 2 commits into
mainfrom
fix/typed-region-guard-storage-byte

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Symptom

Compiling OpenCode v1.18.30 on main (Linux x86_64) fails four modules in codegen, all with the same LLVM IR parse error:

error: use of undefined value '@PERRY_TA_VIEW_GUARD'
  %r96 = load i64, ptr @PERRY_TA_VIEW_GUARD

The modules: packages/opencode/src/id/id.ts, @jridgewell/resolve-uri's UMD bundle, and two @smithy CJS bundles. The build then aborts with "4 module(s) failed to compile".

Cause

Two changes crossed on main:

It is not limited to Float64Array code. Any counted loop whose receiver is not declared a plain Array takes this guard, so a plain Buffer triggers it — id.ts has no typed array at all, only Buffer.alloc(6) and randomBytes(n) in two for loops. 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 i8 at header + 10, inline storage when it is 0. The offset is the runtime's #[repr(C)] TypedArrayHeader layout (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 new a_typed_region_guard_names_only_symbols_that_exist builds the region loop for a Float64Array and for a Buffer receiver. 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).

  • With the fix: passes.
  • With guarded_array.rs reverted: fails at the global assertion, with the precondition holding.
  • With guarded_array.rs reverted 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 -- --check is 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.

Ralph Küpper 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.
@coderabbitai

coderabbitai Bot commented Oct 3, 2026

Copy link
Copy Markdown

Review in Change Stack →

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
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2b16cde6-acee-442a-aaaa-3915b4c728e2
📥 Commits

Reviewing files that changed from the base of the PR and between 0ed699b and 26f865f.

📒 Files selected for processing (2)
  • crates/perry-codegen/src/expr/index_get/guarded_array.rs
  • crates/perry-codegen/src/expr/region_array_loop_tests.rs
 ________________________________________________________________
< This is the kind of code that makes on-call believe in ghosts. >
 ----------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant