Functional In-place Update with Layered Datatype Sharing Michal - - PowerPoint PPT Presentation

functional in place update with layered datatype sharing
SMART_READER_LITE
LIVE PREVIEW

Functional In-place Update with Layered Datatype Sharing Michal - - PowerPoint PPT Presentation

Functional In-place Update with Layered Datatype Sharing Michal Kone cn y LFCS, University of Edinburgh part of a wider collaboration with David Aspinall, Martin Hofmann, Robert Atkey M. Kone cn y, LFCS Edinburgh Theory seminar,


slide-1
SLIDE 1

Functional In-place Update with Layered Datatype Sharing

Michal Koneˇ cn´ y LFCS, University of Edinburgh part of a wider collaboration with David Aspinall, Martin Hofmann, Robert Atkey

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

1

slide-2
SLIDE 2

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Overview

  • LFPL (Linear Functional Programming Language) [Hofmann 2000]
  • functional language ⇒ neat reasoning about programs
  • resource type ♦ ⇒ simple and efficient evaluation using heap
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

2

slide-3
SLIDE 3

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Overview

  • LFPL (Linear Functional Programming Language) [Hofmann 2000]
  • functional language ⇒ neat reasoning about programs
  • resource type ♦ ⇒ simple and efficient evaluation using heap
  • linear typing guarantees correctness of this evaluation

forbids sharing on the heap

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

2

slide-4
SLIDE 4

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Overview

  • LFPL (Linear Functional Programming Language) [Hofmann 2000]
  • functional language ⇒ neat reasoning about programs
  • resource type ♦ ⇒ simple and efficient evaluation using heap
  • linear typing guarantees correctness of this evaluation

forbids sharing on the heap

  • developing less restrictive typings for LFPL

– usage aspects (Aspinall & Hofmann 2002) – explicit sharing in the context (Atkey) – layered datatype sharing (K 2002)

  • Scope: first-order, full recursion, arbitrary inductive datatypes
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

2

slide-5
SLIDE 5

✿✿✿✿✿✿✿✿✿✿✿✿

Append

✿✿✿

in

✿✿✿✿✿✿✿✿✿

LFPL

In ML : append(x, y) = match x with Nil → y | Cons(h, t) → Cons(h, append(t, y)) h : A, t : L(A) ⊢ Cons(h, t) : L(A)

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

3

slide-6
SLIDE 6

✿✿✿✿✿✿✿✿✿✿✿✿

Append

✿✿✿

in

✿✿✿✿✿✿✿✿✿

LFPL

In LFPL: append(x, y) = match x with Nil → y | Cons(h, t)@d → Cons(h, append(t, y))@d h : A, t : L(A), d : ♦ ⊢ Cons(h, t)@d : L(A) elements of ♦: units of heap space/heap locations

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

3

slide-7
SLIDE 7

✿✿✿✿✿✿✿✿✿✿✿✿

Append

✿✿✿

in

✿✿✿✿✿✿✿✿✿

LFPL

In LFPL: append(x, y) = match x with Nil → y | Cons(h, t)@d → Cons(h, append(t, y))@d h : A, t : L(A), d : ♦ ⊢ Cons(h, t)@d : L(A) elements of ♦: units of heap space/heap locations Heap representation:

  • x
  • y

stack heap

v1

  • v2
  • v3 nil

v4

  • v5 nil
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

3

slide-8
SLIDE 8

✿✿✿✿✿✿✿✿✿✿✿✿

Append

✿✿✿

in

✿✿✿✿✿✿✿✿✿

LFPL

In LFPL: append(x, y) = match x with Nil → y | Cons(h, t)@d → Cons(h, append(t, y))@d h : A, t : L(A), d : ♦ ⊢ Cons(h, t)@d : L(A) elements of ♦: units of heap space/heap locations Heap representation:

  • x
  • y

stack heap

v1

  • v2
  • v3 nil

v4

  • v5 nil
  • r
  • y

v1

  • v2
  • v3
  • v4
  • v5 nil
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

3

slide-9
SLIDE 9

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Non-linear

✿✿✿✿✿✿✿✿✿✿✿

typings

In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

4

slide-10
SLIDE 10

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Non-linear

✿✿✿✿✿✿✿✿✿✿✿

typings

In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x :1 L(A), y :2 L(A) ⊢ append(x, y) : L(A) x :3 L(A) ⊢ length(x) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

4

slide-11
SLIDE 11

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Non-linear

✿✿✿✿✿✿✿✿✿✿✿

typings

