Commit d4a80dd7
d4a80dd7642cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(analyze): scan_locals stops at DefNode / ClassNode / ModuleNode
#450 cascade 1. scan_locals had no boundary guard for nested
DefNode / ClassNode / ModuleNode bodies: when called from
infer_main_call_types (the top-level scan) it walked into every
nested method body and recorded local = ... writes as if they
were siblings of main's own locals. Two methods with the same
local name then collided via scan_locals' repeated-write merge
and widened the conflated slot to poly. The poly local poisoned
every call-site arg-type read of that name, and the bare-recv /
module-dispatch widening arms in scan_new_calls propagated poly
into the callee's param types — the chain that left
SqliteAdapter.configure(path) typed sp_RbVal lv_database_path
in the archive even though every call passed a concrete const char *.
Repro shape boiled down:
module CgiIo def self.parse_request(env, stdin) path = env["PATH_INFO"] || "/" # path local : poly (string?|string) { path: path } end end
module Db def self.configure(path); ...; end # widens to sp_RbVal lv_path end
module Main def self.run_setup path = "/tmp/db" # path local : string Db.configure(path) # arg widened to poly via leakage end end
scan_locals from infer_main_call_types walked into CgiIo and Main
both, recorded both writes against a SINGLE main-level path slot
(string + poly → poly per repeated-write merge), and that poly then
flowed into Db.configure's param via the module-dispatch widening
arm in scan_new_calls.
Fix: early-return from scan_locals when nid is a DefNode / ClassNode / ModuleNode. Each of these introduces a fresh local scope; their locals must be collected by separate scan_locals calls scoped to the right outer context (which the infer_function_body_call_types / infer_ivar_types_from_writers / infer_class_body_call_types passes already do correctly).
Validation:
- test 407 pass (+1 regression covering scan_locals stopping at module-internal def bodies, with the canonical Db.configure shape).
- bench 52, optcarrot checksum 59662.
- real-blog archive errors: 56 → 56 (cascade-1 sites are gone but several unrelated errors remain; total error count was already reduced from 61 to 58 by cascades 2 + 3, and cascade 1 closes two more lines for 56 total).
- bootstrap 4-way fixpoint OK.
Closes #450 cascade 1 of 3 (all three cascades now resolved).
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- d4a80dd7642c
- Parent
- c11200dd5775
spinel_analyze.rbmodifiedView file
if nid < 0 return end # Nested DefNode / ClassNode / ModuleNode bodies are separate # scopes — their locals belong to the enclosed method / class / # module and must not leak into the parent scope. Without these # guards, scan_locals called from infer_main_call_types (or any # outer-context caller) walks into every nested method body and # records each `local = ...` write as if it were a sibling of # main's own locals. Two functions with the same local name # but different inferred types then widen to "poly" via the # repeated-write merge below, propagating poly into call-site # arg types and (via the bare-recv / module-dispatch widening # arms in scan_new_calls) into the callee's param types # — the topology behind #450 cascade 1. if @nd_type[nid] == "DefNode" return end if @nd_type[nid] == "ClassNode" || @nd_type[nid] == "ModuleNode" return end # Parallel to `names`: "1" if this local's current stored type was set # by an explicit literal write, "" otherwise. Reset when called with # a fresh (empty) names array.test/scan_locals_def_boundary.rbaddedView file
Loading diff…
test/scan_locals_def_boundary.rb.expectedaddedView file
Loading diff…