FilterFilter et al: inline predicates, skip multi-statement bodies#16
Open
JesseHerrick wants to merge 2 commits intomainfrom
Open
FilterFilter et al: inline predicates, skip multi-statement bodies#16JesseHerrick wants to merge 2 commits intomainfrom
JesseHerrick wants to merge 2 commits intomainfrom
Conversation
The four pipe-collapse rules (FilterFilter, RejectReject, FilterReject, RejectFilter) used to wrap each predicate as `f.(item)` no matter what, producing nasty output like `(&(&1 in list)).(item) && (fn x -> ... end).(item)` whenever the source used a capture or anonymous fn. Now they reuse the MapMap rule's inlining machinery to substitute the iteration variable directly into the predicate body, and skip the rewrite entirely when either side has a multi-statement `fn` body — combining those under `&&`/`||` would change short-circuit semantics and read worse than the original two-pipe chain.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit efc71c9. Configure here.
bugbot caught that combined_predicate hardcoded `:item` as the merged lambda's parameter without checking whether either predicate closed over a variable named `item` — the new lambda would silently shadow it. Apply the same machinery MapMap already uses: prefer the source's own iteration name (from a `fn x -> ...` predicate) when present, and check shadows_free_var? before committing. If the chosen name would shadow a free var on either side, bail out and leave the chain untouched. Also extend free_var_in? to recognize bare-reference predicates (e.g. `Enum.filter(list, item)`) as shadow risks — MapMap already filters these out before reaching the check, so its behavior is unchanged.
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.

The four pipe-collapse rules (FilterFilter, RejectReject, FilterReject, RejectFilter) used to wrap each predicate as
f.(item)no matter what, producing nasty output like(&(&1 in list)).(item) && (fn x -> ... end).(item)whenever the source used a capture or anonymous fn.Now they reuse the MapMap rule's inlining machinery to substitute the iteration variable directly into the predicate body, and skip the rewrite entirely when either side has a multi-statement
fnbody — combining those under&&/||would change short-circuit semantics and read worse than the original two-pipe chain.Note
Medium Risk
Changes AST rewrite behavior for collapsing
Enum.filter/Enum.rejectpipes, which could affect generated code semantics if edge cases are missed despite added safety checks.Overview
Improves the
FilterFilter/RejectReject/FilterReject/RejectFilterpipe-collapsing rewrites to inline simple capture/fnpredicate bodies (instead of always emittingf.(item)calls), producing cleaner merged predicates.Adds guardrails so the collapse is skipped when predicates aren’t safely composable (e.g., multi-statement
fnbodies, non-inlineable forms) or when the chosen parameter name would shadow a free variable in either predicate; tests are expanded to cover the new inlining behavior and the new skip cases.Reviewed by Cursor Bugbot for commit ac3c752. Bugbot is set up for automated code reviews on this repo. Configure here.