Pedigree Types Yu David Liu, Johns Hopkins University / SUNY Binghamton Scott F. Smith, Johns Hopkins University July 7, IWACO’08.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Type Checking.
CSE-321 Programming Languages Polymorphism POSTECH May 15, 2006 박성우.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
1 Chapter 1 Object-Oriented Programming. 2 OO programming and design Object-oriented programming and design can be contrasted with alternative programming.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Confined Types Encapsulation and modularity Seminar November, 2005 presented by: Guy Gueta.
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
1 Basic Object Oriented Concepts Overview l What is Object-Orientation about? l What is an Object? l What is a Class? l Constructing Objects from Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
C++ Training Datascope Lawrence D’Antonio Lecture 3 An Overview of C++
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
1 A Short Introduction to (Object-Oriented) Type Systems Kris De Volder.
Inheritance and Polymorphism CS351 – Programming Paradigms.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Type-Specialized Staged Programming with Process Separation Yu David Liu, State University of New York at Binghamton Christian Skalka, University of Vermont.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Introduction to Object-oriented programming and software development Lecture 1.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
Polymorphism Lecture-10. Print A Cheque A Report A Photograph PrintCheque() PrintReport() PrintPhoto() Printing.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
Inheritance in the Java programming language J. W. Rider.
CSSE501 Object-Oriented Development. Chapter 11: Static and Dynamic Behavior  In this chapter we will examine the differences between static and dynamic.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Object Oriented Programming
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Stephen Davis Ada Object-Oriented Programming. Overview Ada 83 is not considered a true “object-oriented” programming language. Although Ada 83 did support.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Hindley-Milner Type Inference CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Types and Programming Languages Lecture 10 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
OOP Basics Classes & Methods (c) IDMS/SQL News
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
Polymorphism in Methods
CSE341: Programming Languages Lecture 11 Type Inference
Polymorphism.
Inheritance ITI1121 Nour El Kadri.
Chapter 11 Object-Oriented Design
CS 326 Programming Languages, Concepts and Implementation
Object-Orientated Programming
Jim Fawcett CSE776 – Design Patterns Summer 2003
Objects and Aspects: What we’ve seen so far
CSE341: Programming Languages Lecture 11 Type Inference
Representation, Syntax, Paradigms, Types
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 11 Type Inference
CPS120: Introduction to Computer Science
CSE341: Programming Languages Lecture 11 Type Inference
Presentation transcript:

Pedigree Types Yu David Liu, Johns Hopkins University / SUNY Binghamton Scott F. Smith, Johns Hopkins University July 7, IWACO’08

Ownership Type Systems Ownership with Parameterized Classes Universe Types Simple and Intuitive Syntax Parametric Polymorphism and Inference Pedigree 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 { … } An Example Program in Pedigree Types (and in Universe Types) * The two pedigrees above are identical to “peer” and “rep” in Universe Types.

The Example in UML b1:Button :Main v1:View c1:Contoller * The top-down direction indicates ownership.

The General Form of Pedigrees 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 (parent)^a (child)^b where a>=0, b = 0 or 1

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 { … }

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; } void refresh () { … container.refresh();} }

Is (parent)^10 (child)^1 Useful ? “nai, nai!” thus spoke the inference algorithm. * “nai” means “yes” in Greek.

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; } void refresh () { … container.refresh();} }

Options for the Omitted Pedigree Treat it as “sibling”.

Defaulting as “sibling” b1:Button :Main v1:View c1:Contoller c1 is an “uncle” of b1, not a “sibling”.

Options for the Omitted Pedigree Treat it as “sibling”. Treat it as “world”, i.e. shared by everyone.

Defaulting as “world” v1:View :Main s1:System c1: Controller b1:Button v2:View s2:System c2: Controller b2:Button c1: Controller c2: Controller The encapsulation of s1 and s2 is broken!

Options 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).

Options 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.

Pedigree 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.

Pedigree Type Inference A powerful static system with the following features:

Pedigree Type Inference A powerful static system with the following features: It is parametrically polymorphic.

The Need for Polymorphism b1:Button :Main v1:View c1:Contoller d: Dialog b2:Button

Pedigree 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.

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; } void refresh () { … container.refresh();} }

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; } void refresh () { … container.refresh();} } ∨ − a1, b1

Pedigree 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.

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; } void refresh () { … container.refresh();} } ∨ − a1, b1

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) { this.ctrl = ctrl; this.container = v; } void refresh () { … container.refresh();} } ∨ − a1, b1

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) { this.ctrl = ctrl; this.container = v; } void refresh () { … container.refresh();} } ∨ − a1, b1, a2, b2

Pedigree Type Inference A powerful static system with the following features: It is parametrically polymorphic. It correctly handles mutually recursive classes.

Pedigree Type Inference A powerful static system with the following features: It is parametrically polymorphic. It correctly handles mutually recursive classes. It is inter-procedural.

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; } void refresh () { … container.refresh();} }

Pedigree 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.

Pedigree 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 <: sibling parent <: uncle (parent)^a (child)^b <: (parent)^(a+1) (child)^(b+1)

Pedigree 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.

Formal 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 a>=0 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.

Extensions 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 a>=0 and b>1, 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.

Related 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).

Concluding 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.

Thank you!