Skip to content

Conversation

@ianks
Copy link
Collaborator

@ianks ianks commented Dec 14, 2025

Summary

Batch 7 of the stable API implementation plan - Adds Symbol/ID conversion methods to the Stable API:

  • RB_ID2SYM - Convert ID to Symbol
  • RB_SYM2ID - Convert Symbol to ID

These methods handle both static symbols (tagged pointers) and dynamic symbols (heap-allocated).

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

Changes

  • stable_api.rs: Added id2sym() and sym2id() methods to StableApiDefinition trait
  • Implementations: Version-specific implementations for all 7 Ruby versions (2.7, 3.0-3.4, 4.0)
    • Static symbols: Tagged pointers (id << 8) | 0x0c
    • Dynamic symbols: Heap-allocated, struct access
    • id2sym is safe (just bit manipulation)
    • sym2id is unsafe (may access heap for dynamic symbols)
  • Fallback support: C fallback in compiled.c and Rust wrapper in compiled.rs
  • Public API: RB_ID2SYM and RB_SYM2ID 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

Implements #669

- Add id2sym to StableApiDefinition for ID2SYM/RB_ID2SYM
- Add sym2id to StableApiDefinition for SYM2ID/RB_SYM2ID
- Handle both static symbols (tagged pointers) and dynamic symbols
- Implement for Ruby 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0
- Add C fallbacks in compiled.c using ID2SYM and SYM2ID macros
- Add FFI wrappers in compiled.rs
- Add public macro wrappers (ID2SYM, SYM2ID, RB_ID2SYM, RB_SYM2ID)
- Add comprehensive parity tests and functional tests
@ianks ianks marked this pull request as ready for review December 14, 2025 21:21
@ianks ianks merged commit d6ef5d9 into main Dec 14, 2025
61 checks passed
@ianks ianks deleted the feat/stable-api-symbol branch December 14, 2025 21:21
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