In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x :1 L(A), y :2 L(A) ⊢ append(x, y) : L(A) x :3 L(A) ⊢ length(x) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL append(x, x) N N Cons(h, Cons(h, t)@d1)@d2 Y N Cons(length(x), x)@d Y N append(Cons(h, t1)@d1, Cons(h, t2)@d2) Y N

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

4

slide-12
SLIDE 12

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Non-linear

✿✿✿✿✿✿✿✿✿✿✿

typings

In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x :1 L(A), y :2 L(A) ⊢ append(x, y) : L(A) x :3 L(A) ⊢ length(x) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL UAPL append(x, x) N N N Cons(h, Cons(h, t)@d1)@d2 Y N Y Cons(length(x), x)@d Y N Y append(Cons(h, t1)@d1, Cons(h, t2)@d2) Y N N

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

4

slide-13
SLIDE 13

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Non-linear

✿✿✿✿✿✿✿✿✿✿✿

typings

In LFPL: – Every use of a variable is considered destructive – No heap-sharing between arguments LFPL with Usage aspects (UAPL, Aspinall & Hofmann 2002): x :1 L(A), y :2 L(A) ⊢ append(x, y) : L(A) x :3 L(A) ⊢ length(x) : Nat 1 = destructive, 2 = read-only, 3 = read-only & not sharing with the result expression eval? LFPL UAPL DEEL append(x, x) N N N N Cons(h, Cons(h, t)@d1)@d2 Y N Y Y Cons(length(x), x)@d Y N Y Y append(Cons(h, t1)@d1, Cons(h, t2)@d2) Y N N Y

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

4

slide-14
SLIDE 14

✿✿✿✿✿✿✿✿✿✿✿✿✿

Datatype

✿✿✿✿✿✿✿✿✿✿✿✿

portions

✿✿✿✿✿✿✿✿✿✿✿✿

(layers)

L(A) = µX.Unit + ♦(A × X)

  • x

stack heap

  • nil •
  • nil

ff

  • tt
  • ff nil
  • x = [[ff, ff], [], [tt, ff]]
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

5

slide-15
SLIDE 15

✿✿✿✿✿✿✿✿✿✿✿✿✿

Datatype

✿✿✿✿✿✿✿✿✿✿✿✿

portions

✿✿✿✿✿✿✿✿✿✿✿✿

(layers)

L(A) = µX.Unit + ♦(A × X)

  • x

stack heap

  • nil •
  • nil

ff

  • tt
  • ff nil
  • a

x = [[ff, ff], [], [tt, ff]]

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

5

slide-16
SLIDE 16

✿✿✿✿✿✿✿✿✿✿✿✿✿

Datatype

✿✿✿✿✿✿✿✿✿✿✿✿

portions

✿✿✿✿✿✿✿✿✿✿✿✿

(layers)

L(A) = µX.Unit + ♦(A × X)

  • x

stack heap

  • nil •
  • nil

ff

  • tt
  • ff nil
  • a

b

x = [[ff, ff], [], [tt, ff]]

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

5

slide-17
SLIDE 17

✿✿✿✿✿✿✿✿✿✿✿✿✿

Datatype

✿✿✿✿✿✿✿✿✿✿✿✿

portions

✿✿✿✿✿✿✿✿✿✿✿✿

(layers)

L(A) = µX.Unit + ♦(A × X)

  • x

stack heap

  • nil •
  • nil

ff

  • tt
  • ff nil
  • a

b

x = [[ff, ff], [], [tt, ff]] x : L[a](L[b](Bool))

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

5

slide-18
SLIDE 18

✿✿✿✿✿✿✿✿✿✿✿✿✿

Datatype

✿✿✿✿✿✿✿✿✿✿✿✿

portions

✿✿✿✿✿✿✿✿✿✿✿✿

(layers)

L(A) = µX.Unit + ♦(A × X)

  • x

stack heap

  • nil •
  • nil

ff

  • tt
  • ff nil
  • a

b

x = [[ff, ff], [], [tt, ff]] x : L[a](L[b](Bool)) L[a](A) = µX(a).Unit + ♦[a](A × X)

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

5

slide-19
SLIDE 19

✿✿✿✿✿✿✿✿✿

Basic

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Separation

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Assertions

notation type pattern name a⊗b . . . ♦[a] . . . ♦[b] . . . a separated from b

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

6

slide-20
SLIDE 20

✿✿✿✿✿✿✿✿✿

Basic

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Separation

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Assertions

notation type pattern name a⊗b . . . ♦[a] . . . ♦[b] . . . a separated from b ⊗b/a . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated along a ⊗ba . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated across a

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

6

slide-21
SLIDE 21

✿✿✿✿✿✿✿✿✿

