Commit bca35c07

bca35c07ed8aMerged

Ryan Seys <[email protected]> · 6 months ago · 5 files · +2 added · ~3 modified

Description

codegen,runtime: str_poly_hash #inspect dispatch + sym_poly_hash CRuby 4 format

The str_poly_hash dispatch in compile_hash_method_expr lacked an inspect / to_s arm — h.inspect on a str-keyed poly-valued hash fell through the unresolved-call fallback. Add the arm mirroring sym_poly_hash's existing one. The runtime helper sp_StrPolyHash_inspect already exists.

sp_SymPolyHash_inspect previously rendered symbol keys with the Ruby 2.x :b=>val form, which the comment justified as a round-trip convenience. CRuby 4.0 dropped that form in favour of the shorthand {b: val, c: val}, so update the helper to match parity. test/double_splat_kwargs.rb.expected was already stale against CRuby 4 for the same reason — regenerate it.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
bca35c07ed8a
Parent
e4d2ffaa5870

lib/sp_runtime.hmodifiedView file

@@ -3039,11 +3039,9 @@
30393039 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;}}
30403040 static sp_SymPolyHash*sp_SymPolyHash_dup(sp_SymPolyHash*h){sp_SymPolyHash*r=sp_SymPolyHash_new();r->default_v=h->default_v;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;}
30413041 static mrb_bool sp_SymPolyHash_eq(sp_SymPolyHash*a,sp_SymPolyHash*b){if(!a||!b)return a==b;if(a->len!=b->len)return FALSE;for(mrb_int i=0;i<a->len;i++){sp_sym k=a->order[i];if(!sp_SymPolyHash_has_key(b,k))return FALSE;if(!sp_poly_eq(sp_SymPolyHash_get(a,k),sp_SymPolyHash_get(b,k)))return FALSE;}return TRUE;}
3042-/* Hash#inspect for sym_poly_hash. CRuby 3.4+ renders symbol keys
3043- in shorthand: `{b: 2, c: 3}` rather than `{:b=>2, :c=>3}`. We
3044- match the older `=>` form to keep round-tripping simple (callers
3045- that compare against `eval(str)` survive either way). */
3046-static const char*sp_SymPolyHash_inspect(sp_SymPolyHash*h){if(!h){char*r=sp_str_alloc_raw(3);r[0]='{';r[1]='}';r[2]=0;sp_str_set_len(r,2);return r;}sp_String*s=sp_String_new("{");for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,":");sp_String_append(s,sp_sym_to_s(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_poly_inspect(sp_SymPolyHash_get(h,h->order[i])));}sp_String_append(s,"}");return s->data;}
3042+/* Hash#inspect for sym_poly_hash. CRuby 4.0 renders symbol keys
3043+ in shorthand: `{a: 1, b: "x"}` rather than `{:a=>1, :b=>"x"}`. */
3044+static const char*sp_SymPolyHash_inspect(sp_SymPolyHash*h){if(!h){char*r=sp_str_alloc_raw(3);r[0]='{';r[1]='}';r[2]=0;sp_str_set_len(r,2);return r;}sp_String*s=sp_String_new("{");for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_sym_to_s(h->order[i]));sp_String_append(s,": ");sp_String_append(s,sp_poly_inspect(sp_SymPolyHash_get(h,h->order[i])));}sp_String_append(s,"}");return s->data;}
30473045
30483046 /* PolyPolyHash: heterogeneous keys + values (both sp_RbVal). For
30493047 primitives the hash/eql is tag-based (value equality); for OBJ tag