Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting RULES to fire before HERMIT starts #177

Open
roboguy13 opened this issue Sep 22, 2016 · 5 comments
Open

Getting RULES to fire before HERMIT starts #177

roboguy13 opened this issue Sep 22, 2016 · 5 comments
Labels

Comments

@roboguy13
Copy link
Member

Is there a way to get all rewrite RULES that GHC would normally apply to fire before HERMIT's REPL starts running? Or is there a HERMIT command that would do something along those lines (to fire all RULES that currently apply everywhere)?

@xich
Copy link
Member

xich commented Sep 22, 2016

If you want to do it the 'real' way, you could run HERMIT later in the pipeline, after the first round of simplification and rule application.

If you want to be able to do it on a whim, you can (with the diff I just pushed):

do
  f <- compileRulesT (const True) -- all rules
  repeatR $ anytdR (runFoldR f)

But that is not quite the same as what GHC does, because there can be specialization rules on binders. For that you'd need (I'm speculating, haven't typechecked):

do
  f <- compileRulesT (const True)
  repeatR $ anytdR $ runFoldR f <+ (contextonlyT hermitCoreRules >>= unfoldRulesR)

(essentially, the bit after <+ is getting all the spec rules accumulated in the context at each point in the AST and compiling and running those separately)

You could just repeatR $ anytdR $ (map snd <$> getHermitRulesT) >>= unfoldRulesR, but compiling the top-level stuff beforehand will be a huge perf win.

@roboguy13
Copy link
Member Author

@xich Thanks! This might be slightly off-topic but if I were to write a GHC plugin, how would I tell the system to run it later in the pipeline (after the RULES have fired)?

@xich
Copy link
Member

xich commented Oct 4, 2016

If you're using hermitPlugin, you can use one of the guards here:

----------------------------- guards ------------------------------

@xich
Copy link
Member

xich commented Oct 4, 2016

If you are using the default HERMIT (invoking via hermit command as normal), there is a -pN flag, where N is the desired position in the pipeline. PluginM is much more precise though.

@roboguy13
Copy link
Member Author

@xich Well, right now I'm trying to develop a small plugin, which is why this is probably slightly off-topic =). Using HERMIT would be tricky at the moment because hermit-shell isn't working on GHC 8 for the time being and compileRulesT isn't exposed (although that second one would be a fairly quick fix). I've tried appending my pass to the end of the list of passes, but that didn't seem to make a difference (not fully sure though). The list of passes provided to the plugin seems to only contain one element too, which is surprising to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants