Skip to content
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

Merged
merged 7 commits into from
Feb 9, 2024
Merged

[Refactor] Pattern matching #1799

merged 7 commits into from
Feb 9, 2024

Commits on Feb 9, 2024

  1. 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.
    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    4055764 View commit details
    Browse the repository at this point in the history
  2. 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.
    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    2ac4a7a View commit details
    Browse the repository at this point in the history
  3. 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.
    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    a4704b1 View commit details
    Browse the repository at this point in the history
  4. 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.
    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    c966dc0 View commit details
    Browse the repository at this point in the history
  5. 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.
    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    0558986 View commit details
    Browse the repository at this point in the history
  6. Apply suggestions from code review

    Co-authored-by: Viktor Kleen <[email protected]>
    yannham and vkleen committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    5978263 View commit details
    Browse the repository at this point in the history
  7. Post-rebase fixup

    yannham committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    e024740 View commit details
    Browse the repository at this point in the history