Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 2 EEF summer school on Specification,

Slides:



Advertisements
Similar presentations
A SAT characterization of boolean-program correctness K. Rustan M. Leino Microsoft Research, Redmond, WA 14 Nov 2002 IFIP WG 2.4 meeting, Schloβ Dagstuhl,
Advertisements

Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLines CSE 503, Software Engineering University of Washington 26 Apr 2004.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLines CSE 503, Software Engineering University of Washington 28 Apr 2004.
Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte Formal techniques.
Advanced programming tools at Microsoft
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Lunch seminar, Praxis Bath, UK 6 Dec 2005 joint work with Mike Barnett,
Bor-Yuh Evan Chang Daan Leijen Peter Müller David A. Naumann The Spec# programming system Mike Barnett Rob DeLine Manuel Fähndrich Bart Jacobs K. Rustan.
Demand-driven inference of loop invariants in a theorem prover
Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 4 EEF summer school on Specification,
Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 3 EEF summer school on Specification,
Object Invariants in Specification and Verification K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 2 Summer school on Formal Models.
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
1 Towards a Verifying Compiler: The Spec# Approach Wolfram Schulte Microsoft Research Formal Methods 2006 Joint work with Rustan Leino, Mike Barnett, Manuel.
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 3 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Spec# K. Rustan M. Leino Senior Researcher Programming Languages and Methods Microsoft Research, Redmond, WA, USA Microsoft Research faculty summit, Redmond,
Lecture 4 Towards a Verifying Compiler: Data Abstraction Wolfram Schulte Microsoft Research Formal Methods 2006 Purity, Model fields, Inconsistency _____________.
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
K. Rustan M. Leino Peter Müller IFIP WG 2.3 meeting June 2009 Boston, MA.
Program synthesis with Jennisys K. Rustan M. Leino Research in Software Engineering (RiSE), Microsoft Research, Redmond Aleksandar Milicevic MIT IFIP Working.
The Dafny program verifier
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 15 January 2009 Séminaire Digiteo Orsay, France.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Distinguished Lecture Series Max Planck Institute for Software Systems.
UCb Kim Guldstrand Larsen Symbolic Model Checking …and Verification Options How UPPAAL really works & How to make UPPAAL really work.
Windows XP / Microsoft Word Computer Applications.
Lecture #21 Software Model Checking: predicate abstraction Thomas Ball Testing, Verification and Measurement Microsoft Research.
K. Rustan M. Leino Microsoft Research Peter Müller ETH Zurich Angela Wallenburg Chalmers University.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 2 Marktoberdorf.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA Invited talk Informatics Education in Europe (IEE III’08)
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 2 LASER.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 International Summer School Marktoberdorf Marktoberdorf,
On bounded model checking, abstract interpretation, interpolants, and induction K. Rustan M. Leino Microsoft Research, Redmond, WA, USA IFIP WG 2.3, meeting.
Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 EEF summer school on Specification,
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 1 LASER.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 Summer School on Logic and Theorem-Proving in Programming.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 LASER.
Building a program verifier K. Rustan M. Leino Microsoft Research, Redmond, WA 10 May 2006 Guest lecture, Shaz Qadeer’s cse599f, Formal Verification of.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 4 LASER.
Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 5 LASER.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 3 LASER.
K. Rustan M. Leino Microsoft Research, Redmond, WA 10 Oct 2007 IFIP WG 2.3 meeting Santa Fe, NM.
EXAMPLE 2 Using the Cross Products Property = 40.8 m Write original proportion. Cross products property Multiply. 6.8m 6.8 = Divide.
K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 0 1 September 2009 FOSAD 2009, Bertinoro, Italy.
Refinement, reusable libraries, instantiable classes K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Joint work.
It’s All About Properties of Equality. How could properties of equality be applied to solve this equation? Example 1: 3x + 11 = 32 What is the value of.
Program Verification K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond University of Washington CSE P January.
Rustan Leino RiSE, Microsoft Research, Redmond MIT 5 June 2009 Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven.
Lesson 1-3 Example What number goes in the blank to make (7 + 5) + 4 = ___ + (14 – 2) a true equation? Step 1 The expressions inside the parentheses.
K. Rustan M. Leino RiSE, Microsoft Research 17 July 2009 JML seminar Dagstuhl, Germany.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 Marktoberdorf.
K. Rustan M. Leino and Wolfram Schulte Microsoft Research, Redmond ESOP 2007 Braga, Portugal 28 March 2007.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 2 International Summer School Marktoberdorf Marktoberdorf,
Inverse Properties.
Dafny An automatic program verifier for functional correctness
Using and Building an Automatic Program Verifier
Class-local object invariants
Factors that contribute to the environment
درس تطبيقي مادة التربية الفنية للصف الرابع الابتدائي
IN A VALID AND REALIABLE WAY?
Dafny An automatic program verifier for functional correctness
} 2x + 2(x + 2) = 36 2x + 2x + 4 = 36 4x + 4 = x =
Solving Multi Step Equations
Solving Multi Step Equations
Шаттық шеңбері.
Presentation transcript:

Checking correctness properties of object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 2 EEF summer school on Specification, Refinement, and Verification 20 Aug 2002, Turku, Finland

Example: union-find class UnionFind <: Object field nClasses, nElements, … method UnionFind :: init(uf, size) requires 0 <= size modifies uf.nClasses, uf.nElements, … ensures uf.nClasses = uf.nElements = size method UnionFind :: find(uf, c) returns (r) requires 0 <= c < uf.nElements ensures 0 <= r < uf.nClasses method UnionFind :: union(c, d) requires0 <= c <= uf.nElements /\ 0 <= d <= uf.nElements modifies uf.nClasses ensuresuf.nClasses = uf.nClasses 0 \/ uf.nClasses = uf.nClasses 0 - 1

