1
Total Pasta:
Unfailing Pointer Programs
Neil Mitchell, ndm AT cs.york.ac.uk
Department of Computer Science, University of York
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
1
Department of Computer Science, University of York
2
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 ) ; }
3
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
4
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
5
Only has a whi l e statement to loop There must be one variable that is
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 ) { … }
6
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
7
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}
8
{α} i f
α = safe(cond) ∧
9
* s = * cons( i , copy copy( s) ) ;
Now lets expand the | | …
{True} {True} {True}
10
{True} {True} {s::cons} {True} {(s::nil ⇒ True) ∧ (¬s::nil ⇒ s::cons)} {s::cons} {True}
11
Prec and Safe functions A predicate solver Fixed pointing for loops Check that acyclic property is preserved Check all loops terminate
12
The precondition to main is True The precondition to insert is True Both are total functions Also tested on Queues, Binary Trees, 234
Proves all to be total functions
13
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
14
Department of Computer Science, University of York
15
a b c
ni l cons
a b c
cons cons
Notice that the value of b changes, without being mentioned