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

a practical typed variant object model
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Object Encodings

Record-Based Encodings

slide-3
SLIDE 3

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages

slide-4
SLIDE 4

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages Easier to type

slide-5
SLIDE 5

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .

slide-6
SLIDE 6

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .

Variant-Based Encodings

slide-7
SLIDE 7

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .

Variant-Based Encodings

Actor-based languages (Erlang)

slide-8
SLIDE 8

Object Encodings

Record-Based Encodings

Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .

Variant-Based Encodings

Actor-based languages (Erlang) Harder to type

slide-9
SLIDE 9

Record-Based Object Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2 } 1 ❧❡t a = { 2 }

slide-10
SLIDE 10

Record-Based Object Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3 } 1 ❧❡t a = { 2

v = ref 5

3 }

Object fields are record fields

slide-11
SLIDE 11

Record-Based Object Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 } 1 ❧❡t a = { 2

v = ref 5;

3

mth = ❢✉♥ self ->

4

❢✉♥ x -> x+! self.v;

5

foo = ❢✉♥ ✭✮ -> ✭✮

6 }

Object fields are record fields Methods are fields with functions

slide-12
SLIDE 12

Record-Based Object Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 }; 7 a.mth (3) 1 ❧❡t a = { 2

v = ref 5;

3

mth = ❢✉♥ self ->

4

❢✉♥ x -> x+! self.v

5

foo = ❢✉♥ ✭✮ -> ✭✮

6 } ✐♥ 7 a.mth a 3

Object fields are record fields Methods are fields with functions Invocation projects methods

slide-13
SLIDE 13

Record-Based Object Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 }; 7 a.mth (3) 1 ❧❡t a = { 2

v = ref 5;

3

mth = ❢✉♥ self ->

4

❢✉♥ x -> x+! self.v

5

foo = ❢✉♥ ✭✮ -> ✭✮

6 } ✐♥ 7 a.mth a 3

Object fields are record fields Methods are fields with functions Invocation projects methods

We ignore self-hiding for now.

slide-14
SLIDE 14

Duality

Variants ⇐ ⇒ Records

slide-15
SLIDE 15

Variant-Based Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2 } 1 ❧❡t a = ❢✉♥ msg -> 2

♠❛t❝❤ msg ✇✐t❤

3

. . .

slide-16
SLIDE 16

Variant-Based Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3 } 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3

♠❛t❝❤ msg ✇✐t❤

4

. . .

Fields by closure

slide-17
SLIDE 17

Variant-Based Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 } 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3

♠❛t❝❤ msg ✇✐t❤

4

| ‘mth (self ,x) ->

5

x+! self.v

6

| ‘foo ✭✮ -> ✭✮

Fields by closure Methods are other message handlers

slide-18
SLIDE 18

Variant-Based Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 }; 7 a.mth (3) 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3

♠❛t❝❤ msg ✇✐t❤

4

| ‘mth (self ,x) ->

5

x+! self.v

6

| ‘foo ✭✮ -> ✭✮

7 ✐♥ a (‘mth (a ,3))

Fields by closure Methods are other message handlers Invocation is just message passing

slide-19
SLIDE 19

Variant-Based Encoding

(Scala) (OCaml)

1 ♦❜❥❡❝t a { 2

✈❛❧ v = 5

3

❞❡❢ mth(x:Int)

4

:Int = { x+v }

5

❞❡❢ foo(x:Unit ){}

6 }; 7 a.mth (3) 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3

♠❛t❝❤ msg ✇✐t❤

4

| ‘mth (self ,x) ->

5

x+! self.v

6

| ‘foo ✭✮ -> ✭✮

7 ✐♥ a (‘mth (a ,3))

Fields by closure Methods are other message handlers Invocation is just message passing But this doesn’t typecheck!

slide-20
SLIDE 20

Typing Variant Destruction

1 ♠❛t❝❤ v ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

Typechecking variant destruction is tricky

slide-21
SLIDE 21

Typing Variant Destruction

1 ♠❛t❝❤ v ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification

slide-22
SLIDE 22

Typing Variant Destruction

1 ♠❛t❝❤ v ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

: int ∪ bool

Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types

slide-23
SLIDE 23

Typing Variant Destruction

1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

: int ∪ bool

Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient!

slide-24
SLIDE 24

Typing Variant Destruction

1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

: int!

Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient! Record construction is heterogeneously typed

