<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:"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;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
.MsoPapDefault
        {mso-style-type:export-only;
        margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:6.0pt;
        margin-left:0cm;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></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="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal" style="margin-left:36.0pt">My question is earlier: why do we generate code that we will never to get out again?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ah, well, if you say, for example<o:p></o:p></p>
<p class="MsoNormal">                f x = f x<o:p></o:p></p>
<p class="MsoNormal">then it seems reasonably to generate an infinite loop.   I don’t know if that’s what’s happening here, but it seems reasonable in principle.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m unsure about what you are proposing to change.<o:p></o:p></p>
<p class="MsoNormal"><br>
Simon<span style="mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<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">From:</span></b><span lang="EN-US"> Moritz Angermann <moritz.angermann@gmail.com>
<br>
<b>Sent:</b> 17 August 2020 13:28<br>
<b>To:</b> Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Cc:</b> ghc-devs <ghc-devs@haskell.org><br>
<b>Subject:</b> Re: The curious case of #367: Infinite loops can hang Concurrent Haskell<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
On Mon, 17 Aug 2020 at 8:14 PM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
|  and the question then becomes, do we want to investigate if we can<br>
<br>
|  a) detect this is dead code<br>
<br>
|  b) remove it in Cmm or higher, or flat out prevent it from being<br>
<br>
|  generated.<br>
<br>
|  c) we don't care about producing this code, and hope the linker will<br>
<br>
|  eliminate it.<br>
<br>
<br>
<br>
I'm still puzzled.  Why do you thing _cCO is dead?  What alternative code are you thinking we might generate?<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
My question is earlier: why do we generate code that we will never to get out again? The generated code is effectively: while(true);.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
This code does not have to be dead, and there may very well be reasons why we want to generate an infinite loop that can only be terminated from the outside. Maybe it’s just my naive expectation that the user more likely did not want to generate this code.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Once _cCO is entered, there is no way out for the application.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
 Moritz<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
