Commit 007f6c7f
007f6c7ff3f3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · ~3 modified
Description
feat(runtime,analyze,codegen): scalar-nullable scaffolding for int?
Adds the foundation for sentinel-encoded nullable scalar types. The existing T? notation already drives nullable pointer types via NULL (is_nullable_pointer_type); scalars need a different encoding because NULL has no analogue on a bit pattern that's also a valid value.
-
Runtime: SP_INT_NIL = INT64_MIN, with sp_int_is_nil(v) macro. INT64_MIN was chosen because Ruby auto-promotes 2**63 to Bignum (the #597 limitation), so the reserved value falls outside the range spinel already declines to handle on the fast path. Future siblings: SP_FLOAT_NIL (likely struct-based, NaN-tagging deferred), SP_SYM_NIL (sym_id == 0), bool? (3-valued enum). Documented at the typedef site.
-
Analyze + codegen: is_scalar_nullable_type(t) returns 1 for int? (today) and is the call-site test that separates "this nullable uses NULL" from "this nullable uses a sentinel." Keeps is_nullable_pointer_type's existing list untouched so already- landed callers that branch on it continue to mean "NULL-based."
No call sites consume int? yet. This is the scaffolding the next commit (Array#index returning int? instead of poly-widened sp_RbVal) builds on. 582 tests still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 007f6c7ff3f3
- Parent
- 8bcde2a736cf
lib/sp_runtime.hmodifiedView file
typedef int64_t mrb_int;typedef double mrb_float;typedef bool mrb_bool;/* Sentinel value reserved by the int? (scalar-nullable int) type. An int? slot is bit-compatible with mrb_int; SP_INT_NIL marks the "nil" inhabitant. The chosen pattern is INT64_MIN, which Ruby's Integer would auto-promote to Bignum (#597 limitation), so the reservation lines up with spinel's existing fast-path-only spec. `sp_int_is_nil(v)` is the canonical predicate; treat any int? value produced by runtime helpers as opaque outside this macro. */#define SP_INT_NIL ((mrb_int)INT64_MIN)#define sp_int_is_nil(v) ((v) == SP_INT_NIL)/* sp_sym is defined per-program in emit_sym_runtime, but poly helpers below need to reference it by forward declaration. */typedef mrb_int sp_sym;spinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…