-
Notifications
You must be signed in to change notification settings - Fork 89
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
[Refactor] Pattern matching #1799
Commits on Feb 9, 2024
-
Refactoring of pattern destructuring
This commit is a preliminary work for the upcoming ADTs (and more generally the introduction of pattern matching, instead of just having destructuring). The refactoring aims at installing a consistent naming, simplify the representation of patterns and their associated method, and pave the way for other patterns that just records. Indeed, the previous implementation often made the implicit assumptions that patterns were only record patterns.
Configuration menu - View commit details
-
Copy full SHA for 4055764 - Browse repository at this point
Copy the full SHA 4055764View commit details -
Avoid illegal state for record patterns
Record pattern was previously using a tuple `(open: bool, rest: Option<LocIdent>)` to represent the presence of either no tail, an non-capturing tail `..`, or a capturing tail `..rest`. This representation allows the illegal state `(false, Some("x"))`: indeed, if the tail is capturing, the record contract is necessarily open. This commit flattens this representation to a single enum that correctly represents those three different cases, instead of the 4 allowed by the previous representation.
Configuration menu - View commit details
-
Copy full SHA for 2ac4a7a - Browse repository at this point
Copy the full SHA 2ac4a7aView commit details -
Move the alias field to Pattern
The AST of patterns had a special node for an aliased pattern, which was a variant containing the alias and a potentital nested pattern. However, this doesn't model correctly patterns: usually, it doesn't make sense to stack aliases (and the parser won't accept it), but the previous representation accepted ASTs for things like `x @ y @ z @ <pat>`, which incurs additional burden to handle, although it can actually never happen. Additionally, the alias of the top pattern was duplicated as an optional field in the `LetPattern` and `FunPattern` nodes of the `Term` AST. This commit makes things simpler by storing `alias` as an optional field directly in the `Pattern` struct, which makes it accessible without having to pattern match on an enum variant, and forbids nested aliases. Doing so, we remove the duplication from the `LetPattern` and `FunPattern`, which now only takes a pattern instead of an optional identifier and a pattern, leading to code simplification.
Configuration menu - View commit details
-
Copy full SHA for a4704b1 - Browse repository at this point
Copy the full SHA a4704b1View commit details -
Restore old behavior in typed patterns
The refactoring of patterns has introduced a slightly different algorithm for typechecking patterns, which isn't entirely backward-compatible, although it's more consistent. We'll probably rule out (i.e. depreacte) the offending special cases, but until then, this commit restores the previous behavior, which fixes a previously failing test.
Configuration menu - View commit details
-
Copy full SHA for c966dc0 - Browse repository at this point
Copy the full SHA c966dc0View commit details -
Various renamings in destructuring (now pattern)
This commit only applies pure renaming of several symbols of the destructuring module for improved clarity. The whole module is also moved to `term::pattern`, as patterns are just syntactic component of the term AST.
Configuration menu - View commit details
-
Copy full SHA for 0558986 - Browse repository at this point
Copy the full SHA 0558986View commit details -
Apply suggestions from code review
Co-authored-by: Viktor Kleen <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 5978263 - Browse repository at this point
Copy the full SHA 5978263View commit details -
Configuration menu - View commit details
-
Copy full SHA for e024740 - Browse repository at this point
Copy the full SHA e024740View commit details