Big Bang Designing a Statically Typed Scripting Language Pottayil - - PowerPoint PPT Presentation

big bang
SMART_READER_LITE
LIVE PREVIEW

Big Bang Designing a Statically Typed Scripting Language Pottayil - - PowerPoint PPT Presentation

Big Bang Designing a Statically Typed Scripting Language Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn The Johns Hopkins University June 11, 2012 Scripting Languages Terse Flexible Easy to


slide-1
SLIDE 1

Big Bang

Designing a Statically Typed Scripting Language

Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn

The Johns Hopkins University

June 11, 2012

slide-2
SLIDE 2

Scripting Languages

✦ Terse ✦ Flexible ✦ Easy to learn ✦ Amenable to rapid development ✪

slide-3
SLIDE 3

Scripting Languages

✦ Terse ✦ Flexible ✦ Easy to learn ✦ Amenable to rapid development ✪ Dynamically typed

slide-4
SLIDE 4

Advantages of Static Typing

❼ Performance ❼ Debugging ❼ Programmer understanding

slide-5
SLIDE 5

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼

❼ ❼

❼ ❼

slide-6
SLIDE 6

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ ❼

❼ ❼

slide-7
SLIDE 7

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ DRuby does not typecheck the entire Ruby API ❼

❼ ❼

slide-8
SLIDE 8

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ DRuby does not typecheck the entire Ruby API ❼ Typechecking runtime metaprogramming is hard

❼ ❼

slide-9
SLIDE 9

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ DRuby does not typecheck the entire Ruby API ❼ Typechecking runtime metaprogramming is hard

❼ These systems require programmer annotation

❼ ❼

slide-10
SLIDE 10

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ DRuby does not typecheck the entire Ruby API ❼ Typechecking runtime metaprogramming is hard

❼ These systems require programmer annotation

❼ Type annotations reduce terseness ❼

slide-11
SLIDE 11

Typing Existing Scripting Languages

❼ e.g. DRuby, Typed Racket ❼ Existing language features are hard to type

❼ DRuby does not typecheck the entire Ruby API ❼ Typechecking runtime metaprogramming is hard

❼ These systems require programmer annotation

❼ Type annotations reduce terseness ❼ Annotations can be overly restrictive

slide-12
SLIDE 12

Let’s try designing a typed scripting language from scratch

slide-13
SLIDE 13

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ ❼ ❼ ❼ ❼

slide-14
SLIDE 14

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ Be minimalistic: most features are encoded ❼ ❼ ❼ ❼

slide-15
SLIDE 15

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ Be minimalistic: most features are encoded ❼ Use static near-equivalents for dynamic

patterns

❼ ❼ ❼

slide-16
SLIDE 16

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ Be minimalistic: most features are encoded ❼ Use static near-equivalents for dynamic

patterns

❼ Infer all types: no type declarations ❼ ❼

slide-17
SLIDE 17

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ Be minimalistic: most features are encoded ❼ Use static near-equivalents for dynamic

patterns

❼ Infer all types: no type declarations ❼ Use a whole-program typechecking model ❼

slide-18
SLIDE 18

Designing a Typed Scripting Language

❼ Design type system and execution model

concurrently

❼ Be minimalistic: most features are encoded ❼ Use static near-equivalents for dynamic

patterns

❼ Infer all types: no type declarations ❼ Use a whole-program typechecking model ❼ Use type information to improve runtime

memory layout

slide-19
SLIDE 19

BigBang by Example

slide-20
SLIDE 20

BigBang and TinyBang

❼ BigBang encodes to a core language ❼

❼ ❼ ❼ ❼ ❼

slide-21
SLIDE 21

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ ❼ ❼ ❼ ❼

slide-22
SLIDE 22

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ ❼ ❼ ❼

slide-23
SLIDE 23

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ Labels ❼ ❼ ❼

slide-24
SLIDE 24

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ Labels ❼ Onions ❼ ❼

slide-25
SLIDE 25

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ Labels ❼ Onions ❼ Scapes ❼

slide-26
SLIDE 26

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ Labels ❼ Onions ❼ Scapes ❼ Exceptions

