<div dir="ltr"><div>Hi Richard. Thanks for the tips. I haven't learned about zonking, so it may well be what I'm missing here. I'm using some inherited code that includes the following line to get bindings then used with dsEvBinds and mkCoreLets to build an expression:<br><br>>         (_wCs', bnds) <- second evBindMapBinds <$> runTcS (solveWanteds wCs)<br><br>Should I be zonking in here somewhere?<br><br>More context for this code, if helpful:<br><br>> -- | Build a dictionary for the given<br>> buildDictionary' :: HscEnv -> DynFlags -> ModGuts -> Id -> (Id, [CoreBind])<br>> buildDictionary' env dflags guts evar =<br>>     let (i, bs) = runTcMUnsafe env dflags guts $ do<br>>         loc <- getCtLocM (GivenOrigin UnkSkol) Nothing<br>>         let predTy = varType evar<br>>             nonC = mkNonCanonical $<br>>                      CtWanted { ctev_pred = predTy, ctev_dest = EvVarDest evar<br>>                               , ctev_loc = loc }<br>>             wCs = mkSimpleWC [cc_ev nonC]<br>>         -- TODO: Make sure solveWanteds is the right function to call.<br>>         (_wCs', bnds) <- second evBindMapBinds <$> runTcS (solveWanteds wCs)<br>>         -- pprTrace "buildDictionary' _wCs'" (ppr _wCs') (return ())<br>>         warnAllUnsolved _wCs'<br>>         return (evar, bnds)<br>>     in<br>>       (i, runDsMUnsafe env dflags guts (dsEvBinds bs))<br><br>where runTcMUnsafe and runDsMUnsafe use unsafePerformIO (ouch) to <br><br>> runTcMUnsafe :: HscEnv -> DynFlags -> ModGuts -> TcM a -> a<br>> runTcMUnsafe env dflags guts m = unsafePerformIO $ do<br>>     -- What is the effect of HsSrcFile (should we be using something else?)<br>>     -- What should the boolean flag be set to?<br>>     (msgs, mr) <- initTcFromModGuts env guts HsSrcFile False m<br>>     let showMsgs (warns, errs) = showSDoc dflags $ vcat<br>>                                                  $    text "Errors:" : pprErrMsgBagWithLoc errs<br>>                                                    ++ text "Warnings:" : pprErrMsgBagWithLoc warns<br>>     maybe (fail $ showMsgs msgs) return mr<br>><br>> -- TODO: Try initTcForLookup or initTcInteractive in place of initTcFromModGuts.<br>> -- If successful, drop dflags and guts arguments.<br>><br>> runDsMUnsafe :: HscEnv -> DynFlags -> ModGuts -> DsM a -> a<br>> runDsMUnsafe env dflags guts = runTcMUnsafe env dflags guts . initDsTc<br><br>and initTcFromModGuts is something I pulled in from HERMIT.<br><br></div>Thanks and regards, - Conal<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 4, 2016 at 9:37 AM, Richard Eisenberg <span dir="ltr"><<a href="mailto:eir@cis.upenn.edu" target="_blank">eir@cis.upenn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Coercion holes (the payload of a HoleProv) get created for all wanted equality constraints (and for nothing else). If you're working over only class dictionaries, you won't encounter holes. But my guess is that your HasRep somehow induces a wanted equality. If the solver fills the hole -- as it should if the equality is solvable -- then you may just need to zonk it properly. zonkCoHole does the job, but this should be called from zonkTcTypeToType, which I imagine you're already doing.</div><div><br></div><div>I hope this helps,</div><div>Richard</div><br><div><div><div class="h5"><div>On Apr 4, 2016, at 6:21 PM, Conal Elliott <<a href="mailto:conal@conal.net" target="_blank">conal@conal.net</a>> wrote:</div><br></div></div><blockquote type="cite"><div><div class="h5"><div dir="ltr"><div>Hi Simon. Thanks for the reply. My plugin appears to produce the HoleProv indirectly (and to my surprise) while building a dictionary to satisfy a given constraint, using mkNonCanonical and solveWanteds. I don't know why solveWanteds produces a HoleProv in this case and not in the many others I've tried. The constraint being solved in the example I included was 'HasRep (Vec ('S n_aCj7) (Key h_aCj6))', where HasRep is similar to Generic (from GHC.Generics), and there is a HasRep instance for Vec ('S n x). Come to think of it, the free type variable s_aD1S troubles me as well.<br><br>I'm not terribly confident in the code I use for constructing these dictionaries (setting up and calling solveWanteds) during Core-to-Core transformation. Do you know of any relevant example code, docs, etc?<br><br>Yes, I'm using -dcore-lint, as well explicitly linting each small transformation step (while debugging). Doing so has been very helpful in finding bugs quickly.<br><br></div>Cheers, - Conal<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 4, 2016 at 2:48 AM, 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 link="#0563C1" vlink="#954F72" lang="EN-GB">
<div><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Definitely a bug. All HoleProvs should be eliminated by the type checker.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Did your plugin produce a HoleProv?  It definitely should not do so; see the notes with that constructor.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Lint checks for this – did you run with –dcore-lint?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif">Simon<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Calibri",sans-serif"><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 style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US"> ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>]
<b>On Behalf Of </b>Conal Elliott<br>
<b>Sent:</b> 02 April 2016 20:24<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> "opt_univ fell into a hole"<u></u><u></u></span></p>
</div>
</div><div><div><p class="MsoNormal"><u></u> <u></u></p>
<div><p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I'm getting the following error message from a GHC plugin I'm developing (note GHC version):<br>
<br>
    ghc-stage2: panic! (the 'impossible' happened)<br>
      (GHC version 8.1.20160307 for x86_64-apple-darwin):<br>
            opt_univ fell into a hole {aD1S}<br>
<br>
I don't get this error when compiling without my plugin, so I may well be violating a compiler invariant.<br>
<br>
Shortly before the error, the plugin produced the following dictionary expression, which does indeed contain a `UnivCo` with a `HoleProv`. The plugin does sometimes generate `UnivCo`s but not with `HoleProv`.<br>
<br>
    let {<br>
      $dHasRep_aD1T :: HasRep (Vec 'Z s_aD1R[fuv:0])<br>
      $dHasRep_aD1T = $fHasRepVec0 @ s_aD1R[fuv:0] } in<br>
    let {<br>
      $dHasRepZLVeczqZZZLKeyhZRZR_Ii5CR :: HasRep (Vec 'Z (Key h_aCnh))<br>
      $dHasRepZLVeczqZZZLKeyhZRZR_Ii5CR =<br>
        $dHasRep_aD1T<br>
        `cast` ((HasRep<br>
                   (Vec<br>
                      <'Z>_N<br>
                      (Sym U(hole:{aD1S}, Key h_aCnh, s_aD1R[fuv:0])_N))_N)_R<br>
                :: HasRep (Vec 'Z s_aD1R[fuv:0])<br>
                   ~R# HasRep (Vec 'Z (Key h_aCnh))) } in<br>
    $dHasRepZLVeczqZZZLKeyhZRZR_Ii5CR<br>
<br>
Here, `Key` is a type family from `Data.Key` in the keys package, and `Vec` is a GADT of statically length-indexed lists.<br>
<br>
Suggestions?<br>
<br>
Thanks, - Conal<u></u><u></u></p>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div></div></div>
_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br></blockquote></div><br></div></blockquote></div><br></div>