total pasta
play

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. Total Pasta: Unfailing Pointer Programs Neil Mitchell, ndm AT cs.york.ac.uk Department of Computer Science, University of York 1

  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 ) ; } 2

  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 3

  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 4

  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 ) { … } 5

  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 6

  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} 7

  8. Flow Structures (if) � { α } i f el se f ; { β } i f ( cond) t ; el se � α = safe(cond) ∧ (cond ⇒ safe(t ) ∧ prec(t , β )) ∧ ( ¬ cond ⇒ safe(f ) ∧ prec(f , β )) 8

  9. A small example i f i f ( s: : ni l | | s- >head > i ) * s = * cons( i , copy copy( s) ) ; {True} {True} {True} � Now lets expand the | | … 9

  10. Expanding out the | | {(s::nil ⇒ True) ∧ ( ¬ s::nil ⇒ s::cons)} i f i f ( s: : ni l ) {True} st m t ; {True} el se i f ( s- >head > i ) {s::cons} {s::cons} st m t ; {True} Equivalent to: {True} 10

  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 11

  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 12

  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 13

  14. Total Pasta: Unfailing Pointer Programs Neil Mitchell, ndm AT cs.york.ac.uk Department of Computer Science, University of York 14

  15. Starred Assignment a a ni l cons b * a = * c b c cons c cons Notice that the value of b changes, without being mentioned 15

Recommend


More recommend