slide-27
SLIDE 27

BigBang and TinyBang

❼ BigBang encodes to a core language ❼ TinyBang has very few features:

❼ Primitives ❼ Labels ❼ Onions ❼ Scapes ❼ Exceptions

(and that’s all)

slide-28
SLIDE 28

Labels and Onions

❼ Labels simply wrap data ❼ ❼ ❼ ❼

❼ ❼

❵♥❛♠❡ "Tom" ❵♥❛♠❡

slide-29
SLIDE 29

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ ❼ ❼ ❼

❼ ❼

❵♥❛♠❡ "Tom"

("Tom" ≇

❵♥❛♠❡ "Tom")

slide-30
SLIDE 30

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ ❼ ❼

❼ ❼

❵♥❛♠❡ "Tom" & ❵❛❣❡ 10

slide-31
SLIDE 31

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ Data may be unlabeled (vs. extensible records) ❼ ❼

❼ ❼

❵♥❛♠❡ "Tom" & ❵❛❣❡ 10 & 3

slide-32
SLIDE 32

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ Data may be unlabeled (vs. extensible records) ❼ Onion data is projected by type ❼

❼ ❼

(1 & ✭✮ ) + 2

= ⇒

3

slide-33
SLIDE 33

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ Data may be unlabeled (vs. extensible records) ❼ Onion data is projected by type ❼ Onioning is asymmetric (right-precedence)

❼ ❼

(1 & 4) + 2

= ⇒

6

slide-34
SLIDE 34

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ Data may be unlabeled (vs. extensible records) ❼ Onion data is projected by type ❼ Onioning is asymmetric (right-precedence)

❼ Used to encode overriding ❼

(1 & 4) + 2

= ⇒

6

slide-35
SLIDE 35

Labels and Onions

❼ Labels simply wrap data (polymorphic variants) ❼ Onions combine data ❼ Data may be unlabeled (vs. extensible records) ❼ Onion data is projected by type ❼ Onioning is asymmetric (right-precedence)

❼ Used to encode overriding ❼ Important for type checking (later)

(1 & 4) + 2

= ⇒

6

slide-36
SLIDE 36

Scapes

❼ Scapes are functions ❼ ❼ ❼ x -> x

slide-37
SLIDE 37

Scapes

❼ Scapes are functions with input patterns ❼ ❼ ❼ ❵❆ x & ❵❇ y -> x + y

slide-38
SLIDE 38

Scapes

❼ Scapes are functions with input patterns ❼ ❼ ❼ (❵❆ x & ❵❇ y -> x + y) (❵❆ 1 & ❵❇ 2)

= ⇒

3

slide-39
SLIDE 39

Scapes

❼ Scapes are functions with input patterns ❼ Onions of scapes apply the first matching scape ❼ ❼ ❞❡❢ list = ❵❍❞ 4 & ❵❚❧ ❵◆✐❧ ✭✮ ✐♥ ((❵❍❞ h -> h) & (❵◆✐❧ _ -> ✭✮)) list

= ⇒

4

slide-40
SLIDE 40

Scapes

❼ Scapes are functions with input patterns ❼ Onions of scapes apply the first matching scape ❼ Encodes typecasing ❼ ❞❡❢ list = ❵❍❞ 4 & ❵❚❧ ❵◆✐❧ ✭✮ ✐♥ ((❵❍❞ h -> h) & (❵◆✐❧ _ -> ✭✮)) list

∼ =

❞❡❢ list = ❵❍❞ 4 & ❵❚❧ ❵◆✐❧ ✭✮ ✐♥ ❝❛s❡ list ♦❢ ❵◆✐❧ _ -> ✭✮ ❵❍❞ h -> h

slide-41
SLIDE 41

Scapes

❼ Scapes are functions with input patterns ❼ Onions of scapes apply the first matching scape ❼ Encodes typecasing ❼ Refines First-Class Cases [Chae et al. ’06] ❞❡❢ list = ❵❍❞ 4 & ❵❚❧ ❵◆✐❧ ✭✮ ✐♥ ((❵❍❞ h -> h) & (❵◆✐❧ _ -> ✭✮)) list

