Commit 3f45b243
3f45b24309c5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 5 files · +2 added · ~3 modified
Description
fix(analyze,codegen,runtime): sym_str_hash + sym_poly_hash method dispatch
Closes #510. sym_str_hash and sym_poly_hash both got the
right type tag at analyze time but the codegen dispatch had no
arms for merge / fetch / dup / delete — every call
emitted 0 with a "cannot resolve call to '' on sym__hash"
warning. Roundhouse hits this for the runtime/active_record
adapter swap path.
Coverage added:
| Method | sym_str_hash | sym_poly_hash |
|---|---|---|
| merge | runtime helper + dispatch | already had partial; unchanged |
| fetch | already worked | dispatch + analyze infers poly return |
| dup | dispatch (helper already emitted) | dispatch |
| delete | dispatch (helper already emitted) | runtime helper + dispatch |
Coordinated changes:
- codegen emit_raw at sym_str_hash helper setup: new sp_SymStrHash_merge alongside the existing _dup / _delete.
- lib/sp_runtime.h: new sp_SymPolyHash_delete (probe-chain removal, mirrors the str_str_hash and sym_str_hash patterns; re-tombstones with sp_box_nil() since values are sp_RbVal).
- codegen dispatch: merge / dup / delete arms added to the recv_type == "sym_str_hash" block, and fetch / dup / delete arms to the recv_type == "sym_poly_hash" block. fetch's default arg goes through box_expr_to_poly so the ternary's arms agree on sp_RbVal.
- analyze fetch inference:
str_poly_hash/sym_poly_hash/poly_poly_hashreceivers return "poly" (the get arm returns sp_RbVal); without this, the receiving LV slot stayed at int and the C compile rejected the assignment.
Local: 482 tests pass, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 3f45b24309c5
- Parent
- 333ea25766f2
lib/sp_runtime.hmodifiedView file
@@ -1435,6 +1435,10 @@
14351435
static sp_IntArray*sp_SymPolyHash_keys(sp_SymPolyHash*h){sp_IntArray*a=sp_IntArray_new();for(mrb_int i=0;i<h->len;i++)sp_IntArray_push(a,(mrb_int)h->order[i]);return a;}14361436
static sp_PolyArray*sp_SymPolyHash_values(sp_SymPolyHash*h){sp_PolyArray*a=sp_PolyArray_new();for(mrb_int i=0;i<h->len;i++)sp_PolyArray_push(a,sp_SymPolyHash_get(h,h->order[i]));return a;}14371437
static sp_SymPolyHash*sp_SymPolyHash_merge(sp_SymPolyHash*a,sp_SymPolyHash*b){sp_SymPolyHash*r=sp_SymPolyHash_new();for(mrb_int i=0;i<a->len;i++)sp_SymPolyHash_set(r,a->order[i],sp_SymPolyHash_get(a,a->order[i]));for(mrb_int i=0;i<b->len;i++)sp_SymPolyHash_set(r,b->order[i],sp_SymPolyHash_get(b,b->order[i]));return r;}1438+
/* Hash#delete for sym_poly_hash. Removes key and re-tombstones the1439+
slot, shifting probe-chain successors backward and dropping the1440+
key from the insertion-order list. Issue #510. */1441+
static void sp_SymPolyHash_delete(sp_SymPolyHash*h,sp_sym k){mrb_int idx=(mrb_int)(((mrb_int)k)&h->mask);while(h->keys[idx]>=0){if(h->keys[idx]==k){h->keys[idx]=-1;h->vals[idx]=sp_box_nil();h->len--;mrb_int j=(idx+1)&h->mask;while(h->keys[j]>=0){mrb_int nj=(mrb_int)(((mrb_int)h->keys[j])&h->mask);if((j>idx&&(nj<=idx||nj>j))||(j<idx&&nj<=idx&&nj>j)){h->keys[idx]=h->keys[j];h->vals[idx]=h->vals[j];h->keys[j]=-1;h->vals[j]=sp_box_nil();idx=j;}j=(j+1)&h->mask;}{mrb_int oi=0;while(oi<=h->len){if(h->order[oi]==k){while(oi<h->len){h->order[oi]=h->order[oi+1];oi++;}break;}oi++;}}return;}idx=(idx+1)&h->mask;}}14381442
static sp_SymPolyHash*sp_SymPolyHash_dup(sp_SymPolyHash*h){sp_SymPolyHash*r=sp_SymPolyHash_new();for(mrb_int i=0;i<h->len;i++)sp_SymPolyHash_set(r,h->order[i],sp_SymPolyHash_get(h,h->order[i]));return r;}14391443
14401444
/* PolyPolyHash: heterogeneous keys + values (both sp_RbVal). Forspinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/sym_hash_method_dispatch.rbaddedView file
Loading diff…
test/sym_hash_method_dispatch.rb.expectedaddedView file
Loading diff…