Normalisation by Evaluation for SML.NET - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Normalisation by Evaluation for SML.NET

Description:

Use SML.NET frontend to generate large terms in order to evaluate ... 'inline', 'funscope', 'simp', 'floathoist', 'case', 'lastsimp'] Computational metalanguage ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 20
Provided by: samli
Category:

less

Transcript and Presenter's Notes

Title: Normalisation by Evaluation for SML.NET


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_at_N
  • hM,Ni ?1(M) ?2(M)
  • M let x M in N

8
?ml rewrites
  • (?-rules)
  • (?x.M)_at_N Ã MN/x
  • ?i(hM1,M2i) Ã Mi
  • let x M in N Ã NM/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_at_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_at_N ? M ? N ?
  • M ? k k M ?
  • let x M in N ? k M ?(?v. N ?x ? vk)

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_at_(?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 ?
naïve env env/wnf NBE
sort 105 1.24 0.44 0.84
hamlet 5388 16.11 7.01 12.91
raytrace 779 4.94 2.18 3.81
bootstrap 84817 85.01 67.48 137.19
17
Benchmarks (ms)
unknown ? uninterpreted constant
env env/wnf NBE
sort 151 117 101
hamlet 18105 7850 5407
raytrace 914 590 645
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
Write a Comment
User Comments (0)
About PowerShow.com