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

Disable ShowSnippets during Test Generation #4216

Merged
merged 5 commits into from
Jun 27, 2023

Conversation

Dargones
Copy link
Collaborator

The --show-snippets breaks test generation because it relies on casting of Boogie.IToken to Dafny.IToken here and test generation makes changes to the Boogie AST that may introduce new tokens that cannot be cast. This PR disables the option, recently enabled by default, during test generation. An alternative would be to surround the cast with try-catch, but it seems that outside test generation purposes it is probably safe to assume that the cast succeeds. @atomb, @robin-aws would it be possible to merge this before the next release to make sure test generation stays stable?

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Copy link
Collaborator

@davidcok davidcok left a comment

Choose a reason for hiding this comment

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

I suggest you add a comment in the ref-man as well that --show-snippets is always disabled for these two commands.

@Dargones
Copy link
Collaborator Author

Dargones commented Jun 25, 2023

Thank you for pointing out to the reference manual, @davidcok! I have added a note about --show-snippets and have fixed a few things in the existing description of the generate-tests option as well. From the user perspective, I don't think much will change with --snow-snippets being disabled - test generation does not perform verification of the original Dafny code.

@keyboardDrummer
Copy link
Member

test generation makes changes to the Boogie AST that may introduce new tokens that cannot be cast.

Can't we change that?

@Dargones
Copy link
Collaborator Author

Can't we change that?

In principle, yes, and I am working on an overhaul of inlining that will move many AST traversals from Boogie to Dafny and move the code closer to addressing this issue. However, I don't think I know of a way to immediately make sure all tokens can be cast. One major obstacle is that I need to copy Boogie ASTs and the only way of doing this is by printing them to file and then parsing, which loses all connection to Dafny tokens.

In the near future, I think, the only way of making sure test generation does not break is by disabling --sow-snippets.

Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

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

This mostly looks great. The one suggestion I have is to also fix ShowSnippets for the case where there is no Dafny source location information available. I'm thinking that you could replace this code:

if (Options.Get(ShowSnippets)) {
WriteSourceCodeSnippet(tok, tw);
}

with something like

    if (Options.Get(ShowSnippets)) {
      if(tok is IToken dafnyTok) {
        WriteSourceCodeSnippet(dafnyTok, tw);
      } else {
        ErrorWriteLine(tw, "No Dafny location information, so snippet can't be generated."); 
      }
    }

And then make WriteSourceCodeSnippet take a Dafny token instead of a Boogie token.

@Dargones
Copy link
Collaborator Author

Thank you, @atomb! This makes sense, I have made the change.

@atomb
Copy link
Member

atomb commented Jun 27, 2023

One tiny additional thing: it seems like the format check wants some white space changes.

Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

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

Looks good!

@atomb atomb merged commit 2b26b9d into dafny-lang:master Jun 27, 2023
19 checks passed
EkanshdeepGupta pushed a commit that referenced this pull request Jun 28, 2023
The `--show-snippets` breaks test generation because it relies on
casting of `Boogie.IToken` to `Dafny.IToken`
[here](https://github.com/dafny-lang/dafny/blob/d72dc7a85ae5d662dda78f927463d1e56b4a0696/Source/DafnyCore/DafnyConsolePrinter.cs#L54)
and test generation makes changes to the Boogie AST that may introduce
new tokens that cannot be cast. This PR disables the option, recently
enabled by default, during test generation. An alternative would be to
surround the cast with try-catch, but it seems that outside test
generation purposes it is probably safe to assume that the cast
succeeds. @atomb, @robin-aws would it be possible to merge this before
the next release to make sure test generation stays stable?


By submitting this pull request, I confirm that my contribution
is made under the terms of the MIT license.

---------

Co-authored-by: Aleksandr Fedchin <[email protected]>
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.

None yet

4 participants