Skip to content

Add opaque/reveal to Gobra#715

Merged
jcp19 merged 23 commits intoviperproject:masterfrom
dnezam:master
Feb 8, 2024
Merged

Add opaque/reveal to Gobra#715
jcp19 merged 23 commits intoviperproject:masterfrom
dnezam:master

Conversation

@dnezam
Copy link
Contributor

@dnezam dnezam commented Dec 27, 2023

Overview

This pull request implement opaque and reveal for functions and methods in Gobra.

Similar to the meaning of opaque and reveal in Dafny (Dafny's reference), an opaque function does not expose its body by default. The programmer can explicitly reveal the body of a function call using reveal. Please refer to opaque-fac2.gobra and opaque-fac3.gobra for examples.

Motivation

Not unnecessarily exposing the body of a pure function and hence reducing the context of the solver may increase proof stability and improve performance. This is something that @jcp19 and I plan to investigate in the context of my practical work.

Implementation

opaque and reveal are implemented by automatically adding the corresponding annotations on the Viper level.

Related pull requests/commits

QUES in question was added as comment on PR.
@dnezam dnezam marked this pull request as ready for review February 5, 2024 16:15
Copy link
Contributor

@jcp19 jcp19 left a comment

Choose a reason for hiding this comment

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

LGTM. I have a few comments, mostly minor things. After they are addressed, this should be ready to merge

@dnezam
Copy link
Contributor Author

dnezam commented Feb 8, 2024

We currently do not have tests for the following errors:

  • "Cannot reveal a predicate expression instance" (unsure how a test should look like)
  • "Cannot reveal a predicate access" (unsure how a test should look like)
  • "Cannot reveal a closure call" (such a program would probably not even parse)

Is that alright?

@dnezam dnezam requested a review from jcp19 February 8, 2024 11:47
@jcp19
Copy link
Contributor

jcp19 commented Feb 8, 2024

We currently do not have tests for the following errors:

  • "Cannot reveal a predicate expression instance" (unsure how a test should look like)
  • "Cannot reveal a predicate access" (unsure how a test should look like)
  • "Cannot reveal a closure call" (such a program would probably not even parse)

Is that alright?

That is fine. I think the only thing missing is disallowing marking interface methods with opaque. After this, we can merge the PR

@dnezam
Copy link
Contributor Author

dnezam commented Feb 8, 2024

Disallowing marking interfaces with opaque should be line 38-40 in StmtTyping.scala, while the error should be exercised by opaque-interface-fail1.gobra.

@jcp19
Copy link
Contributor

jcp19 commented Feb 8, 2024

Disallowing marking interfaces with opaque should be line 38-40 in StmtTyping.scala, while the error should be exercised by opaque-interface-fail1.gobra.

oops, I missed this; sorry!

Copy link
Contributor

@jcp19 jcp19 left a comment

Choose a reason for hiding this comment

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

LGTM

@jcp19 jcp19 merged commit 88e0a9b into viperproject:master Feb 8, 2024
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