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
# expression for every if-branch below. recv_tmp = new_temp emit(" sp_RbVal " + recv_tmp + " = " + rc + ";") # Compile the call's argument list once. # Compile the call's argument list once. Track the inferred # source type alongside the compiled expression so the int-bit # branch below can unbox a poly arg without re-walking the AST. arg_compiled = "".split(",") arg_types = "".split(",") arg_strs = "" args_id = @nd_arguments[nid] if args_id >= 0 while k < aargs.length ce = compile_expr(aargs[k]) arg_compiled.push(ce) arg_types.push(infer_type(aargs[k])) arg_strs = arg_strs + ", " + ce k = k + 1 end