Ownership, Encapsulation and the Disjointness of Type and Effect Dave Clarke, Sophia Drossopoulou/2002 Encapsulation seminar Dec 1 2005 Sharon Goldschlager.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Programming Languages and Paradigms
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.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Chair of Software Engineering The alias calculus Bertrand Meyer ITMO Software Engineering Seminar June 2011.
ISBN Chapter 3 Describing Syntax and Semantics.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
External Uniqueness Presented by Nir Atias Dave Clarke Tobias Wrigstad Encapsulation Seminar 2006.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
1 Islands : Aliasing Protection In Object-Oriented Languages By : John Hogg OOPSLA 91 Aharon Abadi.
Catriel Beeri Pls/Winter 2004/5 environment1 1 The Environment Model  Introduction and overview  A look at the execution model  Dynamic scoping  Static.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Describing Syntax and Semantics
A Seminar on Encapsulation Noam Rinetzky Mooly Sagiv Summary.
Ownership Types for Object Encapsulation Authors:Chandrasekhar Boyapati Barbara Liskov Liuba Shrira Presented by: Charles Lin Course: CMSC 631.
The different kinds of variables in a Java program.
1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
OOP Languages: Java vs C++
Imperative Programming
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Basic Semantics Associating meaning with language entities.
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.
11/23/2015CS2104, Lecture 41 Programming Language Concepts, COSC Lecture 4 Procedures, last call optimization.
Relationships Relationships between objects and between classes.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
SHEEP CLONING Paley Li, Nicholas Cameron, and James Noble 1.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CMSC 330: Organization of Programming Languages Operational Semantics.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
1 Authorization Sec PAL: A Decentralized Authorization Language.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Lecture 9 Symbol Table and Attributed Grammars
OOP: Encapsulation &Abstraction
Functions.
Nicholas Cameron James Noble Victoria University of Wellington
Java Programming Language
CS 326 Programming Languages, Concepts and Implementation
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Objects and Aspects: What we’ve seen so far
UNIT V Run Time Environments.
COMPILERS Semantic Analysis
CSE 341 Lecture 11 b closures; scoping rules
Chapter 15 Functional Programming 6/1/2019.
Presentation transcript:

Ownership, Encapsulation and the Disjointness of Type and Effect Dave Clarke, Sophia Drossopoulou/2002 Encapsulation seminar Dec Sharon Goldschlager

2 Aim Static reasoning about the program. Aliasing. Non-interference of expressions.

3 Road Map Aim Aliasing to previous lectures General Idea Basic definitions Static rules Dynamic rules Summary

4 Aliasing to previous lectures Islands(Hogg) – prevent static(heap) aliasing using read(destructive) only references, access through a single bridge. Confined types(Bokowski) relate to security – all references are confined to preset space. These methods impose great limitations on the programmer, implementation overhead – cannot have direct reference.

5 General Idea Encapsulation – placing boundary around object properties. Boundary of ownership, instead of containment. Extension of Ownership with effects and effect shapes. Ownership instead of uniqueness.

6 Ownership Owner(context) - another object, “Container”. Object’s Representation – the objects it owns. Induces tree-shaped ordering. owners-as-dominators, all paths from the root of the object graph to an object pass through its owner.

7 Context and Classes Classes parameterized by context, subclasses keep owner. Types c. Context – in text source (p). –Actual – per object (k) in run time. –Variables (z). –this (owner of representation). –world – root context.

