Commit 9d23dacc

9d23dacc9d98Merged

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

Description

fix(analyze): re-run collect_ivars after late module method attach

Follow-up to 8ca93b4 (#573). The reconcile pass adds methods from late-reopened modules into namespaced including classes, but the matching ivar pass had already run by then. Any @x written by a late-attached method (e.g. Dispatch#post writing @session) never reached the host class's @cls_ivar_names, and the C emit referenced a struct field the host's struct didn't declare:

error: no member named 'iv_session' in 'struct sp_NS_IntegrationTest_s'

Track whether reconcile_class_includes actually grew the host's method count, and when it did, re-run collect_ivars on that class. add_ivar already guards on ivar_exists == 0, so the re-run is idempotent on classes that didn't gain methods.

Top-level classes were unaffected: they collect through the top-level Pass 1 path that already runs collect_ivars after the includes resolve.

Fixes the second symptom on #572 (Sam Ruby's 13-line minimal repro in the follow-up comment). The cross-instance sp_poly_eq Heisenbug on the comment_test side stays open pending the -O0 / -fno-strict-aliasing diagnostic experiments.

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

Details

Commit
9d23dacc9d98
Parent
7d71219a20b4

spinel_analyze.rbmodifiedView file

@@ -7682,11 +7682,22 @@
76827682 # why the original include-time collection misses them. Idempotent
76837683 # by virtue of collect_module_methods_into_class' existing
76847684 # "don't add if class already has this method" guard.
7685+ #
7686+ # When a late-reopened method gets added here, any ivar it
7687+ # writes must also propagate into the host class's ivar table so
7688+ # the C struct gets the matching field. The original
7689+ # collect_ivars(ci) call in collect_class_with_prefix ran before
7690+ # this reconcile pass, so it never scanned the now-attached
7691+ # method bodies. Re-run collect_ivars after the method-add for
7692+ # any class whose method count grew here. collect_ivars itself
7693+ # is idempotent (add_ivar guards on ivar_exists), so re-running
7694+ # is safe even when no new method actually attached.
76857695 def reconcile_class_includes
76867696 ci = 0
76877697 while ci < @cls_includes.length
76887698 includes_str = @cls_includes[ci]
76897699 if includes_str != ""
7700+ before_meths = @cls_meth_names[ci]
76907701 names = includes_str.split(";")
76917702 ni = 0
76927703 while ni < names.length
@@ -7695,6 +7706,12 @@
76957706 end
76967707 ni = ni + 1
76977708 end
7709+ if @cls_meth_names[ci] != before_meths
7710+ saved_idx = @current_class_idx
7711+ @current_class_idx = ci
7712+ collect_ivars(ci)
7713+ @current_class_idx = saved_idx
7714+ end
76987715 end
76997716 ci = ci + 1
77007717 end