Commit 74d63c93

74d63c93e2aaMerged

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

Description

Inline a yielding initialize at the Klass.new call site

Pool.new(2) { make_handle } with a yielding initialize previously dropped the block (a yields=1 initialize is never emitted as a function, so the constructor only allocated). The call site now inlines the initialize body with self bound to the fresh object and the literal block feeding its yields -- the same per-call-site specialization as ordinary yield-method inlining, wrapped in a statement expression yielding the object.

analyze: yield_value_type resolves a Klass.new { block } call site to the class's initialize, so @arr.push(yield) types the ivar's element from the block value (block-param typing from yield args already handled Class.new).

Fixes i709.

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

Details

Commit
74d63c93e2aa
Parent
578982b94c50

src/analyze.cmodifiedView file

@@ -255,6 +255,12 @@
255255 } else {
256256 TyKind crt = infer_type(c, crecv);
257257 if (ty_is_object(crt)) rmi = comp_method_in_chain(c, ty_object_class(crt), cn, NULL);
258+ /* `Klass.new { block }`: the block feeds the class's initialize. */
259+ else if (cn && !strcmp(cn, "new") && nt_type(nt, crecv) &&
260+ !strcmp(nt_type(nt, crecv), "ConstantReadNode")) {
261+ int nci = comp_class_index(c, nt_str(nt, crecv, "name"));
262+ if (nci >= 0) rmi = comp_method_in_chain(c, nci, "initialize", NULL);
263+ }
258264 }
259265 if (rmi != mi) continue;
260266 int bb = nt_ref(nt, blk, "body");