Commit 66b4eb49
66b4eb49b5eeMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 10 files · ~10 modified
Description
Merge pull request #1461 from ryanseys/rs-c-hash-inspect-spacing
fix(runtime): space around => in hash inspect (Ruby 3.4+)
Details
- Commit
- 66b4eb49b5ee
- Parent
- e7797e322f1b
- Merge parent
- 933a5552703f
lib/sp_runtime.hmodifiedView file
@@ -2202,16 +2202,16 @@
22022202
tag, so we render them as `#<Object>` rather than recursing. */22032203
static const char*sp_PtrArray_inspect(sp_PtrArray*a){if(!a)return "[]";SP_GC_ROOT(a);sp_String*s=sp_String_new("[");SP_GC_ROOT(s);for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,"#<Object>");}sp_String_append(s,"]");return s->data;}22042204
/* Issue #851: Hash#inspect for typed-hash variants beyond2205-
sym_int_hash. Renders Ruby's `{"k"=>v, ...}` (string keys),2206-
`{42=>"v", ...}` (int keys), or `{:k=>v, ...}` (sym keys but2205+
sym_int_hash. Renders Ruby's `{"k" => v, ...}` (string keys),2206+
`{42 => "v", ...}` (int keys), or `{:k => v, ...}` (sym keys but22072207
non-int value, since the bare `k: v` shorthand only applies22082208
when values are inspectable as one-liners — match CRuby). */2209-
static const char*sp_StrIntHash_inspect(sp_StrIntHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_int_to_s(sp_StrIntHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2209+
static const char*sp_StrIntHash_inspect(sp_StrIntHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s," => ");sp_String_append(s,sp_int_to_s(sp_StrIntHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}22102210
/* Hash#to_proc lookup fn — cap is the hash, args[0] the string key. */22112211
static mrb_int sp_StrIntHash_proc_fn(void *cap, mrb_int argc, mrb_int *args) { if (argc < 1) return 0; return sp_StrIntHash_get((sp_StrIntHash *)cap, (const char *)(uintptr_t)args[0]); }2212-
static const char*sp_StrStrHash_inspect(sp_StrStrHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_str_inspect(sp_StrStrHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2213-
static const char*sp_IntStrHash_inspect(sp_IntStrHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_int_to_s(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_str_inspect(sp_IntStrHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2214-
static const char*sp_IntIntHash_inspect(sp_IntIntHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_int_to_s(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_int_to_s(sp_IntIntHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2212+
static const char*sp_StrStrHash_inspect(sp_StrStrHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s," => ");sp_String_append(s,sp_str_inspect(sp_StrStrHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2213+
static const char*sp_IntStrHash_inspect(sp_IntStrHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_int_to_s(h->order[i]));sp_String_append(s," => ");sp_String_append(s,sp_str_inspect(sp_IntStrHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}2214+
static const char*sp_IntIntHash_inspect(sp_IntIntHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_int_to_s(h->order[i]));sp_String_append(s," => ");sp_String_append(s,sp_int_to_s(sp_IntIntHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}22152215
/* Nested-array inspect: when codegen knows the ptr_array's element22162216
type is one of the four built-in T_array shapes, recurse into the22172217
matching primitive inspect . */@@ -4074,7 +4074,7 @@
40744074
static void sp_StrPolyHash_clear(sp_StrPolyHash*h){if(!h)return;for(mrb_int i=0;i<h->cap;i++)h->keys[i]=NULL;h->len=0;}40754075
static mrb_bool sp_StrPolyHash_eq(sp_StrPolyHash*a,sp_StrPolyHash*b){if(!a||!b)return a==b;if(a->len!=b->len)return FALSE;for(mrb_int i=0;i<a->len;i++){const char*k=a->order[i];if(!sp_StrPolyHash_has_key(b,k))return FALSE;if(!sp_poly_eq(sp_StrPolyHash_get(a,k),sp_StrPolyHash_get(b,k)))return FALSE;}return TRUE;}40764076
/* Issue #851: inspect for str_poly_hash. */4077-
static const char*sp_StrPolyHash_inspect(sp_StrPolyHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s,"=>");sp_String_append(s,sp_poly_inspect(sp_StrPolyHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}4077+
static const char*sp_StrPolyHash_inspect(sp_StrPolyHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(h){for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_str_inspect(h->order[i]));sp_String_append(s," => ");sp_String_append(s,sp_poly_inspect(sp_StrPolyHash_get(h,h->order[i])));}}sp_String_append(s,"}");return s->data;}40784078
/* Convert a narrower StrStrHash to a StrPolyHash. Needed when the40794079
analyzer widens an LV slot to sp_StrPolyHash* (e.g. later poly-value40804080
writes) but the initial RHS is a sibling narrower hash variant —@@ -4111,7 +4111,7 @@
41114111
static void sp_SymPolyHash_clear(sp_SymPolyHash*h){if(!h)return;for(mrb_int i=0;i<h->cap;i++)h->keys[i]=-1;h->len=0;}41124112
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;}41134113
/* Hash#inspect for sym_poly_hash. CRuby 4.0 renders symbol keys4114-
in shorthand: `{a: 1, b: "x"}` rather than `{:a=>1, :b=>"x"}`. */4114+
in shorthand: `{a: 1, b: "x"}` rather than `{:a => 1, :b => "x"}`. */41154115
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_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);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;}41164116
41174117
/* poly_val[sym_key]: runtime dispatch for poly receiver `[]` with symbol arg. */@@ -4447,10 +4447,10 @@
44474447
static sp_PolyArray*sp_PolyPolyHash_values(sp_PolyPolyHash*h){SP_GC_ROOT(h);sp_PolyArray*a=sp_PolyArray_new();SP_GC_ROOT(a);for(mrb_int i=0;i<h->len;i++)sp_PolyArray_push(a,h->vals[h->order[i]]);return a;}44484448
static sp_PolyPolyHash*sp_PolyPolyHash_dup(sp_PolyPolyHash*h){sp_PolyPolyHash*r=sp_PolyPolyHash_new();for(mrb_int i=0;i<h->len;i++)sp_PolyPolyHash_set(r,h->keys[h->order[i]],h->vals[h->order[i]]);return r;}44494449
/* Issue #738: poly_poly_hash inspect using sp_poly_inspect on each4450-
k,v. Output mirrors Ruby's `{k=>v, ...}` for non-symbol keys and4450+
k,v. Output mirrors Ruby's `{k => v, ...}` for non-symbol keys and44514451
`{k: v, ...}` shorthand for symbol keys. */44524452
static const char *sp_poly_inspect(sp_RbVal v);4453-
static const char*sp_PolyPolyHash_inspect(sp_PolyPolyHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(!h){sp_String_append(s,"}");return s->data;}for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_RbVal k=h->keys[h->order[i]];if(k.tag==SP_TAG_SYM){sp_String_append(s,sp_sym_to_s((sp_sym)k.v.i));sp_String_append(s,": ");}else{sp_String_append(s,sp_poly_inspect(k));sp_String_append(s,"=>");}sp_String_append(s,sp_poly_inspect(h->vals[h->order[i]]));}sp_String_append(s,"}");return s->data;}4453+
static const char*sp_PolyPolyHash_inspect(sp_PolyPolyHash*h){SP_GC_ROOT(h);sp_String*s=sp_String_new("{");SP_GC_ROOT(s);if(!h){sp_String_append(s,"}");return s->data;}for(mrb_int i=0;i<h->len;i++){if(i>0)sp_String_append(s,", ");sp_RbVal k=h->keys[h->order[i]];if(k.tag==SP_TAG_SYM){sp_String_append(s,sp_sym_to_s((sp_sym)k.v.i));sp_String_append(s,": ");}else{sp_String_append(s,sp_poly_inspect(k));sp_String_append(s," => ");}sp_String_append(s,sp_poly_inspect(h->vals[h->order[i]]));}sp_String_append(s,"}");return s->data;}44544454
/* Issue #738: Hash#invert -- swap keys and values. Returns a44554455
poly_poly_hash so any (key, value) pair shape is uniformly44564456
representable. str_str_hash_invert lives above (line ~1132)test/bundle_tiny_array.rb.expectedmodifiedView file
Loading diff…
test/hash_block_methods_variants.rb.expectedmodifiedView file
Loading diff…
test/hash_delete_if_select_reject_bang.rb.expectedmodifiedView file
Loading diff…
test/hash_inspect_poly.rb.expectedmodifiedView file
Loading diff…
test/hash_invert.rb.expectedmodifiedView file
Loading diff…
test/hash_replace_variants.rb.expectedmodifiedView file
Loading diff…
test/hash_transform_keys_cross.rb.expectedmodifiedView file
Loading diff…
test/int_array_tally.rb.expectedmodifiedView file
Loading diff…
test/typed_hash_inspect_and_each_value.rb.expectedmodifiedView file
Loading diff…