lowering: equality-section list scans and match-consumed lookups - #93
Merged
Conversation
List.findIndex/find/exists with an equality-section predicate route to list.index / in (C-level scans) instead of a Python-level scan driving a lambda per element. A match whose scrutinee is a fully applied Map.tryFind, List.head, or List.get and whose arms are exactly Some v / None lowers to the if a person would write, with no Option in between. Extends the DESIGN.md 5.2 lever; mechanics in INTERNALS.md.
simontreanor
added a commit
that referenced
this pull request
Aug 30, 2026
…after #90, #91 and #93 Resolves the overlap between the lookup peephole (#93) and the Option/Result ladder (#94): both hooks run in the match lowering, lookup first since it needs no Option at all; the two new list helpers return the _None_ singleton; tests whose scrutinee both passes rewrote now expect the combined output.
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.
Two call-site peepholes found on the Super Scrabble move generator, both extending the DESIGN.md §5.2 lever (inlining fully applied stdlib members).
Equality predicates (#86)
A fully applied
List.findIndex/List.find/List.existswhose predicate is the section(==) x(or the lambdafun y -> x == y/fun y -> y == xwithynot free inx) now lowers to the C-level scan Python answers fastest:xis evaluated once, beforexs, the argument order of the helper call it replaces. Any other predicate, and any partial application (List.findIndex ((==) l)as a value), keeps the generic_pf_find_indexscan.Match-consumed lookups (#88)
A
matchwhose scrutinee is a fully appliedMap.tryFind k m,List.head xs, orList.get i xs, with exactly the unguarded armsSome v/None(va name,_, or a tuple of those), lowers to theifa person would write, in return and value position alike:No
Optionis constructed, so a program whose onlyOptionwas this one emits noSome/None_classes at all. Operands are bound to temps unless they are names or literals (evaluated once);List.getkeeps the helper's exact bounds test0 <= i < len(xs). A refutable payload, a guard, extra arms, or a non-lookup scrutinee fall through to the ordinarymatch.Tests
tests/compile.rs: snapshot tests for every rewrite, the partial-application and non-equality cases that must keep the helper, the non-atomic operand that hoists to a temp, value-positionmatchinside an expression, and e2e runs against the helper semantics (falsy present values""/[], negative index out of range,0.0vs-0.0returning the element found).Docs:
DESIGN.md§5.2 andINTERNALS.md(lowering passes).Closes #86
Closes #88