generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 10
Unify match and match_switch into single match syntax #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DominicPM
wants to merge
7
commits into
awslabs:main
Choose a base branch
from
DominicPM:unify-match-switch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Can now use tuple destructuring in `for` loops and `let`. Closes awslabs#64. Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Minor fixes in `Misc/Array.thy` and `Misc/Remove_Enum_Discriminate_Elims.thy`. Got I/Q compiling again. Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
- Make pattern translations total and tolerate wrapper forms to avoid Match in the bcase frontend. - Allow nested patterns in constructor args by expanding collection/translation logic in Basic_Case_Expression. - Normalize tuple patterns into Pair/TNil shape in the shallow match frontend. - Improve shallow match arg translation to distinguish bindings vs constructors and handle nested tuple patterns. - Add nested-pattern showcase/regression tests (Option/Result, tuples, wildcards, if-let and let-else forms). Closes awslabs#65. Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Can now use Boolean-valued pattern guards, for example:
```rust
match x with {
Some(x) if x > 0 => ...,
None => ...,
_otherwise => ...
}
```
Closes awslabs#67.
Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Move all tests from Micro_Rust_Shallow_Embedding.thy into a new dedicated test theory file organized by language feature category. Changes: - Create Micro_Rust_Shallow_Embedding_Tests.thy with tests organized into 21 sections covering all Micro Rust syntax features - Add missing shallow translations for compound assignment operators (-=, *=, %=, <<=, >>=) in Core_Syntax.thy and Micro_Rust_Shallow_Embedding.thy - Fix double negation (!!) parsing by adding explicit syntax rule and AST translation to expand to nested single negations - Fix double dereference (**) parsing similarly - Add tests for error propagation (?), assert_eq!/assert_ne!, signed casts (i32, i64), and all compound assignment operators - Update ROOT to include new test theory Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Implement Rust-style disjunctive patterns (p1 | p2) that work in all
pattern contexts: match, match_switch, if let, let else, and for loops.
Changes:
- Micro_Rust_Syntax.thy: Add _urust_match_pattern_disjunction syntax
with right-associative precedence [1000, 100] 100
- Core_Syntax.thy: Add shallow pattern syntax and expand disjunctions
in parse_translation (expand_disjunction_pattern, expand_branch).
Add switch branch translations for numeric disjunctive patterns.
- Micro_Rust_Shallow_Embedding.thy: Add translation rule and handle
nested disjunctions in shallow_match_pattern_of
- Micro_Rust_Shallow_Embedding_Tests.thy: Add comprehensive tests
including guards, nested patterns, and match_switch. Use three_case
datatype for non-exhaustive if-let/let-else tests.
Examples now supported:
match x { Some(a) | None => ..., _ => ... }
match_switch n { 1 | 2 | 3 => ..., _ => ... }
if let CaseA(x) | CaseB(x) = val { ... }
let Ok(x) | Err(x) = result else { return; };
match nested { Some(Ok(x) | Err(x)) => x, _ => default }
Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
Users now write `match` for all pattern matching - both algebraic patterns (constructors, tuples) and numeric patterns (0, 1, numerals). The system automatically dispatches to the appropriate backend: - Algebraic patterns → HOL case expression (bcase) - Numeric patterns → numeric case selector (ncase) The dispatch logic analyzes patterns at the AST level: - If any pattern has constructor arguments or is a tuple → algebraic - If any pattern is a numeric literal AND all patterns are switch- compatible (no constructor args) → switch - Otherwise → algebraic (default) Changes: - Remove user-facing `match_switch` syntax (internal `_urust_match_switch` retained for implementation) - Add pattern classification that handles disjunctions recursively - Add comprehensive `value[simp]` tests verifying numeric match evaluation - Test coverage for different word sizes, larger numerals, disjunctive numeric patterns Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
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.
Users now write
matchfor all pattern matching - both algebraic patterns (constructors, tuples) and numeric patterns (0, 1, numerals). The system automatically dispatches to the appropriate backend:The dispatch logic analyzes patterns at the AST level:
Changes:
match_switchsyntax (internal_urust_match_switchretained for implementation)value[simp]tests verifying numeric match evaluationBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.