feat(stable-api): add RARRAY_AREF and RARRAY_ASET with write barrier#682
Draft
feat(stable-api): add RARRAY_AREF and RARRAY_ASET with write barrier#682
Conversation
…rrier Implements #447 - Add rb_obj_write() and rb_obj_written() to StableApiDefinition trait - Implement for Ruby 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0 - Add C fallback implementations in compiled.c - Add FFI wrappers in compiled.rs - Add public RB_OBJ_WRITE and RB_OBJ_WRITTEN macro wrappers - Add comprehensive tests These write barrier methods are critical for GC correctness when storing VALUE references from one heap object to another. They prevent premature collection of young objects referenced by old objects in the generational GC. This is a prerequisite for implementing RARRAY_ASET in batch 6.
Implements #671 - Add rarray_aref() and rarray_aset() to StableApiDefinition trait - Implement for Ruby 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0 - RARRAY_ASET uses rb_gc_writebarrier for GC correctness - Add C fallback in compiled.c - Add FFI wrappers in compiled.rs - Add public RARRAY_AREF and RARRAY_ASET macros - Add comprehensive parity tests - Add show-asm entries for assembly analysis Depends on write barrier implementation from batch3.
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
Batch 6 of the stable API implementation plan - Adds array access methods to the Stable API:
RARRAY_AREF- Get element from array by indexRARRAY_ASET- Set element in array by index (with GC write barrier)RARRAY_ASETrequiresRB_OBJ_WRITEfor GC safety.Changes
rarray_aref()andrarray_aset()methods toStableApiDefinitiontraitRARRAY_AREF: Direct pointer access viararray_const_ptr(obj).offset(idx)RARRAY_ASET: UsesRB_OBJ_WRITEfor GC safety - critical for correctness!compiled.cand Rust wrapper incompiled.rsRARRAY_AREFandRARRAY_ASETmacro wrappers inmacros.rsstable_api_test.rsTesting
All tests pass successfully ✅
Dependencies
Related Issues
StableApiDefinitionGC methods #447 (RB_OBJ_WRITE)Checklist