Commit 04174a70

04174a708e87Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

docs(hash-nullable): note sym-valued hash currently falls through to *PolyHash

Details

Commit
04174a708e87
Parent
cefccdef2a2a

docs/HASH-NULLABLE.mdmodifiedView file

@@ -51,6 +51,24 @@
5151 | `IntStrHash` | `NULL` | `string` |
5252 | `*PolyHash` | (unchanged) | `poly` (already nullable via box_nil) |
5353
54+### Sym-valued hashes
55+
56+spinel currently has no dedicated `*SymHash` variant (no `sym_sym_hash`,
57+`str_sym_hash`, or `int_sym_hash`). Hash literals with symbol values
58+(e.g. `{a: :x}`) infer as `sym_poly_hash` / `str_poly_hash` etc. and
59+box symbols into `sp_RbVal` (SP_TAG_SYM) -- so missing-key already
60+returns `sp_box_nil()`, Ruby-compatible.
61+
62+If a future memory-optimization Phase introduces dedicated
63+`*SymHash` variants (sp_sym = mrb_int storage, 8 bytes/entry vs
64+sp_RbVal's 16 bytes), the natural nil sentinel is
65+`((sp_sym)-1)` -- which already serves as `c_default_val("symbol")`
66+in spinel_codegen.rb. The intern table's index 0 is reserved for
67+the first symbol, so -1 is unambiguously "no symbol". A
68+`sym?` scalar-nullable type would follow the same shape as
69+`int?` (sentinel-based, not pointer-based), gated on
70+`is_scalar_nullable_type`. Out of scope for the current rollout.
71+
5472 ## Call-site Audit
5573
5674 ### Internal-safe callers (no change needed)