Skip to content

feat(stable-api): add RB_OBJ_WRITE and RB_OBJ_WRITTEN for GC write barrier#678

Draft
ianks wants to merge 4 commits intomainfrom
feat/stable-api-write-barrier
Draft

feat(stable-api): add RB_OBJ_WRITE and RB_OBJ_WRITTEN for GC write barrier#678
ianks wants to merge 4 commits intomainfrom
feat/stable-api-write-barrier

Conversation

@ianks
Copy link
Collaborator

@ianks ianks commented Dec 14, 2025

Summary

Batch 3 of the stable API implementation plan - Adds GC write barrier methods RB_OBJ_WRITE and RB_OBJ_WRITTEN to the Stable API.

These methods are critical for maintaining GC correctness when storing VALUE references from one heap object to another. This is a prerequisite for Batch 6 (RARRAY_ASET).

⚠️ Draft Status: Ready for review but marking as draft to coordinate with other batches.

Changes

  • stable_api.rs: Added rb_obj_write() and rb_obj_written() methods to StableApiDefinition trait
  • Implementations: Version-specific implementations for all 7 Ruby versions (2.7, 3.0-3.4, 4.0)
    • Calls rb_gc_writebarrier() and rb_gc_writebarrier_unprotect() internally
    • Direct FFI bindings for better performance
  • Fallback support: C fallback in compiled.c and Rust wrapper in compiled.rs
  • Public API: RB_OBJ_WRITE and RB_OBJ_WRITTEN macro wrappers in macros.rs
  • Tests: Comprehensive parity tests in stable_api_test.rs

Testing

All tests pass successfully ✅

Related Issues

Checklist

  • Code follows project style guide
  • All tests pass
  • Documentation included
  • No breaking changes

@ianks ianks force-pushed the feat/stable-api-write-barrier branch from 9b07443 to fdd1294 Compare December 15, 2025 19:54
@eregon
Copy link

eregon commented Jan 24, 2026

This looks good to me, is there anything I can do to help move this forward?
It's a blocker for truffleruby/truffleruby#3396

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.

2 participants