Basic

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Separation

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Assertions

notation type pattern name a⊗b . . . ♦[a] . . . ♦[b] . . . a separated from b ⊗b/a . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated along a ⊗ba . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated across a ⊗b/a

a b b b b b

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

6

slide-22
SLIDE 22

✿✿✿✿✿✿✿✿✿

Basic

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Separation

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Assertions

notation type pattern name a⊗b . . . ♦[a] . . . ♦[b] . . . a separated from b ⊗b/a . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated along a ⊗ba . . . µX(a).

  • . . . ♦[b] . . .
  • . . .

b separated across a ⊗b/a ⊗ba

a b b b b b a b b b b b

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

6

slide-23
SLIDE 23

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿✿

  • f

✿✿✿✿✿✿✿✿✿✿✿✿

append

b e f a c d

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); argument portions ⊢ append(x, y) : L[e

](L[f ](Bool));

result portions ;

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

7

slide-24
SLIDE 24

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿✿

  • f

✿✿✿✿✿✿✿✿✿✿✿✿

append

b e f a c d

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); argument portions ⊢ append(x, y) : L[e

](L[f ](Bool));

result portions {a} destroyed portions ;

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

7

slide-25
SLIDE 25

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿✿

  • f

✿✿✿✿✿✿✿✿✿✿✿✿

append

b e f a c d

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); argument portions ⊢ append(x, y) : L[e⊆{a,c}](L[f⊆{b,d}](Bool)); result portions, containment {a} destroyed portions ;

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

7

slide-26
SLIDE 26

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿✿

  • f

✿✿✿✿✿✿✿✿✿✿✿✿

append

b e f a c d

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); argument portions {a⊗b, a⊗c, a⊗d} ⊢ separation pre-condition append(x, y) : L[e⊆{a,c}](L[f⊆{b,d}](Bool)); result portions, containment {a} destroyed portions ;

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

7

slide-27
SLIDE 27

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿✿

  • f

✿✿✿✿✿✿✿✿✿✿✿✿

append

b e f a c d

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); argument portions {a⊗b, a⊗c, a⊗d} ⊢ separation pre-condition append(x, y) : L[e⊆{a,c}](L[f⊆{b,d}](Bool)); result portions, containment {a} destroyed portions ⊗f/e ⇐ = {b⊗d, ⊗b/a, ⊗d/c} ; separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

7

slide-28
SLIDE 28

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

h : Bh, t : Bt, d : ♦[ζd]; ⊢

separation pre-condition

Cons(h, t)@d : ;

containment guarantees

;

destroyed portions

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-29
SLIDE 29

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

h : Bh, t : Bt, d : ♦[ζd]; ⊢

separation pre-condition

Cons(h, t)@d : ;

containment guarantees

{ζd} ;

destroyed portions

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-30
SLIDE 30

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

h : Bh, t : Bt, d : ♦[ζd]; {ζd}⊗

  • ND(Bh) ∪ ND(Bt)

separation pre-condition

Cons(h, t)@d : ;

containment guarantees

{ζd} ;

destroyed portions

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-31
SLIDE 31

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

E = L[ζ′⊆{ζd}](Eh) ∪ Et h : Bh, t : Bt, d : ♦[ζd]; {ζd}⊗

  • ND(Bh) ∪ ND(Bt)

separation pre-condition

Cons(h, t)@d : E ;

containment guarantees

{ζd} ;

destroyed portions

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-32
SLIDE 32

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

E = L[ζ′⊆{ζd}](Eh) ∪ Et Eh ∈ EY(Bh) Et ∈ EY(Bt) h : Bh, t : Bt, d : ♦[ζd]; {ζd}⊗

  • ND(Bh) ∪ ND(Bt)

separation pre-condition

Cons(h, t)@d : E ;

containment guarantees

{ζd} ;

destroyed portions

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-33
SLIDE 33

✿✿✿

A

✿✿✿✿✿✿✿✿✿

typing

✿✿✿✿✿✿

rule

[CONS]

Bh = A[ δ

ρ]

Bt = L[ζ](A

  • δ ′

ρ ′

)

E = L[ζ′⊆{ζd}](Eh) ∪ Et Eh ∈ EY(Bh) Et ∈ EY(Bt) h : Bh, t : Bt, d : ♦[ζd]; {ζd}⊗

  • ND(Bh) ∪ ND(Bt)

separation pre-condition

Cons(h, t)@d : E ;

containment guarantees

{ζd} ;

destroyed portions

G

separation rely-guarantees

where G = GM(E) ∪ GY(Eh, Bh) ∪ GY(Et, Bt) ∪

  • ⊗ζξ/ζ′ ⇐

