Lower IList functional combinators to scf loops - #728
Draft
nathanieltornow wants to merge 2 commits into
Draft
Conversation
Evaluate right folds as fn(x1, fn(x2, fn(x3, init))), matching the declared callback signature. Update the interpreter and static unroller; Foldl retains accumulator-first calls. This changes Foldr runtime behavior for callbacks sensitive to argument order. Cover subtraction and distinct element and accumulator types in execution, inference, and unrolling.
Add indexed-loop rewrites for Map, Foldl, Foldr, Scan, ForEach, Any, and All, composed by IListToLoop. Preserve callback calls and inferred result types, using singleton concatenation for output lists. Test execution, empty inputs, types, nested control flow, closure captures, callback effects, and repeated application.
nathanieltornow
force-pushed
the
feat/ilist-map-to-scf
branch
from
September 8, 2026 14:50
5462d71 to
1d49eb2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds rewrite rules and an
IListToLooppass that lowerMap,Foldl,Foldr,Scan,ForEach,Any, andAllto indexedscf.Forloops.Callbacks remain function calls; Map and Scan build output lists through
singleton concatenation.
The PR contains two commits:
element-first callback signature:
foldr(f, [a, b, c], z) = f(a, f(b, f(c, z))).This changes runtime behavior for callbacks that depend on argument order.
needed and rewrites nested regions within the current method.
Rewriting, e.g., Map to Scf, might induce the existing SCF inference issue for growing loop-carried lists (#512). Rerunning inference after lowering could therefore infer unsound list lengths.