Commit 9af97342

9af973420183Merged

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

Description

fix(analyze): invalidate cls_method_return cache after global int->bigint promote

promote_int_to_bigint_globally rewrites @cls_meth_returns in-place but cls_method_return memoizes results into @cls_meth_return_cache on first lookup. Earlier inference passes had already filled the cache with the pre-promotion "int" answers, so post-promotion queries (run as part of annotate_all_node_types' walk) silently returned stale "int" instead of "bigint" for every method whose return slot got promoted.

The user-visible symptom: a method body whose last expression is a typed-call return (e.g. def go; @w.grab; end where Wrapper#grab now returns bigint) had its CallNode annotated as "int". The return-coercion fix from the prior commit then wrapped the already-bigint emit with sp_bigint_new_int, producing C like return sp_bigint_new_int(sp_Wrapper_grab(...)); where sp_Wrapper_grab returns sp_Bigint* — -Werror rejected with "makes integer from pointer without a cast".

Wipe the cache at the start of promote_int_to_bigint_globally so the next lookup refills off the now-promoted tables. The cache has no version stamp (unlike @cls_ivar_type_cache), and the affected key space is small enough that a full clear is the cheapest fix.

While here, add a localised mirror in compile_expr_for_expected_ type: when the expression is an arithmetic CallNode whose recv is bigint, treat the result as bigint even if the cached annotation says otherwise. This handles the same cache-staleness shape for nodes that walk_and_cache never re-visited (block-iteration bodies and a few other lazy-cache cases).

Promote-mode test count: 431 pass / 38 fail / 149 error -> 446 pass / 39 fail / 133 error. Default raise mode unchanged at 618 / 0 / 0. Optcarrot checksum 59662 retained.

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

Details

Commit
9af973420183
Parent
c95f194ba533

spinel_analyze.rbmodifiedView file

@@ -20422,6 +20422,13 @@
2042220422 if @int_overflow_mode != "promote"
2042320423 return
2042420424 end
20425+ # cls_method_return memoizes (ci, mname) -> return_type into
20426+ # @cls_meth_return_cache. Earlier inference passes filled that
20427+ # cache with "int" entries that this sweep is about to render
20428+ # stale (e.g. Wrapper#grab pre-promote = int, post-promote =
20429+ # bigint). The cache has no version stamp, so wipe it whole —
20430+ # next caller refills lazily off the now-promoted tables.
20431+ @cls_meth_return_cache = {}
2042520432 # Top-level methods.
2042620433 mi = 0
2042720434 while mi < @meth_param_types.length