big bang
play

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


  1. 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)

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

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

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

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

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

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

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

  9. 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 ✭✮

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

  11. 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))

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

  13. ❼ 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 & ❵② ✭✮ )

  14. 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)

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

  16. ❼ s❡❧❢ ❼ ❼ Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features

  17. ❼ ❼ Metaprogramming ❼ BigBang uses TinyBang as a core language ❼ BigBang will provide macros for syntax/features ❼ s❡❧❢ , class syntax, etc. defined in this way

  18. ❼ 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

  19. 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])

  20. Typing

  21. ❼ ❼ ❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive

  22. ❼ ❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types

  23. ❼ ❼ ❼ ❼ ❼ ✺ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs

  24. ❼ ❼ ❼ ❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible

  25. ❼ ❼ ❼ ❼ ❩ ✷ Typing Scripting Languages A scripting language’s type system must be: ✽ Expressive ❼ Duck typing, conditional types ❼ No arbitrary cutoffs ✺ Comprehensible ❼ Types should be legible

  26. ❼ ❼ ❼ ❩ ✷ 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

  27. ❼ ❼ ❩ ✷ 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

  28. ❼ ❼ ✷ 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

  29. ❼ ✷ 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

  30. ❼ 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

  31. 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

  32. 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

  33. ❵① ❵② ✭✮ ❼ ❼ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations

  34. ❵① ❵② ✭✮ ❼ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations ❼ Supports duck-typing

  35. ❵① ❵② ✭✮ ✽ ✷ Subtype Inference ✷ ✽ ❼ No programmer type declarations ❼ Supports duck-typing ❼ Supports nominal typing (labels as names)

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

  37. ❼ ❼ ❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction

  38. ❼ ❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site

  39. ❼ ✽ Call-Site Polymorphism ✽ ❼ All functions polymorphic; no ❧❡t restriction ❼ New contour for each non-recursive call site ❼ Only one contour for each recursive cycle

  40. ✽ 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 n CFA and CPA

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

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

  43. ❼ ❼ ❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match

  44. ❼ ❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match ❼ Constraints expanded only if input matches

  45. ❼ ✽ ✺ Path Sensitivity ✺ ✽ ❼ Scape application based on pattern match ❼ Constraints expanded only if input matches ❼ With polymorphism, gives path sensitivity

  46. ✽ ✺ 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]

  47. ✽ ✺ Path Sensitivity ✺ ✽ ❞❡❢ f = ( ❵❆ x -> x) & ( ❵❇ y -> ✭✮ ) ✐♥ f ❵❆ 3

  48. ✽ ✺ Path Sensitivity ✺ ✽ ❞❡❢ f = ( ❵❆ x -> x) & ( ❵❇ y -> ✭✮ ) ✐♥ f ❵❆ 3 : int

  49. ❼ ❼ ❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant

  50. ❼ ❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity:

  51. ❼ ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity: ❼ Makes variable types less clear

  52. ❼ ❼ ✺ ✷ Flow Insensitivity ✷ ✺ ❼ Type of a variable is flow-invariant ❼ Flow sensitivity: ❼ Makes variable types less clear ❼ Brittle to refactoring

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend