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

Function values requires exact domain type #445

Open
RustanLeino opened this issue Nov 28, 2019 · 0 comments
Open

Function values requires exact domain type #445

RustanLeino opened this issue Nov 28, 2019 · 0 comments
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: verifier Translation from Dafny to Boogie (translator)

Comments

@RustanLeino
Copy link
Collaborator

The current encoding of function values in the verifier only expands a function value to its definition if the static types involved in its application are exactly as in the original function definition. This means that, if Y is a subset type of X, then a function of type X -> int cannot be used in a context that expects a Y -> int.

The following repro illustrates:

function Apply<T>(x: T, f: T -> int): int {
  f(x)
}
function F(x: int): int {
  x
}
lemma Test() {
  assert Apply<int>(4, F) == 4;  // this is verified
  assert Apply<nat>(4, F) == 4;  // this reports an error
}

Internally, the axiom about the function value F (which is called F#Handle in the Boogie encoding) has the form (where Apply1 is a function introduced by Dafny in the Boogie encoding to apply arity-1 function handles):

axiom (forall heap: Heap, bx: Box ::
  Apply1(TInt, TInt, heap, F#Handle(), bx)
     == $Box(F($Unbox(bx): int)));

Note the parameters TInt, which make this axiom useless when these types are applied as something else. A better encoding would leave flexibility in these parameters or, ideally, leave those type parameters out altogether among the arguments to Apply.

@robin-aws robin-aws added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: verifier Translation from Dafny to Boogie (translator) labels Jun 23, 2020
@acioc acioc added this to the Post 3.0 milestone Aug 12, 2020
@robin-aws robin-aws removed this from the Post 3.1 milestone Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: verifier Translation from Dafny to Boogie (translator)
Projects
None yet
Development

No branches or pull requests

3 participants