Commit e711be5c
e711be5c57f0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
analyze: route map/collect and select/filter checks through ty_iter_shape
The iterator-shape groups were hardcoded as inline !strcmp(name, "map") || !strcmp(name, "collect") (and select/filter) lists scattered across the
inference passes, duplicating the membership that types.c's ty_iter_shape()
already owns. A new map-like iterator added to ty_iter_shape would silently
miss these sites -- the same mirror-incompleteness class as #1469.
Replace the inline pairs with ty_iter_shape(name) == TY_ITER_MAP /
== TY_ITER_SELECT (12 + 1 sites in analyze_infer.c / analyze_pass.c). The
predicate's MAP membership is exactly {map, collect} and SELECT is exactly
{select, filter}, so the booleans are unchanged.
Pure refactor: emitted C is byte-for-byte identical across optcarrot and all 1007 benchmark/test inputs.
Gates: 950 tests pass, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- e711be5c57f0
- Parent
- 2dec192e5cc6
src/analyze_infer.cmodifiedView file
} /* each_slice(n).map/collect { |...| } chain: return array of block result type */ if (recv >= 0 && rt == TY_UNKNOWN && (!strcmp(name, "map") || !strcmp(name, "collect")) && if (recv >= 0 && rt == TY_UNKNOWN && (ty_iter_shape(name) == TY_ITER_MAP) && nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") && nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "each_slice") && nt_ref(nt, recv, "block") < 0) { } /* each_cons(n).map/collect { |...| } chain: return array of block result type */ if (recv >= 0 && rt == TY_UNKNOWN && (!strcmp(name, "map") || !strcmp(name, "collect")) && if (recv >= 0 && rt == TY_UNKNOWN && (ty_iter_shape(name) == TY_ITER_MAP) && nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") && nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "each_cons") && nt_ref(nt, recv, "block") < 0) { } /* each_cons(n).with_index(off).map/collect { |...| } chain */ if (recv >= 0 && rt == TY_UNKNOWN && (!strcmp(name, "map") || !strcmp(name, "collect")) && if (recv >= 0 && rt == TY_UNKNOWN && (ty_iter_shape(name) == TY_ITER_MAP) && nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") && nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "with_index") && nt_ref(nt, recv, "block") < 0) { if (recv >= 0 && ty_is_array(rt)) { int block = nt_ref(nt, id, "block"); if (block >= 0) { if (!strcmp(name, "map") || !strcmp(name, "collect")) { if (ty_iter_shape(name) == TY_ITER_MAP) { int body = nt_ref(nt, block, "body"); int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL; if (!strcmp(name, "dig") && argc >= 1) return TY_POLY; { int blk = nt_ref(nt, id, "block"); if (blk >= 0 && (!strcmp(name, "map") || !strcmp(name, "collect"))) { if (blk >= 0 && (ty_iter_shape(name) == TY_ITER_MAP)) { int body = nt_ref(nt, blk, "body"); int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL; TyKind et = bn > 0 ? infer_type(c, bb[bn - 1]) : TY_UNKNOWN; !strcmp(name, "begin") || !strcmp(name, "end")) return TY_INT; if (!strcmp(name, "bsearch")) return TY_INT; /* a member, or nil (nullable int) */ int block = nt_ref(nt, id, "block"); if (block >= 0 && (!strcmp(name, "map") || !strcmp(name, "collect"))) { if (block >= 0 && (ty_iter_shape(name) == TY_ITER_MAP)) { int body = nt_ref(nt, block, "body"); int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL; if (!strcmp(name, "values_at") || !strcmp(name, "fetch_values")) return TY_POLY_ARRAY; { int block = nt_ref(nt, id, "block"); if (block >= 0 && (!strcmp(name, "map") || !strcmp(name, "collect"))) { if (block >= 0 && (ty_iter_shape(name) == TY_ITER_MAP)) { int body = nt_ref(nt, block, "body"); int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL; return ty_array_of(bn > 0 ? infer_type(c, bb[bn - 1]) : TY_UNKNOWN); } if (block >= 0 && (!strcmp(name, "select") || !strcmp(name, "filter") || !strcmp(name, "reject"))) return rt; if (block >= 0 && (ty_iter_shape(name) == TY_ITER_SELECT || !strcmp(name, "reject"))) return rt; if (block >= 0 && !strcmp(name, "transform_keys")) { int body = nt_ref(nt, block, "body"); int bn = 0; const int *bb = body >= 0 ? nt_arr(nt, body, "body", &bn) : NULL;src/analyze_pass.cmodifiedView file
Loading diff…