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

Impure assume #779

Merged
merged 1 commit into from
Jul 24, 2024
Merged

Impure assume #779

merged 1 commit into from
Jul 24, 2024

Conversation

bruggerl
Copy link
Contributor

This PR lifts the definition of assume statements such that impure expressions are supported.

In regards to the translation to Viper, consider the following Gobra code snippet:

type person struct { ... }

func test() {
    p := &person{...}
    assume acc(p)
    inhale acc(p)
}

Gobra generates the following Viper code for the assume and inhale statement in the function test:

// assume acc(*p_V0)
inhale (let fn$$4 ==
    (p_V0) in
    perm((ShStructget0of2(fn$$4): Ref).String$$$$_E_$$$) >= write &&
    perm((ShStructget1of2(fn$$4): Ref).Intint$$$$_E_$$$) >= write)
      
// inhale acc(*p_V0)
inhale (let fn$$5 ==
    (p_V0) in
    acc((ShStructget0of2(fn$$5): Ref).String$$$$_E_$$$, write) &&
    acc((ShStructget1of2(fn$$5): Ref).Intint$$$$_E_$$$, write))

This is in line with what Viper does. For example, the Viper program

field f: Int

method test(a: Ref)
{
    assume acc(a.f)
    inhale acc(a.f)
}

gets translated to the following code (obtained with --printTranslatedProgram):

field f: Int

method test(a: Ref)
{
  inhale perm(a.f) >= write
  inhale acc(a.f, write)
}

@bruggerl bruggerl requested a review from jcp19 July 24, 2024 08:21
}

func f() {
p := &person{name: "Pereira", age: 12}
Copy link
Contributor

Choose a reason for hiding this comment

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

😄 😄

@bruggerl bruggerl merged commit b28b858 into master Jul 24, 2024
3 checks passed
@bruggerl bruggerl deleted the bruggerl/impure-assume branch July 24, 2024 10:16
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