owickstrom / idris-vimscript

Compile Idris to Vimscript, like you always wanted.
Other
130 stars 5 forks source link

Choose optimisations to enable based on command-line arguments #7

Closed mrkgnao closed 6 years ago

mrkgnao commented 6 years ago

Idea

The idris executable can pass arguments to code generators like idris-codegen-vim via a flag:

$ idris --help
<snip>
  --cg-opt ARG             Arguments to pass to code generator

We can use this to enable or disable specific optimisations from the command-line. This will be useful when we work on mutual tail-call optimisation, since that will likely be buggy in the initial stages and should preferably be turned off by default.

For starters, a --disable-dead-code-elimination flag would be a good proof-of-concept.

How

The getOpts function in the top-level Main module controls the handling of command-line arguments. We need to parse flags, send them through as additional parameters to the codegenVim function, which will eventually use them to choose what optimisations does.

Further plans

Later, we can expand this into optimisation levels (-O0 or -O2 etc) when we start running heavier transformations.

adicirstei commented 6 years ago

My guess is that this is where the magic happens:

performTransforms :: Program -> Program
performTransforms =
  Annotate.runPass . TCO.runPass . DCE.runPass . Renamer.runPass

Do you have an example where DCE makes at least one line of a difference?

mrkgnao commented 6 years ago

I think every program - even a simple main = pure () -- has tons of dead code that DCE eliminates. In particular, if you disable the DCE pass and try compiling that program, you will find lots of *peek* functions (byte-level operations, I think) that DCE removes otherwise.

Edit: you're right that that's where you need to look.

adicirstei commented 6 years ago

Hi, I've implemented something, you can find in my fork.

We might consider adding some specialized arguments parsing library, but maybe the project is still too young.

adicirstei commented 6 years ago

I'm pretty confident the DCE on github/master is not doing much to the output. Or I am missing something obvious. :) with all optimisation in place without DCE