David Markachev CSE814 Topics What is Spec# - - PowerPoint PPT Presentation

david markachev cse814 topics
SMART_READER_LITE
LIVE PREVIEW

David Markachev CSE814 Topics What is Spec# - - PowerPoint PPT Presentation

David Markachev CSE814 Topics What is Spec# Similarities with SPARK Dealing with an Object Oriented Language Dealing with Abstraction CSE814


slide-1
SLIDE 1

David ¡Markachev ¡ CSE814 ¡

slide-2
SLIDE 2

Topics ¡

What ¡is ¡Spec# ¡ Similarities ¡with ¡SPARK ¡ Dealing ¡with ¡an ¡Object ¡Oriented ¡Language ¡ Dealing ¡with ¡Abstraction ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 2 ¡

slide-3
SLIDE 3

Spec# ¡

Created ¡by ¡Microsoft ¡ Developed ¡to ¡explore ¡specifications ¡and ¡tools ¡for ¡

verifications ¡

Attempt ¡at ¡cost ¡efficient ¡method ¡to ¡develop ¡and ¡

maintain ¡software ¡

Consists ¡of: ¡

The ¡Programming ¡language ¡ The ¡compiler ¡ The ¡verifier: ¡Boogie ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 3 ¡

slide-4
SLIDE 4

Boogie ¡ ¡

Verifier ¡for ¡object-­‑oriented ¡languages ¡ Developed ¡side ¡by ¡side ¡with ¡Spec# ¡ Design-­‑time ¡feedback ¡

Specification ¡violations ¡detected ¡immediately ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 4 ¡

slide-5
SLIDE 5

Boogie ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 5 ¡

Spec# ¡compiler ¡generates ¡CIL ¡ Boogie ¡converts ¡CIL ¡to ¡BoogiePL ¡

slide-6
SLIDE 6

Method ¡Contracts ¡

SPARK ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 6 ¡

Spec# ¡ Pre ¡ ¡requires ¡ Post ¡ ¡ensures ¡ Spec# ¡does ¡not ¡specify ¡

input ¡or ¡output ¡

slide-7
SLIDE 7

Loop ¡Invariants ¡

SPARK ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 7 ¡

Spec# ¡

slide-8
SLIDE 8

Loop ¡Invariants ¡

SPARK ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 8 ¡

Spec# ¡

slide-9
SLIDE 9

Inline ¡Asser>ons ¡

SPARK ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 9 ¡

Spec# ¡

slide-10
SLIDE 10

Variable ¡Modifica>ons ¡

modifies ¡keyword ¡specifies ¡variable ¡modifications ¡ this.** ¡-­‑ ¡All ¡members ¡of ¡the ¡class ¡and ¡all ¡members ¡of ¡

its ¡peers ¡may ¡be ¡modifies ¡

this.* ¡– ¡All ¡members ¡of ¡the ¡class ¡may ¡be ¡modified ¡

Compiler ¡places ¡this.* ¡at ¡the ¡end ¡of ¡every ¡modifier ¡

clause, ¡regardless ¡if ¡one ¡is ¡declared ¡

this.0 ¡tells ¡the ¡compiler ¡not ¡to ¡do ¡this ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 10 ¡

slide-11
SLIDE 11

Variable ¡Modifica>ons ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 11 ¡

slide-12
SLIDE 12

Variable ¡Modifica>ons ¡

Loops ¡inherit ¡the ¡modifies ¡clause ¡of ¡the ¡containing ¡

method ¡

Can ¡result ¡in ¡verifier ¡being ¡unable ¡to ¡determine ¡

certain ¡conditions. ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 12 ¡

slide-13
SLIDE 13

Object ¡Oriented ¡Verifica>on ¡

We ¡need ¡to ¡ensure ¡objects ¡are ¡valid ¡whenever ¡they ¡

are ¡used ¡

Need ¡to ¡ensure ¡specification ¡is ¡not ¡violated ¡by ¡

changes ¡to ¡objects ¡

Need ¡to ¡take ¡into ¡account ¡object ¡ownership ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 13 ¡

slide-14
SLIDE 14

Valid/Mutable ¡State ¡

Objects ¡are ¡either ¡in ¡a: ¡

Valid ¡state ¡

Referred ¡to ¡as ¡Valid ¡Objects ¡ All ¡the ¡object’s ¡invariants ¡hold ¡ The ¡components ¡of ¡the ¡object ¡cannot ¡be ¡changed ¡

Mutable ¡state ¡

Its ¡invariants ¡do ¡no ¡necessarily ¡hold ¡ Its ¡components ¡can ¡be ¡freely ¡updated ¡and ¡altered ¡

expose ¡is ¡used ¡to ¡put ¡an ¡object ¡into ¡a ¡mutable ¡state ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 14 ¡

slide-15
SLIDE 15

Valid/Mutable ¡State ¡

Valid ¡objects ¡with ¡no ¡owner ¡or ¡a ¡mutable ¡owner ¡are ¡

called ¡consistent ¡

There ¡are ¡no ¡possible ¡restrictions ¡on ¡the ¡object ¡

Valid ¡objects ¡with ¡a ¡valid ¡owner ¡are ¡called ¡committed ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 15 ¡

slide-16
SLIDE 16

Object ¡Invariants ¡

A ¡class ¡can ¡have ¡a ¡set ¡of ¡invariants ¡that ¡must ¡always ¡

hold ¡true ¡

These ¡invariants ¡are ¡checked ¡to ¡hold: ¡

After ¡every ¡constructor ¡ After ¡every ¡operation ¡on ¡any ¡relevant ¡variables ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 16 ¡

slide-17
SLIDE 17

Object ¡Invariants ¡

