Local Action and Abstract Separation Logic

Local Action and Abstract Separation Logic

Local Action and Abstract Separation Logic Cristiano Calcagno Peter W. O’Hearn Imperial College, London Queen Mary, University of London Hongseok Yang Queen Mary, University of London Abstract concurrency rule states that processes that operate on sepa- rate resources can be reasoned about independently. Separation logic is an extension of Hoare’s logic which Syntactically, the concurrency and frame rules are supports a local way of reasoning about programs that mu- straightforward. But, the reason for their soundness is sub- tate memory. We present a study of the semantic structures tle, and rests on observations about the local way that im- lying behind the logic. The core idea is of a local action, a perative programs work [37]. Typically, a program accesses state transformer that mutates the state in a local way. We a circumscribed collection of resources; for example, the formulate local actions for a class of models called separa- memory cells accessed during execution (the memory foot- tion algebras, abstracting from the RAM and other specific print). Our purpose in this paper is to describe these seman- concrete models used in work on separation logic. Local tic assumptions in a general way, for a collection of models actions provide a semantics for a generalized form of (se- that abstract away from the RAM and other concrete models quential) separation logic. We also show that our condi- used in work on separation logic. tions on local actions allow a general soundness proof for a By isolating the circumscription principles for a class separation logic for concurrency, interpreted over arbitrary of models, the essential assumptions needed to justify the separation algebras. logic become clearer. In particular, our treatment of concur- rency shows that soundness of a concurrent version of sepa- 1 Introduction ration logic relies only on locality properties of the prim- itive actions (basic commands) in the programming lan- guage. Soundness of the concurrent logic was very diffi- Separation logic is an extension of Hoare’s logic which cult to come by, originally, even for a particular separation has been used to attack the old problem of reasoning about algebra (the RAM model); it was proven in a remarkable the mutation of data structures in memory [33, 17, 23, 34]. work of Brookes [12]. Our treatment of concurrency builds Separation logic derives its power from an interplay be- on Brookes’s original insights, but makes several different tween the separating conjunction connective ∗ and proof choices in formulation which allow for a more general proof rules for commands that use ∗. Chief among these are the that applies to arbitrary separation algebras. We show that frame rule [17, 23] and the concurrency rule [22]. as long as the primitive commands in a language satisfy the {p} C {q} frame rule, one obtains a model of a concurrent logic. This FrameRule is in contrast to Brookes’s original and further papers on {p ∗ r} C {q ∗ r} concurrent separation logics [10, 11, 16, 15], all of which {p1} C1 {q1}{p2} C2 {q2} have proven soundness for particular models in a way that ConcurrencyRule relies on very specific interpretations of the primitive ac- {p1 ∗ p2} C1 k C2 {q1 ∗ q2} tions, rather than for a class of models. The frame rule codifies an intuition of local reasoning. The This paper will not contain any examples of using the idea is that, if we establish a given Hoare triple, then the logic; see, e.g., [36, 28, 5, 4] and their references. precondition contains all the resources that the command will access during computation (other than resources allo- cated after the command starts). As a consequence, any Warning. In this paper we avoid the traditional Hoare additional state will remain unchanged; so the invariant as- logic punning of program variables as logical variables, to sertion R in the rule (the frame axiom), can be freely tacked avoid nasty side conditions in the proof rules; see [9, 27] for onto the precondition and the postcondition. Similarly, the further discussion. This is for theoretical simplicity; our re- sults can be extended to cover variable alteration, as is done (rv, p1) and p0 ◦ p1 is defined then h0 and h1 are com- in most separation logic papers, with their associated modi- patible at l. When all common l-values are compatible, fies clauses. (Furthermore, avoiding the pun is more in line h0 • h1 is defined, and (h0 • h1)(l) = (rv, p0 ◦ p1) for with real languages like C or ML, even if it departs slightly all compatible locations l. An example of a permission from the theoretical tradition in program logic.) algebra is the interval (0, 1] of rational numbers, with ◦ being addition but undefined when permissions add 2 Separation Algebras and Predicates up to more than 1. Another permission algebra is given by the set Most papers on separation logic make use of a domain {R, RW } of read and read-write permissions, where of heaps, which is equipped with a partial operator for glu- R ◦ R = R and RW ◦ p is undefined. At first sight, ing together heaps that are separate in some sense (various it might be thought that this algebra models the idea of senses have appeared in the literature). We abstract from many readers and a single writer. But, unfortunately, this situation with the following definition. it does not allow conversion of a total (RW ) permis- sion to several read permissions, or vice versa. In con- Definition 1 (Separation Algebra) A separation algebra trast, the algebra (0, 1] does allow such conversion us- is a cancellative, partial commutative monoid (Σ, •, u) .A ing identities such as 1/2 + 1/2 = 1; see [8]. partial commutative monoid is given by a partial binary 3. Variables as resource [9, 27] is S × H, where H is as operation where the unity, commutativity and associativity above and laws hold for the equality that means both sides are de- fined and equal, or both are undefined. The cancellative S = Var *fin Val property says that for each σ ∈ Σ, the partial function σ • (·):Σ * Σ is injective. The induced separateness has the “union of disjoint functions” partial monoid (#) and substate () relations are given by structure. Variables-as-resource models can also be mixed with the permission construction. σ0#σ1 iff σ0 • σ1 is defined 4. Multisets over a given set of Places, with • as multiset σ0 σ2 iff ∃σ1. σ2 = σ0 • σ1. union, which can be used to model states in Petri nets without capacity [32]. Examples of separation algebras: 5. The monoid [Places * {marked, unmarked}] of 1. Heaps, as finite partial functions from l-values to r- fin partial functions, again with union of functions with values disjoint domain, can be used to model Petri nets with capacity 1. Note that the • operation in nets with ca- H = L*fin RV pacity 1 is partial, while in nets without capacity it is where the empty partial function is the unit and where total. h0 • h1 takes the union of partial functions when h0 and h1 have disjoint domains of definition. h0 • h1 is Definition 2 Let Σ be a separation algebra. Predicates undefined when h0(l) and h1(l) are both defined for at over Σ are just elements of the powerset P (Σ). It has an least one l-value l ∈ L. By taking L to be the set of ordered total commutative monoid structure (∗, emp) given natural numbers and RV the set of integers we obtain by the RAM model [23, 34]. By taking L to be a set of p ∗ q = {σ • σ | σ #σ ∧ σ ∈ p ∧ σ ∈ q} locations and RV to be certain tuples of values or nil 0 1 0 1 0 1 emp = {u} we obtain models where the heap consists of records [33, 17]. And by taking L to be sequences of field P (Σ) is in fact a boolean BI algebra, where p ∗ (·) and names we obtain a model of hierarchical storage [1]. p u (·) have right adjoints [30]. Because they are left ad- 2. Heaps with permissions [8], joints they preserve all joins, so we automatically get two distributive laws HPerm = L* RV × P fin F X ∗ p = F{x ∗ p | x ∈ X} where P is a permission algebra (i.e., a set with a par- F X u p = F{x u p | x ∈ X}. tial commutative and associative operation ◦ satisfy- ing the cancellativity condition). h0 • h1 is again the Similar laws do not hold generally for d, but the predi- union when the domains are disjoint. Some overlap cates p that satisfy an analogue of the first law play a crucial is allowed, though: when h0(l) = (rv, p0), h1(l) = role in this work. 2 Definition 3 (Precise Predicates) A predicate p ∈ P (Σ) is 1. Safety Monotonicity: (σ, fault) 6∈ R and σ σ0 0 precise if for every σ ∈ Σ, there exists at most one σp σ implies (σ , fault) 6∈ R. such that σp ∈ p. We let Prec denote the set of precise 2. Frame Property: If (σ0, fault) 6∈ R, σ = σ0•σ1 and predicates. 0 0 0 0 0 (σ, σ ) ∈ R then ∃σ0. σ = σ0 • σ1 and (σ0, σ0) ∈ R. Examples of Predicates. The first condition says that if a state has enough resource for safe execution of a command, then so do superstates. l ∈ L rv ∈ R 1. In the heap model, if is an l-value and an The second condition says that if a little state σ0 has enough r-value, then the predicate l 7→ rv ∈ P (Σ) is the set resource for the command to execute safely, then execution {σ} consisting of a single state σ where σ(l) = rv and on any bigger state can be tracked back to the small state.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us