Download presentation
Presentation is loading. Please wait.
Published byBruno Walford Modified over 10 years ago
1
ncameron@doc.ic.ac.uk 1 A Model for Java with Wildcards Nicholas Cameron Sophia Drossopoulou Erik Ernst
2
ncameron@doc.ic.ac.uk 2 Background Wildcards Previous attempts Existential types Subtyping Typing
3
ncameron@doc.ic.ac.uk 3 Background
4
Java 5.0 2004 Adding Wildcards to the Java Language Torgersen, Ernst, Plesner Hansen, von der Ahé, Bracha, Gafter. SAC 04. Existential types to model wildcards ncameron@doc.ic.ac.uk 4
5
Wild FJ Torgersen, Ernst, Plesner Hansen. FOOL 05. ‘On the fly’ existential types No soundness proof J Cameron, Ernst, Drossopoulou. FtfJP 07. Explicit existential types Explicit open/close expressions Partial model Variant Parametric Types Igarashi, Viroli. ECOOP 02, TOPLAS 06. Partial model No capture conversion ncameron@doc.ic.ac.uk 5
6
On Decidability of Nominal Subtyping with Variance Kennedy, Pierce. FOOL 07. Variance and Generalized Constraints for C# Generics Emir, Kennedy, Russo, Yu. ECOOP 06 Typeless Programming in Java 5.0 Plümicke, Bäuerle. PPPJ 06 A Flow-Based Approach for Variant Parametric Types Chin, Craciun, Khoo, Popeea. OOPSLA 06. Subtyping Existential Types Weir, Theimann. FTfJP 08. ncameron@doc.ic.ac.uk 6
7
Wildcards A very brief description
8
Java Type Cup ncameron@doc.ic.ac.uk 8
9
Java Generics Type Cup ncameron@doc.ic.ac.uk 9
10
Generics - Invariant Subtyping Cup ncameron@doc.ic.ac.uk 10 /
11
Java Wildcards Type Cup ncameron@doc.ic.ac.uk 11
12
Bounds Cup ncameron@doc.ic.ac.uk 12
13
Generics - Invariant Subtyping Cup ncameron@doc.ic.ac.uk 13 /
14
Wildcards - Variant Subtyping Cup ncameron@doc.ic.ac.uk 14 /
15
Wildcard Capture void test(Cup cx) {...} void m(Cup c) { this.test(c); } ncameron@doc.ic.ac.uk 15
16
Wildcard Capture void test(Cup cx) {...} void m(Cup c) { this.test(c); //this. test(c); //Z fresh } ncameron@doc.ic.ac.uk 16
17
Our Previous Attempts
18
Naïve Approach Cup ncameron@doc.ic.ac.uk 18
19
Naïve Approach Cup ncameron@doc.ic.ac.uk 19 Expressible but not denotable types
20
'On the fly' Existential Types capture( Cup ) = X.Cup ncameron@doc.ic.ac.uk 20
21
'On the fly' Existential Types capture( Cup ) = X.Cup Too complicated ncameron@doc.ic.ac.uk 21
22
Explicit Existential Types open... close... ncameron@doc.ic.ac.uk 22
23
Explicit Existential Types open... close... Lower Bounds Expressivity ncameron@doc.ic.ac.uk 23
24
Scope Violation void m( X.Cup x) { this. m2(x); } ncameron@doc.ic.ac.uk 24
25
Scope Violation void m( X.Cup x) { this. m2(x); } Alpha Renaming ncameron@doc.ic.ac.uk 25
26
... ncameron@doc.ic.ac.uk 26
27
ncameron@doc.ic.ac.uk Modelling Concepts
28
Tame FJ
29
Explicit existential types Implicit packing (in subtyping ( XS-ENV )) Implicit unpacking (in type rules) Inferred type parameters this. m(x); Separation of subtyping Subclassing, extended subclassing, subtyping Guarding environment... e : T | Tracks unpacked type variables ncameron@doc.ic.ac.uk 29
30
ncameron@doc.ic.ac.uk 30 Existential Types
31
Cup X.Cup ncameron@doc.ic.ac.uk 31
32
Cup X Drink.Cup ncameron@doc.ic.ac.uk 32
33
But Why?
34
Capture conversion Expressible but not denotable types
35
Pair make(List x) {...} void test (Pair x) {...} void m(List l, Pair p) { test(p); } ncameron@doc.ic.ac.uk 35
36
ncameron@doc.ic.ac.uk 36
37
ncameron@doc.ic.ac.uk 37
38
ncameron@doc.ic.ac.uk 38
39
X.Pair Type is expressible but not denotable ncameron@doc.ic.ac.uk 39
40
Pair make(List x) {...} void test (Pair x) {...} void m( X.List l, X,Y.Pair p) { test(p); test(make(l)); X.Pair q = make(l); } ncameron@doc.ic.ac.uk 40
41
Pair make(List x) {...} void test (Pair x) {...} void m( X.List l, X,Y.Pair p) { test(p); test(make(l)); X.Pair q = make(l); } ncameron@doc.ic.ac.uk 41
42
Pair make(List x) {...} void test (Pair x) {...} void m( X.List l, X,Y.Pair p) { test(p); test(make(l)); X.Pair q = make(l); } ncameron@doc.ic.ac.uk 42
43
ncameron@doc.ic.ac.uk 43 Subtyping
44
Wildcards Subtyping Cup ncameron@doc.ic.ac.uk 44
45
Wildcards Subtyping Cup .Cup Cup .Cup Cup Y Tea.Cup ncameron@doc.ic.ac.uk 45
46
, ’ T <: B ’.[T/X]N <: X B.N (S-E NV ) ncameron@doc.ic.ac.uk 46 ┴ ┴
47
Cup .Cup Tea <: Object .[Tea/X]Cup (S-E NV ) ncameron@doc.ic.ac.uk 47 ┴ ┴
48
Cup .Cup Tea <: Drink .[Tea/X]Cup (S-E NV ) ncameron@doc.ic.ac.uk 48 ┴ ┴
49
Cup Y Tea.Cup Y Tea Y <:Tea <: Drink Y Tea.[Y/X]Cup (S-E NV ) ncameron@doc.ic.ac.uk 49 ┴ ┴
50
3 flavours of subtyping?
51
Java 4 Subtyping ncameron@doc.ic.ac.uk 51 Object CoffeeTea Drink List Vector
52
Java 5 Subtyping ncameron@doc.ic.ac.uk 52 Object CoffeeTea Drink Z Drink.List Z.List List Z Drink.Vector Z.Vector Vector X In class C... Z X.List Z X.Vector
53
Tame FJ Subclassing ncameron@doc.ic.ac.uk 53 Object CoffeeTea Drink List Vector X In class C...
54
Tame FJ Extended Subtyping ncameron@doc.ic.ac.uk 54 Z Drink.List Z.List List Z Drink.Vector Z.Vector Vector In class C... Z X.List Z X.Vector
55
Tame FJ Subtyping Tea X In class C...
56
TameFJ Subtyping ncameron@doc.ic.ac.uk 56 Object CoffeeTea Drink Z Drink.List Z.List List Z Drink.Vector Z.Vector Vector X In class C... Z X.List Z X.Vector
57
But Why? Subtyping is too flexible and complicated to use directly in the proofs Subclassing Properties of the class hierarchy – e.g., field/method lookup Extended Subclassing If we need wildcard subtyping, but can't deal with lower bounds E.g., preservation of existential types Subtyping Still required – e.g., result of inversion lemmas, due to T-S UBS ncameron@doc.ic.ac.uk 57
58
ncameron@doc.ic.ac.uk 58 Typing
59
ncameron@doc.ic.ac.uk 59
60
ncameron@doc.ic.ac.uk 60
61
ncameron@doc.ic.ac.uk 61
62
class Cup { Mug f; void m(Cup c) { c.f; } ncameron@doc.ic.ac.uk 62
63
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug ncameron@doc.ic.ac.uk 63 ┴
64
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;this:Cup c.f:Mug | Z ncameron@doc.ic.ac.uk 64 ┴ ┴
65
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;this:Cup c.f:Mug | Z ncameron@doc.ic.ac.uk 65 ┴ ┴
66
ncameron@doc.ic.ac.uk 66
67
ncameron@doc.ic.ac.uk 67
68
ncameron@doc.ic.ac.uk 68
69
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;this:Cup c.f:Mug | Z ncameron@doc.ic.ac.uk 69 ┴ ┴
70
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;Z Mug X;this:Cup c.f:Mug | Z ncameron@doc.ic.ac.uk 70 ┴ ┴ ┴
71
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;Z Mug X;this:Cup c.f:Mug | Z X Z.Mug OK ncameron@doc.ic.ac.uk 71 ┴ ┴ ┴ ┴
72
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;Z Mug X;this:Cup c.f:Mug | Z X Z.Mug OK X;this:Cup c.f: Z.Mug | ncameron@doc.ic.ac.uk 72 ┴ ┴ ┴ ┴ ┴
73
class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c: Z.Cup | fType( f, Cup ) = Mug X;Z Mug X;this:Cup c.f:Mug | Z X Z.Mug OK X;this:Cup c.f: Z.Mug | ncameron@doc.ic.ac.uk 73 ┴ ┴ ┴ ┴ ┴
74
ncameron@doc.ic.ac.uk
75
Full model Proven sound Future Work ‘More full’ - features, translation More expressive? Mechanical proof checking ncameron@doc.ic.ac.uk 75
76
ncameron@doc.ic.ac.uk 76 Thank You! http://www.doc.ic.ac.uk/~ncameron/papers/cameron_ecoop08_full.pdf
77
class Cup { Cup f; Cup m2(String x) {...} void m(Cup c) { c.f = c.f; c.f = c; c.f = c.m2(“a string”); } ncameron@doc.ic.ac.uk 77
78
Variance in C# and Scala C# is invariant, but variance proposed Declaration site annotations Less complex, but less flexible Vs. use site declaration in Java class CovariantCup... Formalisation and soundness C# - Emir, Kennedy, Russo, Yu. ECOOP 06 Scala - Cremet. PhD Thesis, 06 (Virtual types) ncameron@doc.ic.ac.uk 78
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.