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

Extending a trait with an opaque function causes error, but only on the commandline and not on VSCode. #4205

Closed
EkanshdeepGupta opened this issue Jun 21, 2023 · 2 comments · Fixed by #4207
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@EkanshdeepGupta
Copy link
Collaborator

EkanshdeepGupta commented Jun 21, 2023

Dafny version

4.1.0

Code to produce this issue

trait T {
  opaque function bar(): (r: int)
}

class F extends T {
  constructor() {}
  opaque function bar(): (r: int) {
    1
  }
}

Command to run and resulting output

$ ./Binaries/Dafny verify  ~/test/git-issue-549.dfy
git-issue-549.dfy(2,18): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
git-issue-549.dfy(2,18): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
git-issue-549.dfy(6,18): Error: wrong number of arguments to function: _module.F.bar (2 instead of 3)
git-issue-549.dfy(2,18): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
git-issue-549.dfy(6,18): Error: wrong number of arguments to function: _module.F.bar (2 instead of 3)
5 type checking errors detected in /var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl

*** Encountered internal translation error - re-running Boogie to get better debug information

/var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl(2958,6): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
/var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl(2959,8): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
/var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl(2959,29): Error: wrong number of arguments to function: _module.F.bar (2 instead of 3)
/var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl(2962,11): Error: wrong number of arguments to function: _module.T.bar (1 instead of 2)
/var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl(2962,34): Error: wrong number of arguments to function: _module.F.bar (2 instead of 3)
5 type checking errors detected in /var/folders/v7/dtr5626966sf_f5665tczxpw0000gr/T/git-issue-549__module.bpl

What happened?

In the Boogie translation, the override axiom for _module.T.bar in class _module.F seems to have the reveal argument missing.

Lines 2955 to 2962 of boogie_print.bpl:

// override axiom for _module.T.bar in class _module.F
axiom 0 <= $FunctionContextHeight
   ==> (forall this: ref :: 
    { _module.T.bar(this), $Is(this, Tclass._module.F()) } 
      { _module.T.bar(this), _module.F.bar($LZ, this) } 
    _module.F.bar#canCall(this)
         || (0 < $FunctionContextHeight && this != null && $Is(this, Tclass._module.F()))
       ==> _module.T.bar(this) == _module.F.bar($LZ, this));

Whereas, lines 2810-2811:

// function declaration for _module.T.bar
function _module.T.bar($reveal: bool, this: ref) : int;```


Interestingly, this example still verifies on the VSCode extension, but not on the command-line.

### What type of operating system are you experiencing the problem on?

Mac
@EkanshdeepGupta EkanshdeepGupta added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Jun 21, 2023
MikaelMayer added a commit that referenced this issue Jun 22, 2023
I add this as a way to simplify boogie debugging, especially in cases when VSCode is not consistent with the command-line like in #4205

I did not add any test for that as it's meant for Dafny development only, but I tested it manually. I borrowed the code from the driver.
@MikaelMayer
Copy link
Member

I was able to look at the generated boogie code from the language server and the CLI. Here are the differences:

VSCode => CLI

 implementation {:verboseName "F.bar (override check)"} OverrideCheck$$_module.F.bar(this: ref)
 {
   var F_$_Frame: <beta>[ref,Field beta]bool;
 
     // initialize fuel constant
     assume AsFuelBottom(StartFuel__module.F.bar) == StartFuel__module.F.bar;
     assume AsFuelBottom(StartFuelAssert__module.F.bar) == StartFuelAssert__module.F.bar;
     assert true;
-    F_$_Frame := lambda#0(null, $Heap, alloc, false);
+    F_$_Frame := (lambda<alpha> $o: ref, $f: Field alpha :: 
+      $o != null && read($Heap, $o, alloc) ==> false);
     assert (forall<alpha> $o: ref, $f: Field alpha :: false ==> false);
 }

Also, in a lot of other places, I see diffs like this, where VSCode emits an equivalence sign, and CLI emits an ==. @RustanLeino any insights on why that might be the case?
VSCode => CLI

 // #requires axiom for _module.F.bar
 axiom (forall $ly: LayerType, this: ref :: 
   { _module.F.bar#requires($ly, this) } 
   this != null && $Is(this, Tclass._module.F())
-     ==> (_module.F.bar#requires($ly, this) <==> true));
+     ==> _module.F.bar#requires($ly, this) == true);

@MikaelMayer
Copy link
Member

But the problem is not in the comparison above. The CLI generates an extra boogie file that VSCode does not, which is suffixed with _module. I guess it's the exported version of the module.

// function declaration for _module.T.bar
function _module.T.bar($reveal: bool, this: ref) : int;
....
// override axiom for _module.T.bar in class _module.F
axiom 0 <= $FunctionContextHeight
   ==> (forall this: ref :: 
    { _module.T.bar(this), $Is(this, Tclass._module.F()) } 
      { _module.T.bar(this), _module.F.bar($LZ, this) }     // Here is the missing reveal argument
    _module.F.bar#canCall(this)
         || (0 < $FunctionContextHeight && this != null && $Is(this, Tclass._module.F()))
       ==> _module.T.bar(this) == _module.F.bar($LZ, this));

MikaelMayer added a commit that referenced this issue Jun 22, 2023
keyboardDrummer pushed a commit that referenced this issue Jul 10, 2023
I add this as a way to simplify boogie debugging, especially in cases
when VSCode is not consistent with the command-line like in #4205

I did not add any test for that as it's meant for Dafny development
only, but I tested it manually. I borrowed the code from the driver.
Should I still list it as a feature?

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants