well typed programs can t be blamed
play

Well-typed programs cant be blamed (ESOP 2009) Robert Bruce Findler - PowerPoint PPT Presentation

Well-typed programs cant be blamed (ESOP 2009) Robert Bruce Findler Northwestern University Philip Wadler University of Edinburgh Aussois, 1418 October 2013 Part I Evolving a program An untyped program let x = 2 f = y. y + 1 h =


  1. Well-typed programs can’t be blamed (ESOP 2009) Robert Bruce Findler Northwestern University Philip Wadler University of Edinburgh Aussois, 14–18 October 2013

  2. Part I Evolving a program

  3. An untyped program ⌈ let x = 2 f = λy. y + 1 h = λg. g ( g x ) in h f ⌉ − → ⌈ 4 ⌉

  4. A typed program let x = 2 f = λy : Int . y + 1 h = λg : Int → Int . g ( g x ) in h f − → 4 : Int

  5. A partly typed program—narrowing let x = 2 p f = ⌈ λy. y + 1 ⌉ : ⋆ ⇒ Int → Int h = λg : Int → Int . g ( g x ) in h f − → 4 : Int

  6. A partly typed program—narrowing let x = 2 p f = ⌈ λy. false ⌉ : ⋆ ⇒ Int → Int h = λg : Int → Int . g ( g x ) in h f − → blame p Positive (covariant): blame the term contained in the cast Narrowing can give rise to positive blame, but never negative blame

  7. Another partly typed program—widening let x = ⌈ 2 ⌉ p f = ( λy : Int . y + 1 ) : Int → Int ⇒ ⋆ h = ⌈ λg. g ( g x ) ⌉ in ⌈ h f ⌉ − → ⌈ 4 ⌉

  8. Another partly typed program—widening let x = ⌈ true ⌉ p f = ( λy : Int . y + 1 ) : Int → Int ⇒ ⋆ h = ⌈ λg. g ( g x ) ⌉ in ⌈ h f ⌉ − → blame ¯ p Negative (contravariant): blame the context containg the cast Widening can give rise to negative blame, but never positive blame

  9. Part II Blame calculus

  10. Untyped = Uni-typed ⌈ x ⌉ = x p ⌈ c ⌉ = c : A ⇒ ⋆ if ty ( c ) = A p � p ⌈ op ( � op ( ⌈ � ⇒ � if ty ( op ) = � M ) ⌉ = M ⌉ : � A ) : B ⇒ ⋆ A → B ⋆ ⌈ λx. N ⌉ = ( λx : ⋆. ⌈ N ⌉ ) : ⋆ → ⋆ ⇒ ⋆ p ⌈ L M ⌉ = ( ⌈ L ⌉ : ⋆ ⇒ ⋆ → ⋆ ) ⌈ M ⌉ (slogan due to Bob Harper)

  11. Blame calculus: Compatibility A ≺ A A ≺ ⋆ ⋆ ≺ B A ′ ≺ A B ≺ B ′ A → B ≺ A ′ → B ′

  12. Types t : � ty ( op ) = � Γ ⊢ � x : A ∈ Γ ty ( c ) = ι A → B A Γ ⊢ op ( � t ) : B Γ ⊢ x : A Γ ⊢ c : ι Γ , x : A ⊢ t : B Γ ⊢ t : A → B Γ ⊢ s : A Γ ⊢ λx : A. t : A → B Γ ⊢ t s : B Γ ⊢ s : A A ≺ B Γ ⊢ s : G p Γ ⊢ ( s : A ⇒ B ) : B Γ ⊢ ( s : G ⇒ ⋆ ) : ⋆

  13. Reductions ( λx : A. t ) v − → t [ x := v ] op ( � v ) − → δ ( op ,� v ) λx ′ : A ′ . ( v ( x ′ : A ′ p p p v : A → B ⇒ A ′ → B ′ − → ⇒ A ) : B ⇒ B ′ ) p v : ι ⇒ ι − → v p p v : A ⇒ ⋆ − → ( v : A ⇒ G ) : G ⇒ ⋆ if ⋆ � = A ≺ G p p v : ( G ⇒ ⋆ ) : ⋆ ⇒ A − → v : G ⇒ A if G ≺ A p v : ( G ⇒ ⋆ ) : G ⇒ A − → if G �≺ A blame p s − → t s − → blame p E [ s ] − → E [ t ] E [ s ] − → blame p

  14. Part III Subtyping < : + < : − < : < : n

  15. Subtype ⋆ < : ⋆ A < : G A < : ⋆ ι < : ι A ′ < : A B < : B ′ A → B < : A ′ → B ′ Example: Int < : Int Int < : Int Int < : ⋆ Int < : ⋆ ⋆ → Int < : Int → ⋆

  16. Positive subtype—widening A < : + ⋆ ι < : ι A ′ < : − A B < : + B ′ A → B < : + A ′ → B ′ Example: Int < : + ⋆ ⋆ < : − Int Int → Int < : + ⋆ → ⋆

  17. Negative subtype—narrowing ⋆ < : − A A < : − G A < : − ⋆ ι < : ι A ′ < : + A B < : − B ′ A → B < : − A ′ → B ′ Example: Int < : + ⋆ ⋆ < : − Int ⋆ → ⋆ < : − Int → Int

  18. Naive subtype A < : n ⋆ ι < : n ι A < : n A ′ B < : n B ′ A → B < : n A ′ → B ′ Example: Int < : n ⋆ Int < : n ⋆ Int → Int < : ⋆ → ⋆

  19. Part IV The Blame Theorem

  20. Safety t sf p s sf p t sf p λx. t sf p s t sf p x sf p A < : + B s sf p p s : A ⇒ B sf p A < : − B s sf p p s : A ⇒ B sf p p � = q p � = q ¯ s sf p q s : A ⇒ B sf p

  21. � The Blame Theorem Preservation If s sf p and s − → t then t sf p . Progress If s sf p then s − → blame p .

  22. � � The First Tangram Theorem A < : B if and only if A < : + B and A < : − B The First Blame Corollary p Let t be a term where s : A ⇒ B is the only subterm with label p . If A < : B then t − → blame p and t − → blame ¯ p .

  23. � � The Second Tangram Theorem A < : n B if and only if A < : + B and B < : − A The Second Blame Corollary p Let t be a term where s : A ⇒ B is the only subterm with label p . If A < : n B then t − → blame p . p Let t be a term where s : A ⇒ B is the only subterm with label p . If B < : n A then t − → blame p .

  24. A new slogan for type safety Milner (1978): Well-typed programs can’t go wrong. Felleisen and Wright (1994); Harper (2002): Well-typed programs don’t get stuck. Wadler and Findler (2008): Well-typed programs can’t be blamed.

  25. References Well-typed programs can’t be blamed Robert Bruce Findler and Philip Wadler ESOP 2009 Threesomes Jeremy Siek and Philip Wadler POPL 2010 Blame for all Amal Ahmed, Robert Bruce Findler, Jeremy Siek, Philip Wadler POPL 2011

  26. Part V TypeScript: The Next Generation

  27. F ⋆ , JavaScript, and TypeScript A fully abstract compiler from F ⋆ to JavaScript Cedric Fournet, Nikhil Swamy, Juan Chen, Pierre-Evariste Dagand, Pierre-Yves Strub, and Benjamin Livshits POPL 2013 Gradual Typing Embedded Securely in JavaScript K. Bhargavan, G. Bierman, J. Chen, C. Fournet, A. Rastogi, P. Strub, N. Swamy POPL 2014

  28. TypeScript: The Next Generation Joint proposal to MSR with Gavin Bierman. TypeScript interface declares types for third-party module. DefinitelyTyped repository declares types for 150 libraries. But the declaration is taken of faith. TypeScript TNG uses blame calculus to generate wrappers from interface declarations. But there are problems! • Wrappers on functions violate object identity. • How to interpose type checks for update? Proxies may do the job. Hypothesis: TypeScript TNG will aid debugging and increase reliablility of TypeScript and JavaScript code.

  29. A wide-spectrum type system Extend blame calculus to support a wide range of type systems: • dynamic types (as in JavaScript or Racket) • polymorphic types (as in F# or Haskell) • dependent types (as in F ⋆ or Coq) Hypothesis: a wide-spectrum type system will increase the utility of dependent types, by allowing dynamic checks to be used as a fallback when static validation is problematic.

  30. Part VI Other

  31. Other Propositions as Sessions Philip Wadler ICFP 2012 A Practical Theory of Language-Integrate Query James Cheney, Sam Lindley, and Philip Wadler ICFP 2013

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