Total Pasta: Unfailing Pointer Programs Neil Mitchell, ndm AT - - PowerPoint PPT Presentation

total pasta
SMART_READER_LITE
LIVE PREVIEW

Total Pasta: Unfailing Pointer Programs Neil Mitchell, ndm AT - - PowerPoint PPT Presentation

Total Pasta: Unfailing Pointer Programs Neil Mitchell, ndm AT cs.york.ac.uk Department of Computer Science, University of York 1 Pasta Linked List Example l i st { ni l ( ) ; cons( i nt i nt head, pt r pt r t ai l ) ; } - - i


slide-1
SLIDE 1

1

Total Pasta:

Unfailing Pointer Programs

Neil Mitchell, ndm AT cs.york.ac.uk

Department of Computer Science, University of York

slide-2
SLIDE 2

2

Pasta – Linked List Example

l i st { ni l ( ) ; cons( i nt i nt head, pt r pt r t ai l ) ; }

  • -

i nser t s an el em ent i nt o an or der ed l i st i nser t ( i nt i nt i , pt r pt r s) { whi l e whi l e ( s: : cons && s- >head < i ) s = s- >t ai l ; i f i f ( s: : ni l | | s- >head > i ) * s = * cons( i , copy copy( s) ) ; } m ai n( ) { pt r pt r r = ni l ( ) ; i nser t ( 1, r ) ; i nser t ( 9, r ) ; i nser t ( 2, r ) ; i nser t ( 8, r ) ; }

slide-3
SLIDE 3

3

Total Pasta Functions?

Must not crash

i f ( s: : ni l ) s = s- >t ai l ;

Must terminate

whi l e ( s: : cons) s = s;

Don't need to worry about

arithmetic overflow (no addition in Pasta!) recursion (also not in Pasta)

Assume unbounded memory

slide-4
SLIDE 4

4

Subtype checking

Subtype annotations

i f ( x: : cons) …

Subtype assertions

x- >t ai l requires x: : cons

Can use powerset to represent subtypes

Subtype(x) ∈ {{cons,nil}, {nil}, {cons}, ∅}

Type assertions can be discharged by static checking

slide-5
SLIDE 5

5

Termination Checking

Only has a whi l e statement to loop There must be one variable that is

advanced down an acyclic path during every iteration

whi l e ( s: : cons) s = s- >t ai l ;

Requires an acyclic annotation

l i st acycl i c

acycl i c( t ai l ) { … }

slide-6
SLIDE 6

6

My Approach

B/Z inspired approach

Define postconditions for safety Propagate backwards Show the conditions are satisfied

The Method

Assign a postcondition of True Transform post conditions to generate preconditions Total function has precondition of True

slide-7
SLIDE 7

7

Details: Safe and Prec

Safe(α) – the conditions for α to be safe

Safe(s- >t ai l ) = s: : cons

Prec(α, β) – the condition β, with α

Prec(x = y, x: : cons) = y: : cons {y: : cons} x = y {x: : cons}

slide-8
SLIDE 8

8

Flow Structures (if)

{α} i f

i f ( cond) t ; el se el se f ; {β}

α = safe(cond) ∧

(cond ⇒ safe(t ) ∧ prec(t , β)) ∧ (¬cond ⇒ safe(f ) ∧ prec(f , β))

slide-9
SLIDE 9

9

A small example

i f i f ( s: : ni l | | s- >head > i )

* s = * cons( i , copy copy( s) ) ;

Now lets expand the | | …

{True} {True} {True}

slide-10
SLIDE 10

10

Expanding out the | |

i f i f ( s: : ni l ) st m t ; el se i f ( s- >head > i ) st m t ; Equivalent to:

{True} {True} {s::cons} {True} {(s::nil ⇒ True) ∧ (¬s::nil ⇒ s::cons)} {s::cons} {True}

slide-11
SLIDE 11

11

Ingredients of Checking

Prec and Safe functions A predicate solver Fixed pointing for loops Check that acyclic property is preserved Check all loops terminate

slide-12
SLIDE 12

12

Back to the example

The precondition to main is True The precondition to insert is True Both are total functions Also tested on Queues, Binary Trees, 234

Trees, for insertion and deletion

Proves all to be total functions

slide-13
SLIDE 13

13

Future Work

Use a mainstream language, i.e. C++ Extend Pasta with static typing, arithmetic Operate on individual procedures

Currently it expands them ALL inline

Make it go faster

Some runs took hours (i nser t in 234 Tree) Profiling gave 20x speedup with ease

slide-14
SLIDE 14

14

Total Pasta:

Unfailing Pointer Programs

Neil Mitchell, ndm AT cs.york.ac.uk

Department of Computer Science, University of York

slide-15
SLIDE 15

15

Starred Assignment

* a = * c

a b c

ni l cons

a b c

cons cons

Notice that the value of b changes, without being mentioned