Title: Pedigree Types
1Pedigree Types
Yu David Liu, Johns Hopkins University / SUNY
Binghamton Scott F. Smith, Johns Hopkins
University
July 7, 2008 _at_ IWACO08
2Ownership Type Systems
Ownership with ParameterizedClasses
Universe Types
Simple and Intuitive Syntax
Parametric Polymorphism
Pedigree Types
and Inference
3An Example Program in Pedigree Types(and in
Universe Types)
- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
The two pedigrees above are identical to peer
and rep in Universe Types.
4The Example in UML
Main
v1View
c1Contoller
b1Button
The top-down direction indicates ownership.
5The General Form of Pedigrees
(parent)a (child)b where agt0, b 0 or 1
- Good case sibling (parent)1 (child)1
- Good case child (parent)0 (child)1
- Bad case nephew (parent)1 (child)2
- Bad case grandchild (parent)0 (child)2
- Good case self (parent)0 (child)0
- Good case parent (parent)1 (child)0
6- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
7- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
8 Is (parent)10 (child)1 Useful ?
nai, nai! thus spoke the inference algorithm.
nai means yes in Greek.
9- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
10Options for the Omitted Pedigree
11Defaulting as sibling
Main
v1View
c1Contoller
b1Button
c1 is an uncle of b1, not a sibling.
12Options for the Omitted Pedigree
- Treat it as sibling.
- Treat it as world, i.e. shared by everyone.
13Defaulting as world
Main
c1 Controller
c2 Controller
s1System
s2System
v1View
v2View
b1Button
b2Button
The encapsulation of s1 and s2 is broken!
14Options for the Omitted Pedigree
- Treat it as sibling.
- Treat it as world, i.e. shared by everyone.
- Treat it as some pedigree that can be reclaimed
by dynamic casting (a top type pedigree).
15Options for the Omitted Pedigree
- Treat it as sibling.
- Treat it as world, i.e. shared by everyone.
- Treat it as some pedigree that can be reclaimed
by dynamic casting (a top type pedigree). - Treat it as some pedigree that can be inferred
statically.
16Pedigree Types
- A constraint-based type system to embed heap
objects onto the ownership tree reusing the
vocabulary of human genealogy -
- Declare a pedigree only if you care.
- Given a reference with its pedigree omitted, it
is equivalent to think of it having a pedigree of
(parent)a (child)b, where a and b are type
variables to be solved by the inference
algorithm, where a ranges over non-negative
integers and b ranges over 0, 1. - A typechecked program means an ownership tree
exists to embed heap objects. - A type error means an incest-free tree cannot
be constructed.
17Pedigree Type Inference
- A powerful static system with the following
features
18Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
19The Need for Polymorphism
Main
v1View
c1Contoller
b1Button
d Dialog
b2Button
20Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- The technique thinking about ML-style
let-polymorphism in OO languages.
21- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
22- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- (parent)a1 (child)b1 Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
a1, b1
23Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- The technique thinking about ML-style
let-polymorphism in OO languages. - Indirect references are polymorphically treated
as well.
24- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- (parent)a1 (child)b1 Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
a1, b1
25- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
- Timer t
-
- class Controller
- class Button
- parent View container
- (parent)a1 (child)b1 Controller ctrl
- Button(Contoller ctrl, View v)
a1, b1
26- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
- (parent)a2 (child)b2 Timer t
-
- class Controller
- class Button
- parent View container
- (parent)a1 (child)b1 Controller ctrl
- Button(Contoller ctrl, View v)
a1, b1, a2, b2
27Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- It correctly handles mutually recursive classes.
28Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- It correctly handles mutually recursive classes.
- It is inter-procedural.
29- class Main
- public static void main (String args)
- View v1 new View()
- Controller c1 new
Controller() -
-
- class View
- sibling Controller ctrl
- View()
- Button b1 new child
Button(ctrl, this) -
- void refresh()
-
- class Controller
- class Button
- parent View container
- Controller ctrl
- Button(Contoller ctrl, View v)
- this.ctrl ctrl
this.container v
30Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- It correctly handles mutually recursive classes.
- It is inter-procedural.
- It allows for flexible structural subtyping with
recursive object types.
31Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- It correctly handles mutually recursive classes.
- It is inter-procedural.
- It allows for flexible structural subtyping with
recursive object types. - Standard object types are handled via µ- types
Amadio Cardelli. - Pedigree subsumption is also allowed
- self lt sibling
- parent lt uncle
- (parent)a (child)b lt (parent)(a1)
(child)(b1)
32Pedigree Type Inference
- A powerful static system with the following
features - It is parametrically polymorphic.
- It correctly handles mutually recursive classes.
- It is inter-procedural.
- It allows for flexible structural subtyping with
recursive object types. - It is decidable reduced to finding non-negative
solutions to linear diophantine equations, a
well-studied problem.
33Formal Results
- The type system is rigorously defined on top of a
Java-like object model, with following properties
formally proved - The type system is sound (proved via subject
reduction and progress). - Deep ownership preservation any reference at run
time has to point to an object with a pedigree
(parent)a (child)b where agt0 and b 0 or 1. - Shape enforcement if a reference is declared to
have pedigree (parent)a (child)b, then at run
time it points to an object with pedigree
(parent)a (child)b, or a pedigree subsumed by
it.
34Extensions
- We believe Pedigree Types can be extended with
the following features (more discussions in the
paper) - owner-as-modifier ownership tree in our terms,
it means to allow (parent)a (child)b where agt0
and bgt1, as long as the reference is read-only. - Selective exposure allow programmer-defined
policies for exceptional cases, like allow
access from my grandparent. - Opt-out references.
- Dynamic class loading.
35Related Work
- Universe Types (UT)
- Similarity in syntax peer and rep.
- UT features we do not have owner-as-modifiers,
generics, ownership transfer. - Our features parametric polymorphism for omitted
pedigrees a more general form of pedigrees
static inference. - Ownership with Parameterized Classes
- Similarity in expressiveness parametric
polymorphism. - Numerous extension features we do not cover
(yet) effect encapsulation, interaction with
concurrency, selective exposure, multiple
ownership. - Our features minimal declarations (declare only
when you care!), polymorphic inference (sound,
decidable, inter-procedural, consideration for
realistic OO features such as recursive types and
classes).
36Concluding Remarks
- Programmability very low-maintenance declaration
system with minimal extension to the Java object
model. - Expressiveness on par with existing ownership
systems using parameterized classes (additions
self, parent) a powerful inference
algorithm. - Correctness type soundness, ownership
enforcement, shape enforcement. - Future work implementation, advanced features
such as their impact on concurrency.
37Thank you!