Skip to content

feat(stable-api): add RARRAY_AREF and RARRAY_ASET with write barrier#682

Draft
ianks wants to merge 3 commits intomainfrom
feat/stable-api-rarray
Draft

feat(stable-api): add RARRAY_AREF and RARRAY_ASET with write barrier#682
ianks wants to merge 3 commits intomainfrom
feat/stable-api-rarray

Conversation

@ianks
Copy link
Collaborator

@ianks ianks commented Dec 14, 2025

Summary

Batch 6 of the stable API implementation plan - Adds array access methods to the Stable API:

  • RARRAY_AREF - Get element from array by index
  • RARRAY_ASET - Set element in array by index (with GC write barrier)

⚠️ Draft Status: This PR depends on Batch 3 (PR #678) being merged first, as RARRAY_ASET requires RB_OBJ_WRITE for GC safety.

Changes

  • stable_api.rs: Added rarray_aref() and rarray_aset() methods to StableApiDefinition trait
  • Implementations: Version-specific implementations for all 7 Ruby versions (2.7, 3.0-3.4, 4.0)
    • RARRAY_AREF: Direct pointer access via rarray_const_ptr(obj).offset(idx)
    • RARRAY_ASET: Uses RB_OBJ_WRITE for GC safety - critical for correctness!
  • Fallback support: C fallback in compiled.c and Rust wrapper in compiled.rs
  • Public API: RARRAY_AREF and RARRAY_ASET macro wrappers in macros.rs
  • Tests: Comprehensive parity tests in stable_api_test.rs

Testing

All tests pass successfully ✅

Dependencies

⚠️ Requires PR #678 (Batch 3: Write Barrier) to be merged first

Related Issues

Checklist

  • Code follows project style guide
  • All tests pass
  • Documentation included
  • No breaking changes
  • Uses RB_OBJ_WRITE for GC safety

…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.
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