Commit 656878a4

656878a4c1edMerged

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

Description

fix(analyze,codegen): _block fn-ptr csig sees promoted method params

block_params_csig_for_body declared the def's locals from @nd_scope_names[bid] and walked yield args, but method params live in @meth_param_names / @cls_meth_params and weren't in scope. infer_type(yield x) for a param x fell back to "int" and the emitted forward decl said _block(mrb_int, ...) even when x's slot had been promoted to bigint.

Two fixes:

  • analyze: promote_int_to_bigint_globally runs before precompute_all_scope_decls which re-derives @nd_scope_types. Add a second sweep AFTER precompute that walks scope_types and rewrites "int" -> "bigint" so the IR-exported ST lines (and thus the codegen-side csig) see promoted slot types.

  • codegen: block_params_csig_for_body looks up the enclosing method (top-level via @meth_body_ids, instance via @cls_meth _bodies) and declares its params into the scope alongside the body locals. The yield-walk's infer_type calls then resolve a param reference to its bigint type.

Promote-mode test count: 531 pass / 50 fail / 37 error -> 532 pass / 50 fail / 36 error. Default raise mode 618 / 0 / 0; optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
656878a4c1ed
Parent
536eb53e5129

spinel_analyze.rbmodifiedView file

@@ -21489,6 +21489,36 @@
2148921489 compute_live_instance_methods
2149021490 @analysis_frozen = 1
2149121491 precompute_all_scope_decls
21492+ # precompute_all_scope_decls re-derives scope_types from
21493+ # @meth_param_types and from the local refinement pass; in promote
21494+ # mode, the latter may have left some method-body locals as "int"
21495+ # despite the globally-promoted param table. Re-run the scope
21496+ # types int -> bigint sweep so the IR-exported `ST` lines (and
21497+ # thus the codegen-side block_params_csig_for_body) see promoted
21498+ # slot types.
21499+ if @int_overflow_mode == "promote"
21500+ sj = 0
21501+ while sj < @nd_scope_types.length
21502+ stj = @nd_scope_types[sj]
21503+ if stj != ""
21504+ psj = stj.split("|")
21505+ chj = 0
21506+ ppj = 0
21507+ while ppj < psj.length
21508+ if psj[ppj] == "int"
21509+ psj[ppj] = "bigint"
21510+ @needs_bigint = 1
21511+ chj = 1
21512+ end
21513+ ppj = ppj + 1
21514+ end
21515+ if chj == 1
21516+ @nd_scope_types[sj] = psj.join("|")
21517+ end
21518+ end
21519+ sj = sj + 1
21520+ end
21521+ end
2149221522 annotate_all_node_types
2149321523 # Now that @nd_inferred_type is populated for every reachable
2149421524 # node, we can resolve `recv.method(...)`'s receiver class