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

fix: Set/forall comprehensions with subtyping for issue #697 #1522

Merged
merged 38 commits into from
Dec 2, 2021

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Oct 19, 2021

This PR is a quick fix for issues #697 and #698.

The problem: Unsound comprehensions with subset types.

  • For-comprehensions, Exist-comprehensions, Map-comprehensions and Set-comprehensions had a problem when encountering subset types: Dafny was not emiting the code of the subset constraint, to ensure that the constraint of the comprehension is not executed with undesirable data.

The solution implemented in this PR:

How I tested it.

I added 8 tests:

  • git-issues/git-issue-697.dfy: A set comprehension with compilable subset constraint that did not compile correctly and used to crash at execution. Now it compiles and does not crash.
  • git-issues/git-issue-697b.dfy: A map comprehension with compilable subset constraint that did not compile correctly and used to crash at execution. Now it compiles and does not crash.
  • git-issues/git-issue-697c.dfy: A set comprehension, a map comprehension and a forall comprehension with ghost subset constraint that used to compile and crash at execution. Now it does not compiles and raises six errors.
  • git-issues/git-issue-697d.dfy: A set comprehension with ghost & compilable subset constraint that used to compile and crash at execution. Now it compiles and does not crash.
  • git-issues/git-issue-697e.dfy: A forall comprehension with only inferred ghost subset constraint. It used to compile and crash at execution time. Now it compiles and does not crash.
  • git-issues/git-issue-697f.dfy: A ghost subset constraint that is never used in comprehensions. It used to compile and continues to compile, ensuring this PR does not break this existing desirable behavior.
  • git-issues/git-issue-698.dfy: A forall comprehension with compilable subset constraint that did not compile correctly and used to crash at execution. Now it compiles and does not crash.
  • git-issues/git-issue-698b.dfy: An exist comprehension with compilable subset constraint that did not compile correctly and used to crash at execution. Now it compiles and does not crash.

@MikaelMayer MikaelMayer marked this pull request as ready for review November 2, 2021 21:27
@MikaelMayer MikaelMayer enabled auto-merge (squash) November 9, 2021 18:46
Ensures that CheckIsCompilable does not try to report errors if no resolver is provided.
Source/Dafny/Rewriter.cs Outdated Show resolved Hide resolved
Test/git-issues/git-issue-697.dfy Outdated Show resolved Hide resolved
Test/git-issues/git-issue-697.dfy Outdated Show resolved Hide resolved
Test/git-issues/git-issue-697b.dfy Outdated Show resolved Hide resolved
Test/git-issues/git-issue-697b.dfy Show resolved Hide resolved
Source/Dafny/Resolver.cs Outdated Show resolved Hide resolved
Source/Dafny/Resolver.cs Show resolved Hide resolved
Source/Dafny/Util.cs Show resolved Hide resolved
Source/Dafny/Util.cs Show resolved Hide resolved
Test/git-issues/git-issue-697d.dfy Outdated Show resolved Hide resolved
- Fixed Explicitely => Explicitly everywhere.
- Use of NormalizeExpand(true) in the two pattern matching places
- Defined `AsSubsetType` in DafnyAST
- "var" and "int" closer to the for loop
- Simpler getter for ErrorReporter repporter
- Curly braces around newly inserted single if-statements.
- String interpolation for error message
- Removed dead code
- Corrected indentation in dfy files
- Removed useless type annotations in dfy files
- test 697b prints something
- Test 697d tests forall and exists with compilable constraints and prints something.
@MikaelMayer MikaelMayer merged commit 37d38f0 into master Dec 2, 2021
@MikaelMayer MikaelMayer deleted the fix-697 branch December 2, 2021 00:12
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.

Set comprehension should verify element-type subset constraints
2 participants