<div dir="ltr">I definitely plan to investigate the INLINABLE thing.  In small programs, it all appears to be working as expected.  However, in a larger (~50 modules) client project, I think (but have not 100% confirmed) that it is not specializing everything.  The Core certainly has a good number of Reflex dictionaries floating around (I would ideally hope that they would all be eliminated).  Perhaps there is an issue relating to INLINABLE crossing many module or package boundaries.<div><br></div><div>I'll follow up when I have more info about exactly how that's breaking, along with an example I can share (the current one is confidential to my client).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 28, 2016 at 5:14 PM, Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple">
<div class="m_5233268238201574545WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">I’d really like to know why INLINABLE pragmas don’t work. Perhaps an example?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">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. 
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">But let’s see what’s wrong with INLINABLE first.  After all if there’s a bug there, fixing it will benefit everyone.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">SImon<u></u><u></u></span></p>
<p class="MsoNormal"><a name="m_5233268238201574545__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u> <u></u></span></a></p>
<span></span>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@<wbr>haskell.org</a>]
<b>On Behalf Of </b>Ryan Trinkle<br>
<b>Sent:</b> 28 October 2016 00:06<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Specialization plugin<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Hi everyone,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
The original problem:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
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 <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
My attempted solutions:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
 * 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:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
 * Now, I am attempting to write a plugin that adds a SPECIALIZE pragma to every binding whose type mentions Reflex.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
The trouble:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
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
<a href="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" target="_blank">
here</a>, "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?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Ryan<u></u><u></u></p>
</div>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>