Demonstration of the Iris separation logic in Coq Robbert Krebbers 1 - - PowerPoint PPT Presentation

demonstration of the iris separation logic in coq
SMART_READER_LITE
LIVE PREVIEW

Demonstration of the Iris separation logic in Coq Robbert Krebbers 1 - - PowerPoint PPT Presentation

Demonstration of the Iris separation logic in Coq Robbert Krebbers 1 Delft University of Technology, The Netherlands January 21, 2017 @ Coq PL, Paris, France 1 Iris is joint work with: Ralf Jung, Jacques-Hendri Jourdan, Ale s Bizjak, David


slide-1
SLIDE 1

1

Demonstration of the Iris separation logic in Coq

Robbert Krebbers1

Delft University of Technology, The Netherlands

January 21, 2017 @ Coq PL, Paris, France

1Iris is joint work with: Ralf Jung, Jacques-Hendri Jourdan, Aleˇ

s Bizjak, David Swasey, Filip Sieczkowski, Kasper Svendsen, Aaron Turon, Amin Timany, Derek Dreyer, and Lars Birkedal

slide-2
SLIDE 2

2

Iris Proof Mode (IPM)

Goal: reasoning in an object logic in the same style as reasoning in Coq

slide-3
SLIDE 3

2

Iris Proof Mode (IPM)

Goal: reasoning in an object logic in the same style as reasoning in Coq

slide-4
SLIDE 4

2

Iris Proof Mode (IPM)

Goal: reasoning in an object logic in the same style as reasoning in Coq How?

◮ Extend Coq with (spatial and non-spatial)

named proof contexts for an object logic

◮ Tactics for introduction and elimination of all

connectives of the object logic

◮ Entirely implemented using reflection, type

classes and Ltac (no OCaml plugin needed)

slide-5
SLIDE 5

2

Iris Proof Mode (IPM)

Goal: reasoning in Iris in the same style as reasoning in Coq How?

◮ Extend Coq with (spatial and non-spatial)

named proof contexts for Iris

◮ Tactics for introduction and elimination of all

connectives of Iris

◮ Entirely implemented using reflection, type

classes and Ltac (no OCaml plugin needed) Iris: language independent higher-order separation logic for modular reasoning about fine-grained concurrency in Coq

slide-6
SLIDE 6

3

Demo

slide-7
SLIDE 7

4

The setup of IPM in a nutshell

◮ Deep embedding of contexts as association lists: Record envs := Envs { env persistent : env iProp; env spatial : env iProp }. Coercion of envs (∆ : envs) : iProp := ( envs wf ∆ ∗ [∗] env persistent ∆ ∗ [∗] env spatial ∆)% I.

slide-8
SLIDE 8

4

The setup of IPM in a nutshell

◮ Deep embedding of contexts as association lists: Record envs := Envs { env persistent : env iProp; env spatial : env iProp }. Coercion of envs (∆ : envs) : iProp := ( envs wf ∆ ∗ [∗] env persistent ∆ ∗ [∗] env spatial ∆)% I.

Propositions that enjoy P ⇔ P ∗ P

slide-9
SLIDE 9

4

The setup of IPM in a nutshell

◮ Deep embedding of contexts as association lists: Record envs := Envs { env persistent : env iProp; env spatial : env iProp }. Coercion of envs (∆ : envs) : iProp := ( envs wf ∆ ∗ [∗] env persistent ∆ ∗ [∗] env spatial ∆)% I.

Propositions that enjoy P ⇔ P ∗ P

◮ Tactics implemented by reflection: Lemma tac sep split ∆ ∆1 ∆2 lr js Q1 Q2 : envs split lr js ∆ = Some (∆1,∆2) → (∆1 ⊢ Q1) → (∆2 ⊢ Q2) → ∆ ⊢ Q1 ∗ Q2.

slide-10
SLIDE 10

4

The setup of IPM in a nutshell

◮ Deep embedding of contexts as association lists: Record envs := Envs { env persistent : env iProp; env spatial : env iProp }. Coercion of envs (∆ : envs) : iProp := ( envs wf ∆ ∗ [∗] env persistent ∆ ∗ [∗] env spatial ∆)% I.

