Skip to content

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

Merged
ianks merged 1 commit into
mainfrom
feat/stable-api-rarray
Apr 20, 2026
Merged

feat(stable-api): add RARRAY_AREF and RARRAY_ASET with write barrier#682
ianks merged 1 commit into
mainfrom
feat/stable-api-rarray

Conversation

@ianks

@ianks ianks commented Dec 14, 2025

Copy link
Copy Markdown
Collaborator

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

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.
@ianks ianks force-pushed the feat/stable-api-rarray branch from 3a2bd15 to f81356f Compare April 20, 2026 03:44
@ianks ianks marked this pull request as ready for review April 20, 2026 03:44
@ianks ianks merged commit 8854489 into main Apr 20, 2026
61 checks passed
@ianks ianks deleted the feat/stable-api-rarray branch April 20, 2026 03:59
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