Commit abbf1aa4
abbf1aa436d5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): ivar write rhs effective type detection for promote-mode chains
compile_stmt's InstanceVariableWriteNode arm wrapped an int-typed
rhs with sp_bigint_new_int when the slot was promoted to bigint,
but infer_type(rhs) was stale for several rhs shapes that
actually emit bigint at the C level:
@b = @a &= 0x80— rhs is an IVOpWriteNode whose own ivar slot is bigint, so the inner emit returns bigint.@b = (@a = @a & 0x80)— rhs is ParenthesesNode wrapping an IVW whose slot is bigint.@a = @a & 0x80— rhs is a CallNode&on a bigint recv, emitting through the new sp_bigint_new_int(sp_bigint_to_int(...) & sp_bigint_to_int(...)) shape.
Walk into ParenthesesNode, then check the inner node:
- IVW / IVOpWriteNode / IVAndWriteNode / IVOrWriteNode -> consult the target ivar's slot type.
- CallNode setter (
obj.attr=) -> check the attr_writer's ivar slot. - CallNode arith / bitwise on a bigint recv -> bigint.
When any of these resolve to bigint, the outer wrap is suppressed.
Promote-mode test count: 510 pass / 47 fail / 61 error -> 512 pass / 47 fail / 59 error. Default raise mode unchanged at 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- abbf1aa436d5
- Parent
- 531e8355ecec
spinel_codegen.rbmodifiedView file
@@ -25462,8 +25462,60 @@
2546225462
val = compile_expr(expr_id)2546325463
# `--int-overflow=promote` widens ivar slots to bigint; an2546425464
# int-typed RHS (literal, arithmetic, etc.) needs the25465-
# sp_bigint_new_int wrap before assignment.25466-
if ivt == "bigint" && infer_type(expr_id) == "int"25465+
# sp_bigint_new_int wrap before assignment. Detect the25466+
# promote-side stale-cache shapes (IVOpWriteNode rhs whose own25467+
# ivar slot is bigint, ParenthesesNode peek, attr_writer25468+
# setter on a bigint-promoted slot) so the wrap fires only on25469+
# actual int rhs.25470+
rhs_eff_t_ivw = infer_type(expr_id)25471+
if ivt == "bigint" && rhs_eff_t_ivw != "bigint"25472+
eff_rhs_ivw = expr_id25473+
if eff_rhs_ivw >= 0 && @nd_type[eff_rhs_ivw] == "ParenthesesNode"25474+
pb_iv = @nd_body[eff_rhs_ivw]25475+
if pb_iv >= 025476+
ps_iv = get_stmts(pb_iv)25477+
if ps_iv.length == 125478+
eff_rhs_ivw = ps_iv[0]25479+
end25480+
end25481+
end25482+
if eff_rhs_ivw >= 025483+
erhs_t_iv = @nd_type[eff_rhs_ivw]25484+
if erhs_t_iv == "InstanceVariableOperatorWriteNode" || erhs_t_iv == "InstanceVariableAndWriteNode" || erhs_t_iv == "InstanceVariableOrWriteNode" || erhs_t_iv == "InstanceVariableWriteNode"25485+
if @current_class_idx >= 025486+
ivar_inner = cls_ivar_type(@current_class_idx, @nd_name[eff_rhs_ivw])25487+
if base_type(ivar_inner) == "bigint"25488+
rhs_eff_t_ivw = "bigint"25489+
end25490+
end25491+
elsif erhs_t_iv == "CallNode"25492+
rcv_eff = @nd_receiver[eff_rhs_ivw]25493+
mn_eff = @nd_name[eff_rhs_ivw]25494+
if rcv_eff >= 0 && mn_eff.length > 1 && mn_eff[mn_eff.length - 1] == "=" && mn_eff != "==" && mn_eff != "!=" && mn_eff != "<=" && mn_eff != ">="25495+
rt_eff = base_type(infer_type(rcv_eff))25496+
if is_obj_type(rt_eff) == 125497+
rcn_eff = rt_eff[4, rt_eff.length - 4]25498+
rci_eff = find_class_idx(rcn_eff)25499+
if rci_eff >= 025500+
bn_eff = mn_eff[0, mn_eff.length - 1]25501+
if cls_has_attr_writer(rci_eff, bn_eff) == 125502+
if base_type(cls_ivar_type(rci_eff, "@" + bn_eff)) == "bigint"25503+
rhs_eff_t_ivw = "bigint"25504+
end25505+
end25506+
end25507+
end25508+
end25509+
# Arith / bitwise CallNode on a bigint recv emits bigint.25510+
if rhs_eff_t_ivw != "bigint" && rcv_eff >= 0 && (mn_eff == "+" || mn_eff == "-" || mn_eff == "*" || mn_eff == "/" || mn_eff == "%" || mn_eff == "**" || mn_eff == "<<" || mn_eff == ">>" || mn_eff == "&" || mn_eff == "|" || mn_eff == "^")25511+
if base_type(infer_type(rcv_eff)) == "bigint"25512+
rhs_eff_t_ivw = "bigint"25513+
end25514+
end25515+
end25516+
end25517+
end25518+
if ivt == "bigint" && rhs_eff_t_ivw == "int"2546725519
@needs_bigint = 12546825520
val = "sp_bigint_new_int(" + val + ")"2546925521
end