Repository navigation
fix(codegen): treat LLVM macOS and visionOS triples as low-address heap targets - #12247
Merged
Merged
Conversation
added 2 commits
October 9, 2026 04:58
Codegen's inline heap guards use heap_addr_lower_bound_inclusive. It matched rustc spellings (darwin, visionos) but codegen passes LLVM triples: the macOS host default is arm64-apple-macosx15.0.0 and visionOS is arm64-apple-xros1.0. Both fell to the 2 TiB floor, so every inline method, learned-word and property guard missed for heap objects below 2 TiB. mimalloc's arenas sit above 2 TiB, which hid it; Perry's own mmap regions land near 4 GiB and paid the runtime slow path on every call. The test now checks the triples codegen really emits.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (1)
✨ 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 9, 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.
Problem
perry-codegen/src/target_layout.rs::heap_addr_lower_bound_inclusivesets the lowest address that codegen's inline heap guards will dereference. It recognises "mainstream" targets by substring, but codegen passes LLVM triples rather than rustc ones:arm64-apple-macosx15.0.0(codegen/helpers.rs::default_target_triple, and--target macos), which contains neitherdarwinnorios;arm64-apple-xros1.0(--target visionos), which doesn't containvisionos.Both fall to the conservative 2 TiB floor instead of the 1 MiB handle-band floor that the runtime's
is_valid_obj_ptruses on those OSes. Every inline guard built on that floor sends any GC object below 2 TiB to the runtime slow path. That includes class-method direct calls and learned receiver words, the #620 own-method override probe, composed property ICs, inline typed-array/buffer reads and versioned indexed loops.On macOS today this is mostly hidden: mimalloc places its arenas above 2 TiB, so GC objects happen to clear the floor. Anything that puts GC memory below 2 TiB pays the slow path on every call. That includes OS-backed GC regions, which land near 4 GiB on macOS, and libsystem-malloc allocations on visionOS.
Evidence
The bug was found while investigating why Perry-owned mmap GC regions regressed on macOS (portable region branch vs #12132, same generated program code).
sampleprofile on symbolized builds:js_object_get_own_field_or_undefwent from 0% to 7.6% of leaf samples on Commander, withlearn_absent_method_wordandfrom_utf8appearing.js_object_get_own_field_or_undef_learnwas called 24,300 times vs 42 on gc: Perry-owned memory for GC arena blocks (2 MiB OS regions, huge pages by complete units) #12132.js_native_call_method_by_id_learnwas called 7,200 vs 2 times. On Zod (50 iterations) it was 1,850 vs 60.(class_id, ShapeId)word and the header was a plainGC_TYPE_OBJECT. The only failing input was the address gate (0x1_05a7_74e8< 2 TiB; on mimalloc the same receiver sat at0x34c_d52a_74e8).Change
heap_addr_lower_bound_inclusivealso matchesmacosandxros.heap_address_floor_covers_emitted_tripleschecks the floor for the triples codegen really emits:default_target_triple()andresolve_target_triple()for every public--targetname. HarmonyOS keeps the 2 TiB floor, as before.arm64-apple-macosx15.0.0.Linux, Android, Windows, iOS, tvOS, watchOS and WASI triples already matched, so their generated code is unchanged.
Validation
cargo test --release -p perry-codegen --lib: 2,104 passed, 0 failed, 1 ignored. The new test is included.rustfmt --checkis clean.No version bump.