∼ =

❞❡❢ list = ❵❍❞ 4 & ❵❚❧ ❵◆✐❧ ✭✮ ✐♥ ❝❛s❡ list ♦❢ ❵◆✐❧ _ -> ✭✮ ❵❍❞ h -> h

slide-42
SLIDE 42

Mutation

❼ Label contents are mutable ❼

❞❡❢ y = ❵❆ 2 ✐♥ (❵❆ x -> x = 5 ✐♥ y) y = ⇒ ❵❆ 5

slide-43
SLIDE 43

Mutation

❼ Label contents are mutable ❼ But onioning is functional extension

❞❡❢ x = ❵❆ 0 & ❵❇ 1 ✐♥ ❞❡❢ y = ❵❇ 2 & ❵❈ 3 ✐♥ ❞❡❢ z = x & y ✐♥ x = ⇒ ❵❆ 0 & ❵❇ 1

slide-44
SLIDE 44

Mutation

❼ Label contents are mutable ❼ But onioning is functional extension

❞❡❢ x = ❵❆ 0 & ❵❇ 1 ✐♥ ❞❡❢ y = ❵❇ 2 & ❵❈ 3 ✐♥ ❞❡❢ z = x & y ✐♥ z = ⇒ ❵❆ 0 & ❵❇ 2 & ❵❈ 3

slide-45
SLIDE 45

Expressiveness

slide-46
SLIDE 46

Encoding Self

Function self-awareness can be encoded by:

❼ Adding a ❵s❡❧❢ match to each pattern ❼

❵s❡❧❢ x -> x

x:❵s❡❧❢ s❡❧❢ -> x

slide-47
SLIDE 47

Encoding Self

Function self-awareness can be encoded by:

❼ Adding a ❵s❡❧❢ match to each pattern ❼

❵s❡❧❢ ❵❆ a -> e

❵❆ a & ❵s❡❧❢ s❡❧❢ -> e

slide-48
SLIDE 48

Encoding Self

Function self-awareness can be encoded by:

❼ Adding a ❵s❡❧❢ match to each pattern ❼ Adding a ❵s❡❧❢ value to each invocation

f e

f (e & ❵s❡❧❢ f)

slide-49
SLIDE 49

Encoding Self

❞❡❢ factorial = x: ✐♥t

  • >

✐❢ x == 0 t❤❡♥ 1 ❡❧s❡ s❡❧❢ (x-1) * x ✐♥ s❡❧❢ 5

❞❡❢ factorial = x: ✐♥t & ❵s❡❧❢ s❡❧❢

  • >

✐❢ x == 0 t❤❡♥ 1 ❡❧s❡ s❡❧❢ (x-1) * x ✐♥ factorial (5 & ❵s❡❧❢ factorial)

slide-50
SLIDE 50

Encoding Objects

❼ Objects are encoded as onions ❼ ❼ ❝❧❛ss Point { ✐♥t x = 2; ✐♥t y = 3; ✐♥t l1() { r❡t✉r♥ x+y; } }

slide-51
SLIDE 51

Encoding Objects

❼ Objects are encoded as onions ❼ Each field is a labeled value ❼ ❝❧❛ss Point { ✐♥t x = 2; ✐♥t y = 3; ✐♥t l1() { r❡t✉r♥ x+y; } } ❵① 2 & ❵② 3

slide-52
SLIDE 52

Encoding Objects

❼ Objects are encoded as onions ❼ Each field is a labeled value ❼ Message handler scapes encode methods ❝❧❛ss Point { ✐♥t x = 2; ✐♥t y = 3; ✐♥t l1() { r❡t✉r♥ x+y; } } ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ -> s❡❧❢.①+s❡❧❢.②)

slide-53
SLIDE 53

Encoding Objects

❼ Objects are encoded as onions ❼ Each field is a labeled value ❼ Message handler scapes encode methods ❝❧❛ss Point { ✐♥t x = 2; ✐♥t y = 3; ✐♥t l1() { r❡t✉r♥ x+y; } } ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢.①+s❡❧❢.②)

