Commit f7c5a480

f7c5a48082beMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Resolve constant types before ivar inference in the fixpoint

A destructured constant (CLK_1,..,CLK_8 = (1..8).map { |i| i * RP2A03_CC }) is transiently typed poly by infer_write_types before the mapped array's element type settles to int. infer_ivar_types ran next and a monotonic ivar reading the constant (@clk += CLK_1) locked onto that transient poly, so the whole CPU clock cluster stayed boxed even though CLK_* and @clk are ultimately int.

Run infer_global_const_types + infer_multiwrite_const_types before infer_ivar_types so constants carry their settled type when ivar inference reads them. Resolving constants earlier only narrows, so it can't introduce a spurious widening.

optcarrot CPU @clk (and the clock cluster) de-poly: ~445 -> ~488 fps, checksum 59662. make test 845, make bench 57.

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

Details

Commit
f7c5a48082be
Parent
094eb02112d5

src/analyze.cmodifiedView file

@@ -970,11 +970,16 @@
970970 ch |= infer_default_param_types(c);
971971 ch |= infer_block_params(c);
972972 ch |= infer_for_index(c);
973+ /* Resolve constant types before ivar inference: a destructured constant
974+ (`CLK_1,.. = (1..8).map{...}`) is transiently poly in infer_write_types
975+ before its array element type settles, and a monotonic ivar that reads
976+ it (`@clk += CLK_1`) would lock onto that poly. Resolving constants
977+ first feeds the settled type into ivar inference. */
978+ ch |= infer_global_const_types(c);
979+ ch |= infer_multiwrite_const_types(c);
973980 ch |= infer_ivar_types(c);
974981 ch |= infer_cvar_types(c);
975982 ch |= infer_inherited_ivars(c);
976- ch |= infer_global_const_types(c);
977- ch |= infer_multiwrite_const_types(c);
978983 ch |= infer_return_types(c);
979984 if (!ch) break;
980985 }