<br>
<br>
<br>
<br>
S<br>
<br>
<br>
<br>
|  -----Original Message-----<br>
<br>
|  From: Moritz Angermann <<a href="mailto:moritz.angermann@gmail.com" target="_blank">moritz.angermann@gmail.com</a>><br>
<br>
|  Sent: 17 August 2020 10:30<br>
<br>
|  To: Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br>
<br>
|  Cc: ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
<br>
|  Subject: Re: The curious case of #367: Infinite loops can hang<br>
<br>
|  Concurrent Haskell<br>
<br>
|  <br>
<br>
|  Hi Simon,<br>
<br>
|  <br>
<br>
|  sure, I could have been a bit clearer:<br>
<br>
|  <br>
<br>
|  Code we currently generate is:<br>
<br>
|  ```<br>
<br>
|   _cCO:<br>
<br>
|          bl _cCO<br>
<br>
|  ```<br>
<br>
|  <br>
<br>
|  or<br>
<br>
|  <br>
<br>
|  ```<br>
<br>
|   _czf:<br>
<br>
|          mov x17, x18<br>
<br>
|          bl _czf<br>
<br>
|  ```<br>
<br>
|  <br>
<br>
|  and the question then becomes, do we want to investigate if we can<br>
<br>
|  a) detect this is dead code<br>
<br>
|  b) remove it in Cmm or higher, or flat out prevent it from being<br>
<br>
|  generated.<br>
<br>
|  c) we don't care about producing this code, and hope the linker will<br>
<br>
|  eliminate it.|  <br>
<br>
|  Cheers,<br>
<br>
|    Moritz<br>
<br>
|  <br>
<br>
|  On Mon, Aug 17, 2020 at 5:18 PM Simon Peyton Jones<br>
<br>
|  <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<br>
<br>
|  ><br>
<br>
|  > Moritz<br>
<br>
|  ><br>
<br>
|  > I'm not getting this.<br>
<br>
|  ><br>
<br>
|  > |  So, my question then is this: are we fine with ghc generating<br>
<br>
|  this<br>
<br>
|  > |  code? Or, if we are not, do we want to figure out if we can<br>
<br>
|  eliminate<br>
<br>
|  > |  it?<br>
<br>
|  ><br>
<br>
|  > What exactly is "this code" and "it"?<br>
<br>
|  ><br>
<br>
|  > You could be asking<br>
<br>
|  ><br>
<br>
|  > * Should we switch off -fomit-yields by default?<br>
<br>
|  > * Should we implement -fno-omit-yields in a cleverer way that<br>
<br>
|  generates less code?<br>
<br>
|  ><br>
<br>
|  > Or you could be asking something else again.<br>
<br>
|  ><br>
<br>
|  > Your deadlock-detection patch (which is presumably not in GHC) is<br>
<br>
|  very special-case: it detects some infinite loops, but only some.<br>
<br>
|  I'm not sure what role it plays in your thinking.<br>
<br>
|  ><br>
<br>
|  > Simon<br>
<br>
|  ><br>
<br>
|  ><br>
<br>
|  > |  -----Original Message-----<br>
<br>
|  > |  From: ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>> On Behalf Of Moritz<br>
<br>
|  > |  Angermann<br>
<br>
|  > |  Sent: 17 August 2020 09:40<br>
<br>
|  > |  To: ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
<br>
|  > |  Subject: The curious case of #367: Infinite loops can hang<br>
<br>
|  Concurrent<br>
<br>
|  > |  Haskell<br>
<br>
|  > |<br>
<br>
|  > |  Hi there!<br>
<br>
|  > |<br>
<br>
|  > |  While working on a NCG, I eventually came across #367[0], which<br>
<br>
|  make GHC<br>
<br>
|  > |  produce<br>
<br>
|  > |  code that looks similar to this:<br>
<br>
|  > |<br>
<br>
|  > |  ```<br>
<br>
|  > |  label:<br>
<br>
|  > |    [non-branch-instructions]*<br>
<br>
|  > |    brach-instruction label<br>
<br>
|  > |  ```<br>
<br>
|  > |<br>
<br>
|  > |  so essentially an uninterruptible loop. The solution for GHC to<br>
<br>
|  > |  produce code that<br>
<br>
|  > |  can be interrupted is to pass -fno-omit-yields.<br>
<br>
|  > |<br>
<br>
|  > |  So far so good. Out of curiosity, I did add a small piece of code<br>
<br>
|  to<br>
<br>
|  > |  detect this to my NCG<br>
<br>
|  > |  to complain if code like the above was generated[1].<br>
<br>
|  > |<br>
<br>
|  > |  Three weeks ago, I kind of maneuvered myself into a memory blow<br>
<br>
|  up<br>
<br>
|  > |  corner, and then<br>
<br>
|  > |  life happened, but this weekend I managed to find some time to<br>
<br>
|  revert<br>
<br>
|  > |  some memory<br>
<br>
|  > |  blow up and continue working on the NCG.  Turns out I can build a<br>
<br>
|  > |  stage2 "quick" flavour<br>
<br>
|  > |  of the NCG without dynamic support just fine.  I never saw the<br>
<br>
|  dead<br>
<br>
|  > |  lock detection code fire.<br>
<br>
|  > |<br>
<br>
|  > |  Now I did leave the test suite running yesterday night, and when<br>
<br>
|  > |  looking through the<br>
<br>
|  > |  test suite results, there were quite a few failure. Curiously a<br>
<br>
|  lot of<br>
<br>
|  > |  them were due to<br>
<br>
|  > |  ghc missing dynamic support (doh!).  But also quite a few that<br>
<br>
|  failed<br>
<br>
|  > |  due to the deadlock<br>
<br>
|  > |  detection.<br>
<br>
|  > |<br>
<br>
|  > |  T12485, hs_try_putmvar003, ds-wildcard, ds001, read029, T2817,<br>
<br>
|  tc011,<br>
<br>
|  > |  tc021, T4524<br>
<br>
|  > |<br>
<br>
|  > |  So, my question then is this: are we fine with ghc generating<br>
<br>
|  this<br>
<br>
|  > |  code? Or, if we are not, do we want to figure out if we can<br>
<br>
|  eliminate<br>
<br>
|  > |  it? The issue 367 goes into quite a bit of detail why this is<br>
<br>
|  tricky<br>
<br>
|  > |  to handle generally.<br>
<br>
|  > |<br>
<br>
|  > |  Or should we add -fno-omit-yields to the test-cases? The ultimate<br>
<br>
|  > |  option is to just turn of the<br>
<br>
|  > |  detection, and I'm fine with doing so. However I'd rather ask if<br>
<br>
|  > |  anyone sees value in detecting<br>
<br>
|  > |  this or not.<br>
<br>
|  > |<br>
<br>
|  > |  Cheers,<br>
<br>
|  > |   Moritz<br>
<br>
|  > |<br>
<br>
|  > |  --<br>
<br>
|  > |  [0]:<br>
<br>
|  > |<br>
<br>
|  <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl" target="_blank">
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl</a><br>
<br>
|  ab.h<br>
<br>
|  > |  <a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Faskell.org%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933766799&sdata=1AdfLREUvuB5p3h6mfJjnVSGL0VhfSZKEP3p%2FE%2BduuM%3D&reserved=0" target="_blank">
askell.org</a>%2Fghc%2Fghc%2F-<br>
<br>
|  > |<br>
<br>
|  %2Fissues%2F367&amp;data=02%7C01%7Csimonpj%<a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2F40microsoft.com%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933771794&sdata=Rl8Mn93AwVKEFqLSjblQqzA5tWlCodWkBPtDfMFEwEc%3D&reserved=0" target="_blank">40microsoft.com</a>%7C06a6ead06<br>
<br>
|  2e64<br>
<br>
|  > |<br>
<br>
|  1e6c16608d842893959%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63733<br>
<br>
|  2504<br>
<br>
|  > |<br>
<br>
|  423501799&amp;sdata=KKZYaNgl%2FliDXwfcEqWIosjRjDYt%2FDc9i1sBEfS22mQ%3D<br>
<br>
|  &amp<br>
<br>
|  > |  ;reserved=0<br>
<br>
|  > |  [1]:<br>
<br>
|  > |<br>
<br>
|  <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl" target="_blank">
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl</a><br>
<br>
|  ab.h<br>
<br>
|  > |  <a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Faskell.org%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933776794&sdata=7AL8DozHHcbu6%2BGyHo2Cxh6pkBnd%2FNgn8%2FUxhwq4kR0%3D&reserved=0" target="_blank">
askell.org</a>%2Fghc%2Fghc%2F-<br>
<br>
|  > |<br>
<br>
|  %2Fblob%2F46fba2c91e1c4d23d46fa2d9b18dcd000c80363d%2Fcompiler%2FGHC%2F<br>
<br>
|  CmmT<br>
<br>
|  > |  oAsm%2FAArch64%2FPpr.hs%23L134-<br>
<br>
|  > |<br>
<br>
|  159&amp;data=02%7C01%7Csimonpj%<a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2F40microsoft.com%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933786789&sdata=MAEnEV%2B2YTStXo5mxNvtgsAJadQzPF7B4WWf9PdLWkE%3D&reserved=0" target="_blank">40microsoft.com</a>%7C06a6ead062e641e6c1660<br>
<br>
|  8d84<br>
<br>
|  > |<br>
<br>
|  2893959%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63733250442350179<br>
<br>
|  9&am<br>
<br>
|  > |<br>
<br>
|  p;sdata=RMXio8BI9tSjWnKK4HSXA3s%2BXNNM7ntk2ftQjmRJxzE%3D&amp;reserved=<br>
<br>
|  0<br>
<br>
|  > |  _______________________________________________<br>
<br>
|  > |  ghc-devs mailing list<br>
<br>
|  > |  <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<br>
|  > |<br>
<br>
|  <a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail" target="_blank">
https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail</a>.<br>
<br>
|  hask<br>
<br>
|  > |  <a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fell.org%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933791786&sdata=Przw0UpM9RQ2v7WqQmGDW8pOoc5Fzhdvn3dxDt3eB%2BQ%3D&reserved=0" target="_blank">
ell.org</a>%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-<br>
<br>
|  > |<br>
<br>
|  devs&amp;data=02%7C01%7Csimonpj%<a href="https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2F40microsoft.com%2F&data=02%7C01%7Csimonpj%40microsoft.com%7C9a5a96b91e34458dae1d08d842a9016a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637332640933796784&sdata=L2MhSrgu5Izrv45PU0qk5L9K4sw8%2B2t8ekTCuaC1LFA%3D&reserved=0" target="_blank">40microsoft.com</a>%7C06a6ead062e641e6c166<br>
<br>
|  08d8<br>
<br>
|  > |<br>
<br>
|  42893959%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6373325044235017<br>
<br>
|  99&a<br>
<br>
|  > |<br>
<br>
|  mp;sdata=8W595qb3lWsqdAeGeFp0T26DsCXzA6ngrCQLKihCXkA%3D&amp;reserved=0<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>