On the Benefits of Adding Modes on Owners a work in progress - - PowerPoint PPT Presentation

on the benefits of adding modes on owners
SMART_READER_LITE
LIVE PREVIEW

On the Benefits of Adding Modes on Owners a work in progress - - PowerPoint PPT Presentation

On the Benefits of Adding Modes on Owners a work in progress Ownership, Uniqueness and Immutability Johan stlund Tobias Wrigstad Dave Clarke Beatrice kerblom Imagine a linked list with students at some university Imagine a


slide-1
SLIDE 1

On the Benefits of Adding Modes on Owners

— a work in progress —

Johan Östlund Tobias Wrigstad Dave Clarke Beatrice Åkerblom

Ownership, Uniqueness and Immutability

slide-2
SLIDE 2
slide-3
SLIDE 3

Imagine a linked list with students at some university

slide-4
SLIDE 4

Imagine a linked list with students at some university We want the administrator to see who is registered

slide-5
SLIDE 5

Imagine a linked list with students at some university We want the administrator to see who is registered and we want the TAs to be able to mark the students

slide-6
SLIDE 6

Mark students as passed on a course But removing a student is also possible

Read-Only Fails to do Both

Shallow Deep Check what students are registered But cannot fix duplicate registrations

List Node Node Stud ent Stud ent List Node Node Stud ent Stud ent

(e.g., const)

slide-7
SLIDE 7

Mark students as passed on a course But removing a student is also possible — too restrictive

Read-Only Fails to do Both

Shallow Deep Check what students are registered But cannot fix duplicate registrations

List Node Node Stud ent Stud ent List Node Node Stud ent Stud ent

(e.g., const)

slide-8
SLIDE 8

Mark students as passed on a course But removing a student is also possible — too restrictive — too permissive

Read-Only Fails to do Both

Shallow Deep Check what students are registered But cannot fix duplicate registrations

List Node Node Stud ent Stud ent List Node Node Stud ent Stud ent

(e.g., const)

slide-9
SLIDE 9

Mark students as passed on a course But removing a student is also possible — too restrictive — too permissive

Read-Only Fails to do Both

Shallow Deep Check what students are registered But cannot fix duplicate registrations

List Node Node Stud ent Stud ent List Node Node Stud ent Stud ent

(e.g., const)

Ad hoc — can be misused

[Tschantz & Ernst 05]

slide-10
SLIDE 10

Design Goals

  • Partial read-only in a non ad-hoc fashion
  • Multiple simultaneous views of a single object in terms of

modifiability

  • One class for all views
  • Not possible to circumvent read-only
  • Co-existing read-only and immutability
  • Fractional permissions-style immutables
slide-11
SLIDE 11

Joline

Joe

Joe Fractional Permissions Read-only Immutability

1

3

[Clarke & Wrigstad 03] [Clarke & Drossopoulou 02] [Boyland 03] [Noble, Vitek & Potter 98, Kniesel & Thiesen 99, Boyland, Noble & Retert 01, Skoglund & Wrigstad 01, Tschantz & Ernst 05, Haack et al 07, Müller & Rudich 07, …]

slide-12
SLIDE 12

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-13
SLIDE 13

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-14
SLIDE 14

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-15
SLIDE 15

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-16
SLIDE 16

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-17
SLIDE 17

List Node Node Stud ent Stud ent

class List<data outside owner> { this:Node<data> first; } class Node<data outside owner> { data:Object stuff;

  • wner:Node<data> next;

} // a and world are owners a:List<world> l;

A Linked List in Joline

invalid reference [Clarke & Wrigstad 03]

slide-18
SLIDE 18

class List<data- outside owner> { // owner+ this+ this:Node<data> first; } class Node<data- outside owner> { // owner+ this+ data:Object stuff;

  • wner:Node<data> next;

} // Type controls usage // a- and b+ are owners a:List<b> l;

Modes in Joe

l

List Node Node Stud ent Stud ent

3

slide-19
SLIDE 19

a:List<b> — check what students are registered (deep) a:List<b> — Mark students as passed on a course (partial) a:List<b> — Register and deregister students (partial) a:List<b> —

Your regular reference List is owned by a Stuff is owned by b

List Node Node Stud ent Stud ent

slide-20
SLIDE 20

a:List<b> — check what students are registered (deep) a:List<b> — Mark students as passed on a course (partial) a:List<b> — Register and deregister students (partial) a:List<b> —

Your regular reference List is owned by a Stuff is owned by b

List Node Node Stud ent Stud ent

slide-21
SLIDE 21

a:List<b> — check what students are registered (deep) a:List<b> — Mark students as passed on a course (partial) a:List<b> — Register and deregister students (partial) a:List<b> —

Your regular reference List is owned by a Stuff is owned by b

List Node Node Stud ent Stud ent

slide-22
SLIDE 22

a:List<b> — check what students are registered (deep) a:List<b> — Mark students as passed on a course (partial) a:List<b> — Register and deregister students (partial) a:List<b> —

Your regular reference List is owned by a Stuff is owned by b

List Node Node Stud ent Stud ent

slide-23
SLIDE 23

Multiple Views

Bad: Observational exposure [Boyland 03] Good: Context-based read-only

a:List<b> a:List<b>

Teacher Admin

List Node Node Stud ent Stud ent

slide-24
SLIDE 24

Immutability & the * Mode

  • Immutable can trivially be achieved by read-only plus

unique — but the information is lost

  • The *-mode captures immutability in Joe3
  • Only unique pointers can achieve *-dom
  • Nice staged initialisation

<a* inside world, b* outside a> int averageMark(a:List<b> students) { ... }

slide-25
SLIDE 25

~Fractional Permissions

  • Borrowing allows unique variables to be treated as

immutable for the duration of a scope

  • Temporarily nullifies the source variable
  • Automagic confinement through temporary owner
  • Essentially Boyland’s [03] Fractional Permissions

unique:List<d> l; borrow l as x*:temp in { // temp : x:List<d> for duration of block ... }

slide-26
SLIDE 26

Joe ’s Static Semantics

  • Trivial extension to Joline’s static semantics
  • Modes added to owners in type environment
  • Trivial changes to four rules to check that the modes on a

receiver is respected by method calls, field updates and borrowing

  • Revoke clause added to enable finer granularity

void method() revoke this {...} void method(x:Object) revoke x {...}

3

slide-27
SLIDE 27

Modes & Inheritance

  • Subclassing must preserve immutable modes
  • Subclassing to narrow permissions is straight-forward
  • Subclassing to widen permissions is possible
  • Overriding methods must always obey the most

restrictive modes of any super class

  • Modification only possible in new, non-overriding

methods (not in the paper)

slide-28
SLIDE 28

Future Work

  • Prove soundness by extending Joline’s proofs
  • Properly formulate the guarantees of our constructs
  • Explore Universes-style owner-as-modifier
  • Modes on types, not just owner declarations

class Ex {

  • wner+:Object rep;
  • wner-:Object getRep() { return rep; }

void setRep(owner+:Object o) { rep = o; } }

slide-29
SLIDE 29

Thank You! Questions?