Skip to content

Conversation

@ianks
Copy link
Collaborator

@ianks ianks commented Dec 14, 2025

Summary

Adds the fl_able() method to the Stable API for checking if an object can have flags set. This is Batch 1 of the stable API implementation plan and provides the foundation for flag operations (Batch 2: FL_TEST, FL_SET, FL_UNSET).

The fl_able() method returns false for immediate values (nil, true, false, Fixnum, Symbol, Flonum) which don't have flag storage in the Ruby object header, and true for heap objects that can have flags.

Changes

  • stable_api.rs: Added fl_able() method to StableApiDefinition trait
  • Implementations: Version-specific implementations for all 7 Ruby versions (2.7, 3.0-3.4, 4.0)
    • Uses !special_const_p() from the Ruby C API
    • Direct FFI bindings for better performance
  • Fallback support: C fallback in compiled.c and Rust wrapper in compiled.rs using RB_FL_ABLE
  • Public API: FL_ABLE macro wrapper in macros.rs with comprehensive documentation
  • Tests: 7 parity tests in stable_api_test.rs covering all immediate types and heap objects
    • Tests verify correct behavior for nil, true, false, Fixnum, Symbol, Flonum (false cases)
    • Tests verify true cases for String, Array, Hash, Object instances

Testing

All tests pass successfully:

✓ fl_able tests for all immediate types
✓ fl_able tests for heap-allocated objects

Related Issues

Foundation for:

  • Batch 2: FL_TEST, FL_SET, FL_UNSET operations
  • Full stable API for Ruby flag manipulation

Checklist

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

Implements #674

- Add fl_able() to StableApiDefinition trait
- Implement for Ruby 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0
- Add C fallback in compiled.c
- Add public FL_ABLE macro wrapper
- Add parity tests

This is the foundation method for flag operations.
@ianks ianks marked this pull request as draft December 14, 2025 20:18
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