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

A stratified heap with two universes, enabling storing "small" heap predicates in the larger heap #19

Merged
merged 16 commits into from
Mar 12, 2024

Conversation

nikswamy
Copy link
Contributor

@nikswamy nikswamy commented Mar 12, 2024

This PR enriches the memory model of Pulse to use PulseCore.TwoLevelHeap

The underlying memory now contains the following:

  • A small heap, storing objects in universe 1
  • A large heap, storing objects in universe 2

A pair of a small heap and a large heap is called a TwoLevelHeap, or H2.heap.
The core Pulse.Lib.Core.vprop is now an affine H2.heap -> prop, where vprop : Type u#3

(We also have an invariant store in PulseCore.Memory, storing slprop as invariants, this is mostly unchanged, except for a universe level increase, and some other cleanup, notably, directly using PulseCore.MonotonicStateMonad in a universe-polymorphic way, rather than using FStar.MSTTotal, which fixes the state to be in universe 1.)

We also have two functions

  • down : vprop -> small_slprop and
  • up: small_slprop -> vprop, where small_slprop : Type u#2
    And a predicate is_small (p:vprop) = up (down p) == p
    That is, vprop validating is_small can be coerced to small_slprops without loss of information, and then coerced back.

Most familiar predicates are small, e.g, emp, pure, pts_to, ghost_pts_to etc.
The connectives ** and exists* form small vprops if their arguments are also small.

But, we now also have Pulse.Lib.BigReference.pts_to (#a:Type u#2) (x:ref a) (#p:perm) (v:a) : vprop that allows storing terms in universe 2 in the heap, including, notably small_slprop.

An example PulseExample.UseBigRef shows how it works, storing list of closures packed with small vprops denoting their pre and postconditions.

Note, we also have Pulse.Lib.BigGhostReference, for a ghost variant of a reference to store a universe 2 term.

I plan to add one more level to the heap, this one to turn any slprop into a resourceful invariant---so, expect one more universe bump.

@nikswamy
Copy link
Contributor Author

Note, this commit gives a sense of the changes incurred in the Pulse checker and libraries for a universe bump:

e8c7e6d

It's relatively small. If F* had a way to declare top-level universe constants, e.g., let universe mem_level = u#3, then we could possibly isolate the edit to just changing this constant.

@nikswamy nikswamy enabled auto-merge March 12, 2024 04:33
@nikswamy nikswamy merged commit 12e5730 into main Mar 12, 2024
2 checks passed
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.

1 participant