Intensional Polymorphism in Type-Erasure Semantics Karl Crary, Stephanie Weirich, Greg Morrisett Presentation by Nate Waisbrot.

Slides:



Advertisements
Similar presentations
Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
Advertisements

Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
ICFP Principals in Programming Languages: A Syntactic Proof Technique Steve Zdancewic Dan Grossman and Greg Morrisett Cornell University.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Type Analysis and Typed Compilation Stephanie Weirich Cornell University.
The Semantic Soundness of a Type System for Interprocedural Register Allocation and Constructor Registration Torben Amtoft Kansas State University joint.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Type inference and modern type systems Stephanie Weirich University of Pennsylvania.
Cs784(TK)1 Semantics of Procedures and Scopes. Kinds of Scope Static or Lexical scope –determined by structure of program –Scheme, C++, Java, and many.
CSE341: Programming Languages Lecture 27 Generics vs. Subtyping; Bounded Polymorphism Dan Grossman Fall 2011.
Typed Compilation of Recursive Datatypes Joseph C. Vanderwaart, Derek Dreyer, Leaf Petersen, Karl Crary, Robert Harper, and Perry Cheng Carnegie Mellon.
C12, Polymorphism “many forms” (greek: poly = many, morphos = form)
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Type Checking.
Catriel Beeri Pls/Winter 2004/5 last 55 Two comments on let polymorphism I. What is the (time, space) complexity of type reconstruction? In practice –
1 Objects and ClassesStefan Kluth 1.6Objects and Classes 1.6What is an Object? 1.7Objects and Classes 1.8Object Interface, Class Inheritance, Polymorphism.
Typed Assembly Languages COS 441, Fall 2004 Frances Spalding Based on slides from Dave Walker and Greg Morrisett.
C. Varela1 Typing and Parameter Passing Dynamic and Static Typing (EPL 4.1-4, VRH 2.8.3) Parameter Passing Mechanisms (VRH 6.4.4) Carlos Varela RPI.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
Survey of Typed Assembly Language (TAL) Introduction and Motivation –Conventional untyped compiler < Typed intermediate languages –Typed intermediate language.
01/17/20031 Guarded Recursive Datatype Constructors Hongwei Xi and Chiyan Chen and Gang Chen Boston University.
Typed Memory Management in a Calculus of Capabilities David Walker (with Karl Crary and Greg Morrisett)
Good Advice for Type-directed Programming Aspect-oriented Programming and Extensible Generic Functions Geoffrey Washburn [ ] Joint.
STAL David Walker (joint work with Karl Crary, Neal Glew and Greg Morrisett)
Existential Types for Imperative Languages Dan Grossman Cornell University Eleventh European Symposium on Programming April 2002.
Approaches to Typing Programming Languages Robert Dewar.
Closure and Environment Compiler Baojian Hua
LX: A Language for Flexible Type Analysis Stephanie Weirich Cornell University joint work with Karl Crary (CMU)
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Generic Subroutines and Exceptions CS351 – Programming Paradigms.
Inheritance and Polymorphism CS351 – Programming Paradigms.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
COP4020 Programming Languages
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
CS112: Structure of Programming Languages A smorgasbord of topics in programming languages including programming paradigms and syntax, semantics, implementation.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Universal Types Report by Matthias Horbach. Contents Types of Polymorphism System F Basic Properties Erasure Impredicativity Parametricity.
Singleton Kinds and Singleton Types Christopher A. Stone August 2, 1999 Thesis Committee Bob Harper, chair Peter Lee John Reynolds Jon Riecke (Bell Laboratories)
12/2/20151 GC16/3011 Functional Programming Lecture 2 The Lambda Calculus: A Simple Introduction.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
Session 24 Chapter 12: Polymorphism. Polymorphism polymorphism comes from the Greek root for “many forms” polymorphism is about how we can use different.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
A Staged Semantics of Overloading (preliminary) Bill Harrison & Tim Sheard.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Wel come To Seminar On C#.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Chapter 4: Types. Why Have Types? Detect simple kinds of errors: int square(int x) { return x*x; }... int bogus = square(“hello”); String bogus2 = square(3);
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Winter 2013.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2017.
CSE-321 Programming Languages Simply Typed -Calculus
Compiler Construction (CS-636)
Chapter 4: Types.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Zach Tatlock Winter 2018.
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2017.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2019.
Presentation transcript:

Intensional Polymorphism in Type-Erasure Semantics Karl Crary, Stephanie Weirich, Greg Morrisett Presentation by Nate Waisbrot