Propositions that enjoy P ⇔ P ∗ P

◮ Tactics implemented by reflection: Lemma tac sep split ∆ ∆1 ∆2 lr js Q1 Q2 : envs split lr js ∆ = Some (∆1,∆2) → (∆1 ⊢ Q1) → (∆2 ⊢ Q2) → ∆ ⊢ Q1 ∗ Q2.

Context splitting implemented in Gallina

slide-11
SLIDE 11

4

The setup of IPM in a nutshell

◮ Deep embedding of contexts as association lists: Record envs := Envs { env persistent : env iProp; env spatial : env iProp }. Coercion of envs (∆ : envs) : iProp := ( envs wf ∆ ∗ [∗] env persistent ∆ ∗ [∗] env spatial ∆)% I.

Propositions that enjoy P ⇔ P ∗ P

◮ Tactics implemented by reflection: Lemma tac sep split ∆ ∆1 ∆2 lr js Q1 Q2 : envs split lr js ∆ = Some (∆1,∆2) → (∆1 ⊢ Q1) → (∆2 ⊢ Q2) → ∆ ⊢ Q1 ∗ Q2.

Context splitting implemented in Gallina

◮ Ltac wrappers around reflective tactics: Tactic Notation "iSplitL" constr(Hs) := let Hs := words Hs in eapply tac sep split with false Hs ; [env cbv; reflexivity | | fail "iSplitL: hypotheses" Hs "not found in the context" | (* goal 1 *) | (* goal 2 *) ] .

Report sensible error to the user

slide-12
SLIDE 12

5

This talk

Demonstrate some uses of IPM:

◮ Symbolic execution ◮ Lock based concurrency ◮ Verification of a spin lock

slide-13
SLIDE 13

6

Part #1: symbolic execution

slide-14
SLIDE 14

7

Hoare triples

Hoare triples for partial program correctness: {P}e{w. Q} Precondition Binder for return value Postcondition If the initial state satisfies P, then:

◮ e does not get stuck/crash ◮ if e terminates with value v, the final state satisfies Q[v/w]

slide-15
SLIDE 15

8

Separation logic [O’Hearn, Reynolds, Yang]

The points-to connective x → v

◮ provides the knowledge that location x has value v, and ◮ provides exclusive ownership of x

Separating conjunction P ∗ Q: the state consists of disjoint parts satisfying P and Q

slide-16
SLIDE 16

8

Separation logic [O’Hearn, Reynolds, Yang]

The points-to connective x → v

◮ provides the knowledge that location x has value v, and ◮ provides exclusive ownership of x

Separating conjunction P ∗ Q: the state consists of disjoint parts satisfying P and Q Example: {x → v1 ∗ y → v2}swap(x, y){w. w = () ∧ x → v2 ∗ y → v1} the ∗ ensures that x and y are different

slide-17
SLIDE 17

9

Proving Hoare triples using IPM

Consider: {x → v1 ∗ y → v2}swap(x, y){x → v2 ∗ y → v1} How to use IPM to manipulate the precondition?

slide-18
SLIDE 18

9

Proving Hoare triples using IPM

Consider: {x → v1 ∗ y → v2}swap(x, y){x → v2 ∗ y → v1} How to use IPM to manipulate the precondition? Solution: define Hoare triple in terms of weakest preconditions We let:

{P} e {w. Q} (P −

∗ wp e {w. Q}) where wp e {w. Q} gives the weakest precondition under which:

◮ all executions of e are safe ◮ if e terminates with value v, the final state satisfies Q[v/w]

slide-19
SLIDE 19

10

Rules for weakest precondition

Rule of ‘consequence’: wp e {v. wp K[ v ] {Φ}} − ∗ wp K[ e ] {Φ} Value rule: Φ v − ∗ wp v {Φ} Lamda rule: wp e[v/x] {Φ} − ∗ wp (λx.e)v {Φ}

slide-20
SLIDE 20

11

Stateful rules for weakest preconditions

