Commit e4c4118e
e4c4118efb3fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
feat(codegen,analyze): rescue => e binds sp_Exception * (Phase 2.3)
Promote rescue => e binding from a const char * message slot
(plus a @exc_var_names side-channel carrying the class) to a
first-class sp_Exception *. The binding now flows through the same
recv_type == "exception" dispatch arm that Phase 2.2 added for
BuiltinExc.new(...).
- analyze: scan_locals_first_type types the rescue-bound LV as "exception" (was "string"). walk_and_cache no longer needs to push the bound name onto @exc_var_names -- infer_call_type's Phase 2 arm fires via the typed receiver.
- codegen: compile_rescue_chain / compile_rescue_chain_into emit
lv_<name> = sp_exc_new(_rescue_cls_N, _rescue_msg_N);so the LV holds an sp_Exception * with both class and message. - codegen puts/interpolation: add
at == "exception"arms in compile_puts, compile_puts_single, and compile_interpolated soputs e/"#{e}"print the message (CRuby's implicit .to_s), preserving the Phase 1 surface where the LV was the message string. Without these, the pointer was printed as a long long.
The Phase 1 find_exc_var_cls dispatch arms in codegen/analyze are now unreachable (the rescue LV is typed "exception", so my Phase 2 arm wins). Cleanup of the dead code is left for a follow-up commit.
Tests: default 450/0/0, promote 450/0/0, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- e4c4118efb3f
- Parent
- 9c62cd3d05a0
spinel_analyze.rbmodifiedView file
end end end # Rescue reference (=> e) needs to be declared as a local # Rescue reference (=> e) needs to be declared as a local. Phase 2 # promotes the binding to a first-class sp_Exception * (was const # char * in Phase 1); compile_rescue_chain emits the # `lv_<name> = sp_exc_new(<cls>, <msg>);` assignment that fills it. if @nd_type[nid] == "RescueNode" ref = @nd_reference[nid] if ref >= 0 if not_in(lname, names) == 1 if not_in(lname, params) == 1 names.push(lname) types.push("string") types.push("exception") @scan_literal_flags.push("") @scan_empty_flags.push("") @scan_empty_hash_flags.push("") if @nd_type[nid] == "DefNode" return end # RescueNode: register the bound exception var so infer_call_type # recognises `.message` / `.class` / etc. as string-returning methods # within the rescue body. compile_begin_with_rescue does the same # at emit time; we mirror it here. # RescueNode: the bound exception var is typed "exception" (Phase 2.3), # so infer_call_type's recv_type == "exception" arm handles dispatch # without needing the @exc_var_names side-channel. if @nd_type[nid] == "RescueNode" ref_re = @nd_reference[nid] bound_re = "" if ref_re >= 0 bound_re = @nd_name[ref_re] @exc_var_names.push(bound_re) # Class is unknown at analyze time but find_exc_var_cls's # callers only check for non-empty (presence). Use a sentinel. @exc_var_cls_vars.push("?") end cs_re = [] push_child_ids(nid, cs_re) blk_re = @nd_block[nid] walk_and_cache(cs_re[k]) end k = k + 1 end if bound_re != "" @exc_var_names.pop @exc_var_cls_vars.pop end @nd_inferred_type[nid] = infer_type(nid) returnspinel_codegen.rbmodifiedView file
Loading diff…