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:
- Let be the subgraph containing and its ancestors in
- While has at least one edge:
- Let be the set of leaf edges in .
- If is empty fail
- Append to
- 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.