slide-25
SLIDE 25

Typing Variant Destruction

1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2

| ‘Odd y -> y mod 2 = 1

3

| ‘Dbl x -> x + x

: int!

Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient! Record construction is heterogeneously typed Variant destruction is not

slide-26
SLIDE 26

Typing the Variant Encoding

Our objective: a purely type-inferred variant-based

  • bject encoding
slide-27
SLIDE 27

Typing the Variant Encoding

Our objective: a purely type-inferred variant-based

  • bject encoding

This can work! We just need...

slide-28
SLIDE 28

Typing the Variant Encoding

Our objective: a purely type-inferred variant-based

  • bject encoding

This can work! We just need... A couple new expression forms Weakly dependent types Precise polymorphism A whole-program typechecking pass

slide-29
SLIDE 29

Typing the Variant Encoding

Our objective: a purely type-inferred variant-based

  • bject encoding

This can work! We just need... A couple new expression forms Weakly dependent types Precise polymorphism A whole-program typechecking pass ...and then we reap the benefits!

slide-30
SLIDE 30

How We Get It: TinyBang

&

Onions

(Extensible, type-indexed records)

slide-31
SLIDE 31

How We Get It: TinyBang

&

Onions

(Extensible, type-indexed records)

χ ->

Scapes

(Functions with built-in patterns)

slide-32
SLIDE 32

How We Get It: TinyBang

&

Onions

(Extensible, type-indexed records)

+

χ ->

Scapes

(Functions with built-in patterns)

slide-33
SLIDE 33

Variant-Based Object Encoding

TinyBang

1

❵❞❜❧ x -> x + x

Methods are scapes

slide-34
SLIDE 34

Variant-Based Object Encoding

TinyBang

1

❵❞❜❧ x -> x + x

Methods are scapes: functions with patterns

slide-35
SLIDE 35

Variant-Based Object Encoding

TinyBang

1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3

Methods are scapes: functions with patterns Invoke methods by passing messages

slide-36
SLIDE 36

Variant-Based Object Encoding

TinyBang

1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3

Methods are scapes: functions with patterns Invoke methods by passing first-class messages

slide-37
SLIDE 37

Variant-Based Object Encoding

TinyBang

1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3

Methods are scapes: functions with patterns Invoke methods by passing first-class messages (just labeled data)

slide-38
SLIDE 38

Many Methods: Onioning Scapes

1

❵❞❜❧ x -> x + x

slide-39
SLIDE 39

Many Methods: Onioning Scapes

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)

Scapes are combined by onioning

slide-40
SLIDE 40

Many Methods: Onioning Scapes

1 ((❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)

Scapes are combined by onioning Application finds match

slide-41
SLIDE 41

Many Methods: Onioning Scapes

1 ((❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)

1 ♦❜❥❡❝t a { 2

❞❡❢ dbl(x:Int):Int = { x + x }

3

❞❡❢ pos(y:Int): Boolean = { y % 2 == 1 }

4 } 5 a.dbl (2)

slide-42
SLIDE 42

Many Methods: Onioning Scapes

1 ((❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)

⇒ 4

Scapes are combined by onioning Application finds rightmost match (asymmetric)

slide-43
SLIDE 43

Many Methods: Onioning Scapes

1 ((❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)

⇒ 4

Scapes are combined by onioning Application finds rightmost match (asymmetric) Subsumes case expressions

slide-44
SLIDE 44

Many Methods: Onioning Scapes

1 ((❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)

⇒ 4

Scapes are combined by onioning Application finds rightmost match (asymmetric) Subsumes case expressions Generalizes First-Class Cases [Blume et. al. ’06]

slide-45
SLIDE 45

Typing the Onion

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t ∪ ❵♦❞❞ ✐♥t) -> (✐♥t ∪ ❜♦♦❧)

Simple union type loses alignment

slide-46
SLIDE 46

Typing the Onion

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)

Simple union type loses alignment Onion type does not

slide-47
SLIDE 47

Typing the Onion

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)

Simple union type loses alignment Onion type does not Weakly dependent type

slide-48
SLIDE 48

Typing the Onion

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)

Simple union type loses alignment Onion type does not Weakly dependent type Relies heavily on polymorphism

slide-49
SLIDE 49

Fields

Pure variant model: get/set messages

slide-50
SLIDE 50

Fields

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

Pure variant model: get/set messages Hybrid model: variant methods, record fields

slide-51
SLIDE 51

Fields

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01]

