a practical typed variant object model
play

A Practical, Typed Variant Object Model Or, How to Stand On Your - PowerPoint PPT Presentation

A Practical, Typed Variant Object Model Or, How to Stand On Your Head and Enjoy the View Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn The Johns Hopkins University October 22, 2012 Object Encodings


  1. Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t ∪ ❵♦❞❞ ✐♥t ) -> ( ✐♥t ∪ ❜♦♦❧ ) Simple union type loses alignment

  2. Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not

  3. Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not Weakly dependent type

  4. Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not Weakly dependent type Relies heavily on polymorphism

  5. Fields Pure variant model: get/set messages

  6. Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields

  7. Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01]

  8. Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells

  9. Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 4 ✐♥ o. ❩ Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection

  10. Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 4 ✐♥ ( ❵❩ z -> z) o Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection/pattern match

  11. Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 4 ✐♥ ( ❵❩ z -> z) o Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection/pattern match But what about self?

  12. ❵s❡❧❢ ❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮

  13. ❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮ Add ❵s❡❧❢ to all parameters

  14. ❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮ Add ❵s❡❧❢ to all parameters & is pattern conjunction

  15. Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ( ❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker) Add ❵s❡❧❢ to all parameters & is pattern conjunction Add ❵s❡❧❢ to all call sites

  16. Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ( ❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker) Add ❵s❡❧❢ to all parameters & is pattern conjunction Add ❵s❡❧❢ to all call sites Be happy?

  17. Na¨ ıve Self: Type Problems 1 ❞❡❢ obj = ✐❢ something t❤❡♥ 2 ( ❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛r ✭✮ ) & 3 ( ❵❜❛r _ -> 1) 4 ❡❧s❡ 5 ( ❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛③ ✭✮ ) & 6 ( ❵❜❛③ _ -> 2) 7 8 ✐♥ obj ❵❢♦♦ ✭✮

  18. Na¨ ıve Self: Problems α Self = ( ❵❢♦♦ _ & ❵s❡❧❢ α 1 -> ✐♥t ) & ( ❵❜❛r _ -> ✐♥t ) where α 1 has ❵❜❛r � ( ❵❢♦♦ _ & ❵s❡❧❢ α 2 -> ✐♥t ) & ( ❵❜❛③ _ -> ✐♥t ) where α 2 has ❵❜❛③

  19. Na¨ ıve Self: Problems ( ❵❢♦♦ _ & ❵s❡❧❢ α 1 -> ✐♥t ) & < : ( ❵❜❛r _ -> ✐♥t ) α Self where α 1 has ❵❜❛r ( ❵❢♦♦ _ & ❵s❡❧❢ α 2 -> ✐♥t ) & < : ( ❵❜❛③ _ -> ✐♥t ) α Self where α 2 has ❵❜❛③

  20. Self Solutions Classic object encodings [Bruce et. al. ’98]

  21. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation

  22. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility

  23. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98]

  24. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable

  25. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible

  26. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects

  27. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent

  28. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic

  29. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic TinyBang

  30. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic TinyBang Sealing is encodable (no meta-theory)

  31. Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98] Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic TinyBang Sealing is encodable (no meta-theory) Sealed objects can be extended and resealed

  32. Sealing in TinyBang 1 ❞❡❢ r❡❝ seal = obj -> obj & 2 (msg -> obj ( ❵s❡❧❢ (seal obj) & msg)) ✐♥ 3 4 ❞❡❢ point = ❵① 2 & ❵② 4 & 5 ( ❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ 6 7 ❞❡❢ sealedPoint = seal point ✐♥ 8 sealedPoint ❵❧✶ ✭✮ 9 . . .

  33. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =0

  34. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =1

  35. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =2

  36. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =4

  37. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =5

  38. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮

  39. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵✐♥❝ ✭✮

  40. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

  41. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

  42. Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

  43. Other Features 1 ❞❡❢ point = seal ( ❵① 0 & ❵② 0 & ( ❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> 2 s❡❧❢ . ① + s❡❧❢ . ② )) ✐♥ 3 4 ❞❡❢ mixin = ( ❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> ( s❡❧❢ ❵❧✶ ✭✮ ) <= 4) ✐♥ 5 6 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 7 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮ Mixins

  44. Other Features 1 ❞❡❢ point = . . . ✐♥ 2 ❞❡❢ mixin = (( ❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> ( s❡❧❢ ❵❧✶ ✭✮ ) <= 4)) ✐♥ 3 4 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 5 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮ Mixins Higher-order object extension

  45. Other Features 1 ❞❡❢ obj = seal ( ❵① 0 & ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 2 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 3 4 ❞❡❢ obj2 = seal ( (obj &. ❵① ) & ❵② 0 & 5 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 6 s❡❧❢ . ② = s❡❧❢ . ② + s❡❧❢ . ① ✐♥ s❡❧❢ . ② )) ✐♥ 7 8 . . . Mixins Higher-order object extension Data sharing

  46. Other Features 1 ❞❡❢ obj = seal ( ❵① 0 & 2 ( ❵✐♥❝ n: ✐♥t & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + n ✐♥ s❡❧❢ . ① ) & 4 ( ❵✐♥❝ n: ✉♥✐t & ❵s❡❧❢ s❡❧❢ -> 5 s❡❧❢ ❵✐♥❝ 1) ✐♥ 6 7 obj ( ❵✐♥❝ ✭✮ ); obj ( ❵✐♥❝ 4) Mixins Higher-order object extension Data sharing Overloading

  47. Other Features etc. Mixins Higher-order object extension Data sharing Overloading Classes, inheritance, etc.

  48. Type Inference

  49. Type Inference Subtype constraint system

  50. Type Inference Subtype constraint system Assign each subexpression a type variable

  51. Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression

  52. Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints

  53. Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints Check resulting closure for consistency

  54. Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints Check resulting closure for consistency Soundness is proven over inference system

  55. Constraint Types int ∪ unit

  56. Constraint Types int ∪ unit � α \{ int < : α, unit < : α }

Recommend


More recommend