Commit 05f0efac

05f0efac1e37Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · ~1 modified · -2 deleted

Description

Revert "Merge pull request #495 from ydah/fix/nil-numeric-ivar"

This reverts commit 04aa72139cf91ab52ed9f8534d77d2ff96f97847, reversing changes made to efc9c966780f4b7715d51d5103d7f0b3996466a1.

CI's optcarrot integration job (ubuntu/gcc, commit 0f66aaf added it on 2026-05-10, but the optcarrot make target isn't part of make test) fails since this merge with -Werror=int-conversion on self->iv_step += 1, self->iv_timer += self->iv_freq, and similar APU::Pulse / Triangle / Noise ivar arithmetic. Root cause is the new scan_writer_calls path that routes plain @ivar = nil writes through update_ivar_type when the current slot type is scalar — optcarrot's @wave_length = nil (init) followed by @wave_length = 0 if @wave_length (reset) used to stay at int because scan_writer_calls had elsif at != "nil" && ... and silently skipped the nil branch. With #495 the nil write reaches update_ivar_type, the nil_scalar_ivar_mix? guard widens @wave_length to poly, and downstream ivars (@freq = (@wave_length + 1) * 2 * @fixed) cascade to poly, breaking the arithmetic emit at numerous APU sites.

The user-reported scalar-ivar nil-tracking bug the PR fixed is real; a follow-up should re-introduce the widening with a narrower trigger (e.g. only when the ivar is actually read via .nil? somewhere in the program), but that needs more design and shouldn't block CI green.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
05f0efac1e37
Parent
0de86e0ad961

spinel_analyze.rbmodifiedView file

@@ -7748,15 +7748,6 @@
77487748 end
77497749 end
77507750
7751- def scalar_ivar_type?(t)
7752- t == "int" || t == "float" || t == "bool" || t == "symbol"
7753- end
7754-
7755- def nil_scalar_ivar_mix?(old_type, new_type)
7756- (old_type == "nil" && scalar_ivar_type?(new_type)) ||
7757- (new_type == "nil" && scalar_ivar_type?(old_type))
7758- end
7759-
77607751 def update_ivar_type(ci, iname, new_type)
77617752 names = @cls_ivar_names[ci].split(";")
77627753 types = @cls_ivar_types[ci].split(";")
@@ -7809,8 +7800,7 @@
78097800 # `@m = method(:foo)` initially scans as int and a
78107801 # refinement promotes it to `obj_Method` — no heterogeneity
78117802 # to widen for).
7812- if nil_scalar_ivar_mix?(old, new_type) ||
7813- ((old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1)
7803+ if (old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1
78147804 types[k] = "poly"
78157805 @needs_rb_value = 1
78167806 @cls_ivar_types[ci] = types.join(";")
@@ -8102,7 +8092,7 @@
81028092 if new_def == 1 && cur_def == 1 && cur != vtype && cur != "poly"
81038093 replace_ivar_type(ci, iname, "poly")
81048094 @needs_rb_value = 1
8105- elsif vtype != "int" || cur == "nil"
8095+ elsif vtype != "int"
81068096 update_ivar_type(ci, iname, vtype)
81078097 end
81088098 end
@@ -11027,14 +11017,7 @@
1102711017 if ij < ivar_types.length
1102811018 if ivar_names[ij] == iname
1102911019 if ptypes[pi] != ""
11030- old_t = ivar_types[ij]
11031- new_t = ptypes[pi]
11032- if nil_scalar_ivar_mix?(old_t, new_t)
11033- ivar_types[ij] = "poly"
11034- @needs_rb_value = 1
11035- else
11036- ivar_types[ij] = unify_call_types(old_t, new_t, -1)
11037- end
11020+ ivar_types[ij] = unify_call_types(ivar_types[ij], ptypes[pi], -1)
1103811021 end
1103911022 end
1104011023 end
@@ -13801,21 +13784,23 @@
1380113784 # Chain participants bypass the `int` guard so that
1380213785 # `@string_slot = @int_slot = expr_returning_int` widens
1380313786 # the head to poly instead of leaving it stuck at
13804- # `string`. Plain `nil` writes are routed through
13805- # update_ivar_type when the current slot is scalar; object
13806- # nil writes stay on the existing nullable/finalize paths to
13807- # avoid parent-cascade ping-pong across passes.
13787+ # `string`. The `nil` guard stays in place even for
13788+ # chains: `@a = @b = ... = nil` is handled at emit time
13789+ # by `compile_chained_ivar_writes`'s per-slot recurse
13790+ # path (NilNode lowers to a literal `0`, a null pointer
13791+ # constant valid for any slot type), and forcing nil
13792+ # into the slot type interacts badly with parent-cascade
13793+ # update_ivar_type — a subclass write that pins the same
13794+ # slot to a concrete obj type ping-pongs between obj_X
13795+ # and obj_X? across iter rounds and lands on poly,
13796+ # breaking the typed-pointer store at emit time.
1380813797 if chain_inames.length > 1 && at == "int"
1380913798 ci_idx = 0
1381013799 while ci_idx < chain_inames.length
1381113800 update_ivar_type(@current_class_idx, chain_inames[ci_idx], at)
1381213801 ci_idx = ci_idx + 1
1381313802 end
13814- elsif at == "nil"
13815- if scalar_ivar_type?(cls_ivar_type(@current_class_idx, iname))
13816- update_ivar_type(@current_class_idx, iname, at)
13817- end
13818- elsif at != "int" || cls_ivar_type(@current_class_idx, iname) == "nil"
13803+ elsif at != "int" && at != "nil"
1381913804 update_ivar_type(@current_class_idx, iname, at)
1382013805 end
1382113806 end