Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Generating Annotations

Generating Annotations Between Statements

The annotations for transitioning from statement to statement are the recorded PCG actions performed during its analysis.

Generating Annotations Between Basic Blocks

We generate the annotations to get from the state of to its successor . The state of may be to the join of multiple basic blocks (including ).

We generate annotations by performing a join that joins into a copy of and recording the actions that occur. Note that this is the reverse of the join that occurs during the analysis where is joined into . Conceptually, the actions performed by the join are the procedure that weakens state to obtain state .

Generating Annotations for Magic Wands

Clients like Prusti want to generate magic wands from function bodies.

The PCG facilitates this via the UnblockGraph interface. The interface takes a PCG and a PCG node , and returns an ordered list of annotations that describe how to unblock in . Prusti can consume these annotations to generate magic wands.

The interface could trivially be extended to unblock multiple nodes simultaneously

The annotations generated from the UnblockGraph are Borrow PCG edges.

At a high level, the resulting annotations are a topological sort of the edges in the subgraph of that contains and all of its ancestors. Concretely, the procedure to generate the list of annotations is as follows:

  1. Let be the subgraph containing and its ancestors in
  2. While has at least one edge:
    1. Let be the set of leaf edges in .
    2. If is empty fail
    3. Append to
    4. Remove from

We note that the above procedure could fail, for example, could contain a cycle. We expect that in practice this is quite rare. Furthermore, we believe the following property should hold:

For any list of PCG edges forming a cycle, there does not exist any execution path that call satisfy the validity conditions of every edge in the cycle.

Therefore, it should be possible to modify the implementation to e.g. produce multiple lists for distinct paths.