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

More relaxed aliasing checks for imperative programs #973

Merged
merged 1 commit into from
Apr 10, 2021

Conversation

jad-hamza
Copy link
Contributor

No description provided.

@jad-hamza
Copy link
Contributor Author

@samarion @vkuncak Is it ok to disable argument aliasing checks for pure functions?

@vkuncak
Copy link
Collaborator

vkuncak commented Apr 9, 2021 via email

@jad-hamza
Copy link
Contributor Author

I'm not sure about the definition, at least being pure prevents from modifying arguments, but I don't know if local var's are allowed.

Otherwise if they are only not writing, we need to check.

Do you have an example of what can go wrong?

@vkuncak
Copy link
Collaborator

vkuncak commented Apr 9, 2021 via email

@jad-hamza
Copy link
Contributor Author

Right, your example makes sense, if this was allowed, we could assign x.f and y.f to different values and assert that they're different, which would go through while it shouldn't.

Fortunately this is rejected by the effects checker:

import stainless.annotation._

object Test {
  case class A(var x: BigInt)

  @pure
  def f(a: A) = {
    val oldX = a.x
    a.x = 0
    a.x = oldX
  }
}

with the error:

Functions marked @pure cannot have side-effects

def checkPurity(fd: FunAbstraction): Unit = {
val effs = effects(fd.fullBody)
if ((fd.flags contains IsPure) && !effs.isEmpty)
throw ImperativeEliminationException(fd, s"Functions marked @pure cannot have side-effects")

@jad-hamza jad-hamza merged commit 87146e0 into epfl-lara:master Apr 10, 2021
@jad-hamza jad-hamza deleted the relax-aliasing branch April 10, 2021 06:06
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