slide-54
SLIDE 54

Encoding Objects

❞❡❢ o = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢.① + s❡❧❢.② ) ✐♥ (❵① x -> x) o

∼ = o.①

slide-55
SLIDE 55

Encoding Objects

❞❡❢ o = ❵① 2 & ❵② 3 & ( ❵❧✶ ✭✮ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢.① + s❡❧❢.② ) ✐♥

  • ( ❵❧✶ ✭✮ &

❵s❡❧❢ o )

∼ = o.❧✶✭✮

slide-56
SLIDE 56

Encoding Mixins

❼ Inheritance occurs by onion extension ❼ ❞❡❢ mypoint = ❵① 2 & ❵② 3 & (❵❧✶ ✭✮ -> s❡❧❢.① + s❡❧❢.②) ✐♥ ❞❡❢ mixinFar = (❵✐s❋❛r ✭✮

  • > s❡❧❢.❧✶✭✮ > 26)

✐♥ ❞❡❢ myFpoint = mypoint & mixinFar ✐♥ myFpoint .✐s❋❛r ✭✮

slide-57
SLIDE 57

Encoding Mixins

❼ Inheritance occurs by onion extension ❼ Mixins are the extension onion ❞❡❢ mypoint = ❵① 2 & ❵② 3 & (❵❧✶ ✭✮ -> s❡❧❢.① + s❡❧❢.②) ✐♥ ❞❡❢ mixinFar = (❵✐s❋❛r ✭✮

  • > s❡❧❢.❧✶✭✮ > 26)

✐♥ ❞❡❢ myFpoint = mypoint & mixinFar ✐♥ myFpoint .✐s❋❛r ✭✮

slide-58
SLIDE 58

Encoding Classes

❼ Classes are object factories ❼ ❞❡❢ Point = ❵♥❡✇ (❵① x & ❵② y) -> ❵① x & ❵② y & (❵❧✶ ✭✮ -> s❡❧❢.① + s❡❧❢.②) ✐♥ . . .

slide-59
SLIDE 59

Encoding Classes

❼ Classes are object factories ❼ Subclass factories instantiate and extend ❞❡❢ Point = ❵♥❡✇ (❵① x & ❵② y) -> ❵① x & ❵② y & (❵❧✶ ✭✮ -> s❡❧❢.① + s❡❧❢.②) ✐♥ ❞❡❢ Point3D = ❵♥❡✇ (a: ❵① _ & ❵② _ & ❵③ z) -> ❞❡❢ super = (Point .♥❡✇ a) ✐♥ super & ❵③ 0 & (❵❧✶ ✭✮ -> super .❧✶✭✮) + s❡❧❢.③) ✐♥ Point3D (❵♥❡✇ (❵① 1 & ❵② 2 & ❵③ 3))

slide-60
SLIDE 60

Encoding Overloading

❼ Overloading is trivial with scapes ❼ ❼ ❞❡❢ join = ((❵① x:✐♥t & ❵② y:✐♥t) -> x + y) & ((❵① _:✉♥✐t & ❵② _:✉♥✐t) -> ✭✮) ✐♥ join (❵① 1 & ❵② 2) & join (❵① ✭✮ & ❵② ✭✮)

slide-61
SLIDE 61

Encoding Overloading

❼ Overloading is trivial with scapes ❼ Onion extension allows incremental overloading ❼ ❞❡❢ join = ((❵① x:✐♥t & ❵② y:✐♥t) -> x + y) & ((❵① _:✉♥✐t & ❵② _:✉♥✐t) -> ✭✮) ✐♥ ❞❡❢ x = join (❵① 1 & ❵② 2) & join (❵① ✭✮ & ❵② ✭✮) ✐♥ ❞❡❢ join = join & ((❵① x:✐♥t & ❵② _:✉♥✐t) -> x + 1) ✐♥ join (❵① 5 & ❵② ✭✮)

slide-62
SLIDE 62

Encoding Overloading

