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
# why the original include-time collection misses them. Idempotent # by virtue of collect_module_methods_into_class' existing # "don't add if class already has this method" guard. # # When a late-reopened method gets added here, any ivar it # writes must also propagate into the host class's ivar table so # the C struct gets the matching field. The original # collect_ivars(ci) call in collect_class_with_prefix ran before # this reconcile pass, so it never scanned the now-attached # method bodies. Re-run collect_ivars after the method-add for # any class whose method count grew here. collect_ivars itself # is idempotent (add_ivar guards on ivar_exists), so re-running # is safe even when no new method actually attached. def reconcile_class_includes ci = 0 while ci < @cls_includes.length includes_str = @cls_includes[ci] if includes_str != "" before_meths = @cls_meth_names[ci] names = includes_str.split(";") ni = 0 while ni < names.length end ni = ni + 1 end if @cls_meth_names[ci] != before_meths saved_idx = @current_class_idx @current_class_idx = ci collect_ivars(ci) @current_class_idx = saved_idx end end ci = ci + 1 endtest/module_reopen_after_include_ivar.rbaddedView file
Loading diff…
test/module_reopen_after_include_ivar.rb.expectedaddedView file
Loading diff…