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

Pattern Matching #4882

Merged
merged 104 commits into from
Mar 1, 2016
Merged

Pattern Matching #4882

merged 104 commits into from
Mar 1, 2016

Conversation

gafter
Copy link
Member

@gafter gafter commented Aug 29, 2015

An implementation of pattern matching as specified in #206. You can follow the progress here. Much of this work will be pulling pieces of the implementation from https://github.com/semihokur/pattern-matching-csharp

Related features possibly to be added at the same time as pattern-matching:

Progress checklist:

  • Scoping for variables introduced in patterns (binders)
  • SemanticModel.GetDeclaredSymbol for pattern variable declarations.
  • Simple pattern matching expressions expression is Type Identifier in most statements.
  • Extend the parser to handle all of the other specified pattern-matching operations.
    • Add tests for the parser, including precedence tests for the edge cases.
    • Augment TestResource.AllInOneCSharpCode to handle all pattern forms.
  • Check for feature availability in the parser (error if feature not supported).
  • Error pattern matching to a nullable value type
  • Implement pattern matching to a type that is an unconstrained type variable (requires a double type test)
  • Implement and test scoping in remaining "odd" contexts (where the scope is not the enclosing statement)
    • pattern matching in ctor-initializers
    • pattern matching in catch filters
    • pattern matching in field initializers
    • pattern matching in expression-bodied methods and properties
    • pattern matching in an expression-bodied lambda
    • pattern matching in an expression-bodied local function
    • pattern matching in attributes and parameter defaults (lookup and error recovery)
    • test these "odd" contexts in SemanticModel.
  • Semantics and code-gen for all pattern forms
    • Type ID
    • *
    • 3
      • matching with exact type for integral constants (as a short-term hack)
      • matching with appropriate integral conversions
    • var ID
    • Type { ID is Pattern ... }
    • Type ( Pattern ... ) This will be done when Records are integrated.
  • Extend the switch statement to handle patterns
    • Parser
    • Syntax Tests
    • Binding
    • Binding (failure cases) tests
    • Flow analysis
    • Lowering
    • Code-gen tests
  • Allow declaration of operator is This will be done when Records are integrated.
  • An expression form for mutli-armed pattern-matching (match?)
  • Extend the scope of a pattern variable declared in a catch filter to the catch block.
    • Test for error on reusing a variable name, and lambda-capturing.
  • Add a decision tree to enable
    • completeness checking: a mutli-armed pattern-matching expression is required to be complete
    • subsumption checking: a branch of a switch statement or match expression may not be subsumed by the totality of previous branches
  • Generate efficient code like switch does in corresponding situations.
  • Test for name conflicts with locals in enclosing scopes for normal and "odd" contexts.
  • Lots more Tests!

Records will be added in a separate feature branch.

Support for `Expression is Type Identifier` as the first pattern-matching operator
Including implementation of scoping for match-variables
1. Do not parse as a declaration pattern when an identifier might be a contextual identifier with its usual meaning. This occurs in query expressions.
2. Implement flow analysis for declaration patterns: any pattern variables are *definitely assigned when true* for the enclosing `is` pattern matching expression
3. Implement lowering
4. Punch through; one test case works end-to-end.
dangling local declarations in a speculative semantic model,
marking them
        [Fact(Skip = "#206")]
@gafter
Copy link
Member Author

gafter commented Aug 29, 2015

/cc @semihokur

<Field Name="IsVar" Type="bool"/>
</Node>

<Node Name="BoundIsPattern" Base="BoundExpression">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called BoundIsPatternExpression

@gafter
Copy link
Member Author

gafter commented Aug 29, 2015

jaredpar and others added 28 commits February 25, 2016 15:23
It looks like recent changes made highlight refs functional on pattern matching variables.  Locking in the victory.

closes #9110
Test highlight refs on simple pattern match
Test scope of pattern variables declared within an 'if' statement.
Do not allow a local function declaration as an embedded statement.
Handle deep expressions better in the pattern variable finder.
Do not allow a let-statement as an embedded statement.
…tching

Reverse engineered positional matching
Test/fix scoping of pattern variables in an expression-bodied lambdas and query expressions.
This addresses #9104 in the following ways:

- Fixes the gaps in data flow analysis that were causing the original assert in the bug.
- Disables extract method on pattern matching for now.  Filed #9244 to design scenarios here.

In order to fill in the data flow gaps I used commit 9d36a64 as a guide.  This change removed declaration expressions from the code base and hence gave a good outline of where data flow would be affected by pattern declaration expressions.

closes #9104
Implement SymbolInfo for the property name of a property pattern
Disable extract method on pattern matching features
Test/fix scoping of pattern variables in expression-bodied functions and properties.
Pattern format and indentation work
Add a test for an ambiguous property reference in pattern matching.
Merge future to features/patterns
@jaredpar jaredpar merged commit 701c3ae into future Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants