Commit e9816015

e981601509c5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): bigint == nil / != nil constant-folds (Ruby semantic)

Details

Commit
e981601509c5
Parent
e052c0827ef4

spinel_codegen.rbmodifiedView file

@@ -15766,11 +15766,24 @@
1576615766 if lt == "bigint"
1576715767 args_fp = @nd_arguments[nid]
1576815768 arg0_fp_t = ""
15769+ arg0_fp_nid = -1
1576915770 if args_fp >= 0
1577015771 aargs_fp = get_args(args_fp)
1577115772 if aargs_fp.length > 0
1577215773 arg0_fp_t = infer_type(aargs_fp[0])
15774+ arg0_fp_nid = aargs_fp[0]
15775+ end
15776+ end
15777+ # `bigint == nil` / `bigint != nil` (and float / bool / etc.)
15778+ # Ruby semantics: only nil equals nil. Constant-fold so the
15779+ # bigint cmp path doesn't compare against sp_bigint_new_int(0)
15780+ # (which would conflate a stored 0 with nil — see compile_eq).
15781+ if (mname == "==" || mname == "!=") && arg0_fp_nid >= 0 && @nd_type[arg0_fp_nid] == "NilNode"
15782+ rc_nil_b = compile_expr(recv)
15783+ if mname == "=="
15784+ return "(((void)(" + rc_nil_b + ")), FALSE)"
1577315785 end
15786+ return "(((void)(" + rc_nil_b + ")), TRUE)"
1577415787 end
1577515788 recv_fp_t = infer_type(recv)
1577615789 if (recv_fp_t == "float" && arg0_fp_t == "bigint") || (recv_fp_t == "bigint" && arg0_fp_t == "float") || (recv_fp_t == "float" && arg0_fp_t == "float")
@@ -23203,7 +23216,8 @@
2320323216 # Type-strict primitive, or Numeric vs an obj with no user `==`
2320423217 # (BasicObject#== identity -> false in MRI).
2320523218 if other_t == "int" || other_t == "float" || other_t == "bool" || other_t == "nil" ||
23206- other_t == "string" || other_t == "mutable_str" || other_t == "symbol"
23219+ other_t == "string" || other_t == "mutable_str" || other_t == "symbol" ||
23220+ other_t == "bigint"
2320723221 return op == "==" ? "FALSE" : "TRUE"
2320823222 end
2320923223 end
@@ -23285,7 +23299,7 @@
2328523299 # Note: this does NOT fix the underlying hash-missing-key problem
2328623300 # (sp_StrIntHash_get still returns 0 for both stored 0 and miss);
2328723301 # use Hash#has_key? / Hash#fetch when distinguishing matters.
23288- if lt == "int" || lt == "float" || lt == "bool"
23302+ if lt == "int" || lt == "float" || lt == "bool" || lt == "bigint"
2328923303 if op == "=="
2329023304 return "(((void)(" + lc + ")), FALSE)"
2329123305 else
@@ -23296,7 +23310,7 @@
2329623310 if lt == "nil"
2329723311 # Symmetric arm for `nil == int` / `nil != int` (and float/bool).
2329823312 # Same reasoning as the LHS-typed-int arm above.
23299- if at == "int" || at == "float" || at == "bool"
23313+ if at == "int" || at == "float" || at == "bool" || at == "bigint"
2330023314 if op == "=="
2330123315 return "(((void)(" + rc + ")), FALSE)"
2330223316 else