❼ Overloading is trivial with scapes ❼ Onion extension allows incremental overloading ❼ Default arguments are easy too ❞❡❢ inc = a: ❵① x -> ❞❡❢ by = ((_ -> 1) & (❵② y -> y)) a ✐♥ x + by ✐♥ inc (❵① 1 & ❵② 2) + inc (❵① 6)

slide-63
SLIDE 63

Metaprogramming

❼ BigBang uses TinyBang as a core language ❼ ❼ s❡❧❢ ❼ ❼

slide-64
SLIDE 64

Metaprogramming

❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for

syntax/features

❼ s❡❧❢ ❼ ❼

slide-65
SLIDE 65

Metaprogramming

❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for

syntax/features

❼ s❡❧❢, class syntax, etc. defined in this way ❼ ❼

slide-66
SLIDE 66

Metaprogramming

❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for

syntax/features

❼ s❡❧❢, class syntax, etc. defined in this way ❼ User extensions can be specified ❼

slide-67
SLIDE 67

Metaprogramming

❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for

syntax/features

❼ s❡❧❢, class syntax, etc. defined in this way ❼ User extensions can be specified ❼ Similar to Racket (Languages as Libraries

[Tobin-Hochstadt et al., 2011])

slide-68
SLIDE 68

Typing

slide-69
SLIDE 69

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ ❼

❼ ❼ ❼

slide-70
SLIDE 70

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼

❼ ❼ ❼

slide-71
SLIDE 71

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

❼ ❼ ❼

slide-72
SLIDE 72

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ ❼ ❼

slide-73
SLIDE 73

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ ❼

slide-74
SLIDE 74

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼

slide-75
SLIDE 75

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference

slide-76
SLIDE 76

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference

❩ Efficient

slide-77
SLIDE 77

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference

❩ Efficient

❼ Short compile times for dev. iterations

slide-78
SLIDE 78

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference

❩ Efficient

❼ Short compile times for dev. iterations

✷ Easy to Use

slide-79
SLIDE 79

Typing Scripting Languages

A scripting language’s type system must be:

✽ Expressive

❼ Duck typing, conditional types ❼ No arbitrary cutoffs

✺ Comprehensible

❼ Types should be legible ❼ Sources of type errors must be clear ❼ Intuitive non-local inference

❩ Efficient

❼ Short compile times for dev. iterations

✷ Easy to Use

❼ Usable to teach introductory courses

slide-80
SLIDE 80

Typing BigBang

For BigBang, we choose:

✽ ✷

Subtype inference

Call-Site Polymorphism

✽ ✺

Path sensitivity

✺ ✷

Flow insensitivity

✽ ❩

Asymmetric concatenation

Incremental typechecking

✽ Expressive ✺ Comprehensible ❩ Efficient ✷ Easy to Use

slide-81
SLIDE 81

✽ ✷ Subtype Inference ✷ ✽

❼ No programmer type declarations ❼ ❼ ❵① ❵② ✭✮

slide-82
SLIDE 82

✽ ✷ Subtype Inference ✷ ✽

❼ No programmer type declarations ❼ Supports duck-typing ❼ ❵① ❵② ✭✮

slide-83
SLIDE 83

✽ ✷ Subtype Inference ✷ ✽

❼ No programmer type declarations ❼ Supports duck-typing ❼ Supports nominal typing (labels as names) ❵① ❵② ✭✮

slide-84
SLIDE 84

✽ ✷ Subtype Inference ✷ ✽

❼ No programmer type declarations ❼ Supports duck-typing ❼ Supports nominal typing (labels as names) (e.g. ❵① 1 & ❵② 2 & ‘Point ✭✮ )

slide-85
SLIDE 85

✽ Call-Site Polymorphism ✽

❼ All functions polymorphic; no ❧❡t restriction ❼ ❼ ❼

slide-86
SLIDE 86

✽ Call-Site Polymorphism ✽

❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ ❼

slide-87
SLIDE 87

✽ Call-Site Polymorphism ✽

❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ Only one contour for each recursive cycle ❼

slide-88
SLIDE 88

✽ Call-Site Polymorphism ✽

❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ Only one contour for each recursive cycle ❼ A variant of both nCFA and CPA

