charge a framework for higher order separation logic in
play

Charge! a framework for higher-order separation logic in Coq Lars - PowerPoint PPT Presentation

Charge! a framework for higher-order separation logic in Coq Lars Birkedal Logic and Semantics Group Dept. of Comp. Science, Aarhus University (Joint work with J. Bengtson, J.B. Jensen, H. Mehnert, P . Sestoft, F . Sieczkowski) April 2013


  1. Charge! a framework for higher-order separation logic in Coq Lars Birkedal Logic and Semantics Group Dept. of Comp. Science, Aarhus University (Joint work with J. Bengtson, J.B. Jensen, H. Mehnert, P . Sestoft, F . Sieczkowski) April 2013 Lars Birkedal (AU) Charge! Types 2013, Toulouse 1 / 35

  2. Separation Logic Program Logic a la Hoare Logic for reasoning about programs with pointers (or references to shared mutable data) [Reynolds, O’Hearn, . . . , 2000+] Main feature: it facilitates modular reasoning, formalized via so-called frame rule, using a connective called separating conjunction. Lars Birkedal (AU) Charge! Types 2013, Toulouse 2 / 35

  3. Hoare Logic - a recap Programming Language: imperative while -language Assertion Language: first-order logic w. equality Specifications for partial correctness: { P } C { Q } if s � P and C , s → s ′ , then s ′ � Q . Rules for deriving specifications (including rules for first-order logic). Lars Birkedal (AU) Charge! Types 2013, Toulouse 3 / 35

  4. Separation Logic Programming Language: as before but now with C-like pointers Specifications for partial correctness: { P } C { Q } if s , h � P and C , s , h → s ′ , h ′ , then s ′ , h ′ � Q . Assertion Language: first-order logic w. equality + BI connectives: s , h � emp iff h is the empty heap s , h � x �→ 5 iff h is the singleton heap with one location s ( x ) with value 5. s , h � P ∗ Q iff h can be split into h 1 and h 2 , with disjoint domains, such that s , h 1 � P and s , h 2 � Q . s , h � P − − ∗ Q iff . . . . Lars Birkedal (AU) Charge! Types 2013, Toulouse 4 / 35

  5. Example of “small” axiom { x �→ −} dispose ( x ) { emp } Modular Reasoning via Frame Rule: { P } C { Q } { P ∗ R } C { Q ∗ R } (assuming modifies ( C ) ∩ freevar ( R ) = ∅ ). Lars Birkedal (AU) Charge! Types 2013, Toulouse 5 / 35

  6. Higher-Order Separation Logic Example Developed HOSL in ESOP-2005 paper. Stack ADT stackspec = ∃ α : Type . ∃ inv : α × N list → Prop . { emp } new () { s : α. inv ( s , []) } × ∀ s : α. ∀ x : N . ∀ l : N list { inv ( s , l ) } push ( s , x ) { inv ( s , x :: l ) } × ∀ s : α. ∀ x : N . ∀ l : N list { inv ( s , x :: l ) } pop ( s ) { y : N . inv ( s , l ) ∧ y = x } . Modularity: clients can use the spec without knowing anything about how the stack is implemented (since abstract in the inv predicate). Different stack implementations can meet this spec. Lars Birkedal (AU) Charge! Types 2013, Toulouse 6 / 35

  7. Charge! Aims tool for verification of OO (Java / C#) code machine-checkable correctness proofs proofs similar to pen and paper proofs in separation logic automate tedious first-order reasoning where possible Idea: test the theory on larger examples (hard to do with pen and paper) make it available for students to experiment with Real-life test cases: from the C5 collection library for C# uses interfaces heavily to parameterize modules on each other (“interfaces” is the OO way of programming with unknown code) Lars Birkedal (AU) Charge! Types 2013, Toulouse 7 / 35

  8. Other approaches When we started work on Charge: For similar prog. language and logic: Verifast / jStar specialized tools, Verifast: larger TCB (own specialized theorem prover). We focus more on modular reasoning about modular code, using facilities of Coq jStar: no guarantee of soundness since based on user-declared theories Language designed arround type theory: Hoare Type Theory / Ynot [Nanevski, Morrisett, Birkedal, Chlipala, et. al.] now we wanted to test ideas for logic for existing mainstream programming language C-like language: Appel / McCreight macros. useful ideas that we build on, exposes the model of separation logic to user, reasoning about heaps directly, which we seeked to avoid Lars Birkedal (AU) Charge! Types 2013, Toulouse 8 / 35

  9. Overview of Charge! Shallow embedding of HOSL in Coq. Support for program variables in assertions Step-indexed specification logic with quantifiers Nested triples, i.e. step-indexed specifications in assertions Hoare triple defined on semantic commands Building blocks for defining control flow constructs: seq ˆ c 1 ˆ c 1 + ˆ ˆ c ∗ ˆ id c 2 c 2 assume P Instantiation to Java / C# like OO language. Static types replaced by specifications Tactics to automate part of the reasoning. Test applications Pattern for interface specifications (since C5 relies on interfaces) Snapshotable trees (datastructure with sharing ) Lars Birkedal (AU) Charge! Types 2013, Toulouse 9 / 35

  10. Uniform Predicates Definition (Separation Algebra) A separation algebra is a partial, cancellative, commutative monoid (Σ , ◦ , 1 ) where Σ is the carrier, ◦ is the monoid operator, and 1 is the unit element. Generalizes heaps, so we often refer to elements of Σ as heaps. h 1 ⊑ h 2 , if there exists an h 3 such that h 2 = h 1 ◦ h 3 . Definition (Uniform Predicate) UPred (Σ) � { p ⊆ Σ × N | ∀ g , m . ∀ h ⊒ g . ∀ n ≤ m . ( g , m ) ∈ p → ( h , n ) ∈ p ) } Lars Birkedal (AU) Charge! Types 2013, Toulouse 10 / 35

  11. Uniform Predicates, II Lemma UPred (Σ) forms a complete BI algebra. true � Σ × N false � ∅ p ∧ q � p ∩ q p ∨ q � p ∪ q ∀ x : U . f � � � ∃ x : U . f � x : U f x x : U f x p → q � { ( h , n ) | ∀ g ⊒ h . ∀ m ≤ n . ( g , m ) ∈ p → ( g , m ) ∈ q } p ∗ q � { ( h 1 ◦ h 2 , n ) | h 1 # h 2 ∧ ( h 1 , n ) ∈ p ∧ ( h 2 , n ) ∈ q } ∗ q � p − { ( h , n ) | ∀ m ≤ n . ∀ h 1 # h . ( h 1 , m ) ∈ p → ( h ◦ h 1 , m ) ∈ q } For the quantifiers, U is of type Type , i.e. the sort of types in Coq, and f is any Coq function from U to UPred (Σ) . This allows us to quantify over any member of Type in Coq. Lars Birkedal (AU) Charge! Types 2013, Toulouse 11 / 35

  12. Stacks and Assertions Definition stack � var → val . s ≃ V s ′ � ∀ x ∈ V . s x = s ′ x . Stack monad: sm T � { ( f : stack → T , V : P ( var )) | ∀ s , s ′ . s ≃ V s ′ → f s = f s ′ } (intuition: V over-approx of free variables in f ). Definition expr � sm val pure � sm Prop asn (Σ) � sm UPred (Σ) Lemma asn (Σ) forms a complete BI algebra. Lars Birkedal (AU) Charge! Types 2013, Toulouse 12 / 35

  13. Stacks and Substitution Stack monad used to define map f �→ � f If f : T → U , then � f : sm T → sm U . Example Given R : val → T → UPred ( heap ) , then � R : sm val → sm T → sm UPred ( heap ) , i.e. expr → sm T → asn ( heap ) . Make lifting explicit in specifications since restricts how program variables behave under substitution. ( � f e )[ e ′ / x ] = � f ( e [ e ′ / x ]) for any f : val → UPred (Σ) , But do NOT have ( g e )[ e ′ / x ] = g ( e [ e ′ / x ]) for any g : expr → asn (Σ) , because g e may have more free program variables than those appearing in e . Hence in specs we typically quantify over functions into UPred (Σ) , which we then lift to asn (Σ) as needed. Lars Birkedal (AU) Charge! Types 2013, Toulouse 13 / 35

  14. Semantic Commands Definition (pre-command) A pre-command ˜ c relates an initial state to either a terminal state or the special err state: precmd � P ( stack × Σ × (( stack × Σ) ⊎ { err } ) × N ) c ) � n x to mean that ( s , h , x , n ) ∈ ˜ We write ( s , h , ˜ c . Definition (Frame property) A pre-command ˜ c has the frame property in case the following holds. If c ) � n ( s ′ , h ′ ) then there exists h ′ c ) � � n err and ( s , h 1 ◦ h 2 , ˜ ( s , h 1 , ˜ 1 such that h ′ = h ′ c ) � n ( s ′ , h ′ 1 ◦ h 2 and ( s , h 1 , ˜ 1 ) . Lars Birkedal (AU) Charge! Types 2013, Toulouse 14 / 35

  15. Semantic Commands, II Definition (Semantic command) A semantic command satisfies the frame property and does not evaluate to anything in zero steps. c ) � � 0 semcmd � { ˆ c ∈ precmd | ˆ c has the frame property ∧ ∀ s , h , x . ( s , h , ˆ The following are semantic commands: seq ˆ c 1 ˆ c 1 + ˆ ˆ c ∗ ˆ id c 2 c 2 assume P check P (The check -command works like the id -command if pure assertion P can be inferred.) Lars Birkedal (AU) Charge! Types 2013, Toulouse 15 / 35

  16. Specification Logic Definition spec � { S ⊆ N | ∀ m , n . m ≤ n ∧ n ∈ S → m ∈ S } Gives an intuitionistic specification logic: Lemma ( spec , ⊆ ) is a cHA. Definition (Hoare Triple) { P } ˆ c { Q } � { n | ∀ m ≤ n . ∀ k ≤ m . ∀ s , h . c ) � � k err ∧ ( h , m ) ∈ P s → ( s , h , ˆ c ) � k ( s ′ , h ′ ) → ( h ′ , m − k ) ∈ Q s ′ } ∀ h ′ , s ′ . ( s , h , ˆ Lars Birkedal (AU) Charge! Types 2013, Toulouse 16 / 35

  17. Nested Specifications Nested specifications for reasoning about higher-order / unknown code. FunI : spec → UPred (Σ) � λ S . Σ × S . Lemma FunI is monotone, preserves implication, and has a left and a right adjoint. So all specification logic connectives preserved. (Could merge specifiation and assertion logic.) Lars Birkedal (AU) Charge! Types 2013, Toulouse 17 / 35

  18. Recursion Step-indexing used for mutually recursive specifications. ⊲ S � { n + 1 | n ∈ S } ∪ { 0 } Γ ∧ ⊲ S | = S 0 ∈ Γ → 0 ∈ S Löb Γ | = S Lars Birkedal (AU) Charge! Types 2013, Toulouse 18 / 35

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend