Analysis of Functional Transformation and Programs Neil Mitchell - - PDF document

analysis of functional transformation and programs
SMART_READER_LITE
LIVE PREVIEW

Analysis of Functional Transformation and Programs Neil Mitchell - - PDF document

Analysis of Functional Transformation and Programs Neil Mitchell The Thesis Catch Uniplate Checking, safer Generic, shorter Supero Firstify Optimisation, faster Defunctionalisation Uniplate Generics library (similar to SYB1)


slide-1
SLIDE 1

Transformation and Analysis of Functional Programs

Neil Mitchell

slide-2
SLIDE 2

The Thesis Uniplate

Generic, shorter

Firstify

Defunctionalisation

Catch

Checking, safer

Supero

Optimisation, faster

slide-3
SLIDE 3

Uniplate

  • Generics library (similar to SYB1)
  • Write concise traversals over structures
  • Collect all variables in an expression:

[v | Var v <- universe x]

  • Make all variables title-case:

transform f where f (Var (x:xs)) = Var (toUpper x : xs) f x = x

slide-4
SLIDE 4

Uniplate advantages

  • No/few extensions
  • Simple types
  • Concise (~40% shorter than SYB)
  • Fast (at least 50% faster than SYB)
  • Makes use of compiler support
  • Does common stuff well
slide-5
SLIDE 5

Supero

  • A supercompiler

– Evaluate the program at compile time – Resituate so you terminate

  • Old ideas, but rarely implemented

– Supercompilation from Turchin – Homeomorphic embedding from Glück

  • First attempt for Haskell
slide-6
SLIDE 6

Supero improvements

  • New contributions

– A strategy for let bindings – A better generalisation

  • Competitive with C (microbenchmarks)
  • Faster than GHC (small benchmarks)
  • Still a prototype, lots of choices to make
slide-7
SLIDE 7

Firstify

  • Partial defunctionalisation +

First-order analysis method = Higher-order analysis method

  • Take several ingredients

– Arity raising, inlining, specialisation – Add termination bounds

slide-8
SLIDE 8

Firstify results

  • Very practically motivated

– Works well on the nofib suite

  • Stress test: print (0 :: Double)

– Makes use of Arrays, IO Monad, IO Function, Show Continuation, list comprehensions..

slide-9
SLIDE 9

Catch

  • Automatic safety proof

– If Catch says “Safe”, your program will not crash by calling error

  • First-order language (needs Firstify)
  • Division into two parts

– An algorithm (deals with Core) – A constraint language (the lossy bit)

slide-10
SLIDE 10

Catch constraints

  • Constraints must:

– Be finite (for a given type) – Provide three operations – The operations must be consistent

  • MP-constraints represent data type

patterns in a finite way

slide-11
SLIDE 11

Catch results

  • Tried on HsColour

– Real program, real users – Even a web service (hpaste.org) – Found 3 real bugs, now fixed – 1 false positive, but a nice refactoring

  • Very automatic, but still powerful
slide-12
SLIDE 12

Current status

  • Uniplate: already widely used
  • Supero: proof of concept
  • Firstify: works well enough for Catch
  • Catch: useful in some situations