Download Heaps and Hops

Transcript
6.4. Properties of proved programs
6.4.3 Owned portion of a state
Our next property of interest is leak freedom. However, to define what constitutes a leak in
the open semantics, we first neeed to introduce the notion of the (reachable) owned portion,
or reachable local state, of a well-formed open state σ = (σ̇, k). The owned portion of a state
σ corresponds to every piece of state that can be reached in σ by retrieving the footprints
of the messages in the queues of the endpoints present in σ̇ , adding them to the local state,
and then repeating the process until a fixpoint is reached.1 The fixpoint is reached when the
queues accessible from the last local state all have empty footprints.
In the definition below, emp(k) sets the footprints of the buffers of k to u̇; it is the lifting
to open endpoint heaps of the function
˙ → MsgId × Val × State
˙
MsgId × Val × State
(a, v, σ̇) ↦ (a, v, u̇)
In particular, flat(emp(k)) = u̇ for all k .
Definition 6.11 (Owned portion of a state) Let σ = ((s, h, k̇), k) be a well-formed open
state. The reachable owned portion (or simply the owned portion) owned (σ) of the state
σ is defined inductively by:
• if flat(k ⇂ dom(k̇)) = u̇ then owned (σ) ≜ (s, h, k̇);
• otherwise, let σ̇k = flat(k ⇂ dom(k̇)) and k ′ = emp(k ⇂ dom(k̇)) ⊎ k ⇂ (dom(k) ∖
dom(k̇)). Then owned (σ) ≜ owned ((s, h, k̇) ● σ̇k , k ′ ).
This definition is well-founded since the number of buffers with non-empty footprints
decreases strictly at each step. The resulting session state is well-formed.
Reachable owned states allow us to circumscribe the part of the state that the program
owns, either directly (in its local state), or virtually, because the corresponding locations
can become accessible after a certain number of receives.
Flattening gives an over-approximation of the owned portion of a state.
Lemma 6.14 For all open well-formed state σ , if flat(σ) = (σ̇f , k f ), then
owned (σ) ⪯ σ̇f .
Proof The proof is by induction on the number of steps in the computation of owned (σ).
In the base case, we have owned ((σ̇, k)) = σ̇ ⪯ σ̇f . Suppose that the lemma is true
for states whose owned portion is computed in up to n steps. Let σ = (σ̇, k) be a state
whose owned portion can be computed in n + 1 steps, and let σ̇ = (s, h, k̇) and σ̇k =
flat(k ⇂ dom(k̇)) and k ′ = emp(k ⇂ dom(k̇)) ⊎ k ⇂ (dom(k) ∖ dom(k̇)) as in the
1
Gotsman et al. use a similar notion that they call “closure” to get around the issue of cycles of ownership
leaks. [GBC+ 07]
122