1 / 23

Dynamic-frame specifications in Dafny

Dynamic-frame specifications in Dafny. K. Rustan M. Leino RiSE , Microsoft Research. 1 Dec 2008 Invited talk, working group meeting COST Action IC0701, Formal Verification of Object-Oriented Software Madrid, Spain. Dafny. experimental language sequential, object based (no subclassing )

larue
Download Presentation

Dynamic-frame specifications in Dafny

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dynamic-frame specifications in Dafny K. Rustan M. Leino RiSE, Microsoft Research 1 Dec 2008Invited talk, working group meetingCOST Action IC0701, Formal Verification of Object-Oriented SoftwareMadrid, Spain

  2. Dafny • experimental language • sequential, object based (no subclassing) • specifications in the style of dynamic frames • coarse-grained frames (at the level of whole objects, not individual memory locations)

  3. Functional-correctness verifications • queue • linked list with head/tail pointers • in-situ list reversal • integer set • binary tree • Schorr-Waite marking algorithm

  4. Dafny grammar • Program ::= Class* • Class ::= class C<TypeParam*> { Member* } • Member ::= • Field • Method • Function

  5. Fields • var x : T;

  6. Types • T ::= • bool • int • set<T> • seq<T> • C<T*> • object

  7. Methods • method M<TypeParam*> (Param*) returns (Param*) Spec*{ Stmt*}

  8. Statements • Stmt ::= • var x: T; • x := E; • E.f := E’; • x := new C<T*>; • call x* := E.M(E*); • if (E) { Stmt* } else { Stmt* } • while (E) invariant J; decreases F; { Stmt* } • foreach (x in S) { x.f := E; }

  9. Specifications • Spec ::= • requires E; • modifies S; • ensures E; • where “modifies S” means • modifies Heap • ensures (o,f Heap[o,f] = old(Heap)[o,f]  o old(S) ¬old(Heap)[o,alloc]) • modifies clauses are enforced atevery update

  10. Functions • function F<TypeParam*> (Param*): Treads Rd;{Expr} • produces definitional axiom: (Heap,this,x F(Heap,this,x) = Expr)

  11. What is the reads clause good for? • ensures definitional axioms are consistent • reading o.f requires o  Rd • calling a function G requires RdG  Rd • produces frame axiom: • ( h0,h1,this,x  ( o,f  o  Rd  h0[o,f] = h1[o,f])  F(h0,this,x) = F(h1,this,x))

  12. * That’s all! * *) well, pretty much…

  13. Specification idiom: footprints and validity • class C {var footprint: set<object>;function Valid(): boolreads {this},footprint; {this footprint  … } …

  14. Specification idiom: initializer • method Init()modifies {this};ensures Valid() fresh(footprint – {this});

  15. Specification idiom: mutating method • method M()requires Valid();modifies footprint;ensures Valid() fresh(footprint – old(footprint));

  16. Demo: Queue :Queue tail head :Node :Node :Node :Node

  17. Demo: Schorr-Waite • Specification (excerpt): • ensuresroot.marked; • ensures( n, i n.marked  0 ≤ i < |n.children|n.children[i] = null  n.children[i].marked); • Loop invariant (excerpt): • invariantt.marked; • invariant( n, i n.marked  0 ≤ i < |n.children|  nnodeStackn.children[i] = null  n.children[i].marked);

  18. Schorr-Waite termination • decreases { n | ¬ n.marked }, |nodeStack|, |t.children| – t.childrenVisited;

  19. Schorr-Waite: garbage unmarked • ensuresroot.marked; • ensures( n, i n.marked  0 ≤ i < |n.children|n.children[i] = null  n.children[i].marked); • ensures ( n  Reach(root,n)  ¬n.marked);

  20. Lessons, 0 • Dynamic-frame specifications are useful and flexible • A language design around dynamic frames can be simple • Thus good in teaching? • Specifications are verbose, but perhaps simplification techniques can be applied (like in Spec# or Chalice) • Currently missing in Dafny: scopes for axioms

  21. Lessons, 1 • Pure methods are hard, functions are easy • SMT solvers work better with ghost fields than with functions • Reachability is not always necessary in specifications • Sets and sequences are nice as value types • Generics are a cinch • Decreases bound checks can be more liberal than naïve translation

  22. Lessons, 2 • SMT solvers can be used for functional-correctness verification • Inductive predicates seem useful • cases fit nicely with matching triggers • take us in the direction of the input languages of interactive theorem provers • Need: better views/visualizations of program states to clarify error messages and, generally, what’s going on

  23. Parting note • Try it for yourself:http://research.microsoft.com/boogie/dafny

More Related