1 / 19

Normalisation by Evaluation for SML.NET

Normalisation by Evaluation for SML.NET. Sam Lindley University of Edinburgh. Outline of the talk. SML.NET NBE for  ml Implementing NBE for SML.NET Other normalisation algorithms Benchmarks Conclusions and Future work. Goals.

major
Download Presentation

Normalisation by Evaluation for SML.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Normalisation by Evaluation for SML.NET Sam Lindley University of Edinburgh

  2. Outline of the talk • SML.NET • NBE for ml • Implementing NBE for SML.NET • Other normalisation algorithms • Benchmarks • Conclusions and Future work

  3. Goals • Use SML.NET frontend to generate large terms in order to evaluate the efficiency of NBE in a non-trivial setting • Apply NBE in the actual compiler

  4. SML.NET • A whole program compiler • Uses the monadic intermediate language MIL • Does lots of rewriting • Rewriting is currently a bottleneck

  5. SML.NET compilation ML Frontend MIL Rewriting Optimised MIL Backend .NET bytecode

  6. Rewriting phases val opts = ["presimp ", "simp", "funscope", "arity", "simp", "eq", "simp", "mono", "simp", "units", "simp", "arity", "tailrec", "simp", "inline", "funscope", "simp", "floathoist", "case", "lastsimp"]

  7. Computational metalanguage (ml) Types ,  := o | ! | T  Terms (ml) M,N := c | x | x.M | M@N | hM,Ni | 1(M) | 2(M) | [M] | let x = M in N

  8. ml rewrites (-rules) (x.M)@N Ã M{N/x} i(hM1,M2i) Ã Mi let x = [M] in N Ã N{M/x} (commuting-conversions) let y = (let x = M in N) in P Ã let x = M in let y = N in P (-expansions) M Ãx.M@x M Ãh1(M),2(M)i M Ã let x = M in [x]

  9. Residualising semantics for ml « o ¬ = ml « ! ¬ = «  ¬!«  ¬ « T ¬ = («  ¬!ml) !ml « x ¬ = (x) « x.M ¬ = v.« M ¬ [x  v] « M@N ¬ = « M ¬« N ¬ « [M] ¬ k = k « M ¬ « let x = M in N ¬ k= « M ¬(v.« N ¬[x  v]k)

  10. NBE for ml # : «¬!ml (‘reify’) #o e = e #! f = x . # (f ("x)) (x “fresh”) #T c = c (v . [#v]) ": ml!«¬ (‘reflect’) "o e = e "! e = v. "(e@(#v)) "T e = k . let x = e in k ("x) (x “fresh”) norm e = #« e ¬ «c¬ = " c

  11. Some variations • Suppress  expansions • -reduction instead of expansion • shift / reset instead of local continuations • State monad instead of continuations monad (either local or global)

  12. Changes from ml to MIL • Church instead of Curry-typing • Distinction between values and computations • Arity raising • Debugging info • Effect annotations • Extra term constructors: polymorphism, sums, recursive types, exceptions, references, .NET interoperability, etc.

  13. Adapting NBE for MIL (1) • Ignore ‘unknown’ subterms • Map unknown values to * and unknown computations to [*] • Define « * ¬ v = « * ¬, « 1(*) ¬ = « * ¬, etc. • Potentially wipes out a lot of the source term

  14. Adapting NBE for MIL (2) • Treat unknown term constructors as uninterpreted constants • Reflect at the appropriate type • Necessary to include types in the semantics for -expansion

  15. Spectrum of normalisation algorithms • Naïve algorithm • Naïve algorithm + environments • Go via wnf using environments + closures • NBE

  16. Benchmarks (ms) unknown  *

  17. Benchmarks (ms) unknown  uninterpreted constant

  18. Future work / work in progress • Polymorphism • Evaluate different approaches to sums and recursive types • Exceptions • Effects • Target MIL instead of MIL • Incorporate NBE into the actual compiler

  19. Conclusions • NBE is fast • Carefully optimised normalisers can sometimes be even faster (but start to look very much like NBE) • NBE is a useful implementation tool • NBE algorithms can be derived by program translation

More Related