Commit 01243a91

01243a919961Merged

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

Description

Fallback typing and missing poly/predicate paths for optcarrot

More gaps surfaced compiling optcarrot's PPU/APU; gate stays green (test 845, bench 57):

  • Default any unresolved non-parameter local to poly (boxed) instead of aborting codegen. These are block params over poly receivers and locals fed by dynamically-dispatched calls (optcarrot's memory-map procs); reads go through the tag-dispatching poly paths.
  • Re-run local write-type inference after the method-reference param backstop and ivar up-propagation, so a local derived from a now-pinned param/ivar is typed; re-apply bigint loop-var promotion afterward since the rerun resets locals.
  • NoMethodError gate: an unresolved call on a poly/nil/int/unknown receiver yields a typed nil/0 placeholder (such calls are runtime-nil-guarded), matching the existing policy; a concrete object receiver still errors.
  • poly uniq/uniq! with a block: dedup by the block key (sp_poly_eq), writing survivors back in place for the bang form.
  • nil? on pointer-backed concrete types (Fiber/Proc/…) tests the NULL pointer; on value types (Range/Time/Symbol/…) it is constant false.

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

Details

Commit
01243a919961
Parent
a5de83a09a4c

src/analyze.cmodifiedView file

@@ -1316,14 +1316,27 @@
13161316 if (!prop_changed) break;
13171317 }
13181318
1319- /* A block param that inference never resolved holds a yielded value of
1320- unknown static type (e.g. an element of a poly receiver iterated by
1321- uniq!/each): declare it boxed (poly) rather than failing codegen. Set
1322- before the node-type cache is rebuilt so reads of the param see poly. */
1319+ /* The method-reference backstop and ivar up-propagation above changed param
1320+ and ivar types after the main fixpoint, so re-run local write-type inference:
1321+ a local like `xfine = 8 - (data & 0x7)` only becomes int once its method's
1322+ `data` param is pinned to int by the backstop. */
1323+ for (int iter = 0; iter < 8; iter++) if (!infer_write_types(c)) break;
1324+ /* infer_write_types resets non-param locals, undoing the earlier bigint
1325+ loop-variable promotion, so re-apply it. */
1326+ detect_bigint_loop_vars(c);
1327+ propagate_bigint_cascade(c);
1328+
1329+ /* A non-parameter local that inference never resolved holds a value of unknown
1330+ static type -- a block param bound to an element of a poly receiver, or a
1331+ local fed by a dynamically-dispatched call (e.g. optcarrot's memory-map
1332+ procs). Declare it boxed (poly) rather than failing codegen; reads then go
1333+ through the tag-dispatching poly paths. Method params are excluded: the
1334+ backstop above already pins or drops those. Set before the node-type cache
1335+ is rebuilt so reads of the local see poly. */
13231336 for (int s = 0; s < c->nscopes; s++)
13241337 for (int i = 0; i < c->scopes[s].nlocals; i++) {
13251338 LocalVar *blv = &c->scopes[s].locals[i];
1326- if (blv->is_block_param && blv->type == TY_UNKNOWN) blv->type = TY_POLY;
1339+ if (!blv->is_param && blv->type == TY_UNKNOWN) blv->type = TY_POLY;
13271340 }
13281341
13291342 /* finalize: gc-root needs + full node type cache */