Commit 5a7a9672
5a7a9672f859Merged
Ryan Seys <[email protected]> · 5 months ago · 8 files · +4 added · ~4 modified
Description
feat(iter): tap/then expression position + Enumerable#filter_map
Two value-position iterator gaps (to be split):
-
tap / then / yield_self in expression position: tap runs the block for its side effect and yields the (unchanged) receiver; then yields the block's value. Works across receiver types, so
p(x.tap{...})anda.map{}.tap{}chains no longer hit 'unsupported call'. -
Enumerable#filter_map: had block-param typing but no codegen/result-type. A dedicated emitter builds a boxed result array keeping each truthy block value (sp_poly_truthy); the call type infers to a poly array. Output matches CRuby for nilable (
expr if cond) and plain-transform bodies. Array receivers; range filter_map is a later slice.
Details
- Commit
- 5a7a9672f859
- Parent
- 9b8de269b07f
src/analyze_infer.cmodifiedView file
!strcmp(name, "find") || !strcmp(name, "detect")) return ty_array_elem(rt); /* returns an element */ if (!strcmp(name, "partition")) return TY_POLY_ARRAY; /* [[truthy...],[falsy...]] */ if (!strcmp(name, "filter_map")) return TY_POLY_ARRAY; /* map then drop falsy */ } /* grep/grep_v without a block filter by `pattern === e`, preserving the receiver's array type. */src/codegen_call.cmodifiedView file
Loading diff…
src/codegen_fold.cmodifiedView file
Loading diff…
src/codegen_internal.hmodifiedView file
Loading diff…
test/filter_map.rbaddedView file
Loading diff…
test/filter_map.rb.expectedaddedView file
Loading diff…
test/tap_then_expr.rbaddedView file
Loading diff…
test/tap_then_expr.rb.expectedaddedView file
Loading diff…