Type Specialisation John Hughes Chalmers University.

Slides:



Advertisements
Similar presentations
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
Advertisements

Debugging Natural Semantics Specifications Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information Science.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Kathleen Fisher cs242 Reading: “A history of Haskell: Being lazy with class”,A history of Haskell: Being lazy with class Section 6.4 and Section 7 “Monads.
Chair of Software Engineering From Program slicing to Abstract Interpretation Dr. Manuel Oriol.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
1 Introduction to Data Types (Section 7.1) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
CS ExCo Advanced in Topics Object-Oriented Programming.
Distributed Meta- Programming Rui Shi, Chiyan Chen and Hongwei Xi Boston University.
Lightweight Abstraction for Mathematical Computation in Java 1 Pavel Bourdykine and Stephen M. Watt Department of Computer Science Western University London.
A Type System for Well-Founded Recursion Derek Dreyer Carnegie Mellon University POPL 2004 Venice, Italy.
Tim Sheard Oregon Graduate Institute Lecture 4: Staging Interpreters CSE 510 Section FSC Winter 2004 Winter 2004.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Architectural Modeling Notations.
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Previous finals up on the web page use them as practice problems look at them early.
Generative type abstraction and type-level computation (Wrestling with System FC) Stephanie Weirich, Steve Zdancewic University of Pennsylvania Dimitrios.
Distributed Meta- Programming (To appear GPCE’06) Rui Shi, Chiyan Chen and Hongwei Xi Boston University.
Dynamic Semantics COS 441 Princeton University Fall 2004.
Tag-Elimination and Jones Optimality Walid Taha (Yale) Henning Makholm (DIKU) John Hughes (Chalmers)
1 A Short Introduction to (Object-Oriented) Type Systems Kris De Volder.
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.
Data Flow in Static Profiling Cathal Boogerd, Delft University, The Netherlands Leon Moonen, Simula Research Lab, Norway ?
Staging in Haskell What is Staging What does it Mean Using Template Haskell.
Elimination Day 2. When the two equations don’t have an opposite, what do you have to do? 1.
CMSC 202 Lesson 19 Polymorphism 2. Warmup What is wrong with the following code? What error will it produce? (Hint: it already compiles) for (unsigned.
Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint Edwin Westbrook, Mathias Ricken, and Walid Taha.
Dan Johnson.  Functional language that started development in  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
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.
Compiling Functional Programs Mooly Sagiv Chapter 7
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
Singleton Kinds and Singleton Types Christopher A. Stone August 2, 1999 Thesis Committee Bob Harper, chair Peter Lee John Reynolds Jon Riecke (Bell Laboratories)
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
CS 2104 – Prog. Lang. Concepts Functional Programming II Lecturer : Dr. Abhik Roychoudhury School of Computing From Dr. Khoo Siau Cheng’s lecture notes.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Deriving Pre-Condition for ABCE1 Deriving Preconditions for Array Bound Check Elimination Dana N. XU Joint work with W.N. CHIN and S.C. KHOO Dept of Computer.
Bridging the Gap between TDPE and SDPE Eijiro Sumii Department of Information Science, Graduate School of Science, University of Tokyo.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Inheritance 2 Mehdi Einali Advanced Programming in Java 1.
First Order Haskell Neil Mitchell York University λ.
A Staged Semantics of Overloading (preliminary) Bill Harrison & Tim Sheard.
Types and Programming Languages
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Shifting the Blame A blame calculus with delimited control Taro Sekiyama* Atsushi Igarashi Soichiro Ueda Kyoto University Gradual typing.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Virtual Functions Outline 20.1Introduction 20.2Type Fields and switch Statements 20.3Virtual.
The Ins and Outs of Gradual Type Inference Avik Chaudhuri Basil Hosmer Adobe Systems Aseem Rastogi Stony Brook University.
CPSC 252Inheritance II Page 1 Inheritance & Pointers Consider the following client code: const int MAXCLOCKS = 2; Clock* clockPtr[ MAXCLOCKS ]; clockPtr[0]
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);
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
Type Checking and Type Inference
CS 326 Programming Languages, Concepts and Implementation
Tim Sheard Oregon Graduate Institute
Michael Leuschel Declarative Systems & Software Engineering
Chapter 4: Types.
Objective caml Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 18, 2002.
Implicit Differentiation
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
Semantic Analysis Chapter 6.
8 Code Generation Topics A simple code generator algorithm
Polymorphism 2 CMSC 202.
CMSC 202 Lesson 19 Polymorphism 2.
Advanced Functional Programming
Computer Science II for Majors
Presentation transcript:

