Commit 0b192292
0b192292e54cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · +1 added
Description
bench: add poly-cells exerciser to surface poly-param counts
bm_jekyll_lite landed clean at 0 poly across every category, which makes it a useless before/after target for backward-inference work. bm_poly_cells deliberately stresses the patterns that survive after analyze's current type inference:
- Cell#set(v) / Sheet#put(v) called from 3 sites with String, Int, and Array — params widen to poly via genuine polyvariance, the same shape Active Record setters hit in real-blog.
- @value ivar in Cell takes all three types, widens to poly.
- render_one(v) dispatches by is_a?(String/Integer/Array). Each
branch returns string-typed, but
return vin the is_a?(String) arm doesn't carry the narrow to the function's return-type unification, so the function ends up poly.
Baseline SP_POLY_REPORT for measurement: params: 5 / 3 poly ivars: 5 / 1 poly returns: 9 / 2 poly locals: 4 / 0 poly
The 3 poly params are genuine polyvariance (multiple call sites with
incompatible types). The 1 poly ivar is the same shape one level
down. The 2 poly returns are the analyze gap that backward-inference
shape additions should be able to close — return v inside
is_a?(C) should narrow before contributing to the return unify.
Output is deterministic and matches CRuby. Bench suite now 54/54 pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 0b192292e54c
- Parent
- 1d5291554707
benchmark/bm_poly_cells.rbaddedView file
# Polyvariance-rich exerciser. A `Cell.set(v)` accepts mixed-type# `v` across call sites (string / int / array), so `@value` is a# genuinely poly ivar and `set`'s param is a genuinely poly param.# `render_one(v)` dispatches by is_a? — another poly param whose# return narrows by branch but spinel currently keeps the# function-level return as poly. Shape mirrors real-blog's# Active Record setter pattern in ~80 lines, so SP_POLY_REPORT# counts move visibly with each backward-inference refinement.class Cell attr_accessor :value def initialize @value = "" end def set(v) @value = v end def get @value endendclass Sheet def initialize @cells = [] @count = 0 end def put(v) c = Cell.new c.set(v) @cells.push(c) @count = @count + 1 end def count @count end def cells @cells endenddef render_one(v) if v.is_a?(String) return v end if v.is_a?(Integer) return v.to_s end if v.is_a?(Array) return "[" + v.length.to_s + " items]" end "?"ends = Sheet.news.put("hello")s.put(42)s.put([1, 2, 3])s.put("world")s.put(99)puts "count: " + s.count.to_sarr = s.cellsi = 0while i < arr.length puts render_one(arr[i].get) i = i + 1end