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

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 10, 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

I expect to see a way smaller commits

@metalurgical
Copy link
Copy Markdown
Contributor Author

metalurgical commented Apr 10, 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

I expect to see a way smaller commits

I understand the concern around splitting the PR, and in many cases I would agree that smaller, separated commits improve reviewability.

In this case, however, the core of the change is concentrated in:

Everything else follows from this and consists of new logic rather than modifications to existing behavior.

It has been structured as a single unit so it can be reviewed in a working state.

Splitting this into separate commits would likely introduce more overhead by requiring context to be reconstructed across commits and would be simpler to review as it currently is.

Additionally, I did add the example case that was presented on the original issue as a test case as well for completeness (in a separate commit).

Happy to discuss it further if that would help.

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