Nicholas Cameron James Noble Victoria University of Wellington

Slides:



Advertisements
Similar presentations
1 Variant Ownership with Existential Types Nicholas Cameron Sophia Drossopoulou Imperial College London.
Advertisements

1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Generic programming in Java
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
Abstract Data Types and Encapsulation Concepts
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 17 Animated Version Generics and Type Safety.
Existential Quantification for Variant Ownership Nicholas Cameron Sophia Drossopoulou Imperial College London (Victoria University of Wellington)‏
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
Multiple Ownership Nicholas Cameron Sophia Drossopoulou James Noble Matthew Smith.
Multiple Ownership Nicholas Cameron Sophia Drossopoulou James Noble Matthew Smith.
Object-Oriented Programming Chapter Chapter
Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.
Encoding Ownership Types in Java Nicholas Cameron James Noble Victoria University of Wellington, New Zealand.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 1.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.
Tribal Ownership Nicholas Cameron James Noble Tobias Wrigstad Victoria University of Wellington Uppsala University.
Comparing Universes and Existential Ownership Types Nicholas Cameron Werner Dietl ETH Zurich Victoria University of Wellington.
2-Oct-16 Basic Object-Oriented Concepts. 2 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions,
On Subtyping, Wildcards, and Existential Types
Copyright © Jim Fawcett Spring 2017
Java Unit 11: Inheritance I
CSE341: Programming Languages Lecture 11 Type Inference
4. Java language basics: Function
OOP: Encapsulation &Abstraction
Classes (Part 1) Lecture 3
Multi-Methods in Cecil
Component Based Software Engineering
Introducing Java Generics and Collections
CompSci 230 S Programming Techniques
11.1 The Concept of Abstraction
Nested class.
Borrowing and Lending.
Chapter 19 Generics Dr. Clincy - Lecture.
More inheritance, Abstract Classes and Interfaces
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Winter 2013.
Java Programming Language
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 11 Type Inference
Generic programming in Java
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2017.
Generics.
JAsCo an Aspect-Oriented approach tailored for
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Zach Tatlock Winter 2018.
CISC/CMPE320 - Prof. McLeod
CPS120: Introduction to Computer Science
Fundaments of Game Design
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2017.
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 11 Type Inference
Creating and Using Classes
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2019.
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Nicholas Cameron James Noble Victoria University of Wellington OGJ Gone Wild Nicholas Cameron James Noble Victoria University of Wellington

Ownership Types Partition the heap, etc., etc. Context parameters Familiar ideas Parametricity, substitution, syntactic, static typing, ... But different Parametric dependent phantom types?

OGJ Ownership types can be enforced in Java generics Potanin, Noble, Clarke, Biddle; OOPSLA '06 Ownership types can be enforced in Java generics Type parameters represent context parameters

OGJ Example: class List<X, Owner> { List<X, Owner> next; X datum; } class C { List<Object<World>, This> aList;

OGJ Example: class List<X, Owner> { List<X, Owner> next; X datum; } class C { List<Object<World>, This> aList;

OGJ Example: class List<X, Owner> { List<X, Owner> next; X datum; } class C { List<Object<World>, This> aList;

OGJ Java type system does most of the work The World class is a class like any other

OGJ BUT, This is magic!

OGJ The OGJ type system has special treatment for the This context Not present in Java Mimics the this context in ownership types systems: Cannot be named outside of the class Inside the current object's owner Enforces encapsulation

Let's go wild!

Let's go wild! Wildcards can be used to emulate This Now we don't need any magic – the Java type system does ownership!

Let's go wild! Let's look more closely at the behaviour of This

This Only an implicit link to the this object Can only be named inside a class definition Cannot be named outside Is inside (= subtype of) the owner of the current object Each use represents a unique context

This All these properties can be mimicked using wildcards:

This Can only be named inside a class definition

This Can only be named inside a class definition Use a regular type parameter for This: class List<X, Owner, This> { ... } This can then be used as normal in the class body

This Cannot be named outside

This Cannot be named outside Always use a wildcard to instantiate the type parameter: List<Object<World>, World, ?>

This Is inside (= subtype of) the owner of the current object

This Is inside (= subtype of) the owner of the current object Use an upper bound on This Which will automatically (and implicitly) be inherited by the wildcard class List<X, Owner, This extends Owner> List<Object<World>, World, ?>

This Each use represents a unique context

This Each use represents a unique context This is the behaviour we expect from wildcards: each wildcard hides a (potentially) unique type

Topology vs Encapsulation

Topology Statically describe the structure of the heap Soundness means a reference with a given owner will never contain an object with a different owner

Encapsulation Owners-as-dominators Restricts which objects can hold references to which other objects

Topology Can be enforced simply by using the pattern described earlier This parameter must be instantiated by ?

Topology

Encapsulation Requires all wildcards, except those in the This position, to have lower bounds Similar to JoƎ Cameron, Drossopoulou; ESOP '09 Also all context parameters must be outside Owner Common to ownership types systems

Encapsulation

Still Magic? Extra well-formedness constraint Topology: only pre-processor step Encapsulation: small change to type checker – but not type rules No extra behaviour No extra syntax For the descriptive system – no change to type checking

So what?

So what? We don't actually expect you to program like this But you can if you want to Right now, with a regular Java compiler

So what? Ownership parametricity is exactly the same as type parametricity No magic! Standard type theoretic ideas A step towards better understanding ownership types

Thank you! Questions? ncameron@ecs.vuw.ac.nz