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

Make the Boogie representation of the Dafny heap use only Box #4020

Merged
merged 26 commits into from
Aug 2, 2023

Conversation

atomb
Copy link
Member

@atomb atomb commented May 16, 2023

This PR makes a simple but significant change to the Boogie representation of the Dafny heap, ensuring that all values stored in it are of type Box. This makes the polymorphism in the Boogie $Heap variable irrelevant, but does not remove it. Removing it will, unfortunately, require slightly more significant changes to Dafny itself, more than the prelude. I plan that in a separate PR, but this one already seems to reduce resource use and resource use variation a little bit, so I thought it'd be good to merge it now. These changes seem to work best if done in very small steps.

The ReadHeap method now takes an optional type, which will ultimately be provided at all call sites. Once it is, the Field type in the prelude will no longer need a parameter and the heap can become truly monomorphic. The correct value to pass in isn't obvious at all call sites, however, so I'm filling each one in incrementally as I conclude what the right parameter should be.

(Note: there are a few tests that currently fail, but I'm working on fixing them. They're independent of the main content of this PR, just perturbed by essentially any verification change.)

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

@atomb atomb force-pushed the simplify-boogie-prelude branch 2 times, most recently from 19f21ae to 364e19c Compare June 27, 2023 23:37
@atomb atomb force-pushed the simplify-boogie-prelude branch 4 times, most recently from 0e0f8ff to c84f471 Compare July 3, 2023 23:43
@atomb atomb changed the title [WIP] Simplify Boogie prelude [WIP] Make Boogie representation of Dafny heap use only Box Jul 25, 2023
This doesn't cover all uses, but fills in the obvious cases.
@atomb atomb changed the title [WIP] Make Boogie representation of Dafny heap use only Box Make Boogie representation of Dafny heap use only Box Jul 26, 2023
@atomb atomb marked this pull request as ready for review July 26, 2023 22:32
@atomb atomb changed the title Make Boogie representation of Dafny heap use only Box Make the Boogie representation of the Dafny heap use only Box Jul 26, 2023
@atomb atomb changed the title Make the Boogie representation of the Dafny heap use only Box Make the Boogie representation of the Dafny heap use only Box Jul 26, 2023
@@ -1,3 +1,4 @@
// UNSUPPORTED: windows,posix
Copy link
Member Author

Choose a reason for hiding this comment

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

This test repeatedly fails essentially whenever we make any change to the Boogie encoding. So I'm disabling it for now. I think it could be refactored to be less difficult, but that would be a somewhat involved job.

Copy link
Member

Choose a reason for hiding this comment

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

At least it's still tested on other OS, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not tested anywhere. One of the other tests in that directory is disabled, too, because it doesn't reliably verify. Ultimately, it's interesting code but I'm not sure it's testing something particularly valuable. And it's so brittle that changing essentially anything in the encoding causes it to fail, even if it makes other things better.

MikaelMayer
MikaelMayer previously approved these changes Jul 28, 2023
Copy link
Member

@MikaelMayer MikaelMayer 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! If it helps performance, I think monomorphization is a good process, especially as it will make the code more maintainable (I have some other ideas)

@@ -649,7 +649,7 @@ procedure $IterHavoc1(this: ref, modi: Set Box, nw: Set Box);
procedure $IterCollectNewObjects(prevHeap: Heap, newHeap: Heap, this: ref, NW: Field (Set Box))
returns (s: Set Box);
ensures (forall bx: Box :: { s[bx] } s[bx] <==>
read(newHeap, this, NW)[bx] ||
(read(newHeap, this, NW) : Set Box)[bx] ||
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed, but because you will eventually remove the alpha from read, you add it preventively, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly. And the code in Dafny that generates Boogie code does this for some but not all instances of read, as well. Once it does it everywhere, we can remove the type parameter to Field.

@@ -1,3 +1,4 @@
// UNSUPPORTED: windows,posix
Copy link
Member

Choose a reason for hiding this comment

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

At least it's still tested on other OS, right?

RustanLeino
RustanLeino previously approved these changes Jul 28, 2023
Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

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

Thanks for doing this work. I look forward to the polymorphic map types being removed, since they add a Boogie-level of boxing on top of the boxing that Dafny already does.

@atomb atomb dismissed stale reviews from RustanLeino and MikaelMayer via a18154d July 28, 2023 23:57
@atomb atomb enabled auto-merge (squash) August 1, 2023 23:05
@atomb atomb merged commit a93e928 into dafny-lang:master Aug 2, 2023
18 checks passed
@atomb atomb self-assigned this Aug 28, 2023
@atomb atomb deleted the simplify-boogie-prelude branch January 4, 2024 17:07
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

3 participants