Commit 73905e7e
73905e7e5796Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): bigint widening only when recv is numeric
@arr_of_int_arrays[i] << v (v promoted bigint LV) emitted
sp_bigint_shl on sp_IntArray * recv because the legacy lt
widening fired on any non-bigint recv. The bigint dispatch only
makes sense when recv itself is numeric (int / float / bigint
plus nullable variants). Typed containers, strings, poly, etc.
have their own per-type dispatch arms further down.
Promote-mode test: +1 (558 -> 559). Default 631/0/0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 73905e7e5796
- Parent
- da759d8ac0eb
spinel_codegen.rbmodifiedView file
@@ -15627,21 +15627,23 @@
1562715627
def compile_operator_expr(nid, mname, recv)1562815628
# Bigint operators1562915629
lt = infer_type(recv)15630-
# Don't widen lt to "bigint" via the arg-side promote when the15631-
# recv is genuinely poly — the poly recv dispatch (sp_poly_shl15632-
# / sp_poly_band etc.) is the correct path. `(@h[k] ||= []) <<15633-
# v` where v is a promoted bigint LV would otherwise emit15634-
# sp_bigint_shl on the poly recv. The legacy widening predates15635-
# promote mode and assumed the arg-side bigint implied both15636-
# operands were numeric.15637-
if lt != "bigint" && lt != "poly" && lt != "string" && lt != "mutable_str"15638-
# Check if argument is bigint (direct type or via emit walker).15639-
args_id = @nd_arguments[nid]15640-
if args_id >= 015641-
aargs = get_args(args_id)15642-
if aargs.length > 015643-
if infer_type(aargs[0]) == "bigint" || expr_emit_is_bigint(aargs[0]) == 115644-
lt = "bigint"15630+
# Widen lt to "bigint" only when recv is itself a numeric type15631+
# (int, float, bigint, or nullable variants). Other recv shapes15632+
# (poly / typed containers like int_array / str_array / strings /15633+
# ptr_array / hashes) have their own per-type dispatch arms15634+
# later in the file -- forcing them through the bigint block15635+
# would emit sp_bigint_shl on an sp_IntArray * receiver and the15636+
# like. The legacy widening predates promote mode.15637+
if lt != "bigint"15638+
lt_b = base_type(lt)15639+
if lt_b == "int" || lt_b == "float" || lt_b == "bigint"15640+
args_id = @nd_arguments[nid]15641+
if args_id >= 015642+
aargs = get_args(args_id)15643+
if aargs.length > 015644+
if infer_type(aargs[0]) == "bigint" || expr_emit_is_bigint(aargs[0]) == 115645+
lt = "bigint"15646+
end1564515647
end1564615648
end1564715649
end