Commit 9c62cd3d
9c62cd3d05a0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · ~3 modified
Description
feat(codegen,analyze): built-in exception .new returns sp_Exception * (Phase 2.2)
Promote built-in exception .new from the Phase 1 (const char* msg
- side-channel cls name) lowering to a first-class sp_Exception *.
-
analyze: infer_call_type / infer_constructor_type emit "exception" for
<BuiltinExc>.new(...). infer_call_type also returns the right shape for.class/.message/.to_s/.inspect/.full_message(string),.backtrace(nil), and the type-checking predicates.is_a?/.kind_of?/.instance_of?(bool) when the receiver types as exception. The recv-type check is gated by the method name first so non-exception calls don't pay the recursion. -
codegen: new c_type/is_nullable_pointer_type/c_default_val arms lower "exception" to
sp_Exception *with NULL default. compile_constructor_expr emitssp_exc_new("<Cls>", <msg>). A new recv_type == "exception" dispatch arm lowers .class/.message/etc. emit_raise_one_arg detects sp_Exception * LVs and CallNode results typing as exception, emitting sp_raise_exc directly. -
runtime: sp_exc_class_name / sp_exc_message / sp_raise_exc accept
volatile sp_Exception *so callers can pass volatile LV slots (required across setjmp) without -Wdiscarded-qualifiers.
Tests: default 450/0/0, promote 450/0/0, optcarrot checksum 59662.
The rescue => e side-channel (@exc_var_names / find_exc_var_cls)
is still in place; Phase 2.3 will migrate it onto sp_Exception *.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 9c62cd3d05a0
- Parent
- 31bcc60f50e7
lib/sp_runtime.hmodifiedView file
e->msg = msg ? msg : sp_str_empty; return e;}static const char *sp_exc_class_name(sp_Exception *e) { return e ? e->cls_name : "RuntimeError"; }static const char *sp_exc_message(sp_Exception *e) { return e ? e->msg : sp_str_empty; }static void sp_raise_exc(sp_Exception *e) {/* Accept `volatile` pointers: LV slots holding sp_Exception * are declared volatile when they live across setjmp, so callers may pass volatile-qualified pointers in. The pointee itself isn't volatile (cls_name/msg are stable post-construction), so we strip volatile internally for one access. */static const char *sp_exc_class_name(volatile sp_Exception *ve) { sp_Exception *e = (sp_Exception *)ve; return e ? e->cls_name : "RuntimeError";}static const char *sp_exc_message(volatile sp_Exception *ve) { sp_Exception *e = (sp_Exception *)ve; return e ? e->msg : sp_str_empty;}static void sp_raise_exc(volatile sp_Exception *ve) { sp_Exception *e = (sp_Exception *)ve; if (!e) sp_raise("(nil exception)"); sp_raise_cls(e->cls_name, e->msg);}spinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…