Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 A Model for Java with Wildcards Nicholas Cameron Sophia Drossopoulou Erik Ernst.

Similar presentations


Presentation on theme: "1 A Model for Java with Wildcards Nicholas Cameron Sophia Drossopoulou Erik Ernst."— Presentation transcript:

1 1 A Model for Java with Wildcards Nicholas Cameron Sophia Drossopoulou Erik Ernst

2 2 Background Wildcards Previous attempts Existential types Subtyping Typing

3 3 Background

4 Java Adding Wildcards to the Java Language Torgersen, Ernst, Plesner Hansen, von der Ahé, Bracha, Gafter. SAC 04. Existential types to model wildcards 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 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. 6

7 Wildcards A very brief description

8 Java Type Cup 8

9 Java Generics Type Cup 9

10 Generics - Invariant Subtyping Cup 10 /

11 Java Wildcards Type Cup 11

12 Bounds Cup 12

13 Generics - Invariant Subtyping Cup 13 /

14 Wildcards - Variant Subtyping Cup 14 /

15 Wildcard Capture void test(Cup cx) {...} void m(Cup c) { this.test(c); } 15

16 Wildcard Capture void test(Cup cx) {...} void m(Cup c) { this.test(c); //this. test(c); //Z fresh } 16

17 Our Previous Attempts

18 Naïve Approach Cup 18

19 Naïve Approach Cup 19 Expressible but not denotable types

20 'On the fly' Existential Types capture( Cup ) =  X.Cup 20

21 'On the fly' Existential Types capture( Cup ) =  X.Cup Too complicated 21

22 Explicit Existential Types open... close... 22

23 Explicit Existential Types open... close... Lower Bounds Expressivity 23

24 Scope Violation void m(  X.Cup x) { this. m2(x); } 24

25 Scope Violation void m(  X.Cup x) { this. m2(x); } Alpha Renaming 25

26 ... 26

27 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 29

30 30 Existential Types

31 Cup  X.Cup 31

32 Cup  X  Drink.Cup 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); } 35

36 36

37 37

38 38

39  X.Pair Type is expressible but not denotable 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); } 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); } 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); } 42

43 43 Subtyping

44 Wildcards Subtyping Cup 44

45 Wildcards Subtyping Cup .Cup Cup .Cup Cup  Y  Tea.Cup 45

46 ,  ’ T <: B   ’.[T/X]N <:  X  B.N (S-E NV )‏ 46 ┴ ┴

47 Cup .Cup  Tea <: Object  .[Tea/X]Cup (S-E NV )‏ 47 ┴ ┴

48 Cup .Cup  Tea <: Drink  .[Tea/X]Cup (S-E NV )‏ 48 ┴ ┴

49 Cup  Y  Tea.Cup Y  Tea Y <:Tea <: Drink   Y  Tea.[Y/X]Cup (S-E NV )‏ 49 ┴ ┴

50 3 flavours of subtyping?

51 Java 4 Subtyping 51 Object CoffeeTea Drink List Vector

52 Java 5 Subtyping 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 53 Object CoffeeTea Drink List Vector X In class C...

54 Tame FJ Extended Subtyping 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 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 57

58 58 Typing

59 59

60 60

61 61

62 class Cup { Mug f; void m(Cup c) { c.f; } 62

63 class Cup { Mug f; void m(Cup c) { c.f; } X;this:Cup c:  Z.Cup |  fType( f, Cup ) = Mug 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 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 65 ┴ ┴

66 66

67 67

68 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 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 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 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 |  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 |  73 ┴ ┴ ┴ ┴ ┴

74

75 Full model Proven sound Future Work ‘More full’ - features, translation More expressive? Mechanical proof checking 75

76 76 Thank You!

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”); } 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)‏ 78


Download ppt "1 A Model for Java with Wildcards Nicholas Cameron Sophia Drossopoulou Erik Ernst."

Similar presentations


Ads by Google