Skip to content

Comments

Unify match and match_switch into single match syntax#75

Open
DominicPM wants to merge 1 commit intoawslabs:mainfrom
DominicPM:unify-match-switch
Open

Unify match and match_switch into single match syntax#75
DominicPM wants to merge 1 commit intoawslabs:mainfrom
DominicPM:unify-match-switch

Conversation

@DominicPM
Copy link
Contributor

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 value[simp] tests verifying numeric match evaluation
  • Test coverage for different word sizes, larger numerals, disjunctive numeric patterns

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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>
@dominic-mulligan-aws dominic-mulligan-aws added the enhancement New feature or request label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants