Skip to content

feat: implement structured pattern matching with nested constructor support#275

Open
metalurgical wants to merge 2 commits intoBlockstreamResearch:masterfrom
metalurgical:issue_250
Open

feat: implement structured pattern matching with nested constructor support#275
metalurgical wants to merge 2 commits intoBlockstreamResearch:masterfrom
metalurgical:issue_250

Conversation

@metalurgical
Copy link
Copy Markdown
Contributor

@metalurgical metalurgical commented Apr 6, 2026

Introduce a full pattern matching pipeline for match expressions, including typed pattern representation, validation, and a structured decision tree.

This establishes a foundation for deterministic and type-safe match evaluation, enabling correct handling of nested patterns and complex destructuring.

Additionally extract tests for parse to new file to reduce file bloat and improve maintainability.

Overview Diagram

flowchart TD
    A["match syntax"] --> B{"Old vs New"}

    B -->|Old| C["2 arms only → normalize"]
    B -->|New| D["multiple arms → analyze → validate → compile"]

    C --> E["Match.left/right"]
    D --> E
Loading

Expanded Diagram

flowchart TD
    A["match syntax"] --> B{"Old vs New"}

    B -->|Old| C1["exactly 2 arms required"]
    C1 --> C2["classify arm pair"]
    C2 --> C3["Left/Right or None/Some or False/True"]
    C3 --> E["Match.left/right"]

    B -->|New| D1["parse multiple arms"]
    D1 --> D2["convert to structured pattern representation"]
    D2 --> D3["assign types to patterns"]

    D3 --> D4["ensure all arms use the same match kind"]
    D4 --> D5["check for duplicate arms"]
    D5 --> D6["check for overlapping patterns"]
    D6 --> D7["check for unreachable arms"]
    D7 --> D8["check exhaustiveness"]

    D8 --> D9["build decision tree"]
    D9 --> D10["convert back to two-arm form"]
    D10 --> E["Match.left/right"]
Loading

…upport

Introduce a full pattern matching pipeline for match expressions, including typed pattern representation, validation, and a structured decision tree.

This establishes a foundation for deterministic and type-safe match evaluation, enabling correct handling of nested patterns and complex destructuring.

Additionally extract tests for parse to new file to reduce file bloat and improve maintainability
@metalurgical metalurgical requested a review from delta1 as a code owner April 6, 2026 14:00
@metalurgical
Copy link
Copy Markdown
Contributor Author

Resolves #250
Closes #250

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 9, 2026

Quite tough to review, as a single commit contains too many changes

The main reason for having smaller commits is to isolate possible regressions, so when the commit history follows the rule of a "logical sequence of clearly defined independent changes" it is easier to debug

For example, if at some point a bug/regression is discovered, I can write a test and find the exact commit that introduced it
But if this regression happened in a commit like this, it would be much harder to say where exactly

This is why I have to ask you to split this MR into smaller commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants