<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1214347725;
mso-list-type:hybrid;
mso-list-template-ids:-463033184 134807553 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoPlainText" style="margin-left:36.0pt">However, looking at the pass order in `SimplCore`, specialisation runs very early before any major simplification but SpecConstr runs very late right at the end of the pipeline. Does anyone know the justification
for this?<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Here’s my thought<o:p></o:p></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoPlainText" style="mso-list:l0 level1 lfo1">Typeclass specialisation makes a specialised copy of a function in which many higher order calls (via the dictionary) are replaced with calls to known functions. That exposes LOTS of stuff to all phases
of optimisation including the strictness analyser. So running it early is good.<o:p></o:p></li><li class="MsoPlainText" style="mso-list:l0 level1 lfo1">Moreover typeclass specialisation is exposed simply by type at which we call an overloaded function, and that is apparent early. So running it early is OK.<o:p></o:p></li><li class="MsoPlainText" style="mso-list:l0 level1 lfo1">SpecConstr just eliminates data constructor allocation and case expressions, so it is less likely to unleash a cascade of further optimisations.
<o:p></o:p></li><li class="MsoPlainText" style="mso-list:l0 level1 lfo1">Moreover, SpecConstr only works when we have f (a:b), and calls like that are more likely to be exposed after we’ve optimised the program. So do it late.<o:p></o:p></li></ul>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">All of these things are doubtless only sort-of-true. Concrete examples to the contrary would be useful.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Simon<o:p></o:p></p>
<p class="MsoPlainText">-----Original Message-----<o:p></o:p></p>
<p class="MsoPlainText">From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Joachim Breitner<o:p></o:p></p>
<p class="MsoPlainText">Sent: 20 March 2018 13:42<o:p></o:p></p>
<p class="MsoPlainText">To: ghc-devs@haskell.org<o:p></o:p></p>
<p class="MsoPlainText">Subject: Re: Why does SpecConstr run far later than specialisation<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Hi,<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Am Dienstag, den 20.03.2018, 13:23 +0000 schrieb Matthew Pickering:<o:p></o:p></p>
<p class="MsoPlainText">> As far as I understand it, the goals of SpecConstr and specialisation
<o:p></o:p></p>
<p class="MsoPlainText">> are the same. One works for normal value arguments and one works for
<o:p></o:p></p>
<p class="MsoPlainText">> special type class dictionary arguments.<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> However, looking at the pass order in `SimplCore`, specialisation runs
<o:p></o:p></p>
<p class="MsoPlainText">> very early before any major simplification but SpecConstr runs very
<o:p></o:p></p>
<p class="MsoPlainText">> late right at the end of the pipeline.<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> Does anyone know the justification for this? It seems intuitively that
<o:p></o:p></p>
<p class="MsoPlainText">> they should work in the same way.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Just a guess: We want the demand analyzer to run before SpecConstr, because I expect that there are many functions where both the demand analyzer are happy to do something, and SpecConstr is happy to do something, but the worker-wrapper
done by DmdAnal is strictly preferable (no code duplication, for example.)<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">But the Specializer and the demand analyzer have no overlap, and we we do want to strictness-analyzer the type-class-specialized code.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">But as I said, it’s just a guess.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Cheers,<o:p></o:p></p>
<p class="MsoPlainText">Joachim<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">--<o:p></o:p></p>
<p class="MsoPlainText">Joachim “nomeata” Breitner<o:p></o:p></p>
<p class="MsoPlainText"> mail@joachim-breitner.de<o:p></o:p></p>
<p class="MsoPlainText"> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.joachim-breitner.de%2F&data=04%7C01%7Csimonpj%40microsoft.com%7Cff102ef484bd411807e108d58e68796c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636571501747132026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=R1t%2FW5BJeJPausEfMIfbYOgwj5qLaX5Hda4Z4LwDoJk%3D&reserved=0<o:p></o:p></p>
</div>
</body>
</html>