Commit 16d5b8d9

16d5b8d94593Merged

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

Description

codegen(promote): answer frozen? on a poly receiver

n.frozen? where n widened to poly under promote matched none of the scalar arms (TY_INT/FLOAT/SYMBOL/BOOL/NIL/STRING) and fell through to the poly method dispatch, which has no frozen? arm and returned the false default. Add a TY_POLY arm backed by a new sp_poly_frozen runtime helper: scalars are always frozen, a string checks its frozen flag, a heap object checks its GC-header bit.

Fixes promote-mode method_introspection.

Default test 992/0/0 and optcarrot checksum 59662 unchanged.

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

Details

Commit
16d5b8d94593
Parent
436535602be9

lib/sp_runtime.hmodifiedView file

@@ -4478,6 +4478,14 @@
44784478 method (called with the int arg, int ABI) or an int array. Used when
44794479 inference proves the double index `@table[i][j]` yields an int (a method
44804480 dispatch table). Falls back to coercing the generic poly result. */
4481+/* frozen? on a poly value: scalars (int/float/sym/bool/nil/bigint) are always
4482+ frozen in Ruby; a string checks its frozen flag; a heap object checks its GC
4483+ header bit. Used when a receiver widened to poly under promote. */
4484+static inline mrb_bool sp_poly_frozen(sp_RbVal v) {
4485+ if (v.tag == SP_TAG_STR) return v.v.s ? sp_str_is_frozen_val(v.v.s) : TRUE;
4486+ if (v.tag == SP_TAG_OBJ) return sp_gc_is_frozen(v.v.p);
4487+ return TRUE;
4488+}
44814489 static inline mrb_int sp_poly_index_int(sp_RbVal a, mrb_int i) {
44824490 if (a.tag == SP_TAG_INT) return (a.v.i >> i) & 1;
44834491 if (a.tag == SP_TAG_OBJ) {