Commit a6d2bd93
a6d2bd938dedMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(analyze,codegen): hash literal int/bigint values share sym_int_hash storage
Under promote mode {x:, sum: 18} (x is bigint LV, 18 is int literal)
inferred as sym_poly_hash via the "mixed value types" branch, while
scan_locals declared the LV slot as sym_int_hash from the initial
all-int snapshot. set_var_type then widened the codegen-side tracked
type to sym_poly_hash on the write, but the C declaration stayed
sp_SymIntHash * -- read sites dispatched as sym_poly_hash and the
cast (sp_SymPolyHash *)(lv) over a SymIntHash payload was UB.
Treat int and bigint as numerically compatible in the all_same check of both infer_hash_val_type (codegen) and infer_hash_val_type_raw (analyze). They lower to the same mrb_int slot storage with sp_bigint_to_int at set/get boundaries. The two-side parity prevents the analyze cache from disagreeing with the codegen literal emit.
Picks up hash_shorthand under promote.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- a6d2bd938ded
- Parent
- 6f40f601bd2a
spinel_analyze.rbmodifiedView file
eid = elems[0] if @nd_type[eid] == "AssocNode" first_vt = infer_type(@nd_expression[eid]) # Check if all values have the same type # Same int/bigint normalization as the codegen-side # infer_hash_val_type: both lower to mrb_int hash storage with # sp_bigint_to_int at the boundaries. first_vt_norm = (first_vt == "bigint") ? "int" : first_vt all_same = 1 k = 1 while k < elems.length eid2 = elems[k] if @nd_type[eid2] == "AssocNode" vt2 = infer_type(@nd_expression[eid2]) if vt2 != first_vt vt2_norm = (vt2 == "bigint") ? "int" : vt2 if vt2_norm != first_vt_norm all_same = 0 end end if all_sym_keys == 1 && (first_vt == "int" || first_vt == "bool" || first_vt == "nil") return "sym_int_hash" end # promote-mode bigint values map onto sym_int_hash storage by # unboxing each bigint via sp_bigint_to_int at the codegen # set/get sites (mirrors the codegen-side infer_hash_val_type). # Keeping the analyzer/codegen inferences aligned avoids a # set_var_type widening to sym_poly_hash that would mis-cast # the SymIntHash slot at read sites. if all_sym_keys == 1 && first_vt == "bigint" return "sym_int_hash" end # Symbol values get sym_poly_hash storage so dig / lookup # preserves the sp_TAG_SYM tag (sym_int_hash would # round-trip through mrb_int and lose the symbol-ness).spinel_codegen.rbmodifiedView file
Loading diff…