Specialize macro list folds#929
Merged
Merged
Conversation
Recognize map and filter macro fold shapes during planning and build result lists with a mutable evaluation-local buffer. This avoids repeated accumulator list copying while preserving generic fold fallback for non-standard accumulator references.
XN137
previously approved these changes
Jul 22, 2026
| IteratorT it = ((IterableT) foldRange).iterator(); | ||
| while (it.hasNext() == True) { | ||
| it.next(); | ||
| rangeCnt++; |
Contributor
There was a problem hiding this comment.
should this try to use Sizer first or instead (as we do in listCapacity) ?
Member
Author
There was a problem hiding this comment.
Nice catch! I already have a follow-up for that.
XN137
approved these changes
Jul 22, 2026
| continue; | ||
| } | ||
| if (include != True) { | ||
| result = noSuchOverload(null, Operator.Conditional.id, include); |
Contributor
There was a problem hiding this comment.
minor sonnet finding:
EvalExhaustiveListFold.eval() handles errors inconsistently depending on their source.
Filter errors overwrite result unconditionally:
if (include != True) {
result = noSuchOverload(null, Operator.Conditional.id, include); // always overwrites
continue;
}
Transform errors only set result if it's still null:
if (result == null) {
if (isUnknownOrError(value)) {
result = value; // only captures the first
}
}
The consequence: if a transform error occurs on element 1, then a filter error occurs on element 2, the transform error is silently replaced by the filter error. Conversely, multiple transform errors always return the first one, while
multiple filter errors return the last one. There's also no test covering the filter-returns-error path in exhaustive mode at all (both existing exhaustive tests use include == False or a transform that errors, not a filter that returns
a non-boolean).
The fix would be to guard the filter-error assignment with the same result == null check:
if (include != True) {
if (result == null) {
result = noSuchOverload(null, Operator.Conditional.id, include);
}
continue;
}
This is a low-severity issue since exhaustive mode is primarily for cost estimation and observability rather than production evaluation paths, and erroring filter conditions are rare. But the inconsistency is real and would be easy to
fix.
Member
Author
There was a problem hiding this comment.
Good catch! I'll keep it in mind!
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.
Recognize map and filter macro fold shapes during planning and build result lists with a mutable evaluation-local buffer.
This avoids repeated accumulator list copying while preserving generic fold fallback for non-standard accumulator references.