= {δ(ξ)⊗δ′(ξ)}

  • ξ∈AddrD(A)
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

8

slide-34
SLIDE 34

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-35
SLIDE 35

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic:

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); ∅ ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆∅](L[f⊆∅](Bool));

containment guarantees

∅;

destroyed portions

⊗f/e ⇐ = ∅

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-36
SLIDE 36

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression

t : L[a](L[b](Bool)), z : L[c](L[d](Bool)); ∅ ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆∅](L[f⊆∅](Bool));

containment guarantees

∅;

destroyed portions

⊗f/e ⇐ = ∅

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-37
SLIDE 37

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression

h : L[a](Bool), y : L[b](L[c](Bool)), d : ♦[d]; {a⊗d, b⊗d, c⊗d} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{b,d}](L[f⊆{a,c}](Bool));

containment guarantees

{d};

destroyed portions

⊗f/e ⇐ = {a⊗c, ⊗c/b}

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-38
SLIDE 38

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression

h : L[a](Bool), y : L[b](L[c](Bool)), d : ♦[d], t : L[e](L[f](Bool)) {a⊗d, b⊗d, c⊗d, d⊗e, d⊗f} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[g⊆∅](L[h⊆∅](Bool));

containment guarantees

{d};

destroyed portions

⊗h/g ⇐ = ∅

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-39
SLIDE 39

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); { a⊗c , a⊗d } ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{ c }](L[f⊆{ d }](Bool));

containment guarantees

{ a };

destroyed portions

⊗f/e ⇐ = { ⊗d/c }

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-40
SLIDE 40

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression and repeat

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); { a⊗b , a⊗c, a⊗d} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{a, c }](L[f⊆{b, d }](Bool));

containment guarantees

{a};

destroyed portions

⊗f/e ⇐ = {b⊗d, ⊗d/c}

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-41
SLIDE 41

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression and repeat until fixpoint is found

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); {a⊗b, a⊗c, a⊗d} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{a,c}](L[f⊆{b,d}](Bool));

containment guarantees

{a};

destroyed portions

⊗f/e ⇐ = {b⊗d, ⊗b/a , ⊗d/c}

separation rely-guarantees

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-42
SLIDE 42

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression and repeat until fixpoint is found

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); {a⊗b, a⊗c, a⊗d} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{a,c}](L[f⊆{b,d}](Bool));

containment guarantees

{a};

destroyed portions

⊗f/e ⇐ = {b⊗d, ⊗b/a , ⊗d/c}

separation rely-guarantees

  • Typing rules need to be – monotone
  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-43
SLIDE 43

✿✿✿✿✿✿✿✿✿✿

Typing

✿✿

a

✿✿✿✿✿✿✿✿✿✿✿✿✿✿

recursive

✿✿✿✿✿✿✿✿✿✿✿✿

program

  • annotating expressions - need annotated function symbols
  • initial annotation - optimistic
  • then annotate expression and repeat until fixpoint is found

x : L[a](L[b](Bool)), y : L[c](L[d](Bool)); {a⊗b, a⊗c, a⊗d} ⊢

separation pre-condition

match x with Nil → y | Cons(h, t)@d → let z = Cons(h, y)@d in append(t, z) : L[e⊆{a,c}](L[f⊆{b,d}](Bool));

containment guarantees

{a};

destroyed portions

⊗f/e ⇐ = {b⊗d, ⊗b/a , ⊗d/c}

separation rely-guarantees

  • Typing rules need to be – monotone

– stable under strengthening of premises

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

9

slide-44
SLIDE 44

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Conclusion

  • powerful and efficient static analysis of functional in-place udate
  • implemented in Haskell
slide-45
SLIDE 45

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Conclusion

  • powerful and efficient static analysis of functional in-place udate
  • implemented in Haskell
  • Future: – Infer formal proofs of correctness (ala Necula&Lee)
slide-46
SLIDE 46

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Conclusion

  • powerful and efficient static analysis of functional in-place udate
  • implemented in Haskell
  • Future: – Infer formal proofs of correctness (ala Necula&Lee)

– Infer resource usage approximations? (Hofmann&Jost)

slide-47
SLIDE 47

✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿

Conclusion

  • powerful and efficient static analysis of functional in-place udate
  • implemented in Haskell
  • Future: – Infer formal proofs of correctness (ala Necula&Lee)

– Infer resource usage approximations? (Hofmann&Jost) – Scope: allocation, higher order, arrays

  • M. Koneˇ

cn´ y, LFCS Edinburgh Theory seminar, January 21, 2003 Layered Sharing

10