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
end end def scalar_ivar_type?(t) t == "int" || t == "float" || t == "bool" || t == "symbol" end def nil_scalar_ivar_mix?(old_type, new_type) (old_type == "nil" && scalar_ivar_type?(new_type)) || (new_type == "nil" && scalar_ivar_type?(old_type)) end def update_ivar_type(ci, iname, new_type) names = @cls_ivar_names[ci].split(";") types = @cls_ivar_types[ci].split(";") # `@m = method(:foo)` initially scans as int and a # refinement promotes it to `obj_Method` — no heterogeneity # to widen for). if nil_scalar_ivar_mix?(old, new_type) || ((old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1) if (old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1 types[k] = "poly" @needs_rb_value = 1 @cls_ivar_types[ci] = types.join(";") if new_def == 1 && cur_def == 1 && cur != vtype && cur != "poly" replace_ivar_type(ci, iname, "poly") @needs_rb_value = 1 elsif vtype != "int" || cur == "nil" elsif vtype != "int" update_ivar_type(ci, iname, vtype) end end if ij < ivar_types.length if ivar_names[ij] == iname if ptypes[pi] != "" old_t = ivar_types[ij] new_t = ptypes[pi] if nil_scalar_ivar_mix?(old_t, new_t) ivar_types[ij] = "poly" @needs_rb_value = 1 else ivar_types[ij] = unify_call_types(old_t, new_t, -1) end ivar_types[ij] = unify_call_types(ivar_types[ij], ptypes[pi], -1) end end end # Chain participants bypass the `int` guard so that # `@string_slot = @int_slot = expr_returning_int` widens # the head to poly instead of leaving it stuck at # `string`. Plain `nil` writes are routed through # update_ivar_type when the current slot is scalar; object # nil writes stay on the existing nullable/finalize paths to # avoid parent-cascade ping-pong across passes. # `string`. The `nil` guard stays in place even for # chains: `@a = @b = ... = nil` is handled at emit time # by `compile_chained_ivar_writes`'s per-slot recurse # path (NilNode lowers to a literal `0`, a null pointer # constant valid for any slot type), and forcing nil # into the slot type interacts badly with parent-cascade # update_ivar_type — a subclass write that pins the same # slot to a concrete obj type ping-pongs between obj_X # and obj_X? across iter rounds and lands on poly, # breaking the typed-pointer store at emit time. if chain_inames.length > 1 && at == "int" ci_idx = 0 while ci_idx < chain_inames.length update_ivar_type(@current_class_idx, chain_inames[ci_idx], at) ci_idx = ci_idx + 1 end elsif at == "nil" if scalar_ivar_type?(cls_ivar_type(@current_class_idx, iname)) update_ivar_type(@current_class_idx, iname, at) end elsif at != "int" || cls_ivar_type(@current_class_idx, iname) == "nil" elsif at != "int" && at != "nil" update_ivar_type(@current_class_idx, iname, at) end endtest/nil_scalar_ivar_widen.rbdeleted
Loading diff…
test/nil_scalar_ivar_widen.rb.expecteddeleted
Loading diff…