Commit 20239660
20239660ca1bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Emit sp_sym_intern whenever codegen lowers a call through it
Symbol#upcase / #downcase on a method-returned symbol used inside
string interpolation lowered to
sp_sym_to_s(sp_sym_intern(sp_str_upcase(sp_sym_to_s(...)))), but
sp_sym_intern was never defined, so the build failed at link:
undefined reference to 'sp_sym_intern'. Found via the spinelgems
harness (nagiosplugin: "#{name.upcase} #{status.upcase}").
The sp_sym_intern definition is gated on @needs_sym_intern, which
analyze sets as a memoized side effect of infer_call_type. For a symbol
whose type only settles late in the fixpoint (a branch-poly method
return), the .upcase node's type was memoized before the receiver
resolved to symbol, so the flag stayed 0 in the IR -- yet codegen
still emitted the call. (The other forms -- local symbol, literal,
non-interpolated -- happen to infer in an order that sets the flag.)
Re-derive the flag in codegen from the now-stable types, via a
generate_code pre-scan (scan_for_sym_intern_usage) run before the gated
emit_sym_runtime, mirroring scan_for_method_usage / class-hierarchy
pre-scans. Detects Symbol#upcase/#downcase and String#to_sym/
#intern, the two emit sites that lower through sp_sym_intern.
Closes #1355
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 20239660ca1b
- Parent
- bc76f889a5c1
spinel_codegen.rbmodifiedView file
end end end # @needs_sym_intern decides whether emit_sym_runtime defines # sp_sym_intern, but analyze sets that flag as a memoized side effect # of infer_call_type and misses cases where the type only settles # late -- e.g. `Symbol#upcase` on a method-returned symbol inside # string interpolation, where codegen still emits the sp_sym_intern # call (compile_*_method_expr) and the link then fails on the missing # definition. Re-derive the flag here from the now-stable codegen # types, before the gated emit. Issue #1355. if @needs_sym_intern == 0 scan_for_sym_intern_usage(@root_id) end emit_sym_runtime emit_ffi_externs # Emit program-specific regexp patterns # The codegen-side arms also flip the flag, but most of them # run after emit_class_methods -- the pre-scan is what makes # the gate effective. # Pre-scan for constructs codegen lowers through sp_sym_intern: # `Symbol#upcase` / `#downcase` (re-intern the case-folded name) and # `String#to_sym` / `#intern` (runtime intern). Mirrors the emit-site # conditions in the Symbol / String method compilers so the gated # sp_sym_intern definition lands whenever a call to it is emitted, # independent of analyze's @needs_sym_intern timing. Issue #1355. def scan_for_sym_intern_usage(nid) if nid < 0 return end if @needs_sym_intern == 1 return end if @nd_type[nid] == "CallNode" msi = @nd_name[nid] rsi = @nd_receiver[nid] if rsi >= 0 rtsi = infer_type(rsi) if (msi == "upcase" || msi == "downcase") && rtsi == "symbol" @needs_sym_intern = 1 return end if (msi == "to_sym" || msi == "intern") && base_type(rtsi) == "string" @needs_sym_intern = 1 return end end end cs = [] push_child_ids(nid, cs) k = 0 while k < cs.length scan_for_sym_intern_usage(cs[k]) k = k + 1 end end def scan_for_method_usage(nid) if nid < 0 returntest/symbol_upcase_interpolation.rbaddedView file
Loading diff…
test/symbol_upcase_interpolation.rb.expectedaddedView file
Loading diff…