Flexible immutability with frozen objects
Download
1 / 28

flexible immutability with frozen objects - PowerPoint PPT Presentation


  • 185 Views
  • Updated On :

Flexible Immutability with Frozen Objects. K. Rustan M. Leino Microsoft Research Peter Müller ETH Zurich Angela Wallenburg Chalmers University. Executive summary. Context Verification system for object-oriented programs Contribution

Related searches for flexible immutability with frozen objects

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'flexible immutability with frozen objects' - Mercy


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Flexible immutability with frozen objects l.jpg

Flexible Immutability with Frozen Objects

K. Rustan M. LeinoMicrosoft Research

Peter MüllerETH Zurich

Angela WallenburgChalmers University


Executive summary l.jpg
Executive summary

  • Context

    • Verification system for object-oriented programs

  • Contribution

    • Specification and structuring technique for objects that no longer undergo change


Object invariants l.jpg
Object Invariants

  • class C {int x, y, z;invariant x < 0  y ≤ z;}

  • Boogie methodology (used in Spec#)

  • Spec# demo: shows/ads


Invariants over multiple objects l.jpg
Invariants over multiple objects

:C

  • class C { T t;invariantt.x = 10;}

  • class D { T s;invariants.x = 23;}

  • Spec# demo: guitar/level

:D

t

s

:T


Ownership l.jpg
Ownership

:C

  • class C {rep T t;invariantt.x = 10;}

  • class D {rep T s;invariants.x = 23;}

  • Spec# demo: rep

:D

t

owner

s

:T

owner

:T


Object states l.jpg
Object states

  • An object is valid if it is not exposed

  • (o  o.owner.valid o.valid)

  • An object is consistent if it is valid and its owner is not valid

  • Spec# demo: strum

:RockBand

:Guitar

:GtString

:GtString


Classes of immutable objects l.jpg
Classes of immutable objects

  • Spec# demo: roadie/immutable


Classes of immutable objects21 l.jpg
Classes of immutable objects

  • Spec# demo: roadie/immutable

  • Example summary:

    • Cannot share a rep object

    • Base class of immutable class cannot be mutable

    • Cannot apply mutable methods on an immutable object


Frozen objects l.jpg
Frozen objects

  • Indicate which instances, not just whole classes, are immutable

  • Indicate when an object becomes immutable

  • Frozen objects can be mentioned in invariants

  • freeze operation transfers ownership to an fictitious freezer object


Using frozen in rockband l.jpg
Using frozen in RockBand

  • classRockBand {frozen Roadie rd;invariantrd.Strength = 5;RockBand() { Roadie r = new Roadie(5);r.SchlepInstruments();r.PrepareStage();freeze r; rd = r; } …}


Rockband picture l.jpg
RockBand picture

freezer

:RockBand

rd

gt

owner

owner

:Guitar

:Roadie


Immutable classes revisited l.jpg
Immutable classes revisited

  • Special case of frozen objects

  • Frozen objects give good encoding of immutable classes


Alternative design l.jpg
Alternative design

  • Partial ownership

  • Chalice demo: RockBand


Chalice demo rockband l.jpg
Chalice demo: RockBand

classRockBand {

var r: Roadie

invariantrd(r) && r != null

invariantacc(r.strength) && r.strength == 5

method Main() {

vararnold := new Roadie

arnold.strength := 5

varabba := newRockBand

abba.r := arnold

shareabba

varnoDoubt := newRockBand

noDoubt.r := arnold

sharenoDoubt

}

}

class Roadie {

var strength: int

}

Monitor invariant might not hold. Insufficient fraction at 4.13 for Roadie.strength.


Conclusion l.jpg
Conclusion

  • Frozen objects are flexible. A program can:

    • decide which instances are frozen

    • decide when each instance becomes frozen

  • Frozen objects can fit into any system with ownership and ownership transfer

  • Frozen objects can encode immutable types

  • Invariants can be written over frozen objects

  • Future: implement in Spec#

  • http://research.microsoft.com/specsharp


ad