Commit 645783f1

645783f13089Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · ~1 modified

Description

Detect needs_* flags from class ivars and method types

Scan class ivar types, method return types, and param types to set needs_hash, needs_rb_array, needs_poly, needs_sp_string, needs_str_split. Previously only top-level variables were checked.

C compile errors on lrama: 519 → 419.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
645783f13089
Parent
e63fe27ab2e5

src/codegen.cmodifiedView file

@@ -2059,6 +2059,37 @@
20592059 for (int i = 0; i < ctx->class_count; i++)
20602060 ctx->classes[i].class_tag = 0x0040 + i; /* NaN-box class tag base */
20612061
2062+ /* Detect needs from class ivars and method params/returns */
2063+ for (int ci = 0; ci < ctx->class_count; ci++) {
2064+ class_info_t *cls = &ctx->classes[ci];
2065+ for (int ii = 0; ii < cls->ivar_count; ii++) {
2066+ spinel_type_t k = cls->ivars[ii].type.kind;
2067+ if (k == SPINEL_TYPE_SP_STRING) ctx->needs_sp_string = true;
2068+ if (k == SPINEL_TYPE_HASH) ctx->needs_hash = true;
2069+ if (k == SPINEL_TYPE_ARRAY) ctx->needs_gc = true;
2070+ if (k == SPINEL_TYPE_RB_ARRAY) { ctx->needs_rb_array = true; ctx->needs_poly = true; }
2071+ if (k == SPINEL_TYPE_RB_HASH) { ctx->needs_rb_hash = true; ctx->needs_poly = true; }
2072+ if (k == SPINEL_TYPE_STR_ARRAY) ctx->needs_str_split = true;
2073+ if (k == SPINEL_TYPE_POLY) ctx->needs_poly = true;
2074+ }
2075+ for (int mi = 0; mi < cls->method_count; mi++) {
2076+ method_info_t *m = &cls->methods[mi];
2077+ spinel_type_t rk = m->return_type.kind;
2078+ if (rk == SPINEL_TYPE_HASH) ctx->needs_hash = true;
2079+ if (rk == SPINEL_TYPE_RB_ARRAY) { ctx->needs_rb_array = true; ctx->needs_poly = true; }
2080+ if (rk == SPINEL_TYPE_RB_HASH) { ctx->needs_rb_hash = true; ctx->needs_poly = true; }
2081+ if (rk == SPINEL_TYPE_STR_ARRAY) ctx->needs_str_split = true;
2082+ if (rk == SPINEL_TYPE_SP_STRING) ctx->needs_sp_string = true;
2083+ if (rk == SPINEL_TYPE_POLY) ctx->needs_poly = true;
2084+ for (int pi = 0; pi < m->param_count; pi++) {
2085+ spinel_type_t pk = m->params[pi].type.kind;
2086+ if (pk == SPINEL_TYPE_HASH) ctx->needs_hash = true;
2087+ if (pk == SPINEL_TYPE_RB_ARRAY) { ctx->needs_rb_array = true; ctx->needs_poly = true; }
2088+ if (pk == SPINEL_TYPE_POLY) ctx->needs_poly = true;
2089+ }
2090+ }
2091+ }
2092+
20622093 /* Detect needs_sp_string: any SP_STRING-typed variable triggers mutable string runtime */
20632094 for (int i = 0; i < ctx->var_count; i++) {
20642095 if (ctx->vars[i].type.kind == SPINEL_TYPE_SP_STRING) {