Commit 2f3d03c6

2f3d03c6f06dMerged

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

Description

Include the source line in unresolved-call warnings

warn_unresolved_call now appends "(line N)" to the "cannot resolve call to ..." diagnostic, reading the line from the per-node @nd_line slot that --line-map (on by default in the ./spinel driver) already stamps. The line is folded into the dedupe key too, so the same unresolved shape on different lines is reported once per site rather than collapsed. When lines aren't stamped (the bootstrap parse path, or --no-line-map) the suffix is empty and the warning degrades to its previous line-less form.

The one caller without a node id in scope (obj_op_dispatch_expr, which takes types not a node) keeps the default and emits no line.

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

Details

Commit
2f3d03c6f06d
Parent
daac6b0b0e14

spinel_codegen.rbmodifiedView file

@@ -6341,9 +6341,10 @@
63416341 # call's C expression (the historical silent-no-op behaviour) so
63426342 # existing tests/benches whose outputs happen to coincide with `0`
63436343 # keep compiling.
6344- def warn_unresolved_call(mname, recv_tag)
6344+ def warn_unresolved_call(mname, recv_tag, nid = -1)
63456345 ctx = current_method_context_str
6346- key = mname + ":" + recv_tag + ":" + ctx
6346+ lsuf = warn_line_suffix(nid)
6347+ key = mname + ":" + recv_tag + ":" + ctx + ":" + lsuf
63476348 i = 0
63486349 while i < @unresolved_call_warnings.length
63496350 if @unresolved_call_warnings[i] == key
@@ -6352,7 +6353,22 @@
63526353 i = i + 1
63536354 end
63546355 @unresolved_call_warnings.push(key)
6355- $stderr.puts "warning: in " + ctx + ": cannot resolve call to '" + mname + "' on " + recv_tag + " (emitting 0)"
6356+ $stderr.puts "warning: in " + ctx + lsuf + ": cannot resolve call to '" + mname + "' on " + recv_tag + " (emitting 0)"
6357+ end
6358+
6359+ # Render " (line N)" for a diagnostic when per-node source lines were
6360+ # stamped (--line-map / SPINEL_DEBUG, the default for `./spinel app.rb`
6361+ # via the driver). Empty when no line is available -- e.g. the bootstrap
6362+ # parse path doesn't stamp lines (@nd_line stays 0) -- so the warning
6363+ # degrades cleanly to its line-less form.
6364+ def warn_line_suffix(nid)
6365+ if nid >= 0 && nid < @nd_line.length
6366+ ln = @nd_line[nid]
6367+ if ln > 0
6368+ return " (line " + ln.to_s + ")"
6369+ end
6370+ end
6371+ ""
63566372 end
63576373
63586374 # Same dedupe pattern as warn_unresolved_call but for unknown
@@ -19734,7 +19750,7 @@
1973419750 # on (`@hook && @hook.fire(...)` where @hook starts nil and is
1973519751 # later assigned). Keep the warn for visibility, fall back to
1973619752 # silent 0 on int/poly recvs.
19737- warn_unresolved_call(mname, base_type(recv_type))
19753+ warn_unresolved_call(mname, base_type(recv_type), nid)
1973819754 rb_unr = base_type(recv_type)
1973919755 if rb_unr == "int" || rb_unr == "poly" || rb_unr == "nil"
1974019756 return "0"
@@ -20517,7 +20533,7 @@
2051720533 # user sees the problem is far better than a silently-empty binary.
2051820534 # See the matching warn at the receiver-form fallthrough above for
2051920535 # why this is a warn-and-emit-0 rather than a hard error.
20520- warn_unresolved_call(mname, "(no receiver)")
20536+ warn_unresolved_call(mname, "(no receiver)", nid)
2052120537 "0"
2052220538 end
2052320539
@@ -23733,7 +23749,7 @@
2373323749 return "sp_str_byteslice(" + rc + ", " + compile_expr_as_int(a_bsl[0]) + ", 1)"
2373423750 end
2373523751 end
23736- warn_unresolved_call(mname, "string")
23752+ warn_unresolved_call(mname, "string", nid)
2373723753 return "0"
2373823754 end
2373923755 # String#ascii_only? -- true iff every byte is 7-bit ASCII.
@@ -23781,7 +23797,7 @@
2378123797 return "sp_str_setbyte(" + rc + ", " + compile_expr_as_int(a_sb[0]) + ", " + compile_expr_as_int(a_sb[1]) + ")"
2378223798 end
2378323799 end
23784- warn_unresolved_call(mname, "string")
23800+ warn_unresolved_call(mname, "string", nid)
2378523801 return "0"
2378623802 end
2378723803 if mname == "bytesize"
@@ -32087,7 +32103,7 @@
3208732103 # `cannot resolve call to 'X' on Y (emitting 0)` pattern so editors
3208832104 # / CI grep for compile noise still surface this case.
3208932105 if poly_dispatch_arms_emitted == 0
32090- warn_unresolved_call(mname, "poly (no concrete user-class arm)")
32106+ warn_unresolved_call(mname, "poly (no concrete user-class arm)", nid)
3209132107 end
3209232108 tmp
3209332109 end
@@ -49141,7 +49157,7 @@
4914149157 if disp != ""
4914249158 emit(" lv_" + bp1 + " = " + disp + ";")
4914349159 else
49144- warn_unresolved_call(sym_op, elem_t)
49160+ warn_unresolved_call(sym_op, elem_t, nid)
4914549161 end
4914649162 else
4914749163 blk = @nd_block[nid]