Specialization plugin

Simon Peyton Jones simonpj at microsoft.com
Fri Oct 28 21:14:59 UTC 2016


I’d really like to know why INLINABLE pragmas don’t work. Perhaps an example?

Only the type checker currently can conjure up dictionaries.  It would presumably not be impossible to do so later, but it’d be quite a new thing, involving invoking the constraint solver.  The pattern-match overlap checker does this; but without needing to generate any evidence bindings.

But let’s see what’s wrong with INLINABLE first.  After all if there’s a bug there, fixing it will benefit everyone.

SImon

From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Ryan Trinkle
Sent: 28 October 2016 00:06
To: ghc-devs at haskell.org
Subject: Specialization plugin

Hi everyone,

I'm trying my hand at writing a GHC plugin to generate specializations for all uses of a particular typeclass, and I've run into some trouble.  I'd appreciate it if someone could point me in the right direction!  I'm new to GHC development, so I may just be overlooking some simple stuff.

The original problem:
Reflex's interface is presented as a typeclass, which allows the underlying FRP engine to be selected by instance resolution.  Although some programs make use of this (particularly the semantics test suite), most only ever use one implementation.  However, since their code is typically written polymorphically, the implementation cannot be inlined and its rewrite rules cannot fire.  This means that the typeclass

My attempted solutions:
 * Initially, I wrote a plugin that adds INLINABLE pragmas to everything.  This helped; small programs now generally see the inlining/rule-firings I was hoping for.  However, in large programs, this does not occur.  I'm looking into this, but also trying another approach:
 * Now, I am attempting to write a plugin that adds a SPECIALIZE pragma to every binding whose type mentions Reflex.

The trouble:
Since SPECIALIZE pragmas seem to be removed during typechecking (DsBinds.dsSpec), I can't directly add them.  I would like to, perhaps, invoke Specialise.specBind; however, I'm not sure how to obtain the necessary instance - as mentioned here<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fblob%2Fc36904d66f30d4386a231ce365a056962a881767%2Fcompiler%2Fspecialise%2FSpecialise.hs%23L288&data=02%7C01%7Csimonpj%40microsoft.com%7C4f36dab755db4a4fa6c808d3febdc2db%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636132063386504026&sdata=7RujfUJye8RbuLdOVnJTac4Wm%2B7WfLsHanWZrNhGJbA%3D&reserved=0>, "only the type checker can conjure [dictionaries] up".  Perhaps it's possible to explicitly create that dictionary somewhere and extract it for use during the plugin pass?


Thanks,
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20161028/d7f83a46/attachment-0001.html>


More information about the ghc-devs mailing list