slide-89
SLIDE 89

✽ Call-Site Polymorphism ✽

❞❡❢ f = x -> ❵❆ x ✐♥ ❞❡❢ x = f 0 ✐♥ ❞❡❢ y = f ✭✮ ✐♥ ❞❡❢ z = f (❵❇ 2 & ❵❈ 3) ✐♥ . . . ❵❆ ❵❆ ✭✮ ❵❆ ❵❇ ❵❈

slide-90
SLIDE 90

✽ Call-Site Polymorphism ✽

❞❡❢ f = x -> ❵❆ x ✐♥ ❞❡❢ x = f 0 ✐♥ ❞❡❢ y = f ✭✮ ✐♥ ❞❡❢ z = f (❵❇ 2 & ❵❈ 3) ✐♥ . . . x =

⇒ ❵❆ 0

y =

⇒ ❵❆ ✭✮

z =

⇒ ❵❆ (❵❇ 2 & ❵❈ 3)

slide-91
SLIDE 91

✽ ✺ Path Sensitivity ✺ ✽

❼ Scape application based on pattern match ❼ ❼ ❼

slide-92
SLIDE 92

✽ ✺ Path Sensitivity ✺ ✽

❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ ❼

slide-93
SLIDE 93

✽ ✺ Path Sensitivity ✺ ✽

❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ With polymorphism, gives path sensitivity ❼

slide-94
SLIDE 94

✽ ✺ Path Sensitivity ✺ ✽

❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ With polymorphism, gives path sensitivity ❼ Refines Conditional Types [Aiken et al. ’94]

slide-95
SLIDE 95

✽ ✺ Path Sensitivity ✺ ✽

❞❡❢ f = (❵❆ x -> x) & (❵❇ y -> ✭✮) ✐♥ f ❵❆ 3

slide-96
SLIDE 96

✽ ✺ Path Sensitivity ✺ ✽

❞❡❢ f = (❵❆ x -> x) & (❵❇ y -> ✭✮) ✐♥ f ❵❆ 3

: int

slide-97
SLIDE 97

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼

❼ ❼ ❼

slide-98
SLIDE 98

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

❼ ❼ ❼

slide-99
SLIDE 99

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

❼ Makes variable types less clear ❼ ❼

slide-100
SLIDE 100

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

❼ Makes variable types less clear ❼ Brittle to refactoring ❼

slide-101
SLIDE 101

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

❼ Makes variable types less clear ❼ Brittle to refactoring ❼ Doesn’t help that much

slide-102
SLIDE 102

✺ ✷ Flow Insensitivity ✷ ✺

❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

❼ Makes variable types less clear ❼ Brittle to refactoring ❼ Doesn’t help that much

❼ Could be added later if needed

slide-103
SLIDE 103

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼

❼ ❼ ❼ ❼ ❼

slide-104
SLIDE 104

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ ❼ ❼ ❼ ❼

slide-105
SLIDE 105

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ Subtyping ❼ ❼ ❼ ❼

slide-106
SLIDE 106

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ Subtyping ❼ Overriding ❼ ❼ ❼

slide-107
SLIDE 107

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ Subtyping ❼ Overriding ❼ Multiple inheritance ❼ ❼

slide-108
SLIDE 108

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ Subtyping ❼ Overriding ❼ Multiple inheritance ❼ Evaluation order ❼

slide-109
SLIDE 109

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ In PL design, asymmetry can be good ❼ Examples of asymmetry:

❼ Subtyping ❼ Overriding ❼ Multiple inheritance ❼ Evaluation order ❼ Module dependencies

slide-110
SLIDE 110

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ ❼

❵❆ ✐♥t

❵❆ ✐♥t ❼ ❼

slide-111
SLIDE 111

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼

❵❆ ✐♥t

❵❆ ✐♥t ❼ ❼

slide-112
SLIDE 112

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼ Only presence information is pushed forward

❵❆ ✐♥t

❵❆ ✐♥t ❼ ❼

slide-113
SLIDE 113

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼ Only presence information is pushed forward

❼ Type system can express “α has ❵❆ ✐♥t” ❼

