<div dir="ltr">Thank you for confirming, Simon.<div><br></div><div>I opened <a href="https://gitlab.haskell.org/ghc/ghc/issues/16735">https://gitlab.haskell.org/ghc/ghc/issues/16735</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 2, 2019 at 8:33 AM Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-GB">
<div class="gmail-m_5287886517086356437WordSection1">
<p class="MsoNormal">Nick<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">That looks outright wrong to me. Would you like to make a ticket for it? It should be easy to fix.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m surprised it has not caused more trouble before now.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Well spotted and well diagnosed! <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Simon<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 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>Nicolas Frisby<br>
<b>Sent:</b> 01 June 2019 04:24<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> should TcCanonical.rewriteEvidence preserve ctev_nosh?<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
A bit of context and then my question.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2Fblob%2Fmaster%2Fcompiler%2Ftypecheck%2FTcCanonical.hs%23L2226&data=02%7C01%7Csimonpj%40microsoft.com%7Cd90efcd1da6f4058c00c08d6e640c7c2%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636949563239275987&sdata=F7dgkceI2512TafrGNP38xvWAv2%2F6HKQscRnU%2Bypbf8%3D&reserved=0" target="_blank">https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/typecheck/TcCanonical.hs#L2226</a>
declares `rewriteEvidence` with the comment that "rewriteEvidence old_ev new_pred co ... Returns a new_ev : new_pred, with same wanted/given/derived flag as old_ev".<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
However, the `CtWanted` case just immediately calls `newWanted`, which ignores the incoming `ctev_nosh` flag and always uses `WDeriv`.<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<br>
```<br>
rewriteEvidence ev@(CtWanted { ctev_dest = dest<br>
<br>
, ctev_loc = loc }) new_pred co <br>
<br>
= do { mb_new_ev <- newWanted loc new_pred<br>
```<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
(This is true in 8.6.5 and also right now at 6febc444c0abea6c033174aa0e813c950b9b2877.)<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Thus I'm seeing a [W] is become a [WD], which seems to contradict the comment's "same flag" claim.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
MY QUESTION ======> Is this "WD unsplitting" the intended behavior? See canonicalization tc-trace below.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
If it is intended, I'll probably write a follow-up question asking for more advice. The constraint solver is looping unproductively because my plugin keeps discarding the (re-)emitted [D] shadow as a tautology, then the [W] "unsplits" during canonicalization
(even though my plugin didn't touch the [W]), this re-emits the same [D] (via a fundep), and so on.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
My continual disclaimer recently is that I'm seeing this behavior with my in-development plugin activated, so it's entirely I'm pushing GHC into unfamiliar waters or even just plain violating some invariants without realizing it. But this trace looks rather
isolated from plugins.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Thanks! -Nick<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Here's a -ddump-tc-trace of a canonicalization that goes from [W] to [WD] happen (with GHC 8.6.5):<br>
<br>
runStage canonicalization {<br>
workitem = [W] $dMonadFree_a35V {0}:: MonadFree<br>
((fs_a2UF[sk:1] :- Const e_a2UE[sk:1])<br>
:+ Const e_a2UE[sk:1])<br>
(Free fs_a2UF[sk:1]) (CDictCan)<br>
flatten_args {<br>
(fs_a2UF[sk:1] :- Const e_a2UE[sk:1]) :+ Const e_a2UE[sk:1]<br>
Free fs_a2UF[sk:1]<br>
matchFamTcM<br>
Matching: (fs_a2UF[sk:1] :- Const e_a2UE[sk:1])<br>
:+ Const e_a2UE[sk:1]<br>
Match failed<br>
matchFamTcM<br>
Matching: fs_a2UF[sk:1] :- Const e_a2UE[sk:1]<br>
Match failed<br>
Unfilled tyvar fs_a2UF[sk:1]<br>
Unfilled tyvar e_a2UE[sk:1]<br>
flatten/flat-cache hit<br>
:- [* -> *, fs_a2UF[sk:1], Const e_a2UE[sk:1]]<br>
s_a35Z[fmv:1]<br>
Unfilled tyvar s_a35Z[fmv:1]<br>
Unfilled tyvar e_a2UE[sk:1]<br>
matchFamTcM<br>
Matching: s_a35Z[fmv:1] :+ Const e_a2UE[sk:1]<br>
Match failed<br>
New coercion hole: co_a365<br>
Emitting new coercion hole<br>
{co_a365} :: (s_a35Z[fmv:1] :+ Const e_a2UE[sk:1])<br>
GHC.Prim.~# s_a364[fmv:1]<br>
extendFlatCache<br>
:+ [* -> *, s_a35Z[fmv:1], Const e_a2UE[sk:1]]<br>
[WD]<br>
s_a364[fmv:1]<br>
flatten/flat-cache miss<br>
:+ [* -> *, s_a35Z[fmv:1], Const e_a2UE[sk:1]]<br>
s_a364[fmv:1]<br>
[WD] hole{co_a365} {0}:: (s_a35Z[fmv:1] :+ Const e_a2UE[sk:1])<br>
GHC.Prim.~# s_a364[fmv:1]<br>
Unfilled tyvar fs_a2UF[sk:1]<br>
flatten }<br>
s_a364[fmv:1]<br>
Free fs_a2UF[sk:1]<br>
Emitting new wanted<br>
$dMonadFree_a366 :: MonadFree s_a364[fmv:1] (Free fs_a2UF[sk:1])<br>
arising from a use of ‘wrap’ at tests/ill-typed/T7.hs:77:14-17<br>
addTcEvBind<br>
a2V1<br>
[W] $dMonadFree_a35V<br>
= $dMonadFree_a366<br>
`cast` ((MonadFree<br>
(Sym {co_a365} ; ((:+)<br>
<* -> *>_N (Sym {co_a360}) <Const e_a2UE[sk:1]>_N)_N)<br>
<Free fs_a2UF[sk:1]>_N)_R<br>
:: MonadFree s_a364[fmv:1] (Free fs_a2UF[sk:1])<br>
~R# MonadFree<br>
((fs_a2UF[sk:1] :- Const e_a2UE[sk:1]) :+ Const e_a2UE[sk:1])<br>
(Free fs_a2UF[sk:1]))<br>
canClass<br>
[W] $dMonadFree_a35V {0}:: MonadFree<br>
((fs_a2UF[sk:1] :- Const e_a2UE[sk:1]) :+ Const e_a2UE[sk:1])<br>
(Free fs_a2UF[sk:1])<br>
MonadFree s_a364[fmv:1] (Free fs_a2UF[sk:1])<br>
ContinueWith [WD] $dMonadFree_a366 {0}:: MonadFree<br>
s_a364[fmv:1] (Free fs_a2UF[sk:1])<br>
end stage canonicalization }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
and later<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
try_fundeps<br>
[WD] $dMonadFree_a36h {0}:: MonadFree<br>
s_a36f[fmv:1] (Free fs_a2UF[sk:1]) (CDictCan)<br>
emitFunDepDeriveds 1<br>
0<br>
[fs_a2UF[sk:1] ~ s_a36f[fmv:1]]<br>
False<br>
Emitting new derived equality<br>
[D] _ {0}:: fs_a2UF[sk:1] GHC.Prim.~# s_a36f[fmv:1]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
and then my plugin discards that [D] as a tautological, and then the [W] gets unsplit and the [D] comes back around etc<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote></div>