Authors' background Part of Cornell University's TAL (Typed Assembly Language) group Creating intermediate languages to compile into TAL

Three styles of polymorphism Get a value and inspect its type –Easy and efficient, but not powerful Pass types as first-class objects –Powerful, but slow and complicated for the compiler Pass values which represent types –Best of both worlds

Passing values Recall the paper "Dynamically Typing in a Statically Typed Language" (Abadi, Cardelli, Pierce, and Plotkin) Types are tied to values -- you can't have one without the other

Dynamic types Dynamic(5  int)dynamic value f : dynamic  dynamicdynamic function x:dynamic. typecase x of int  …   …     …

Passing types Values are described by types Types are described by kinds We could keep going… (System F  )

Overview of System F . x: .xThe polymorphic identity function .  The type of the identity function iden [int] 5Application of the identity function . . x: . y: . (x  y)a pair function . . (    )its type pair [int] [string] 0 “zero”application

Overview of i ML Start with System F, add the ability to work with types alone . .    the pair-type function Type  Type  Typethe kind of the pair-type function pairT [int] [string]this gives us the type (int  string) Now add the typecase construct: typecase [ .int]  substitute  for  and return an int int  0

i ML syntax  ::= Type |  c ::=  | int | c  c | c  c |  : .c | c c | Typerec c(c int, c , c  )  ::= c |  |    |  : .  e ::= x | i | x: .e | fix f: .v | e e | |  e |  : .v | e[c] | typecase [ .  ] … v::= i | x: .e | fix f: .v | |  : .v

Typing hierarchy 56 x:int.x int int  int Type types: values: .  Type  Type kinds:

What's wrong with type passing? Types must be kept separate from values –Doubles the type-checker's work –Compiling it down to TAL is hard Language semantics require types to always be passed

Solution: type representations Make new type, "representation" Get back all the simplicity of normal value- passing As a bonus, gain some abstraction

Overview of type representations R  (R int,R int )The representation of int  int R( R(int)  R(int) )Its type

Syntax of R  ::= Type |  c ::=  | int | c  c | c  c |  : .c | c c | R(c) | Typerec c(c int, c , c , c R )  ::= c |  |    |  : .  |  : .  e ::= x | i | x: .e | fix f: .v | e e | |  e |  : .v | e[c] | pack e as .  hiding  | unpack = e in e | R int | R  (e,e) | R  (e,e) | R R (e) | typecase [ .c] … v::= i | x: .e | fix f: .v | |  : .v | pack v as .  hiding  | R int | R  (v,v) | R  (v,v) | R R (v)

TypeToString: dynamic types typeToString : dynamic  string x:dynamic. typecase x of int  "int" string  "string"   "function"  ×   "<" + typeToString Dynamic(    1 x) + "," + typeToString Dynamic(    2 x) + ">" 

TypeToString: type-passing fix typeToString :  :Type.string.  :Type. typecase [ .string]  of int  "int" string  "string"   typeToString [  ] + "  " + typeToString [  ]  ×   "<" + typeToString [  ] + "," + typeToString [  ] + ">"

TypeToString: type representations fix typeToString :  :Type.R(  )  string.  :Type. x:R(  ). typecase [ .string] x of R int  "int" R string  "string" R  (x,y) as   typeToString [  ] x + "  " + typeToString [  ] y R × (x,y) as  ×   "<" + typeToString [  ] x + "," + typeToString [  ] y + ">"

Type erasure A well-typed program in typed -calculus has an equivalent in untyped -calculus Typed: x: .x Untyped: x.x

TypeToString: with types erased fix typeToString :  :Type.R(  )  string.  :Type. x:R(  ). typecase [ .string] x of R int  "int" R string  "string" R  (x,y) as   typeToString [  ] x + "  " + typeToString [  ] y R × (x,y) as  ×   "<" + typeToString [  ] x + "," + typeToString [  ] y + ">"

Type refinement Do dead-code elimination based on the type of the representation Propagate information about the type of an argument back through the function

Monomorphic closure x: .yA function with a free variable  Its type (if y has type  ) We want to eliminate free variables f = ( (x  e):   env.  y e)  The closed function  env.((   env)   )  envIts type

Polymorphic closure The same closed function, with type passing  :Kind.  env:Type.  : .  :  = . ((   env)   )  env

Closure with representations f’ =  x:(   R(  )).  2 x f’ : (   R(  ))   f’’ = pack (f’’  R  ) as  env.((   env)   )  env hiding R(  ) f’’ :  env.((   env)   )  env

Summary Create a value to represent a type Pass the value, not the type Passing values is easy Knowing types at runtime is useful