Let us just translate the Hoare rules naively: ℓ → v − ∗ wp ! ℓ {w. w = v ∗ ℓ → v} ℓ → v1 − ∗ wp ℓ := v2 {w. w = () ∗ ℓ → v2} Problems:

◮ Having to frame and weaken to apply these rules ◮ Equalities in the postconditions

slide-21
SLIDE 21

11

Stateful rules for weakest preconditions

Let us just translate the Hoare rules naively: ℓ → v − ∗ wp ! ℓ {w. w = v ∗ ℓ → v} ℓ → v1 − ∗ wp ℓ := v2 {w. w = () ∗ ℓ → v2} Problems:

◮ Having to frame and weaken to apply these rules ◮ Equalities in the postconditions

‘Backwards’ or ‘predicate transformer’ formulation: ℓ → v ∗ (ℓ → v − ∗ Φ v) − ∗ wp ! ℓ {Φ} ℓ → v1 ∗ (ℓ → v2 − ∗ Φ ()) − ∗ wp ℓ := v2 {Φ} Resources that have to be given up Resources that are given back

slide-22
SLIDE 22

12

Nicer definition of the Hoare triple [J-O. Kaiser]

{P} e {

x RETw. Q} (∀Φ. P − ∗ (∀

  • x. Q −

∗ Φ w) − ∗ wp e {Φ}) Resources that have to be given up Resources that are given back

slide-23
SLIDE 23

13

Demo

slide-24
SLIDE 24

14

Part #2: lock based concurrency

slide-25
SLIDE 25

15

Concurrent separation logic [O’Hearn]

The par rule: {P1}e1{Q1} {P2}e2{Q2} {P1 ∗ P2}e1||e2{Q1 ∗ Q2}

slide-26
SLIDE 26

15

Concurrent separation logic [O’Hearn]

The par rule: {P1}e1{Q1} {P2}e2{Q2} {P1 ∗ P2}e1||e2{Q1 ∗ Q2} For example: {x → 4 ∗ y → 6} x := ! x + 2 y := ! y + 2 {x → 6 ∗ y → 8}

slide-27
SLIDE 27

15

Concurrent separation logic [O’Hearn]

The par rule: {P1}e1{Q1} {P2}e2{Q2} {P1 ∗ P2}e1||e2{Q1 ∗ Q2} For example: {x → 4 ∗ y → 6} {x → 4} {y → 6} x := ! x + 2 y := ! y + 2 {x → 6 ∗ y → 8}

slide-28
SLIDE 28

15

Concurrent separation logic [O’Hearn]

The par rule: {P1}e1{Q1} {P2}e2{Q2} {P1 ∗ P2}e1||e2{Q1 ∗ Q2} For example: {x → 4 ∗ y → 6} {x → 4} {y → 6} x := ! x + 2 y := ! y + 2 {x → 6} {y → 8} {x → 6 ∗ y → 8}

slide-29
SLIDE 29

15

Concurrent separation logic [O’Hearn]

The par rule: {P1}e1{Q1} {P2}e2{Q2} {P1 ∗ P2}e1||e2{Q1 ∗ Q2} For example: {x → 4 ∗ y → 6} {x → 4} {y → 6} x := ! x + 2 y := ! y + 2 {x → 6} {y → 8} {x → 6 ∗ y → 8} Works great for concurrent programs without shared memory: concurrent quick sort, concurrent merge sort, . . .

slide-30
SLIDE 30

16

What about shared state?

A simple problem: {True} let x = ref(0) in let y = ref(4) in swap x y assert (! x + ! y = 4) {True}

slide-31
SLIDE 31

16

What about shared state?

A simple problem: {True} let x = ref(0) in let y = ref(4) in let z = new lock() in acquire z acquire z swap x y assert (! x + ! y = 4) release z release z {True}

slide-32
SLIDE 32

17

Specification of a lock

Specifications of the operations: {P}new lock(){l. IsLock(l, P)} {IsLock(l, P)}acquire l{P } {IsLock(l, P) ∗ P}release l{True} The IsLock predicate can be shared among threads: IsLock(l, P) ⇔ IsLock(l, P) ∗ IsLock(l, P) Lock invariant

