<div dir="ltr"><div dir="ltr"><div>Correction!<br></div>The problem happens in integer-gmp:<br><a href="https://github.com/ghc/ghc/blob/master/libraries/integer-gmp/src/GHC/Integer/Type.hs#L761-L770">https://github.com/ghc/ghc/blob/master/libraries/integer-gmp/src/GHC/Integer/Type.hs#L761-L770</a><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 5, 2018 at 5:27 PM Csaba Hruska <<a href="mailto:csaba.hruska@gmail.com">csaba.hruska@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>An example for the duplication please check the <a href="https://github.com/ghc/ghc/blob/master/libraries/integer-simple/GHC/Integer/Type.hs#L373-L380" target="_blank">divModInteger</a> function from integer-simple GHC.Integer.Type.<br></div><div><div>The STG (GHC 8.2.2) generated from <b><span class="m_5685414598476393737gmail-pl-en">divModInteger</span> </b><i><span class="m_5685414598476393737gmail-pl-k">::</span> <span class="m_5685414598476393737gmail-pl-en"><span class="m_5685414598476393737gmail-pl-c1">Integer</span></span> <span class="m_5685414598476393737gmail-pl-k">-></span> <span class="m_5685414598476393737gmail-pl-en"><span class="m_5685414598476393737gmail-pl-c1">Integer</span></span> <span class="m_5685414598476393737gmail-pl-k">-></span> (<span class="m_5685414598476393737gmail-pl-k">#</span> <span class="m_5685414598476393737gmail-pl-en"><span class="m_5685414598476393737gmail-pl-c1">Integer</span></span>, <span class="m_5685414598476393737gmail-pl-en"><span class="m_5685414598476393737gmail-pl-c1">Integer</span></span> <span class="m_5685414598476393737gmail-pl-k">#</span>) </i>contains duplications in a closure binder list.</div><br></div><div>Using my custom STG printer it looks like:</div><div style="margin-left:40px"><font size="1"><font face="monospace,monospace">module GHC.Integer.Type where<br></font></font></div><div style="margin-left:40px"><font size="1"><font face="monospace,monospace"><br></font></font></div><div style="margin-left:40px"><font size="1"><font face="monospace,monospace">using GHC.Prim<br>using GHC.Tuple<br>using GHC.Types<br></font></font></div><div style="margin-left:40px"><font size="1"><font face="monospace,monospace"><br></font></font></div><div style="margin-left:40px"><font size="1"><font face="monospace,monospace">GHC.Integer.Type.divModInteger {-083-} =<br> closure (F:) (B:<br> n.s84123 {-s84123-}<br> d.s84124 {-s84124-}) {<br> case GHC.Integer.Type.quotRemInteger {-084-}<br> n.s84123 {-s84123-}<br> d.s84124 {-s84124-}<br> of qr.s84125 {-s84125-} {<br> GHC.Prim.(#,#) {-86-} ipv.s84126 {-s84126-} ipv1.s84127 {-s84127-} -><br> let $j.s84128 {-s84128-} =<br> closure (F:<br> d.s84124 {-s84124-}<br><span style="background-color:rgb(244,204,204)"><span style="color:rgb(0,0,0)"><b> ipv.s84126 {-s84126-}</b></span></span><br><span style="background-color:rgb(207,226,243)"><span style="color:rgb(0,0,0)"><b> ipv1.s84127 {-s84127-}</b></span></span><br><span style="background-color:rgb(244,204,204)"><span style="color:rgb(0,0,0)"><b> ipv.s84126 {-s84126-}</b></span></span><br><span style="color:rgb(0,0,0)"><span style="background-color:rgb(207,226,243)"> <b>ipv1.s84127 {-s84127-}</b></span>) (B:</span><br> wild.s84129 {-s84129-}) {<br> let $j1.s84130 {-s84130-} =<br> closure (F:<br> d.s84124 {-s84124-}<br> ipv.s84126 {-s84126-}<br> ipv1.s84127 {-s84127-}<br> ipv.s84126 {-s84126-}<br> ipv1.s84127 {-s84127-}<br> wild.s84129 {-s84129-}) (B:<br> wild1.s84131 {-s84131-}) {<br> case _stg_prim_negateInt#<br> wild.s84129 {-s84129-}<br> of sat.s84132 {-s84132-} {<br> DEFAULT -><br> case _stg_prim_==#<br> wild1.s84131 {-s84131-}<br> sat.s84132 {-s84132-}<br> of sat.s84133 {-s84133-} {<br> DEFAULT -><br> case _stg_prim_tagToEnum#<br> sat.s84133 {-s84133-}<br> of wild2.s84134 {-s84134-} {<br> GHC.Types.False {-612-} -><br> GHC.Prim.(#,#) {-86-}<br> ipv.s84126 {-s84126-}<br> ipv1.s84127 {-s84127-}<br> GHC.Types.True {-645-} -><br> case GHC.Integer.Type.plusInteger {-066-}<br> ipv1.s84127 {-s84127-}<br> d.s84124 {-s84124-}<br> of r'.s84135 {-s84135-} {<br> DEFAULT -><br> case GHC.Integer.Type.plusInteger {-066-}<br> ipv.s84126 {-s84126-}<br> GHC.Integer.Type.lvl11 {-r50574-}<br> of q'.s84136 {-s84136-} {<br> DEFAULT -><br> GHC.Prim.(#,#) {-86-}<br> q'.s84136 {-s84136-}<br> r'.s84135 {-s84135-}<br> }<br> }<br> }<br> }<br> }}<br> <br> in case ipv1.s84127 {-s84127-} <br> of wild1.s84137 {-s84137-} {<br> GHC.Integer.Type.S# {-621-} i#.s84138 {-s84138-} -><br> case _stg_prim_<#<br> i#.s84138 {-s84138-} 0#<br> of sat.s84140 {-s84140-} {<br> DEFAULT -><br> case _stg_prim_>#<br> i#.s84138 {-s84138-} 0#<br> of sat.s84139 {-s84139-} {<br> DEFAULT -><br> case _stg_prim_-#<br> sat.s84139 {-s84139-}<br> sat.s84140 {-s84140-}<br> of sat.s84141 {-s84141-} {<br> DEFAULT -><br> $j1.s84130 {-s84130-}<br> sat.s84141 {-s84141-}<br> }<br> }<br> }<br> <a href="http://GHC.Integer.Type.Jp#" target="_blank">GHC.Integer.Type.Jp#</a> {-r5813-} dt.s84142 {-s84142-} -><br> $j1.s84130 {-s84130-} 1#<br> GHC.Integer.Type.Jn# {-r5814-} dt.s84143 {-s84143-} -><br> $j1.s84130 {-s84130-} -1#<br> }}<br> <br> in case d.s84124 {-s84124-} <br> of wild.s84144 {-s84144-} {<br> GHC.Integer.Type.S# {-621-} i#.s84145 {-s84145-} -><br> case _stg_prim_<#<br> i#.s84145 {-s84145-} 0#<br> of sat.s84147 {-s84147-} {<br> DEFAULT -><br> case _stg_prim_>#<br> i#.s84145 {-s84145-} 0#<br> of sat.s84146 {-s84146-} {<br> DEFAULT -><br> case _stg_prim_-#<br> sat.s84146 {-s84146-}<br> sat.s84147 {-s84147-}<br> of sat.s84148 {-s84148-} {<br> DEFAULT -><br> $j.s84128 {-s84128-}<br> sat.s84148 {-s84148-}<br> }<br> }<br> }<br> <a href="http://GHC.Integer.Type.Jp#" target="_blank">GHC.Integer.Type.Jp#</a> {-r5813-} dt.s84149 {-s84149-} -><br> $j.s84128 {-s84128-} 1#<br> GHC.Integer.Type.Jn# {-r5814-} dt.s84150 {-s84150-} -><br> $j.s84128 {-s84128-} -1#<br> }<br> }}<br></font></font><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 5, 2018 at 2:08 PM Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<br></div><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_5685414598476393737m_-3312551194861425370WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt">I don’t think there should be duplicates in either. Do you have a test case that shows duplicates?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></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"> ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>>
<b>On Behalf Of </b>Csaba Hruska<br>
<b>Sent:</b> 04 November 2018 11:22<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Re: StgRhsClosure freevar and argument name duplicates<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Is it possible that GHC generates STG with invalid binding semantics for certain cases that the Cmm codegen fix or ignore?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
This could explain my observations.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I've checked the Stg linter source (StgLint.hs ; GHC 8.2.2 and github master) and it does not check StgRhsClosure free var and binder list at all.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
And the scope checker function (addInScopeVars) does not check for duplicates.<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">
Any thoughts?<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">
Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Csaba<u></u><u></u></p>
</div>
</div>
</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">
On Sat, Nov 3, 2018 at 9:53 AM Csaba Hruska <<a href="mailto:csaba.hruska@gmail.com" target="_blank">csaba.hruska@gmail.com</a>> wrote:<u></u><u></u></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">
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Hi,<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">
Can StgRhsClosure's freevar list ([occ]) or argument list ([bndr]) contain duplicates?<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">
Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Csaba<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">
<span style="font-size:7.5pt;font-family:"Courier New"">data GenStgRhs bndr occ</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> = StgRhsClosure</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> CostCentreStack -- CCS to be attached (default is CurrentCCS)</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> StgBinderInfo -- Info about how this binder is used (see below)</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> <b>[occ]</b> -- non-global free vars; a list, rather than</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> -- a set, because order is important</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> !UpdateFlag -- ReEntrant | Updatable | SingleEntry</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> <b>[bndr]</b> -- arguments; if empty, then not a function;</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> -- as above, order is important.</span><br>
<span style="font-size:7.5pt;font-family:"Courier New""> (GenStgExpr bndr occ) -- body</span><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>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote></div>
</blockquote></div>