Repository navigation
Conversation
`A { x, .. } | B { x, .. } => x` failed with duplicate-binding errors.
Each alternative now binds its names afresh, and a name both bind is
the left alternative's binding. The alternatives must bind the same
names with one type and binding mode (8-0159, 8-0160, 8-0161), and
8-0076 is gone.
The decision tree gives each binding alternative rows of its own, so a
leaf binds what its alternative matched; `match` lowers each arm per
leaf. Outside `match` the matching leaves meet in one block: bindings
every leaf shares bind there once, and values that depend on the
alternative bind per leaf. An access bound at a different part in each
alternative can't meet there, so it is reported (8-0162). Irrefutable
patterns with binding alternatives are tested like `let ... else`.
References and rename found the uses of a binding and one binding site, so renaming `x` in `A(x) | B(x)` left the other alternative's `x`. The first alternative's site is the definition, and the others count as references.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e406e15cc5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Each `|` pattern that binds names was expanded up front into a row per combination of alternatives. `(a | a, b | b, ...)` over 20 fields took 44 s and 12 GB before the decision tree dropped the redundant rows, and checking an `if let`, `let` or `for` expanded the same way. A row now expands a binding `|` pattern only when a switch tests its column, and records the alternative it takes; a leaf binds by walking the arm's pattern through those choices. The check for accesses bound apart compares each binding's occurrences, once the body's types are known.
…dings # Conflicts: # crates/language-server/src/functionality/rename.rs
`V { n: x | x }` and `T { t: (true, x, _) | (false, _, x) }` run, and a
name missing from an alternative is reported at the field.
Each row carried its checked pattern for every column, so a switch could find the binding `|` patterns it tests, and swapping or specializing the matrix rebuilt it to keep them in step. A row's pattern at a column now comes from its root, the alternatives it took and the column's occurrence, and the matrix operations are matchcov's again.
A `match` lowered an arm's body at every decision-tree leaf that reaches it: once per `|` alternative, and once per path to a catch-all arm. An arm reached from several leaves now has one body. Each leaf binds what depends on its path and jumps to it, and the body binds what every leaf binds at one path. An arm whose leaves bind an access at different parts keeps a body per leaf, since an access has one definition. With a four-alternative arm and a two-leaf catch-all arm, runtime code at -O1 drops from 1259 to 743 bytes.
Pattern checking expanded every alternative of a `|`, so each `|` column doubled the rows of the exhaustiveness matrix: `(a | a, ...)` over 22 columns took 1.7 GB in `fe check`, and `((a, _) | (_, a), ...)` over 16 took 480 MB. The decision tree expanded `(a, _) | (_, a)` the same way. An alternative after one that matches anything (a wildcard, or the only constructor of its type with such fields) matches nothing more. Leave such alternatives out of the patterns matchcov sees and of the decision tree's expansion. Thirty such columns now check in 0.1 s.
This branch has not been deployed
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 alternatives of a
|pattern may now bind names, as in Rust:This used to fail with 8-0032 duplicate binding and 8-0076 "bindings in
|patterns are not supported".|where a switch tests its column, and a leaf binds what the alternative it took matched.if let,while let,let,let ... elseandfor, the matching leaves meet in one block. Bindings every leaf shares bind there once; values that depend on the alternative bind per leaf. An access (mut x,ref x) bound at a different part in each alternative would need two targets, which normalized IR doesn't allow, so it is reported as 8-0162 with a hint to usematch(it previously failed with an internal 16-0004).Also:
matcharm reached from several decision-tree leaves (each|alternative, or each path to a catch-all arm) lowers its body once; the leaves bind and jump to it. An arm that binds an access at a different part per alternative keeps a body per leaf. A probe contract's runtime code goes from 1259 to 743 bytes.|column no longer doubles the matrix.Docs in
docs/language/patterns.md.