Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 4 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Boyce/DiPrima 9th ed, Ch 2.8: The Existence and Uniqueness Theorem Elementary Differential Equations and Boundary Value Problems, 9th edition, by William.
Constraint Semantics for Abstract Read Permissions 28 th July 2014, FTfJP, Uppsala John Tang Boyland (UW-Milwaukee/ETH Zurich) Peter Müller, Malte Schwerhoff,
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
Copyright © Cengage Learning. All rights reserved.
Lecture 6 Hyperreal Numbers (Nonstandard Analysis)
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Introduction to Computability Theory
Foundations of Programming Languages: Introduction to Lambda Calculus
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
13. The Weak Law and the Strong Law of Large Numbers
A logic for reasoning about digital rights Riccardo Pucella, Vicky Weissman Cornell University.
Taming the Wildcards: Combining Definition- and Use-Site Variance – Altidor John Altidor Taming the Wildcards: Combining Definition- and Use-Site Variance.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
22 March 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Understanding PML Paulo Pinheiro da Silva. PML PML is a provenance language (a language used to encode provenance knowledge) that has been proudly derived.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
PROBABILITY AND STATISTICS FOR ENGINEERING Hossein Sameti Department of Computer Engineering Sharif University of Technology The Weak Law and the Strong.
Logic CL4 Episode 16 0 The language of CL4 The rules of CL4 CL4 as a conservative extension of classical logic The soundness and completeness of CL4 The.
Existential Quantification for Variant Ownership Nicholas Cameron Sophia Drossopoulou Imperial College London (Victoria University of Wellington)‏
Formal Specification of Intrusion Signatures and Detection Rules By Jean-Philippe Pouzol and Mireille Ducassé 15 th IEEE Computer Security Foundations.
A Universe-Type-Based Verification Technique for Mutable Static Fields and Methods Alexander J Summers Sophia Drossopoulou Imperial College London Peter.
LDK R Logics for Data and Knowledge Representation PL of Classes.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Copyright © Cengage Learning. All rights reserved.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Multiple Ownership Nicholas Cameron Sophia Drossopoulou James Noble Matthew Smith.
1 Use graphs and not pure logic Variables represented by nodes and dependencies by edges. Common in our language: “threads of thoughts”, “lines of reasoning”,
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Encoding Ownership Types in Java Nicholas Cameron James Noble Victoria University of Wellington, New Zealand.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
CMSC 330: Organization of Programming Languages Operational Semantics.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
Types and Programming Languages Lecture 10 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1/20 Arrays Changki PSWLAB Arrays Daniel Kroening and Ofer Strichman Decision Procedure.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
1 Lecture 3 The Languages of K, T, B and S4. 2 Last time we extended the language PC to the language S5 by adding two new symbols ‘□’ (for ‘It is necessary.
1 Authorization Sec PAL: A Decentralized Authorization Language.
LDK R Logics for Data and Knowledge Representation Description Logics: family of languages.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
Comparing Universes and Existential Ownership Types Nicholas Cameron Werner Dietl ETH Zurich Victoria University of Wellington.
On Subtyping, Wildcards, and Existential Types
1 Representing and Reasoning on XML Documents: A Description Logic Approach D. Calvanese, G. D. Giacomo, M. Lenzerini Presented by Daisy Yutao Guo University.
The Language of Sets If S is a set, then
Nicholas Cameron James Noble Victoria University of Wellington
Axiomatic Number Theory and Gödel’s Incompleteness Theorems
The Relationship Between Separation Logic and Implicit Dynamic Frames
Rationale Behind the Precise Formulation of the Four Quantifier Rules
Chapter 19 Generics Dr. Clincy - Lecture.
Logics for Data and Knowledge Representation
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
13. The Weak Law and the Strong Law of Large Numbers
Knowledge Representation I (Propositional Logic)
Logics for Data and Knowledge Representation
13. The Weak Law and the Strong Law of Large Numbers
Presentation transcript:

Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas Cameron Alexander J. Summers Victoria Univ. of Wellington New Zealand ETH Zurich Zürich

Outline  Java Wildcards & Existential Types  Semantic Model for Existential Types  Soundness & (In-)Completeness  Weak Independence & Completeness  Conclusions

Outline  Java Wildcards & Existential Types  Semantic Model for Existential Types  Soundness & (In-)Completeness  Weak Independence & Completeness  Conclusions

Wildcards in Java ►Based on Java Generics (since Java 5.0) – Parameterised types : List, List >, etc. ►Generic types are subtype invariant – List and List are incomparable ►Wildcards introduce “hiding” of type parameters – List is a type (a List of “something”) – List subtype of List ►Bounded wildcards allow subtype variance – List subtype of List

Existential Types ►Existential types allow type information to be hidden ►Bounded existentials expose some information about hidden type, e.g.,  X:[String Object].C ►Standard representation of wildcard types –C represented by  X:[  Object].C –C represented by  X:[B Object].C ►For Java, introduction and elimination of existential types is handled implicitly (by subtyping). ►Java has f-bounded types (type variables may occur in each other’s bounds, mutually)

Why use Existential Types? ►Not all types that can occur during type checking of Java programs can be written using the Java syntax ►i.e., there are types that are expressible but not denotable in Java ►Not true for existential types –All Java types can be denoted using existential types –e.g.,  X.Pair can arise during type-checking (but Pair corresponds to  X,Y.Pair )

Syntactic Type Assignment ►Types and type environments are defined by: Class types N ::= C types T ::= X | ∃ Δ.N type bounds B ::= T | ⊥ type environments Δ ::= X : [B B] ►We use σ for type substitutions, and use a judgement Δ ⊢ σ to express that σ maps the type variables in Δ to types within their declared bounds ►Syntactic subtyping Δ ⊢ T 1 ≤ T 2 handles subclassing, existential types and their bounds ►e.g., Δ, Δ 1 ⊢ σ ⇒ Δ ⊢ σ(N) ≤ ∃ Δ 1.N

Outline  Java Wildcards & Existential Types  Semantic Model for Existential Types  Soundness & (In-)Completeness  Weak Independence & Completeness  Conclusions

Our semantics for types ►Idea: interpret existential types as unions –all the possible concrete types the existential might “hide” ►What are “concrete types”? –One idea: use structural types to describe fields and methods guaranteed to exist in the runtime object –but Java uses a nominal type system –allows use of fields and methods based only on class type –Each runtime object has an associated closed class type –We use these as the “concrete types” of our model

Our semantics for types ►Semantic types S are sets of closed class types –all the possible runtime types the type might permit ►We give a semantic interpretation of closed types –open types will be dealt with later ►We map closed types to semantic types as follows: [[ N ]] = { N ’ | N ’ ⊑ N } [[ ⊥ ]] = ∅ [[ ∃Δ.N ]] = U σ with Δ ⊢ σ [[ σ(N) ]]

Our semantics for types [[ N ]] = { N ’ | N ’ ⊑ N } [[ ⊥ ]] = ∅ [[ ∃Δ.N ]] = U σ with Δ ⊢ σ [[ σ(N) ]] ►For example... [[ Object ]] = { Object, String, List, … } [[ ∃X : [String Object], ∃Y : [X Object]. Pair ]] = { Pair, Pair, Pair }

Semantic subtyping ►We define subtyping on semantic types simply as S 1 ≤ S 2 ⇔ S 1 ⊆ S 2 ►We extend this notion to syntactic types, as follows: Δ ⊨ T 1 ≤ T 2 ⇔ ∀ σ, Δ ⊢ σ ⇒ [[ σ( T 1 ) ]] ⊆ [[ σ( T 2 ) ]] ►We now have two subtyping judgements: syntactic Δ ⊢ T 1 ≤ T 2 and semantic subtyping Δ ⊨ T 1 ≤ T 2 ►Is syntactic subtyping sound? Δ ⊢ T 1 ≤ T 2 ⇒ Δ ⊨ T 1 ≤ T 2 ? ►Is syntactic subtyping complete? Δ ⊢ T 1 ≤ T 2 ⇐ Δ ⊨ T 1 ≤ T 2 ?

Outline  Java Wildcards & Existential Types  Semantic Model for Existential Types  Soundness & (In-)Completeness  Weak Independence & Completeness  Conclusions

Soundness ►Since type soundness for Java Wildcards is known [Cameron et al. 2008] we would hope that soundness of subtyping holds. ►In fact, we proved this (Theorem 1 in paper): Soundness: Δ ⊢ T 1 ≤ T 2 ⇒ Δ ⊨ T 1 ≤ T 2 ►By defining a suitable semantic type assignment we extended the soundness result to the type system ►Completeness could be reasonably expected: –result w.r.t. nominal subtyping (weaker than structural) –decidability of the syntactic type system is open ►However, completeness turns out not to hold

Incompleteness 1 ►Consider the type ∃X : [C C]. List ►The semantic model “knows” that X must hide C : –[[ ∃X : [C C]. List ]] = {List } = [[List ]] ►In particular, ⊨ ∃X : [C C]. List ≤ List holds ►This subtyping cannot be derived syntactically –syntactic rules cannot identify the “uniqueness” of X ►What if we add a rule specifically for such cases? Δ ⊢ ∃X : [B U]. N ≤ N{B/X} Δ ⊢ B ≤ U Δ ⊢ U ≤ B (eq)

Incompleteness 2 ►This is still not enough. Consider now the types T 1 = ∃X : [ ⊥ Y], ∃Y : [X Object]. Pair T 2 = ∃Z : [ ⊥ Object]. Pair ►The bounds on X and Y can only be satisfied if the same (closed class) type is chosen to replace each –the model shows this: [[ T 1 ]] = [[ T 2 ]] ►In particular, ⊨ T 1 ≤ T 2 holds, but not syntactically ►Further examples make completeness unfeasible ►But, could we find a restricted type language for which completeness does hold?

Outline  Java Wildcards & Existential Types  Semantic Model for Existential Types  Soundness & (In-)Completeness  Weak Independence & Completeness  Conclusions

Completeness? When does Δ ⊨ T 1 ≤ T 2 ⇒ Δ ⊢ T 1 ≤ T 2 hold ?

Completeness? When does Δ ⊨ T 1 ≤ T 2 ⇒ Δ ⊢ T 1 ≤ T 2 hold ?

Completeness? When does Δ ⊨ T 1 ≤ T 2 ⇒ Δ ⊢ T 1 ≤ T 2 hold ?

Completeness? ⊨ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ?

Completeness? ⊨ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ? [[ ∃Δ 1.N 1 ]] ⊆ [[ ∃Δ 2.N 2 ]] ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ? U σ 1 with Δ 1 ⊢ σ 1 [[ σ 1 (N 1 ) ]] ⊆ U σ 2 with Δ 2 ⊢ σ 2 [[ σ 2 (N 2 ) ]] ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ?

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ?

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ?

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ?

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? Y = Y X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? X X Y = Y X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ ? Y = Y X X X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ there exists σ 3 with Δ 2 ⊢ σ 3 such that N 1 = σ 3 (N 2 ) Y = Y X X X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ there exists σ 3 with Δ 2 ⊢ σ 3 such that N 1 = σ 3 (N 2 ) ⇒ ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 Y = Y X X X X

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ there exists σ 3 with Δ 2 ⊢ σ 3 such that N 1 = σ 3 (N 2 ) ►The red property below is sufficient to deduce completeness ( Δ 1 is “rich” in the language of paper) ►Previous pictures suggest it is enough for there to be “sufficiently different” instantiations for Δ 1 ►This is not quite enough, with multiple variables ►e.g., Δ 1 = X : [ ⊥ C], Y : [X X] and Δ 2 = Z : [ ⊥ C] and N 1 = Pair and N 2 = Pair

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇒ there exists σ 3 with Δ 2 ⊢ σ 3 such that N 1 = σ 3 (N 2 ) ►The red property below is sufficient to deduce completeness ( Δ 1 is “rich” in the language of paper) ►Previous pictures suggest it is enough for there to be “sufficiently different” instantiations for Δ 1 ►This is not quite enough, with multiple variables ►e.g., Δ 1 = X : [ ⊥ C], Y : [X X] and Δ 2 = Z : [ ⊥ C] and N 1 = Pair and N 2 = Pair

Completeness? (forall σ 1 with Δ 1 ⊢ σ 1 there exists σ 2 with Δ 2 ⊢ σ 2 such that σ 1 (N 1 ) = σ 2 (N 2 )) ⇏ there exists σ 3 with Δ 2 ⊢ σ 3 such that N 1 = σ 3 (N 2 ) ►The red property below is sufficient to deduce completeness ( Δ 1 is “rich” in the language of paper) ►Previous pictures suggest it is enough for there to be “sufficiently different” instantiations for Δ 1 ►This is not quite enough, with multiple variables ►e.g., Δ 1 = X : [ ⊥ C], Y : [X X] and Δ 2 = Z : [ ⊥ C] and N 1 = Pair and N 2 = Pair

Completeness? ►The red property below is sufficient to deduce completeness ( Δ 1 is “rich” in the language of paper) ►Previous pictures suggest it is enough for there to be “sufficiently different” instantiations for Δ 1 ►This is not quite enough, with multiple variables ►e.g., Δ 1 = X : [ ⊥ C], Y : [X X] and Δ 2 = Z : [ ⊥ C] and N 1 = Pair and N 2 = Pair ►We need that each variable in Δ 1 gets sufficiently varied instantiations independently of the others...

Weak Independence ►We define two types to be sufficiently different if the uppermost class types in their structure differ ►We say Δ 1 is weakly independent if for each variable X in Δ 1 there exist two substitutions σ 1, σ 2 such that σ 1 (X) is sufficiently different from σ 2 (X) and for all other variables Y in Δ 1, σ 1 (Y) = σ 2 (Y) ►Essentially, each variable gets the chance to vary independently of the others ►e.g., X : [ ⊥ C], Y : [X X] is not weakly independent, but X : [String Object], Y : [X Object] is

Weak Completeness ►We proved a weak completeness result: If ⊨ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 and Δ 1 is weakly independent, then ⊢ ∃Δ 1.N 1 ≤ ∃Δ 2.N 2 ►Recall: all types can be written in the form ∃Δ.N (in which Δ is possibly empty) – this is not a restriction ►The result does not apply (yet) to open types (those featuring type parameters of the enclosing class) ►However, for closed types with weakly independent environments, syntactic subtyping is sound and complete with respect to our semantic model

Conclusions and Future Work ►Defined a semantic model for Java Wildcards ►Proved soundness of Java subtyping w.r.t. model ►Completeness does not hold in general ►Identified a restriction (weakly-independent environments) under which completeness holds ►For future work, open types should be handled ►Can we find a weaker restriction for completeness? ►Can non-trivial incompleteness arise in Java? ►we conjecture not, which would give us strong soundness and completeness results for Java subtyping

Finally… ►Thank you for listening! Y = Y X X X X