flexible immutability with frozen objects l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Flexible Immutability with Frozen Objects PowerPoint Presentation
Download Presentation
Flexible Immutability with Frozen Objects

Loading in 2 Seconds...

play fullscreen
1 / 28

Flexible Immutability with Frozen Objects - PowerPoint PPT Presentation


  • 197 Views
  • Uploaded 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

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

Flexible Immutability with Frozen Objects

K. Rustan M. LeinoMicrosoft Research

Peter MüllerETH Zurich

Angela WallenburgChalmers University

executive summary
Executive summary
  • Context
    • Verification system for object-oriented programs
  • Contribution
    • Specification and structuring technique for objects that no longer undergo change
object invariants
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
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
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
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
Classes of immutable objects
  • Spec# demo: roadie/immutable
classes of immutable objects21
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
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
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
RockBand picture

freezer

:RockBand

rd

gt

owner

owner

:Guitar

:Roadie

immutable classes revisited
Immutable classes revisited
  • Special case of frozen objects
  • Frozen objects give good encoding of immutable classes
alternative design
Alternative design
  • Partial ownership
  • Chalice demo: RockBand
chalice demo rockband
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
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