slide-33
SLIDE 33

17

Specification of a lock

Specifications of the operations: {P}new lock(){l. IsLock(l, P)} {IsLock(l, P)}acquire l{P ∗ Locked(l)} {IsLock(l, P) ∗ Locked(l) ∗ P}release l{True} The IsLock predicate can be shared among threads: IsLock(l, P) ⇔ IsLock(l, P) ∗ IsLock(l, P) Lock invariant

slide-34
SLIDE 34

18

The proof of our program

{True} let x = ref(0) in let y = ref(4) in let z = new lock() in acquire z swap x y release z acquire z assert (! x + ! y = 4) release z {True}

slide-35
SLIDE 35

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in let z = new lock() in acquire z swap x y release z acquire z assert (! x + ! y = 4) release z {True}

slide-36
SLIDE 36

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in acquire z swap x y release z acquire z assert (! x + ! y = 4) release z {True}

slide-37
SLIDE 37

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) acquire z swap x y release z acquire z assert (! x + ! y = 4) release z {True}

slide-38
SLIDE 38

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z swap x y release z {True} acquire z assert (! x + ! y = 4) release z {True}

slide-39
SLIDE 39

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y release z {True} acquire z assert (! x + ! y = 4) release z {True}

slide-40
SLIDE 40

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y {x → n2 ∗ y → n1 ∗ n1 + n2 = 4} release z {True} acquire z assert (! x + ! y = 4) release z {True}

slide-41
SLIDE 41

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y {x → n2 ∗ y → n1 ∗ n1 + n2 = 4} release z {True} {True} acquire z assert (! x + ! y = 4) release z {True}

slide-42
SLIDE 42

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y {x → n2 ∗ y → n1 ∗ n1 + n2 = 4} release z {True} {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} assert (! x + ! y = 4) release z {True}

slide-43
SLIDE 43

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y {x → n2 ∗ y → n1 ∗ n1 + n2 = 4} release z {True} {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} assert (! x + ! y = 4) {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} release z {True}

slide-44
SLIDE 44

18

The proof of our program

{True} let x = ref(0) in {x → 0} let y = ref(4) in {x → 0 ∗ y → 4} let z = new lock() in allocate IsLock(z, ∃n1, n2. x → n1 ∗ y → n2 ∗ n1 + n2 = 4) {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} swap x y {x → n2 ∗ y → n1 ∗ n1 + n2 = 4} release z {True} {True} acquire z {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} assert (! x + ! y = 4) {x → n1 ∗ y → n2 ∗ n1 + n2 = 4} release z {True} {True}

slide-45
SLIDE 45

19

Demo

slide-46
SLIDE 46

20

Part #3: verification of a spin lock

slide-47
SLIDE 47

21

Demo

slide-48
SLIDE 48

22

Part #4: conclusions

slide-49
SLIDE 49

23

Current Iris projects

◮ Concurrent algorithms (Jung, Krebbers, Swasey, Timany) ◮ The Rust type system (Jung, Jourdan, Dreyer, Krebbers) ◮ Logical relations (Krogh-Jespersen, Svendsen, Timany, Birkedal, Tassarotti, Jung, Krebbers) ◮ Weak memory concurrency (Kaiser, Dang, Dreyer, Lahav, Vafeiadis) ◮ Object calculi (Swasey, Dreyer, Garg) ◮ Logical atomicity (Krogh-Jespersen, Zhang, Jung) ◮ Defining Iris in Iris (Krebbers, Jung, Jourdan, Bizjak, Dreyer, Birkedal)

slide-50
SLIDE 50

24

Coq wish list

◮ Data types in Ltac ◮ Side-effecting tactics that can return a value ◮ More expressive parsing mechanism for tactic

notations

◮ Exception handling in Ltac to generate better

error messages

◮ Opt-out from backtracking Ltac semantics ◮ Better ways to seal-off definitions

slide-51
SLIDE 51

25

Thank you!

Download Iris at http://iris-project.org/