8 Example class List { Link head; void add(Data d) writes under(this) { head = new Link (d, head); } class Main<> { List list; Main() writes this { list = new List ; } void populate() writes under(this.1) { list.add(new Data ); } static void main() writes under(world) { Main<> main = new Main<>; main.populate(); } this is current object. 1 st parameter is owner context. No parameter means World is the owner. Owner this restricts access to current object and objects inside it. no reference into the inside.

9 Representation Representation – objects owned by this. Representation context – representation of context. Example representation of previous program:

10 Simple Alias Deduction using Ownership List shared; List encaps; Shared, encaps cannot be aliases. Their Link objects are disjoint. Their Data objects are disjoint.

11 Method Effects And Their Shapes Effect can be read or write (implying read). Shape denotes collection of contexts. Methods must specify (1 or 2) pairs. Example void exmpl_method() reads p writes under p.2 { … }

12 Dynamic Aliasing Dynamic aliases - created during program execution when a reference is changed (iterator). Break (briefly) owners-as-dominators for stack, local variables. bool equals(List other) { Link thislink = this.head; Link otherlink = other.head;... thislink.data.equal(otherlink.data)... }

13 Dynamic Aliasing owners-as-dominators property enforces deep ownership. Type of each dynamic alias contains the name of the aliased representation entity. List list = new List ; Iterator iter = list.makeIterator(); Conclusion Dynamic aliases cannot be stored in an object’s field.

14 Formalism Notation - Static

15 Formalism Notation - Dynamic ActualContext – world and one for each object created.

16 Semantics Blocks Environment E assigns types to free variables, locations, context variables constraints. Binding B map context variables to actual Contexts, and variables to values.

17 Formalism Notation

18 means directly inside. is the transitive closure of. is the reflexive transitive closure of. Context Relations Relational inclusion

19 Valid Contexts CTX-VAR: context variable should be related to a context. CTX-REP: variable/location may denote representation context. CTX-WORLD: world is a valid context.

20 Context Ordering Representation context directly inside owner Relational composition

21 Effect Shapes

22 Subshaping Set Rules Simple set theory properties.

23 Subshaping Geometric Rules SUBSHAPE-UNDER: ordering of under effects, under effect at a particular level contains all deeper under effects.

24 Effects and Subeffecting Subeffect Write imply read

25 Type Rules

26 Values VAL-NULL: null can have any type. VAL-W: Type of variables, locations as in environment. EXP-FROMVAL: variable can be seen as expression with no effect.

27 Expressions EXPR-NEW: Produces no effect. EXP-FIELD: Type of expression is field type with parameter substitution. EXR-UPDATE: Likewise, rhs,lhs matching types.

28 Let Expression Dynamic Alias Effect rd x, x not in scope at end  under-approximation: super-effect rd a.1. What’s the effect of

29 Expressions EXP-SUB: Expression of some type is of its super-type, and effect need not be accurate. EXP-CALL: Matching of types, and binding of formal-actual parameter.

30 Inheritance Rules

31 Method, Program PROG: Well-formed program contains only well-formed classes. METHOD: Type, effect of body match declaration.

32 Extension Lemma E’>>E: E’ extends E, i.e. E is subsequence in E’. B’>>B: B’ extends B, i.e. B is subsequence in B’. Lemma: Assume E:B├ ή If E’>>E and E’:B├ ◊, then E’:B├ ή. (extention) If B’>>B and E:B’├ ◊, then E:B’├ ή. (substitution)

33 Dynamic Notation CMAP: map from class context parameters where method m is declared to the actual contexts, for correct evaluation of the method body e.

34 Evaluation relation an expression configuration to a final configuration. Dynamic Relations Computation relation a computation configuration to a final configuration.

35 Evaluation Rules EV-LET: 1 st computation, bind value to x, then evaluate expression with new heap, binding. EV-VAR: Variables - lookup in binding list.

36 Computation Rules - Field COMP-FIELD: Effect reading object in i. COMP-UPDATE: Write value to field. Effect writing object in i.

37 Computation Rules - New COMP-NEW: New heap location bound to object. Fields initialized to null. Object type is determined by parameter lookup in binding list B. No effect!

38 Computation Rules - Call COMP-CALL: object from binding, determine type c, method lookup. Binding of class parameters to actual, this, method formal parameter to actual’s value.

39 Reasoning Basics Fields/variables of disjoint types cannot be aliases. Disjointness of effect shapes determine whether expressions potentially interfere. Disjointness according to Tree-shaped partial order. Non-overlapping places in the inheritance hierarchy.

40 Disjointness Notation Rules are valid for all valid bindings B of free variables.

41 Disjointness of Context DCTX-NEQ: Different related context are not equal. DCTX-TYPE: Representation context of non- aliases are disjoint. DCTX-LOC: Disjoint locations – clearly.

42 Disjointness of Type DTYPE-CLASS: Non inherited – disjoint. DTYPE-CTX: Same position argument. DTYPE-SUB: Subtypes preserve disjointness.

43 Disjointness of Effect Shape Based on Set theory. DFX-0: Good effect shape disjoint from empty. DFX-SUB: Subshape of a disjoint is also disjoint. DFX-UNION: Union of shapes disjoint to other, is disjoint.

44 Disjointness of Effect Shape

45 Effect Shapes Based Non-Interference Deduction Interference - one reads, another writes or both write to same location. Expressions with non-interfering effects imply non-interfering execution: the evaluation order is immaterial, same results, same heap.

46 Non-Interference Example Assume E p#q  E list #list  wr under(list1)#wr under list2

47 Deduction Implications Loop fusion leads to optimization.

48 Summary of Contributions Ownership as basis for reasoning. Support inheritance and dynamic aliases. Computational effects. Aliasing and interference deduction. Formal semantics and analysis framework.

49 The End