Presentation is loading. Please wait.

Presentation is loading. Please wait.

Type Specialisation John Hughes Chalmers University.

Similar presentations


Presentation on theme: "Type Specialisation John Hughes Chalmers University."— Presentation transcript:

1 Type Specialisation John Hughes Chalmers University

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

3 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

4 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

5 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

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

7 1987: Partial Evaluation and Mixed Computation

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

9 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

10 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

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

12 1995: Neil’s Seminar @ 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.

13 1995: Neil’s Seminar @ 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?

14 1995: Neil’s Seminar @ 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!

15 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

16 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

17 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!

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

19 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´

20 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

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

22 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) …

23 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!


Download ppt "Type Specialisation John Hughes Chalmers University."

Similar presentations


Ads by Google