❵❆ ✐♥t ❼ ❼

slide-114
SLIDE 114

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼ Only presence information is pushed forward

❼ Type system can express “α has ❵❆ ✐♥t” ❼ But not “α only has ❵❆ ✐♥t”

❼ ❼

slide-115
SLIDE 115

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼ Only presence information is pushed forward

❼ Type system can express “α has ❵❆ ✐♥t” ❼ But not “α only has ❵❆ ✐♥t”

❼ Upper bounds inferred from usage ❼

slide-116
SLIDE 116

✽ ❩ Asymmetric Concatenation ❩ ✽

❼ Onion projection prefers rightmost element ❼ Not based on row typing ❼ Only presence information is pushed forward

❼ Type system can express “α has ❵❆ ✐♥t” ❼ But not “α only has ❵❆ ✐♥t”

❼ Upper bounds inferred from usage ❼ Monomorphic variant of TinyBang closure is

polynomial (vs. previous NP-complete result [Palsberg et al. ’03])

slide-117
SLIDE 117

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ ❼

❼ ❼ ❼ ❼

slide-118
SLIDE 118

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼

❼ ❼ ❼ ❼

slide-119
SLIDE 119

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼ Solution:

❼ ❼ ❼ ❼

slide-120
SLIDE 120

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼ Solution:

❼ Track differences between software versions ❼ ❼ ❼

slide-121
SLIDE 121

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼ Solution:

❼ Track differences between software versions ❼ Delete constraints for removed code ❼ ❼

slide-122
SLIDE 122

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼ Solution:

❼ Track differences between software versions ❼ Delete constraints for removed code ❼ Include constraints from new code ❼

slide-123
SLIDE 123

❩ Incremental Typechecking ❩

❼ For scripts, edit-compile-debug must be fast ❼ Type constraint closure can be slow ❼ Solution:

❼ Track differences between software versions ❼ Delete constraints for removed code ❼ Include constraints from new code ❼ Perform closure again

slide-124
SLIDE 124

Limitations

❼ Typical type system limitations

❼ ❼

slide-125
SLIDE 125

Limitations

❼ Typical type system limitations

❼ Recursion limits contour creation ❼

slide-126
SLIDE 126

Limitations

❼ Typical type system limitations

❼ Recursion limits contour creation ❼ Flow-insensitivity

slide-127
SLIDE 127

Limitations

❼ Typical type system limitations

❼ Recursion limits contour creation ❼ Flow-insensitivity

❼ Syntactic limitations

slide-128
SLIDE 128

Limitations

❼ Typical type system limitations

❼ Recursion limits contour creation ❼ Flow-insensitivity

❼ Syntactic limitations

❼ No string-to-label functionality

slide-129
SLIDE 129

Compilation

slide-130
SLIDE 130

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼

❼ ❼ ❼

slide-131
SLIDE 131

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ ❼ ❼

slide-132
SLIDE 132

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ No unnecessary boxing ❼ ❼

slide-133
SLIDE 133

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ No unnecessary boxing ❼ Reduce pointer arithmetic ❼

slide-134
SLIDE 134

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ No unnecessary boxing ❼ Reduce pointer arithmetic ❼ Definitely no runtime hashing

slide-135
SLIDE 135

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ No unnecessary boxing ❼ Reduce pointer arithmetic ❼ Definitely no runtime hashing

❼ Still path-sensitive across modules

slide-136
SLIDE 136

Compilation

What will we want out of a compiler?

❼ Compiles scripts to native binaries (via LLVM) ❼ Optimizes layout using type information

❼ No unnecessary boxing ❼ Reduce pointer arithmetic ❼ Definitely no runtime hashing

❼ Still path-sensitive across modules

How do we get this?

slide-137
SLIDE 137

Whole-Program Compilation!

slide-138
SLIDE 138

Whole-Program Compilation

Why do we need a whole-program view?

❼ No declarations of types or module signatures ❼ ❼

slide-139
SLIDE 139

Whole-Program Compilation

Why do we need a whole-program view?

❼ No declarations of types or module signatures ❼ General layout for extensible data structures is

