Commit 4327f89d

4327f89d4558Merged

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

Description

codegen: gate the promote-only poly fixes out of the default hot path

Two correctness fixes for --int-overflow=promote leaked into default/wrap codegen and regressed optcarrot (the per-frame tick boxes ints and dispatches on poly ivars):

  • emit_boxed for TY_INT used sp_box_int_or_nil (a SP_INT_NIL sentinel check) on every int boxed into poly. The sentinel only appears when an int? value widens to poly, which is promote-only; default int values are never the sentinel. Gate it to promote (~+60 fps on optcarrot).
  • the poly method-dispatch key guarded tag == SP_TAG_OBJ ? cls_id : ... to stop a boxed scalar (cls_id 0) aliasing user class 0. That collision only arises when a scalar reaches a poly dispatch, which under promote is the attr SIGSEGV; in default the guard is pure per-dispatch overhead. Gate it to promote.

The generated default-mode optcarrot C is now byte-identical to the pre-promote baseline. promote-mode tests (attr, int_opt_p_inspect, class_method_open_class_call, ...) still pass; default test 999; optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
4327f89d4558
Parent
d75e657b0d1c

src/codegen.cmodifiedView file

@@ -121,7 +121,11 @@
121121 }
122122 const char *fn = NULL;
123123 switch (t) {
124- case TY_INT: fn = "sp_box_int_or_nil"; break;
124+ /* A nullable-int sentinel (SP_INT_NIL) only flows into a poly box under
125+ --int-overflow=promote (where int? widens to poly); in default/wrap mode
126+ a real int is never the sentinel, so skip the per-box check there -- it is
127+ on the hot path (every int boxed into poly, e.g. optcarrot's pixels). */
128+ case TY_INT: fn = g_promote_mode ? "sp_box_int_or_nil" : "sp_box_int"; break;
125129 case TY_FLOAT: fn = "sp_box_float"; break;
126130 case TY_BIGINT: fn = "sp_box_bigint"; break;
127131 case TY_STRING: fn = "sp_box_str"; break;