slide-52
SLIDE 52

Fields

1

(❵❞❜❧ x -> x + x) &

2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells

slide-53
SLIDE 53

Fields

1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

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

slide-54
SLIDE 54

Fields

1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

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

slide-55
SLIDE 55

Fields

1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2

(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &

3

❵❩ 5

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?

slide-56
SLIDE 56

Na¨ ıve Self

1 ❞❡❢ ticker = 2

❵① 0 &

3

(❵✐♥❝ _ ->

4

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)

5 ✐♥ ticker ❵✐♥❝ ✭✮

❵s❡❧❢ ❵s❡❧❢

slide-57
SLIDE 57

Na¨ ıve Self

1 ❞❡❢ ticker = 2

❵① 0 &

3

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

4

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)

5 ✐♥ ticker ❵✐♥❝ ✭✮

Add ❵s❡❧❢ to all parameters

❵s❡❧❢

slide-58
SLIDE 58

Na¨ ıve Self

1 ❞❡❢ ticker = 2

❵① 0 &

3

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

4

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)

5 ✐♥ ticker ❵✐♥❝ ✭✮

Add ❵s❡❧❢ to all parameters

& is pattern conjunction ❵s❡❧❢

slide-59
SLIDE 59

Na¨ ıve Self

1 ❞❡❢ ticker = 2

❵① 0 &

3

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

4

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)

5 ✐♥ ticker (❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker)

Add ❵s❡❧❢ to all parameters

& is pattern conjunction

Add ❵s❡❧❢ to all call sites

slide-60
SLIDE 60

Na¨ ıve Self

1 ❞❡❢ ticker = 2

❵① 0 &

3

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

4

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)

5 ✐♥ ticker (❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker)

Add ❵s❡❧❢ to all parameters

& is pattern conjunction

Add ❵s❡❧❢ to all call sites Be happy?

slide-61
SLIDE 61

Na¨ ıve Self: Type Problems

1 ❞❡❢ obj = 2

✐❢ something t❤❡♥

3

(❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛r ✭✮) &

4

(❵❜❛r _ -> 1)

5

❡❧s❡

6

(❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛③ ✭✮) &

7

(❵❜❛③ _ -> 2)

8 ✐♥ obj ❵❢♦♦ ✭✮

slide-62
SLIDE 62

Na¨ ıve Self: Problems

αSelf =

(❵❢♦♦ _ & ❵s❡❧❢ α1 -> ✐♥t) & (❵❜❛r _ -> ✐♥t) where α1 has ❵❜❛r

  • (❵❢♦♦ _ & ❵s❡❧❢ α2 -> ✐♥t) &

(❵❜❛③ _ -> ✐♥t) where α2 has ❵❜❛③

slide-63
SLIDE 63

Na¨ ıve Self: Problems

αSelf <:

(❵❢♦♦ _ & ❵s❡❧❢ α1 -> ✐♥t) & (❵❜❛r _ -> ✐♥t) where α1 has ❵❜❛r

αSelf <:

(❵❢♦♦ _ & ❵s❡❧❢ α2 -> ✐♥t) & (❵❜❛③ _ -> ✐♥t) where α2 has ❵❜❛③

slide-64
SLIDE 64

Self Solutions

Classic object encodings [Bruce et. al. ’98]

slide-65
SLIDE 65

Self Solutions

Classic object encodings [Bruce et. al. ’98]

Type of self is fixed at instantiation

slide-66
SLIDE 66

Self Solutions

Classic object encodings [Bruce et. al. ’98]

Type of self is fixed at instantiation No object extensibility

slide-67
SLIDE 67

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]

slide-68
SLIDE 68

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

slide-69
SLIDE 69

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

slide-70
SLIDE 70

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

slide-71
SLIDE 71

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

slide-72
SLIDE 72

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

slide-73
SLIDE 73

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

slide-74
SLIDE 74

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)

slide-75
SLIDE 75

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

slide-76
SLIDE 76

Sealing in TinyBang

1 ❞❡❢ r❡❝ seal = obj -> 2

  • bj &

3

(msg -> obj (❵s❡❧❢ (seal obj) & msg)) ✐♥

4 ❞❡❢ point = 5

❵① 2 & ❵② 4 &

6

(❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢.① + s❡❧❢.②) ✐♥

7 ❞❡❢ sealedPoint = seal point ✐♥ 8 sealedPoint ❵❧✶ ✭✮ 9 . . .

slide-77
SLIDE 77

Resealing Objects

1 . . . 2 ❞❡❢ obj = seal ( 3

❵① 0 &

4

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

5

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8

  • bj &

9

(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->

10

s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥

11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮

x =0

slide-78
SLIDE 78

Resealing Objects

1 . . . 2 ❞❡❢ obj = seal ( 3

❵① 0 &

4

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

5

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8

  • bj &

9

(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->

10

s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥

11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮

x =1

slide-79
SLIDE 79

Resealing Objects

1 . . . 2 ❞❡❢ obj = seal ( 3

❵① 0 &

4

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

5

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8

  • bj &

9

(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->

10

s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥

11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮

x =2

slide-80
SLIDE 80

Resealing Objects

1 . . . 2 ❞❡❢ obj = seal ( 3

❵① 0 &

4

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

5

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8

  • bj &

9

(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->

10

s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥

11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮

x =4

slide-81
SLIDE 81

Resealing Objects

1 . . . 2 ❞❡❢ obj = seal ( 3

❵① 0 &

4

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

5

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8

  • bj &

9

(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->

10

s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥

11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮

x =5

slide-82
SLIDE 82

Resealing Objects

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

slide-83
SLIDE 83

Resealing Objects

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

❵✐♥❝ ✭✮

slide-84
SLIDE 84

Resealing Objects

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

❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

slide-85
SLIDE 85

Resealing Objects

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

❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

slide-86
SLIDE 86

Resealing Objects

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

❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮

slide-87
SLIDE 87

Other Features

1 ❞❡❢ point = seal (❵① 0 & ❵② 0 & 2

(❵❧✶ _ & ❵s❡❧❢ s❡❧❢ ->

3

s❡❧❢.① + s❡❧❢.②)) ✐♥

4 ❞❡❢ mixin = (❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> 5

(s❡❧❢ ❵❧✶ ✭✮) <= 4) ✐♥

6 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 7 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮

Mixins

slide-88
SLIDE 88

Other Features

1 ❞❡❢ point =

. . . ✐♥

2 ❞❡❢ mixin = ((❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> 3

(s❡❧❢ ❵❧✶ ✭✮) <= 4)) ✐♥

4 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 5 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮

Mixins Higher-order object extension

slide-89
SLIDE 89

Other Features

1 ❞❡❢ obj = seal ( 2

❵① 0 & (❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

3

s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥

4 ❞❡❢ obj2 = seal ( 5

(obj &. ❵①) & ❵② 0 &

6

(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->

7

s❡❧❢.② = s❡❧❢.② + s❡❧❢.① ✐♥ s❡❧❢.②)) ✐♥

8 . . .

Mixins Higher-order object extension Data sharing

slide-90
SLIDE 90

Other Features

1 ❞❡❢ obj = seal ( 2

❵① 0 &

3

(❵✐♥❝ n:✐♥t & ❵s❡❧❢ s❡❧❢ ->

4

s❡❧❢.① = s❡❧❢.① + n ✐♥ s❡❧❢.①) &

5

(❵✐♥❝ n:✉♥✐t & ❵s❡❧❢ s❡❧❢ ->

6

s❡❧❢ ❵✐♥❝ 1) ✐♥

7 obj (❵✐♥❝ ✭✮); obj (❵✐♥❝ 4)

Mixins Higher-order object extension Data sharing Overloading

slide-91
SLIDE 91

Other Features etc.

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

slide-92
SLIDE 92

Type Inference

slide-93
SLIDE 93

Type Inference

Subtype constraint system

slide-94
SLIDE 94

Type Inference

Subtype constraint system Assign each subexpression a type variable

slide-95
SLIDE 95

Type Inference

Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression

slide-96
SLIDE 96

Type Inference

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

slide-97
SLIDE 97

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

slide-98
SLIDE 98

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

slide-99
SLIDE 99

Constraint Types int ∪ unit

slide-100
SLIDE 100

Constraint Types int ∪ unit

  • α\{int <: α, unit <: α}
slide-101
SLIDE 101

Constraint Closure

5 + 3

slide-102
SLIDE 102

Constraint Closure

5 + 3

α1 α2

slide-103
SLIDE 103

Constraint Closure

5 + 3

α1 α2 α3

slide-104
SLIDE 104

Constraint Closure

5 + 3

int α1 α2 α3

slide-105
SLIDE 105

Constraint Closure

5 + 3

int α1 α2 α3

slide-106
SLIDE 106

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-107
SLIDE 107

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-108
SLIDE 108

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-109
SLIDE 109

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-110
SLIDE 110

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-111
SLIDE 111

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-112
SLIDE 112

Constraint Closure

5 + 3

int α1 α2 α3 +

slide-113
SLIDE 113

Functions

x -> x + x

slide-114
SLIDE 114

Functions

x -> x + x

+

slide-115
SLIDE 115

Functions

x -> x + x

+

slide-116
SLIDE 116

Functions

x -> x + x

+

slide-117
SLIDE 117

Functions

x -> x + x

+

slide-118
SLIDE 118

Functions

x -> x + x

slide-119
SLIDE 119

Application

(x -> x + x) 5

slide-120
SLIDE 120

Application

(x -> x + x) 5

slide-121
SLIDE 121

Application

(x -> x + x) 5

slide-122
SLIDE 122

Application

(x -> x + x) 5

slide-123
SLIDE 123

Application

(x -> x + x) 5

❼ +

slide-124
SLIDE 124

Application

(x -> x + x) 5

❼ +

slide-125
SLIDE 125

Application

(x -> x + x) 5

❼ +

slide-126
SLIDE 126

Application

(x -> x + x) 5

❼ +

slide-127
SLIDE 127

Application

(x -> x + x) 5

❼ +

slide-128
SLIDE 128

Application

(x -> x + x) 5

❼ +

slide-129
SLIDE 129

Application

(x -> x + x) 5

❼ +

slide-130
SLIDE 130

Application

(x -> x + x) 5

❼ +

slide-131
SLIDE 131

Application

(x -> x + x) 5

❼ +

slide-132
SLIDE 132

Application

(x -> x + x) 5

❼ +

slide-133
SLIDE 133

Application

(x -> x + x) 5 :

✐♥t

❼ +

slide-134
SLIDE 134

Polymorphism

slide-135
SLIDE 135

Polymorphism

Let-bound polymorphism

slide-136
SLIDE 136

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

slide-137
SLIDE 137

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

slide-138
SLIDE 138

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

Objects are not local

slide-139
SLIDE 139

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

Objects are not local Requires type annotations

slide-140
SLIDE 140

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

Objects are not local Requires type annotations

TinyBang uses call-site polymorphism

slide-141
SLIDE 141

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

Objects are not local Requires type annotations

TinyBang uses call-site polymorphism

Each call site is freshly polyinstantiated

slide-142
SLIDE 142

Polymorphism

Let-bound polymorphism

Type-parametric methods fail

Local polymorphism

Objects are not local Requires type annotations

TinyBang uses call-site polymorphism

Each call site is freshly polyinstantiated Recursion reuses variable contours

slide-143
SLIDE 143

Polymorphic Application

❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)

❼ ❼

slide-144
SLIDE 144

Polymorphic Application

❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)

❼ ❼

slide-145
SLIDE 145

Polymorphic Application

❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)

❼ ❼ &

slide-146
SLIDE 146

Polymorphic Application

❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)

❼ ❼ &

slide-147
SLIDE 147

Polymorphic Application

❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)

❼ ❼ &

slide-148
SLIDE 148

BigBang

Aims to infer types for script-like programs

slide-149
SLIDE 149

BigBang

Aims to infer types for script-like programs Uses type information for better performance

slide-150
SLIDE 150

BigBang

Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang

slide-151
SLIDE 151

BigBang

Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc.

slide-152
SLIDE 152

BigBang

Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc. Enough polymorphism for scripting intuitions

slide-153
SLIDE 153

BigBang

Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc. Enough polymorphism for scripting intuitions ...without divergence or exponential blow-up

slide-154
SLIDE 154

Summary

TinyBang encodes objects as scapes and onions

slide-155
SLIDE 155

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed

slide-156
SLIDE 156

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function

slide-157
SLIDE 157

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable

slide-158
SLIDE 158

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model

slide-159
SLIDE 159

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model Requires whole-program typechecking

slide-160
SLIDE 160

Summary

TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model Requires whole-program typechecking

Questions?