Space-Efficient Gradual Typing

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Static Contract Checking for Haskell Dana N. Xu University of Cambridge Ph.D. Supervisor: Simon Peyton Jones Microsoft Research Cambridge.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
1 Space-Efficient Gradual Typing David Herman Northeastern University Aaron Tomb, Cormac Flanagan University of California, Santa Cruz.
Safety as a Software Metric Matthias Felleisen and Robert Corky Cartwright Rice University.
Architectural Reasoning in ArchJava Jonathan Aldrich Craig Chambers David Notkin University of Washington ECOOP ‘02, 13 June 2002.
Misc. Announcements Assignment available end of the day today –Due back in 11/03 (after break) Will also update slides on website –Today Midterm next week.
Type Checking in Cool Alex Aiken (Modified by Mooly Sagiv)
MinML: an idealized programming language CS 510 David Walker.
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
Simon Peyton Jones Microsoft Research Joint work with Dana Xu, University of Cambridge Dec 2007.
Cormac Flanagan University of California, Santa Cruz Hybrid Type Checking.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 Static Contract Checking for Haskell Dana N. Xu INRIA France Work done at University of Cambridge Joint work with Simon Peyton Jones Microsoft Research.
4 Dec 2001Kestrel1 From Patterns to Programming Languages Matthias Felleisen Northeastern University.
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
Programming Language Support for Generic Libraries Jeremy Siek and Walid Taha Abstract The generic programming methodology is revolutionizing the way we.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Sound Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen Chalmers University of Technology.
11/23/2015CS2104, Lecture 41 Programming Language Concepts, COSC Lecture 4 Procedures, last call optimization.
Hack for HHVM Converting Facebook Julien Verlaguet Software Engineer.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Static Checking and Type Systems Chapter 6. 2 Static versus Dynamic Checking Static checking: the compiler enforces programming language’s static semantics.
1 Static Contract Checking for Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen.
PLAN: Packet Language for Active Networks Michael Hicks joint work with Jon Moore, Pankaj Kakkar, Carl Gunter, and Scott Nettles Switchware Project Computer.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
1 Static Contract Checking for Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Shifting the Blame A blame calculus with delimited control Taro Sekiyama* Atsushi Igarashi Soichiro Ueda Kyoto University Gradual typing.
1 Space-Efficient Gradual Typing David Herman Northeastern University Aaron Tomb, Cormac Flanagan University of California, Santa Cruz.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
A Theory of Hygienic Macros David Herman Northeastern University.
The Ins and Outs of Gradual Type Inference Avik Chaudhuri Basil Hosmer Adobe Systems Aseem Rastogi Stony Brook University.
Hybrid Type Checking An implementation of λ H David Waern Rickard Nilsson.
Lecture 9 : Universal Types
Type Checking and Type Inference
Programming Languages and Compilers (CS 421)
Component Based Software Engineering
MEMORY REPRESENTATION OF STACKS
A lightening tour in 45 minutes
Final Review In Text: Chapters 1-3, 5-11,
Midterm Review In Text: Chapters 1-3, 5, 15.
Programming Languages and Compilers (CS 421)
Final Review In Text: Chapters 1-3, 5-10,
Midterm Review In Text: Chapters 1-3, 5-10, 15.
Chap. 6 :: Control Flow Michael L. Scott.
CSE 341 Section 5 Winter 2018.
Final Review In Text: Chapters 1-3, 5-12,
Continuation Marks A john clements talk.
Organization of Programming Languages
Language-based Security
Combining Compile-Time and Run-Time Components
Search techniques.
Sub-system interfaces
Runtime Safety Analysis of Multithreaded Programs
Midterm Review In Text: Chapters 1-3, 5-11, 15.
point when a program element is bound to a characteristic or property
Programming Languages Dan Grossman 2013
Binding 10: Binding Programming C# © 2003 DevelopMentor, Inc.
Static Contract Checking for Haskell
Presentation transcript:

Space-Efficient Gradual Typing David Herman Northeastern University Aaron Tomb, Cormac Flanagan University of California, Santa Cruz

The point Naïve type conversions in functional programming languages are not safe for space. But they can and should be.

Software evolution via hybrid type checking Gradual Typing: Software evolution via hybrid type checking

Dynamic vs. static typing

Gradual typing Dynamic Typing Static Typing

Type checking let x = f() in … let y : Int = x - 3 in …

Type checking let x : ? = f() in … let y : Int = x - 3 in …

Type checking let x : ? = f() in … let y : Int = x - 3 in … - : Int × Int → Int

Type checking let x : ? = f() in … let y : Int = <Int>x - 3 in …

Type checking let x : ? = f() in … let y : Int = <Int>x - 3 in …

Evaluation let x : ? = f() in … let y : Int = <Int>x - 3 in …

Evaluation let x : ? = 45 in … let y : Int = <Int>x - 3 in …

Evaluation let y : Int = <Int>45 - 3 in …

Evaluation let y : Int = 45 - 3 in …

Evaluation let y : Int = 42 in …

Evaluation (take 2) let x : ? = f() in … let y : Int = <Int>x - 3 in …

Evaluation (take 2) let x : ? = true in … let y : Int = <Int>x - 3 in …

Evaluation (take 2) let y : Int = <Int>true - 3 in …

error: “true is not an Int” Evaluation (take 2) error: “true is not an Int”

Space Leaks

Space leaks fun even(n) = if (n = 0) then true else odd(n - 1) fun odd(n) = if (n = 0) then false else even(n - 1)

Space leaks fun even(n : Int) = if (n = 0) then true else odd(n - 1) fun odd(n : Int) : Bool = if (n = 0) then false else even(n - 1)