Type Specialisation John Hughes Chalmers University

Type Specialisation (With thanks to Neil Jones) John Hughes Chalmers University

1985: A Weird Program Called MIX! The Mix Equation (mix prog x) y = prog x y The Futamura Projections  Specialised program mix interp prog = code because code data = interp prog data

1985: A Weird Program Called MIX! The Mix Equation (mix prog x) y = prog x y The Futamura Projections  Specialised program mix mix interp = compiler because compiler prog = mix interp prog = code

1985: A Weird Program Called MIX! The Mix Equation (mix prog x) y = prog x y The Futamura Projections  Specialised program mix mix mix = compiler-generator because compiler-generator interp = mix mix interp = compiler

Why Did He Use Scheme? Why not: A language with lazy evaluation? A language with types?

1987: Partial Evaluation and Mixed Computation

A ”Hughes” a measure of the irrelevance of a talk to the workshop topic.

1987: Partial Evaluation and Mixed Computation Challenging Problems eliminating tags from typed interpreters data V = N Int | F (V -> V) eval  (Const n) = N n eval  (Lam x e) = F ( v. eval (bind x v  ) e) … Lam ”x” (Const 3) F ( v. N 3) mix

1987: Partial Evaluation and Mixed Computation Challenging Problems eliminating tags from typed interpreters type specialisation data V = N Int | F (V -> V) … Int Int->Int (Int->Int)->Int

1987: Partial Evaluation and Mixed Computation Challenging Problems eliminating tags from typed interpreters type specialisation optimal specialisation of typed interpreters mix self-interp prog  prog x. 3 F ( x. N 3)

1995: Neil’s Chalmers How can we recognise an interpreter for a strongly typed language? How can we derive a type-checker from an interpreter? An approach for a first-order language.

1995: Neil’s Chalmers How can we recognise an interpreter for a strongly typed language? How can we derive a type-checker from an interpreter? An approach for a first-order language. Surely one can do better?

1995: Neil’s Chalmers How can we recognise an interpreter for a strongly typed language? How can we derive a type-checker from an interpreter? An approach for a first-order language. Invitation to Dagstuhl Seminar on Partial Evaluation!

Key Idea: Offline Partial Evaluation Annotations in the source code classify operations as static -- performed by mix dynamic -- built into residual program eval  (Const n) = N (lift n) eval  (Lam x e) = F ( v. eval (bind x v  ) e) … bind x v  = y. if x=y then v else  y Underlined operations are dynamic

Key Idea: Offline Partial Evaluation Annotations in the source code classify operations as static -- performed by mix dynamic -- built into residual program eval  (Const n) = N (lift n) eval  (Lam x e) = F ( v. eval (bind x v  ) e) … bind x v  = y. if x=y then v else  y Lam ”x” (Const 3) F ( v. N 3) mix

Key Idea: Offline Partial Evaluation Annotations in the source code classify operations as static -- performed by mix dynamic -- built into residual program eval  (Const n) = N (lift n) eval  (Lam x e) = F ( v. eval (bind x v  ) e) … bind x v  = y. if x=y then v else  y Don’t underline the tags! But we have to!

Interesting Properties N (z+lift 1)N Int x. case x of N n -> N (n+lift 1) F f -> … N Int -> N Int N (z+lift 1)N Int

Keep Track of Tags by Type Inference! e  e´ :  ´  ´ ::= Int |  ´->  ´ | C  ´ Residual types  |- e  e´ :  ´  |- C e  e´ : C  ´  |- e  e´ : Ck  1´ , xk  e´ :  1´ |- ek  ek´ :  2´  |- case e of {Cj xj -> ej}  ek´ :  2´

Reformulate Partial Evaluation in Terms of Type Inference e  e´ :  ´  ´ ::= Int |  ´->  ´ | C  ´ | n | … Residual types x. x+1  x.  : 2 -> 3 x. x+z  : close in x. x+z

Real Increase in Power Type specialisation = Type-based analysis + type-directed transformation Examples Monomorphisation Typed defunctionalisation Constructor specialisation for -calculus By type-specialising a suitable interpreter.

Continuing Work Simple type specialiser as a back-end for PE to achieve optimality (PADO II). Principal type specialisations. Strategies for controlling polyvariance (type-based cloning) …

Continuing Work Simple type specialiser as a back-end for PE to achieve optimality (PADO II). Principal type specialisations & polymorphism. Strategies for controlling polyvariance (type-based cloning) … Thank you Neil!