Commit 466d417b

466d417be9faMerged

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

Description

Make spinelc compile the legacy analyze pass to a working binary

Three emitted-C fixes that take legacy/spinel_analyze.rb from 35 cc type errors to a clean compile+link (1.9 MB binary, 0 errors, 0 undefined refs):

  • hash.each / each_pair: box a concrete key/value into a poly-declared block param (the param may be poly via a name shared across hashes of differing element types), mirroring the each_value/each_key path.
  • call arg materialization: coerce a poly arg into a concrete scalar param (sp_poly_to_s / sp_poly_to_i / sp_poly_to_f) instead of assigning sp_RbVal to a const char* / mrb_int / mrb_float slot.
  • compiler_state IR-emit helpers (ir_emit_int/str/sa/ia) are called only by the synthesized dump_compiler_state_ir, which has no AST, so the param-type backstop never binds them -> they stayed TY_UNKNOWN and were pruned as unreachable, leaving the dump calling undefined functions. Seed their fixed signature types (buf:string, name:string, value:int/string/str_array/ int_array; returns string) before the backstop so the binding also propagates into the helpers they call (ir_join_ints / ir_escape).

Gates: 845 test, 57 bench, optcarrot checksum 59662 -- all green.

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

Details

Commit
466d417be9fa
Parent
88018fc528c4

src/analyze.cmodifiedView file

@@ -1385,6 +1385,28 @@
13851385 would stay TY_UNKNOWN and be dropped below, leaving an undefined function at
13861386 the poly-dispatch call site. */
13871387 build_ie_map(c);
1388+ /* Seed the synthesized compiler_state IR-emit helpers' signature types. They
1389+ are called only by the synthesized dump_compiler_state_ir (which has no
1390+ AST), so the param backstop below can't bind them from a call site;
1391+ unseeded they stay TY_UNKNOWN, get pruned, and the dump then references an
1392+ undefined function. Seeding BEFORE the backstop lets the binding propagate
1393+ into the helpers they call (ir_join_ints / ir_escape). */
1394+ for (int s = 0; s < c->nscopes; s++) {
1395+ Scope *sc = &c->scopes[s];
1396+ const char *snm = sc->name;
1397+ if (!snm || sc->nparams < 3) continue;
1398+ if (strcmp(snm, "ir_emit_int") && strcmp(snm, "ir_emit_str") &&
1399+ strcmp(snm, "ir_emit_sa") && strcmp(snm, "ir_emit_ia")) continue;
1400+ LocalVar *pb = scope_local(sc, sc->pnames[0]);
1401+ LocalVar *pn = scope_local(sc, sc->pnames[1]);
1402+ LocalVar *pv = scope_local(sc, sc->pnames[2]);
1403+ if (pb) pb->type = TY_STRING;
1404+ if (pn) pn->type = TY_STRING;
1405+ if (pv) pv->type = !strcmp(snm, "ir_emit_int") ? TY_INT :
1406+ !strcmp(snm, "ir_emit_str") ? TY_STRING :
1407+ !strcmp(snm, "ir_emit_sa") ? TY_STR_ARRAY : TY_INT_ARRAY;
1408+ sc->ret = TY_STRING; /* each returns the accumulated buf (a string) */
1409+ }
13881410 for (int it = 0; it < 8; it++) { if (!infer_param_types(c)) break; }
13891411
13901412 /* Backstop step 2: a reachable method that STILL has TY_UNKNOWN params was