Example, client var uf, r0, r1, r2 in uf := new(UnionFind); uf.init(12); uf.union(3, 8); uf.union(8, 6); uf.union(10, 11); r0 := uf.find(3); r1 := uf.find(5); r2 := uf.find(6); assert r0 r1; assert r0 = r2 end

Example, implementation class StandardUnionFind <: UnionFind mimpl StandardUnionFind :: find(uf, c) returns (r) is … class FastUnionFind <: UnionFind mimpl FastUnionFind :: find(uf, c) returns (r) is …

null istype(o, T) o = null \/ typeof(o) <: T istype(o, T) o = null \/ typeof(o) <: T x.f := E assert x null ; f[x] := E x.f := E assert x null ; f[x] := E

Type casts x := typecast(E, T) assert istype(E, T) ; x := E x := typecast(E, T) assert istype(E, T) ; x := E

Example: binary method class T <: Object method T :: equal(x, y) returns (b) requires typeof(x) = typeof(y) class U <: T mimpl U :: equal(x, y) returns b is var yy in yy := typecast(y, U); // compare x and yy … end

Types of parameters method OutputStream :: putText(wr, s) … method T :: print(t, wr) requires istype(wr, OutputStream)

Types of parameters method OutputStream :: putText(wr, s) … method T :: print(t, wr) requires istype(wr, OutputStream) method print(t: T, wr: OutputStream) …

Types of fields field T :: f: U// class T { … f: U … } ( f, T, U :: isField(f, T, U) ( o :: istype(f[o], U)))

Types of fields field T :: f: U// class T { … f: U … } ( f, T, U :: isField(f, T, U) ( o ::istype(o, T) ==> istype(f[o], U)))

Types of fields field T :: f: U// class T { … f: U … } ( f, T, U :: isField(f, T, U) ( o ::istype(o, T) ==> istype(f[o], U))) Initially: assume isField(f, T, U) havoc f havoc f ; assume isField(f, T, U)

More about allocation initially, for every parameter x: assume alloc[x] initially, for every parameter x: assume alloc[x] mimpl T :: m(x) is var y in y := new(T); assert x y end mimpl T :: m(x) is var y in y := new(T); assert x y end

Even more about allocation mimpl T :: m(x) is var y in y := new(T); assert x.f y end mimpl T :: m(x) is var y in y := new(T); assert x.f y end

Even more about allocation mimpl T :: m(x) is var y in y := new(T); assert x.f y end mimpl T :: m(x) is var y in y := new(T); assert x.f y end isField(f, T, U, a) … /\ ( o :: a[o] ==> a[f[o]] ) isField(f, T, U, a) … /\ ( o :: a[o] ==> a[f[o]] ) whenever f or alloc is changed: assume isField(f, T, U, alloc) whenever f or alloc is changed: assume isField(f, T, U, alloc)

Exercise Prove the following program correct: method p(x) modifies x.f method m(x) modifies x.f mimpl m(x) is var y in x.p(); y := new(T); assert x.f y end Prove the following program correct: method p(x) modifies x.f method m(x) modifies x.f mimpl m(x) is var y in x.p(); y := new(T); assert x.f y end

Strengthening specifications class T <: Object method T :: m(x, y, z) requires P modifies w ensures Q class U <: T method U :: m(x, y, z) requires P modifies w ensures Q /\ R … u.m(y, z) ; assert R … ?

Strengthening specifications class T <: Object method T :: m(x, y, z) returns (r) requires P modifies w ensures Q class U <: T method U :: n(x, y, z) returns (r) requires P modifies w ensures Q /\ R mimpl U :: m(x, y, z) is r := x.n(y, z) … r := u.n(y, z) ; assert R …

Modifies and objects modifies x.f modifies f ensures ( o :: o.f = o.f 0 \/ o = x) modifies x.f modifies f ensures ( o :: o.f = o.f 0 \/ o = x)

Exercise class T <: Object field f method T :: m(x, y, z) requires P modifies x.f ensures Q class U <: T field g method U :: m(x, y, z) requires P modifies x.f, x.g ensures Q ?

What else is missing? Data abstraction Data abstraction Information hiding Information hiding Programming methodology Programming methodology …

References K. Rustan M. Leino. Toward Reliable Modular Programs. PhD thesis, California Institute of Technology. Technical Report Caltech- CS-TR-95-03, Caltech, K. Rustan M. Leino. Toward Reliable Modular Programs. PhD thesis, California Institute of Technology. Technical Report Caltech- CS-TR-95-03, Caltech, K. Rustan M. Leino. Ecstatic: An object-oriented programming language with an axiomatic semantics. In Foundations of Object- Oriented Languages (FOOL 4), K. Rustan M. Leino. Ecstatic: An object-oriented programming language with an axiomatic semantics. In Foundations of Object- Oriented Languages (FOOL 4), K. Rustan M. Leino and Greg Nelson. Data abstraction and information hiding. Research Report 160, Compaq SRC, Nov To appear in TOPLAS. K. Rustan M. Leino and Greg Nelson. Data abstraction and information hiding. Research Report 160, Compaq SRC, Nov To appear in TOPLAS. K. Rustan M. Leino. Data groups: Specifying the modification of extended state. In OOPSLA 98, pp , ACM, K. Rustan M. Leino. Data groups: Specifying the modification of extended state. In OOPSLA 98, pp , ACM, 1998.