Commit 43d5c4b6

43d5c4b693d4Merged

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

Description

fix(codegen): build arg_types alongside arg_compiled in poly dispatch

Eliminates the two cannot resolve call warnings that appeared each time spinel compiled itself:

warning: cannot resolve call to 'arg_types' on (no receiver) warning: cannot resolve call to 'length' on int

Both came from one line in compile_poly_method_call (added in PR #240's poly-int bit-extraction fix), where the SP_TAG_INT branch checked arg_types.length > 0 && arg_types[0] == "poly" to decide whether to unbox the index argument. The local variable was never declared — only arg_compiled was — so spinel's own self-compile saw arg_types as a bare-name call (warning #1) and .length then dispatched on the resulting 0 int default (warning #2).

Fix: build arg_types in the same loop that fills arg_compiled / arg_strs, pushing infer_type(aargs[k]) per arg. The runtime guard at the SP_TAG_INT branch now sees the real inferred types and unboxes a poly-tagged index correctly.

Behavior was already accidentally fine before — the warning was non-fatal and 0.length == 0 made the condition always false, so no poly-typed arg[0] ever got the unbox treatment. With the fix in place the unbox path is also actually live, which is what PR #240 originally intended.

295 pass / bootstrap clean. The bench output is now warning-free.

Refs #240

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

Details

Commit
43d5c4b693d4
Parent
9a76fc98a8dd

spinel_codegen.rbmodifiedView file

@@ -21843,8 +21843,11 @@
2184321843 # expression for every if-branch below.
2184421844 recv_tmp = new_temp
2184521845 emit(" sp_RbVal " + recv_tmp + " = " + rc + ";")
21846- # Compile the call's argument list once.
21846+ # Compile the call's argument list once. Track the inferred
21847+ # source type alongside the compiled expression so the int-bit
21848+ # branch below can unbox a poly arg without re-walking the AST.
2184721849 arg_compiled = "".split(",")
21850+ arg_types = "".split(",")
2184821851 arg_strs = ""
2184921852 args_id = @nd_arguments[nid]
2185021853 if args_id >= 0
@@ -21853,6 +21856,7 @@
2185321856 while k < aargs.length
2185421857 ce = compile_expr(aargs[k])
2185521858 arg_compiled.push(ce)
21859+ arg_types.push(infer_type(aargs[k]))
2185621860 arg_strs = arg_strs + ", " + ce
2185721861 k = k + 1
2185821862 end