Sometimes ¡invariants ¡must ¡be ¡temporarily ¡violated ¡ expose(x) ¡{ ¡/*code*/ ¡} ¡

When ¡the ¡object ¡is ¡in ¡a ¡mutable ¡state, ¡its ¡invariants ¡will ¡

not ¡be ¡checked ¡until ¡after ¡the ¡block ¡exits. ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 17 ¡

slide-18
SLIDE 18

Aggregate ¡Objects ¡

How ¡do ¡we ¡determine ¡if ¡a ¡complex ¡class ¡has ¡been ¡

modified? ¡

Aggregate ¡Objects! ¡

Objects ¡that ¡are ¡defined ¡by ¡their ¡member ¡variables ¡ Representing ¡member ¡variables ¡are ¡called ¡components ¡ Components ¡are ¡designated ¡by ¡the ¡[Rep] ¡tag ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 18 ¡

slide-19
SLIDE 19

Aggregate ¡Objects ¡

Components ¡are ¡owned ¡by ¡their ¡containing ¡class ¡

Owner ¡must ¡be ¡mutable ¡in ¡order ¡for ¡any ¡operations ¡to ¡

be ¡put ¡upon ¡a ¡component. ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 19 ¡

slide-20
SLIDE 20

Peers ¡

Objects ¡may ¡be ¡defined ¡other ¡objects ¡but ¡do ¡not ¡own ¡

them ¡

Peers ¡

Defined ¡by ¡[Peer] ¡tag ¡ Can ¡be ¡modified ¡by ¡containing ¡class ¡ Is ¡not ¡necessarily ¡only ¡acted ¡upon ¡by ¡containing ¡class ¡ Is ¡owned ¡by ¡the ¡owner ¡of ¡the ¡containing ¡class ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 20 ¡

slide-21
SLIDE 21

Peer ¡Consistency ¡

In ¡order ¡to ¡ensure ¡the ¡validity ¡of ¡all ¡objects ¡being ¡

modified ¡or ¡used: ¡

Spec# ¡adds ¡a ¡pre ¡and ¡post ¡condition ¡to ¡every ¡method ¡

All ¡in-­‑coming ¡parameters ¡and ¡their ¡peers ¡must ¡be ¡consistent ¡ All ¡in-­‑coming ¡parameters ¡and ¡their ¡peers ¡must ¡not ¡be ¡bound ¡

by ¡the ¡invariants ¡of ¡their ¡owner ¡

This ¡means ¡that ¡we ¡can ¡safely ¡act ¡on ¡these ¡objects ¡without ¡

risking ¡breaking ¡any ¡invariants ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 21 ¡

slide-22
SLIDE 22

Virtual ¡Methods ¡

Methods ¡can ¡be ¡overridden ¡in ¡C# ¡by ¡subclasses ¡ How ¡we ¡deal ¡with ¡contracts ¡of ¡overridden ¡functions? ¡ Overriding ¡function ¡inherit ¡the ¡contracts ¡

They ¡can ¡still ¡add ¡to ¡the ¡contract ¡ Contracts ¡of ¡the ¡super ¡class ¡cannot ¡be ¡removed ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 22 ¡

slide-23
SLIDE 23

Virtual ¡Methods ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 23 ¡

slide-24
SLIDE 24

Pure ¡Spec# ¡Func>ons ¡

Pure ¡functions ¡do ¡not ¡modify ¡the ¡state ¡of ¡the ¡program ¡

in ¡any ¡way. ¡

Designated ¡by ¡the ¡[Pure] ¡tag ¡ Property ¡getters ¡are ¡implicitly ¡pure ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 24 ¡

slide-25
SLIDE 25

Conclusion ¡

Spec# ¡offers ¡many ¡features ¡SPARK ¡does ¡ Spec# ¡handles ¡object ¡orientation ¡ Spec# ¡handles ¡inheritance ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 25 ¡

slide-26
SLIDE 26

Ques>ons? ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 26 ¡

slide-27
SLIDE 27

References ¡

[1] ¡Barnett, ¡M., ¡Leino, ¡R., ¡& ¡Schulte, ¡W. ¡(n.d.). ¡Spec#. ¡Retrieved ¡

November ¡4, ¡2014, ¡from ¡ http://research.microsoft.com/en-­‑us/projects/specsharp/ #overview ¡ ¡

[2] ¡Barnett, ¡M., ¡Chang, ¡B., ¡DeLine, ¡R., ¡Jacobs, ¡B., ¡& ¡Leino, ¡R. ¡

(n.d.). ¡Boogie: ¡A ¡Modular ¡Reusable ¡Verifier ¡for ¡Object-­‑Oriented ¡

  • Programs. ¡Retrieved ¡November ¡5, ¡2014, ¡from ¡

http://research.microsoft.com/en-­‑us/projects/specsharp/ krml160.pdf ¡

[3] ¡Leino, ¡R. ¡(n.d.). ¡Spec#. ¡Retrieved ¡November ¡5, ¡2014, ¡from ¡

http://specsharp.codeplex.com/wikipage?title=Tutorial ¡

[4] ¡Barnett, ¡M., ¡Lahiri, ¡S., ¡Lal, ¡A., ¡Leino, ¡R., ¡McMillian, ¡K., ¡

Moskal, ¡M., ¡... ¡Schulte, ¡W. ¡(n.d.). ¡Related ¡Projects. ¡Retrieved ¡ November ¡27, ¡2014, ¡from ¡ http://research.microsoft.com/en-­‑us/projects/boogie/ ¡

CSE814 ¡ Spec#: ¡Contracts ¡and ¡Specifications ¡for ¡C# ¡ 27 ¡