Commit ba3f14d2

ba3f14d27e53Merged

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

Description

Merge pull request #1462 from ryanseys/rs-c-callable-forward-base

feat(block): forward a callable value to iterators via synthetic-block desugar

Details

Commit
ba3f14d27e53
Parent
66b4eb49b5ee
Merge parent
e51563f7d39e

src/analyze.cmodifiedView file

@@ -399,6 +399,7 @@
399399 elsewhere. Lets bare calls/ivar refs in the block resolve against the
400400 receiver's class during inference (codegen mirrors this via an_ie_class_id). */
401401 int *g_ie_node_class = NULL;
402+static int g_ie_node_class_cap = 0;
402403
403404 void mark_ie_subtree(Compiler *c, int node, int cls) {
404405 if (node < 0) return;
@@ -542,7 +543,14 @@
542543 /* (Re)build the instance_eval/exec node→class map from current receiver types. */
543544 void build_ie_map(Compiler *c) {
544545 const NodeTable *nt = c->nt;
545- if (!g_ie_node_class) g_ie_node_class = malloc(sizeof(int) * (size_t)nt->count);
546+ /* sized to nt->count, which can grow mid-analysis when forwarded callables
547+ are desugared into synthetic blocks; resize so per-node writes stay bounded */
548+ if (g_ie_node_class_cap < nt->count) {
549+ int *grown = realloc(g_ie_node_class, sizeof(int) * (size_t)nt->count);
550+ if (!grown) return; /* OOM: keep the old map rather than leak/deref NULL */
551+ g_ie_node_class = grown;
552+ g_ie_node_class_cap = nt->count;
553+ }
546554 for (int i = 0; i < nt->count; i++) g_ie_node_class[i] = -1;
547555 for (int id = 0; id < nt->count; id++) {
548556 const char *ty = nt_type(nt, id);
@@ -1526,6 +1534,7 @@
15261534 ch |= propagate_prep_params(c);
15271535 ch |= infer_string_params(c);
15281536 ch |= infer_default_param_types(c);
1537+ ch |= desugar_value_callable_forwards(c); /* &proc -> { |x| proc.call(x) } */
15291538 ch |= infer_block_params(c);
15301539 ch |= infer_for_index(c);
15311540 /* Resolve constant types before ivar inference: a destructured constant