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

Enforce purity for class invariants #1475

Merged
merged 1 commit into from Nov 9, 2023
Merged

Conversation

mario-bucev
Copy link
Collaborator

Also adds some explanation when purity is expected, specifying which impure functions were called.
Closes #1474

@vkuncak
Copy link
Collaborator

vkuncak commented Nov 7, 2023

Can we also have a first few lines in docs on purity annotation of parameters? Here is a patch for reference to the thesis.

patch.txt

@mario-bucev
Copy link
Collaborator Author

Yes, good idea!

@mario-bucev
Copy link
Collaborator Author

I've added some examples for @pure parameters in the section discussing @extern functions and methods of non-sealed traits.

@vkuncak
Copy link
Collaborator

vkuncak commented Nov 8, 2023

This test fails?

import stainless._
import stainless.lang._
import stainless.annotation._

object i1306b {
  def root(a: BigInt): BigInt = {
    require(a >= 0)
    var i: BigInt = 0
    def nextSquare = ((i + 1) * (i + 1))
    def accessI(x: BigInt, y: BigInt) = i + x + y
    def modifyI(x: BigInt, y: BigInt) = { i += x + y }
    (while (nextSquare <= a) {
      decreases(a - nextSquare)
      val z = accessI(a, nextSquare)
      assert(z == i + a + (i + 1) * (i + 1))
      val w = accessI(a, i)
      assert(w == i + a + i)
      i = i + 1
    }) invariant { i >= 0 && ((i * i) <= a) }
    i
  } ensuring { root => (root * root) <= a && a < ((root + 1) * (root + 1)) }
}

@mario-bucev
Copy link
Collaborator Author

This one is flaky, funnily enough I've just opened a PR to disable it (#1478).
The CI was unexpectedly slower for some of the PRs, there might be other processes running on the server.

@vkuncak vkuncak merged commit 34be0ae into epfl-lara:main Nov 9, 2023
2 checks passed
@mario-bucev mario-bucev deleted the fix-i1474 branch November 9, 2023 15:07
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.

Crash in Inox type checker when using freshCopy
2 participants