Space leaks fun even(n : Int) = if (n = 0) then true else odd(n - 1) fun odd(n : Int) : Bool = if (n = 0) then false else <Bool>even(n - 1)

Space leaks fun even(n : Int) = if (n = 0) then true else odd(n - 1) fun odd(n : Int) : Bool = if (n = 0) then false else <Bool>even(n - 1) non-tail call!

x Space leaks even(n) →* odd(n - 1) →* <Bool>even(n - 2) →* <Bool>odd(n - 3) →* <Bool><Bool>even(n - 4) →* <Bool><Bool>odd(n - 5) →* <Bool><Bool><Bool>even(n - 6) →* … x

Naïve Function Casts

Casts in functional languages <Int>n → n <Int>v → error: “failed cast” (if v∉Int) <σ→τ>λx:?.e → …

Casts in functional languages <Int>n → n <Int>v → error: “failed cast” (if v∉Int) <σ→τ>λx:?.e → λz:σ.<τ>((λx:?.e) z) Very useful, very popular… unsafe for space. fresh, typed proxy cast result

More space leaks fun evenk(n : Int, k : ? → ?) = if (n = 0) then k(true) else oddk(n – 1, k) fun oddk(n : Int, k : Bool → Bool) = then k(false) else evenk(n – 1, k)

More space leaks fun evenk(n : Int, k : ? → ?) = if (n = 0) then k(true) else oddk(n – 1, <Bool→Bool>k) fun oddk(n : Int, k : Bool → Bool) = then k(false) else evenk(n – 1, <?→?>k)

x More space leaks (…without even using k0!) evenk(n, k0) →* oddk(n - 1, <Bool→Bool>k0) →* oddk(n - 1, λz:Bool.<Bool>k0(z)) →* evenk(n - 2, <?→?>λz:Bool.<Bool>k0(z)) →* evenk(n - 2, λy:?.(λz:Bool.<Bool>k0(z))(y)) →* oddk(n - 3, <Bool→Bool>λy:?.(λz:Bool.<Bool>k0(z))(y)) →* oddk(n – 3, λx:Bool.(λy:?.(λz:Bool.<Bool>k0(z))(y))(x)) →* evenk(n - 4, <?→?>λx:Bool.(λy:?.(λz:Bool.<Bool>k0(z))(y))(x)) →* evenk(n - 4, λw:?.(λx:Bool.(λy:?.(λz:Bool.<Bool>k0(z))(y))(x))(w)) →* oddk(n - 5, <Bool→Bool>λw:?.(λx:Bool.(λy:?.(λz:Bool.<Bool>k0(z))(y))(x))(w)) →* oddk(n - 5, λv:Bool.<Bool>(λw:?.(λx:Bool.(λy:?.(λz:Bool.<Bool>k0(z))(y))(x))(w))(v)) →* … (…without even using k0!) x

Space-Efficient Gradual Typing

Intuition Casts are like function restrictions (Findler and Blume, 2006) Can their representation exploit the properties of restrictions?

Exploiting algebraic properties Closure under composition: <Bool>(<Bool> v) = (<Bool>◦<Bool>) v

Exploiting algebraic properties Idempotence: <Bool>(<Bool> v) = (<Bool>◦<Bool>) v = <Bool> v

Exploiting algebraic properties Distributivity: (<?→?>◦<Bool→Bool>) v = <(Bool◦?)→(?◦Bool)> v

Space-efficient gradual typing Generalize casts to coercions (Henglein, 1994) Change representation of casts from <τ> to <c> Merge casts at runtime: This coercion can be simplified! <c>(<d> e) → <c◦d>e merged before evaluating e

Space-efficient gradual typing Generalize casts to coercions (Henglein, 1994) Change representation of casts from <τ> to <c> Merge casts at runtime: <c>(<d> e) → <c◦d>e <c′>e

ü Tail recursion even(n) →* odd(n - 1) →* <Bool>even(n - 2) →* <Bool>odd(n - 3) →* <Bool><Bool>even(n - 4) →* <Bool>even(n - 4) →* <Bool>odd(n - 5) →* <Bool><Bool>even(n - 6) →* <Bool>even(n - 6) →* … ü

ü Bounded proxies evenk(n, k0) →* oddk(n - 1, <Bool→Bool>k0) →* evenk(n - 2, <?→?><Bool→Bool>k0) →* evenk(n - 2, <Bool→Bool>k0) →* oddk(n - 3, <Bool→Bool>k0) →* evenk(n - 4, <?→?><Bool→Bool>k0) →* evenk(n - 4, <Bool→Bool>k0) →* oddk(n - 5, <Bool→Bool>k0) →* … ü

Guaranteed. Theorem: any program state S during evaluation of a program P is bounded by kP · sizeOR(S) sizeOR(S) = size of S without any casts

Related work Gradual typing Function proxies Coercions Siek and Taha (2006, 2007) Function proxies Findler and Felleisen (1998, 2006): Software contracts Gronski, Knowles, Tomb, Freund, Flanagan (2006): Hybrid typing, Sage Tobin-Hochstadt and Felleisen (2006): Interlanguage migration Coercions Henglein (1994): Dynamic typing Space efficiency Clinger (1998): Proper tail recursion

Contributions Space-safe representation and semantics of casts for functional languages Supports function casts and tail recursion Three implementation strategies (coercion-passing style, trampoline, continuation marks) Earlier error detection (see paper) Proof of space efficiency

The point, again Naïve type conversions in functional programming languages are not safe for space. But they can and should be. Thank you. dherman@ccs.neu.edu