Commit 10437959
1043795935b5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · ~4 modified
Description
fix(analyze,codegen): endless range + send-with-symbol + sym-valued sym hash typing
Followup to the earlier #555 commit (085fc41), extending the covered cases from 9 to 10:
Case 12: (1..).send(:include?, 2.4) == true. Two pieces:
- RangeNode compile: when @nd_left / @nd_right is -1 (or
NilNode), emit INT64_MIN / INT64_MAX sentinels so
Range#include? / #cover? lower correctly. Iteration
over an endless range is still an infinite loop (not
special-cased).
- send dispatch: in compile_call_expr, detect
`recv.send(:sym_name, args...)` and temporarily mutate
@nd_name + @nd_args to make the dispatch see the
direct call signature, then restore. This routes
through all the existing typed-receiver / built-in /
poly-recv dispatch machinery rather than duplicating
it for the send shape.
Symbol-valued sym-keyed hash typing: {foo: :bar} was
falling through to str_int_hash (the bottom-of-function
default) because infer_hash_val_type's sym_int_hash arm
only accepted int / bool / nil values. Symbols lower to
mrb_int storage (sym ids), so adding "symbol" to that arm
is sound and consistent with the existing sym_int_hash
layout. Mirrored in analyze and codegen.
Cases remaining: 07 (Array#dig over heterogeneous poly_array
of hashes -- the dig dispatch on a poly element falls
through to nil; symbol-valued hash typing helps the
standalone hash case but the array-of-hash dispatch needs
the dig branches plus poly value materialization), and 11
(=~ returns pos+1 sentinel; load-bearing for the existing
truthiness convention at position 0, so 0-indexed semantics
would need =~ to return poly int|nil which is a separate,
larger change).
Refs #555
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 1043795935b5
- Parent
- d6eb4b9bf36b
spinel_analyze.rbmodifiedView file
end return "str_str_hash" end if all_sym_keys == 1 && (first_vt == "int" || first_vt == "bool" || first_vt == "nil") if all_sym_keys == 1 && (first_vt == "int" || first_vt == "bool" || first_vt == "nil" || first_vt == "symbol") return "sym_int_hash" end # Every value already inferred as poly (the slot wasspinel_codegen.rbmodifiedView file
Loading diff…
test/equality_should_be_true.rbmodifiedView file
Loading diff…
test/equality_should_be_true.rb.expectedmodifiedView file
Loading diff…