-
Notifications
You must be signed in to change notification settings - Fork 28
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
Introduce support for closures #479
Conversation
…e domain, satisfies functions, default getter
…lements expressions
…avoid access permissions problems
I think your suggestion is ok. @jcp19 At some point, we should unify the nodes, e.g. something like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the encoding files. I have some comments, but overall looks quite positive. You definitely need more documentation. I still need to review the desugarer and the encoding parts (after you add documentation).
src/main/scala/viper/gobra/translator/encodings/closures/ClosureDomainEncoder.scala
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/MethodObjectEncoder.scala
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/MethodObjectEncoder.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/MethodObjectEncoder.scala
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureEncoding.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureEncoding.scala
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureEncoding.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureEncoding.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureSpecsEncoder.scala
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments
src/main/scala/viper/gobra/frontend/info/implementation/resolution/NameResolution.scala
Outdated
Show resolved
Hide resolved
… termination measures when unnecessary
src/main/scala/viper/gobra/translator/encodings/closures/ClosureDomainEncoder.scala
Outdated
Show resolved
Hide resolved
src/main/scala/viper/gobra/translator/encodings/closures/ClosureDomainEncoder.scala
Outdated
Show resolved
Hide resolved
I have now looked at everything. I have a few more comments, but nothing should be particularly big. After my comments are addressed, I think we can merge it and then do later changes in new pull requests. Some parts in the ghost checker seem odd, but I have the impression that the fault lies with how we have handled interface implementation proofs so far. |
Co-authored-by: Felix Wolf <[email protected]>
Co-authored-by: Felix Wolf <[email protected]>
@Felalolf I have now addressed all of the comments |
Looking at the tests, it looks like the warning that closures are an experimental feature is being printed on every test, even those that do not use the feature at all - this suggests that the closure encoding is always generated, regardless of whether it is used. Could we generate the closures' viper code only when we need them? |
This PR introduces support for closure verification in Gobra.
The new primitives are:
Function and method objects, operands with function types obtained from functions or methods. They can be assigned to variables and treated as closures. For example, assuming there exist function
f1
and methodSomeStruct.m1
, one can writec := f1
orc := SomeStruct{...}.m1
.Closure spec instances, entities that use existing functions or function literals, in combination with 0 or more parameters, to express properties of closures. For examples, assume that there exists function (or literal)
func fsp(n int, m bool) (r int)
. The possible closure spec instances arefsp
,fsp{2}
,fsp{m: true}
,fsp{2, true}
, which have respective typesfunc(int, bool)int
,func(bool)int
,func(int)int
,func()int
. Each parameter is associated with one argument of the base function.Implementation assertions, which assert that a closure implements a particular spec. Example:
c implements fsp{m: true}
. This means that it can be called assuming the preconditions offsp
, and ensuring the postconditions offsp
.Calls with spec, which allow to call a closure using some spec that we know it implements. Example:
c(3) as fsp{m: true}
. For the purposes of verification, this is equivalent to callingfsp(3, true)
, with the additional precondition thatc
implementsfsp{m: true}
.Closure spec implementation proofs, that allow to verify that a closure implements a certain spec. Example:
The proof verifies if, assuming the preconditions of
fsp
and assigning valuetrue
to the argumentm
, it's possible to establish the preconditions off
and, after the call, the postconditions offsp
are established. After this statement, the assertionc implements fsp{m: true}
holds.Spec implementation proofs can also be used with function or method objects. In this case, the call in the proof can be a normal function/method invocation. For example, assuming
f1
is a function, we can write (if the type of the function matches the type of the spec):From now on
f1 implements fsp{3}
holds and it's possible to callf1(_) as fsp{3}
. Similarly for methods.