Documentation

Cvc.Typed.Theory.Sep

Separation logic, typed #

A solver's heap is declared once, at the Lean types of its locations and data. The two constructors that depend on it hang off the handle declareSepHeap answers, so a location or a datum of the wrong type does not compile:

let h ← s.declareSepHeap Int Int
s.assert (← h.pto x y)     -- `x y : Term Int`
let n ← h.nil              -- `n : Term Int`

sepEmp, sepStar and sepWand need no heap. getValueSepHeap and getValueSepNil describe the model's heap as formulas.

Separating conjunction: the heap splits in two, one part satisfying each side.

Equations
Instances For
    def Cvc.Typed.Term.sepStarN [Ω] (terms : Terms Bool) (atLeastTwoElements : 2 ≤ Array.size terms := by (try grind) <;> fail "failed to prove term array has at least two elements") :

    sepStar over two or more terms.

    Equations
    Instances For

      Separating implication, the magic wand.

      Equations
      Instances For

        Holds exactly when the heap is empty.

        Equations
        Instances For
          inductive Cvc.Typed.View.Sep [Ω] :
          Typ → Type

          Sep's operators, taken apart one level, indexed by the sort each produces.

          Instances For

            Sep's operators with a result of sort Bool.

            • sepEmp [Ω] : OnBool

              Holds exactly when the heap is empty.

            • sepStar [Ω] (kids : Kids Bool) : OnBool

              Separating conjunction: the heap splits in two, one part satisfying each side.

              kids holds every operand, two or more.

            • sepWand [Ω] (lft rgt : Term Bool) : OnBool

              Separating implication, the magic wand.

            Instances For
              def Cvc.Typed.View.Sep.of [Ω] (τ : Typ) (t : Term τ.Denote) :

              Takes a term apart one level, at its sort, if Sep owns its operator and the term's sort fits it.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                structure Cvc.Typed.Solver.Heap [Ω] (solver : Solver) (α β : Type) :

                The heap of a solver, at the Lean types of its locations and its data.

                Produced by declareSepHeap, and the only way to Heap.pto or Heap.nil.

                Instances For
                  def Cvc.Typed.Solver.Heap.toUntyped [Ω] {α β : Type} {solver : Solver} (h : solver.Heap α β) :

                  The sort-erased heap it wraps, which carries α and β as Srts; free.

                  Equations
                  Instances For
                    @[reducible, inline]
                    abbrev Cvc.Typed.Solver.Heap.erase [Ω] {α β : Type} {solver : Solver} (h : solver.Heap α β) :

                    The sort-erased heap it wraps, which carries α and β as Srts; free.

                    Equations
                    Instances For
                      def Cvc.Untyped.Solver.Heap.toTypedAs [Ω] (α β : Type) [ToTyp α] [ToTyp β] {solver : Typed.Solver} (h : Heap solver) :
                      Env (solver.Heap α β)

                      Types a sort-erased heap at locations α and data β, checking its two sorts against theirs.

                      toTyped infers α and β from the expected type; typeCheckAs and typeCheck are the same two functions under the names that say what they do.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Cvc.Untyped.Solver.Heap.toTyped [Ω] {α β : Type} [ToTyp α] [ToTyp β] {solver : Typed.Solver} (h : Heap solver) :
                        Env (solver.Heap α β)

                        Types a sort-erased heap at locations α and data β, checking its two sorts against theirs.

                        toTyped infers α and β from the expected type; typeCheckAs and typeCheck are the same two functions under the names that say what they do.

                        Equations
                        Instances For
                          @[reducible, inline]
                          abbrev Cvc.Untyped.Solver.Heap.typeCheckAs [Ω] (α β : Type) [ToTyp α] [ToTyp β] {solver : Typed.Solver} (h : Heap solver) :
                          Env (solver.Heap α β)

                          Types a sort-erased heap at locations α and data β, checking its two sorts against theirs.

                          toTyped infers α and β from the expected type; typeCheckAs and typeCheck are the same two functions under the names that say what they do.

                          Equations
                          Instances For
                            @[reducible, inline]
                            abbrev Cvc.Untyped.Solver.Heap.typeCheck [Ω] {α β : Type} [ToTyp α] [ToTyp β] {solver : Typed.Solver} (h : Heap solver) :
                            Env (solver.Heap α β)

                            Types a sort-erased heap at locations α and data β, checking its two sorts against theirs.

                            toTyped infers α and β from the expected type; typeCheckAs and typeCheck are the same two functions under the names that say what they do.

                            Equations
                            Instances For
                              def Cvc.Typed.Solver.declareSepHeap [Ω] (s : Solver) (α β : Type) [ToTyp α] [ToTyp β] :
                              Env (s.Heap α β)

                              Declares the heap's location and data sorts, and answers the handle they are reached through.

                              cvc5 allows this once per solver, and rejects a second call even at the same sorts. It has to come before any separation-logic constraint: asserting one against an undeclared heap is an error.

                              Equations
                              Instances For
                                def Cvc.Typed.Solver.Heap.sorts {α β : Type} [Ω] {s : Solver} (h : s.Heap α β) :

                                The location sort and the data sort, in that order.

                                Equations
                                Instances For
                                  def Cvc.Typed.Solver.Heap.nil {α β : Type} [Ω] {s : Solver} (h : s.Heap α β) :
                                  Env (Term α)

                                  sep.nil, the null location, at the heap's location sort.

                                  Equations
                                  Instances For
                                    def Cvc.Typed.Solver.Heap.pto {α β : Type} [Ω] {s : Solver} (h : s.Heap α β) (loc : Term α) (data : Term β) :

                                    The points-to constraint: loc points to data in a heap holding nothing else.

                                    The operands are the heap's own indices, so the mismatch the sort-erased version has to check is not expressible here.

                                    Equations
                                    Instances For

                                      Reading a heap back #

                                      Both answer a formula describing the model's heap rather than a value, so both are Term Bool whatever the heap's types.

                                      A formula describing the model's heap, such as (pto (as @Loc_1 Loc) 0); not a value.

                                      Equations
                                      Instances For

                                        A formula giving sep.nil in the model, such as (= (as sep.nil Loc) (as @Loc_0 Loc)).

                                        Equations
                                        Instances For

                                          getValueSepHeap in Env, not checked to follow a sat answer.

                                          Equations
                                          Instances For

                                            getValueSepNil in Env, not checked to follow a sat answer.

                                            Equations
                                            Instances For