an introduction to separation logic
play

An introduction to separation logic James Brotherston Programming - PowerPoint PPT Presentation

An introduction to separation logic James Brotherston Programming Principles, Logic and Verification Group Dept. of Computer Science University College London, UK J.Brotherston@ucl.ac.uk Logic Summer School, ANU, 7 December 2015 1/ 19


  1. An introduction to separation logic James Brotherston Programming Principles, Logic and Verification Group Dept. of Computer Science University College London, UK J.Brotherston@ucl.ac.uk Logic Summer School, ANU, 7 December 2015 1/ 19

  2. Introduction Verification of imperative programs is classically based on Hoare triples: { P } C { Q } where C is a program and P, Q are assertions in some logical language. 2/ 19

  3. Introduction Verification of imperative programs is classically based on Hoare triples: { P } C { Q } where C is a program and P, Q are assertions in some logical language. These are read, roughly speaking, as for any state σ satisfying P , if C transforms state σ to σ ′ , then σ ′ satisfies Q . 2/ 19

  4. Introduction Verification of imperative programs is classically based on Hoare triples: { P } C { Q } where C is a program and P, Q are assertions in some logical language. These are read, roughly speaking, as for any state σ satisfying P , if C transforms state σ to σ ′ , then σ ′ satisfies Q . (with some wriggle room allowing us to deal with faulting or non-termination in various ways.) 2/ 19

  5. Hoare-style verification A Hoare-style program logic therefore relies on three main components: 3/ 19

  6. Hoare-style verification A Hoare-style program logic therefore relies on three main components: 1. a language of programs, and an operational semantics explaining how they transform states; 3/ 19

  7. Hoare-style verification A Hoare-style program logic therefore relies on three main components: 1. a language of programs, and an operational semantics explaining how they transform states; 2. a language of logical assertions, and a semantics explaining how to read them as true or false in a particular state; 3/ 19

  8. Hoare-style verification A Hoare-style program logic therefore relies on three main components: 1. a language of programs, and an operational semantics explaining how they transform states; 2. a language of logical assertions, and a semantics explaining how to read them as true or false in a particular state; 3. a formal interpretation of Hoare triples, together with (sound) proof rules for manipulating them. 3/ 19

  9. Hoare-style verification A Hoare-style program logic therefore relies on three main components: 1. a language of programs, and an operational semantics explaining how they transform states; 2. a language of logical assertions, and a semantics explaining how to read them as true or false in a particular state; 3. a formal interpretation of Hoare triples, together with (sound) proof rules for manipulating them. We’ll look at these informally first, then introduce a little more formal detail. 3/ 19

  10. Programs, informally We consider a standard while language with pointers, memory (de)allocation and recursive procedures. 4/ 19

  11. Programs, informally We consider a standard while language with pointers, memory (de)allocation and recursive procedures.E.g.: deltree(*x) { if x=nil then return; else { l,r := x.left,x.right; deltree(l); deltree(r); free(x); } } 4/ 19

  12. Assertions, informally Our assertion language lets us describe heap data structures such as linked lists and trees. 5/ 19

  13. Assertions, informally Our assertion language lets us describe heap data structures such as linked lists and trees. E.g., binary trees with root pointer x can be defined by: x = nil : emp ⇒ tree ( x ) x � = nil : x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) ⇒ tree ( x ) 5/ 19

  14. Assertions, informally Our assertion language lets us describe heap data structures such as linked lists and trees. E.g., binary trees with root pointer x can be defined by: x = nil : emp ⇒ tree ( x ) x � = nil : x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) ⇒ tree ( x ) where • emp denotes the empty heap; 5/ 19

  15. Assertions, informally Our assertion language lets us describe heap data structures such as linked lists and trees. E.g., binary trees with root pointer x can be defined by: x = nil : emp ⇒ tree ( x ) x � = nil : x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) ⇒ tree ( x ) where • emp denotes the empty heap; • x �→ ( y, z ) denotes a single pointer to a pair of data cells; 5/ 19

  16. Assertions, informally Our assertion language lets us describe heap data structures such as linked lists and trees. E.g., binary trees with root pointer x can be defined by: x = nil : emp ⇒ tree ( x ) x � = nil : x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) ⇒ tree ( x ) where • emp denotes the empty heap; • x �→ ( y, z ) denotes a single pointer to a pair of data cells; • ∗ means “and separately in memory”. 5/ 19

  17. An example proof deltree(*x) { if x=nil then return; else { l,r := x.left,x.right; deltree(l); deltree(r); free(x); } } 6/ 19

  18. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; else { l,r := x.left,x.right; deltree(l); deltree(r); free(x); } } { emp } 6/ 19

  19. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { l,r := x.left,x.right; deltree(l); deltree(r); free(x); } } { emp } 6/ 19

  20. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; deltree(l); deltree(r); free(x); } } { emp } 6/ 19

  21. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l); deltree(r); free(x); } } { emp } 6/ 19

  22. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l); { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } deltree(r); free(x); } } { emp } 6/ 19

  23. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l); { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } deltree(r); { x �→ ( l, r ) ∗ emp ∗ emp } free(x); } } { emp } 6/ 19

  24. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l); { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } deltree(r); { x �→ ( l, r ) ∗ emp ∗ emp } free(x); { emp ∗ emp ∗ emp } } } { emp } 6/ 19

  25. An example proof { tree ( x ) } deltree(*x) { if x=nil then return; { emp } else { { x �→ ( y, z ) ∗ tree ( y ) ∗ tree ( z ) } l,r := x.left,x.right; { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l); { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } deltree(r); { x �→ ( l, r ) ∗ emp ∗ emp } free(x); { emp ∗ emp ∗ emp } } { emp } } { emp } 6/ 19

  26. Frame property Consider the following step in the previous example: { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l) { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } 7/ 19

  27. Frame property Consider the following step in the previous example: { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l) { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } Implicitly, this relies on a framing property, namely: { tree ( l ) } deltree(l) { emp } { x �→ ( l, r ) ∗ tree ( l ) ∗ tree ( r ) } deltree(l) { x �→ ( l, r ) ∗ emp ∗ tree ( r ) } 7/ 19

  28. Classical failure of frame rule The so-called frame rule, { P } C { Q } { F ∧ P } C { F ∧ Q } is well known to fail in standard Hoare logic. 8/ 19

  29. Classical failure of frame rule The so-called frame rule, { P } C { Q } { F ∧ P } C { F ∧ Q } is well known to fail in standard Hoare logic.E.g., { x = 0 } x := 2 { x = 2 } { y = 0 ∧ x = 0 } x := 2 { y = 0 ∧ x = 2 } is not valid (because y could alias x ). 8/ 19

  30. Classical failure of frame rule The so-called frame rule, { P } C { Q } { F ∧ P } C { F ∧ Q } is well known to fail in standard Hoare logic.E.g., { x = 0 } x := 2 { x = 2 } { y = 0 ∧ x = 0 } x := 2 { y = 0 ∧ x = 2 } is not valid (because y could alias x ). As we’ll see, using the “separating conjunction” ∗ instead of ∧ will however give us a valid frame rule. 8/ 19

  31. Heap memory model • We assume an infinite set Val of values of which an infinite subset Loc ⊂ Val are allocable locations; nil is a non-allocable value. 9/ 19

  32. Heap memory model • We assume an infinite set Val of values of which an infinite subset Loc ⊂ Val are allocable locations; nil is a non-allocable value. • Stacks map variables to values, s : Var → Val . 9/ 19

  33. Heap memory model • We assume an infinite set Val of values of which an infinite subset Loc ⊂ Val are allocable locations; nil is a non-allocable value. • Stacks map variables to values, s : Var → Val . • Heaps map finitely many locations to values, h : Loc ⇀ fin Val . We write e for the empty heap (undefined on all locations). 9/ 19

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