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
if @int_overflow_mode != "promote" return end # cls_method_return memoizes (ci, mname) -> return_type into # @cls_meth_return_cache. Earlier inference passes filled that # cache with "int" entries that this sweep is about to render # stale (e.g. Wrapper#grab pre-promote = int, post-promote = # bigint). The cache has no version stamp, so wipe it whole — # next caller refills lazily off the now-promoted tables. @cls_meth_return_cache = {} # Top-level methods. mi = 0 while mi < @meth_param_types.lengthspinel_codegen.rbmodifiedView file
Loading diff…