inefficient

slide-140
SLIDE 140

Whole-Program Compilation

Why do we need a whole-program view?

❼ No declarations of types or module signatures ❼ General layout for extensible data structures is

inefficient

❼ So we must know what could arrive at each

call site

slide-141
SLIDE 141

Whole-Program Compilation

How can we live with ourselves?

❼ Intermediate work (constraint sets, etc.) can

be stored and reused

❼ ❼ ❼

slide-142
SLIDE 142

Whole-Program Compilation

How can we live with ourselves?

❼ Intermediate work (constraint sets, etc.) can

be stored and reused

❼ Coding to a module signature is limited; not all

interface semantics are typeable

❼ ❼

slide-143
SLIDE 143

Whole-Program Compilation

How can we live with ourselves?

❼ Intermediate work (constraint sets, etc.) can

be stored and reused

❼ Coding to a module signature is limited; not all

interface semantics are typeable

❼ Vast layout optimization potential ❼

slide-144
SLIDE 144

Whole-Program Compilation

How can we live with ourselves?

❼ Intermediate work (constraint sets, etc.) can

be stored and reused

❼ Coding to a module signature is limited; not all

interface semantics are typeable

❼ Vast layout optimization potential ❼ Shared libraries are still possible

slide-145
SLIDE 145

Layout

❼ Standard approach: common layout form (as

C++)

❼ ❼

❼ ❼

slide-146
SLIDE 146

Layout

❼ Standard approach: common layout form (as

C++)

❼ Existing work handles flexible data structures

❼ ❼

❼ ❼

slide-147
SLIDE 147

Layout

❼ Standard approach: common layout form (as

C++)

❼ Existing work handles flexible data structures

❼ A Calculus with Polymorphic and Polyvariant Flow

Types [Wells et al. ’02]

❼ ❼

slide-148
SLIDE 148

Layout

❼ Standard approach: common layout form (as

C++)

❼ Existing work handles flexible data structures

❼ A Calculus with Polymorphic and Polyvariant Flow

Types [Wells et al. ’02]

❼ A Polymorphic Record Calculus and Its

Compilation [Ohori ’95] ❼ ❼

slide-149
SLIDE 149

Layout

❼ Standard approach: common layout form (as

C++)

❼ Existing work handles flexible data structures

❼ A Calculus with Polymorphic and Polyvariant Flow

Types [Wells et al. ’02]

❼ A Polymorphic Record Calculus and Its

Compilation [Ohori ’95] ❼ Onions: more flexible, new problems ❼

slide-150
SLIDE 150

Layout

❼ Standard approach: common layout form (as

C++)

❼ Existing work handles flexible data structures

❼ A Calculus with Polymorphic and Polyvariant Flow

Types [Wells et al. ’02]

❼ A Polymorphic Record Calculus and Its

Compilation [Ohori ’95] ❼ Onions: more flexible, new problems ❼ Whole-program types will help us!

slide-151
SLIDE 151

Where Are We?

We have:

❼ A TinyBang interpreter ❼ ❼ ❼ ❼ ❼

slide-152
SLIDE 152

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ ❼ ❼ ❼

slide-153
SLIDE 153

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features ❼ ❼ ❼

slide-154
SLIDE 154

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features

We need:

❼ ❼ ❼

slide-155
SLIDE 155

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features

We need:

❼ A TinyBang-to-LLVM compiler ❼ ❼

slide-156
SLIDE 156

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features

We need:

❼ A TinyBang-to-LLVM compiler ❼ A BigBang metaprogramming system ❼

slide-157
SLIDE 157

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features

We need:

❼ A TinyBang-to-LLVM compiler ❼ A BigBang metaprogramming system ❼ A layout calculus and optimization tool

slide-158
SLIDE 158

Where Are We?

We have:

❼ A TinyBang interpreter ❼ A TinyBang type system and soundness proof ❼ Effective encodings for language features

We need:

❼ A TinyBang-to-LLVM compiler ❼ A BigBang metaprogramming system ❼ A layout calculus and optimization tool

...

slide-159
SLIDE 159

Questions?