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

Ordered, nested matching of datatypes and constants #458

Merged
merged 148 commits into from
Apr 7, 2020

Conversation

osavaryb
Copy link
Contributor

Added support for ordered, nested matching of datatypes and constants.

Olivier Savary Belanger added 30 commits October 22, 2019 13:26
…asePatterns and construct MatchCase (with Arguments) instead of CasePatterns
…o more testing. Also, investigate weird printing without rprint option
…out). MultipleMatching(tuple) not implemented. Constant matching not implemented
…nchExpr, will change its return type and do this
…BranchStatement, will make it work on RBranchExpr tomorrow
…branch in branches, which may happen on malformed input
…bug report dafny-lang#369 and related (throw an error on Bar(Bar) if Bar(value:Foo), but desugar if Bar(value:int))
…in [3]. Leaving a bit of debug code in while I perform most testing
@robin-aws
Copy link
Member

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: a9ec0cd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@osavaryb
Copy link
Contributor Author

osavaryb commented Mar 5, 2020

Return path, inductive lemmas

In Test/dafny3/Inc.dfy.expect, the "this return path" location has changed (from before the PR). All the places where this occurs (which I think is just in this file) in this file seem to be in inductive lemmas. Is there a bug to look into there?

Location of case, not variable declaration> L9 of Test/git-issues/git-issue-495.dfy L9 and L565 of Test/dafny0/ResolutionErrors.dfy seem like they may be the same problem. It seems that the bound variable gets the location of the enclosing constructor. Can this be changed?

I'll have a closer look at this over the weekend, the second issue (with git-issue-495 and ResolutionErrors) is due to how the selector's token (used when generating fresh variables in the PM compiler) is overwritten by the RBranch's token when let-bound in that branch. I should be able to get better error location by overwriting these token earlier. 

Missing-case error messages

In a program like:

function F(xs: List): int {
  match xs  // missing case in case statement: Nil
  case Cons(x, Cons(y, rest)) => 5
  case Nil => 8
}

I don't find the error message as helpful as I would wish. The missing Nil is not the one that is given in the function, but the Nil in Cons(_, Nil). Is there a way to make such error messages more specific?
This is a bit complicated since the missing case error is thrown by the verifier while doing a semantic exhaustiveness check...I may be able to generate the missingCases during NestedMatch desugaring instead of while resolving the Match.

There's also something else with this message. There are no "case statements" in Dafny--they are "match statements". Furthermore, the function above does not have a "match statement" but a "match expression".

This is unrelated to the PR, but I will update the error messages in Translator.cs

Verification message for missing case

In the program

datatype Dt = Real(real)
method U(d: Dt) {
  match d  // assertion violation
  case Real(15.0) =>
}

This program is erroneous, because it's missing cases for non-15.0 reals. However, the error message is just the mysterious "assertion violation". This should be improved.

 This example gets desugared to  match d {
    case Real(_mcc#0: real) =>
      {
        assert _mcc#0 == 15.0;
      }
I may be able to do better by attaching a custom error message to the assertion generated by the lack of default case in a constant match.

Checking redundant cases

The analysis incorrectly reports a "redundant branch" error for this program:

datatype PairOfNumbers = P(int, int)
method M(p: PairOfNumbers) {
  match p
  case P(10, 10) =>
  case P(10, 11) =>  // this branch is redundant
  case _ =>
}

Fixed (and added as test case in PatternMatching.dfy), thank you!

Olivier Savary Belanger added 21 commits March 12, 2020 09:15
…Container stands for a location from the source file.
… error message for missing cases in constant matching
Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

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

I reviewed the latest commits. Thank you for the changes!

I'm thinking the only remaining issue is getting the tests to all pass (StateMonad.dfy is failing).

Source/Dafny/DafnyAst.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Test/patterns/PatternMatching.dfy Show resolved Hide resolved
Test/patterns/PatternMatching.dfy.expect Outdated Show resolved Hide resolved
@RustanLeino RustanLeino merged commit f414931 into dafny-lang:master Apr 7, 2020
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.

5 participants