<div dir="ltr">well said iavor.<div>It perhaps hints at the register allocators needing some love? I hope to dig deep into those myself later this year, but maybe it needs some wibbles to clean up for 7.8 right now?</div></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 8, 2014 at 2:14 AM, Iavor Diatchki <span dir="ltr"><<a href="mailto:iavor.diatchki@gmail.com" target="_blank">iavor.diatchki@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I find it a bit perplexing (and not at all constructive) that we are arguing over semantics here.  We have a program (1 module, ~1000 lines of "no fancy extension Haskell"), which causes GHC to panic.  This is a bug.  An invariant that we were assuming did not actually hold.  Hence the message that the "impossible" happened.  If GHC decides to refuse to compile a program, it should not panic but, rather, explain what happened and maybe suggest a workaround.</div>


<div><br></div><div>I am not familiar with GHC's back-end, but it seems that there might be something interesting that's going on here.   The SHA library works fine with 7.6.3, and it compiles (admittedly very slowly) using GHC head on my 64-bit machine.   So something has changed, and it'd be nice if we understood what's causing the problem.</div>


<div><br></div><div>Ben suggested that the issue might be the INLINE pragmas, but clearly that's not the problem, as Adam reproduced the same behavior without those pragmas.  If the issue is indeed with the built-in inline heuristics, it sounds like we either should fix the heuristics, or come up with some suggestions about what to avoid in user programs.  Or, perhaps, the issue something completely unrelated (e.g., a bug in the register allocator).   Either way, I think this deserves a ticket.</div>

<span class="HOEnZb"><font color="#888888">
<div><br></div><div>-Iavor</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">

On Tue, Jan 7, 2014 at 10:11 PM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Adam, <div>I agree that it should be considered a misfeature (or at the very least a good stress test that currently breaks the register allocator). That said,</div>


<div>INLINE / INLINEABLE are only needed for intermodule optimization, have you tried using the special "inline" primop selectively, or using INLINEABLE plus selective inline? I think inline should work in the defining module even if you don't provide an INLINE or INLINEABLE. </div>





<div><br></div><div>question 1: does the code compile well when you use -fllvm? (seems like the discussion so far has been NCG focused).</div>
<div>how does the generated assembly fair that way vs the workaroudn path on NCG?</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, Jan 7, 2014 at 6:57 PM, Adam Wick <span dir="ltr"><<a href="mailto:awick@galois.com" target="_blank">awick@galois.com</a>></span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div>On Jan 7, 2014, at 2:27 AM, Ben Lippmeier <<a href="mailto:benl@ouroborus.net" target="_blank">benl@ouroborus.net</a>> wrote:<br>





> On 07/01/2014, at 9:26 , Adam Wick <<a href="mailto:awick@galois.com" target="_blank">awick@galois.com</a>> wrote:<br>
><br>
>>> Not if we just have this one test. I'd be keen to blame excessive use of inline pragmas in the SHA library itself, or excessive optimisation flags. It's not really a bug in GHC until there are two tests that exhibit the same problem.<br>





>><br>
>> The SHA library uses SPECIALIZE, INLINE, and bang patterns in fairly standard ways. There’s nothing too exotic in there, I just basically sprinkled hints in places I thought would be useful, and then backed those up with benchmarking.<br>





><br>
> Ahh. It's the "sprinkled hints in places I thought would be useful" which is what I'm concerned about. If you just add pragmas without understanding their effect on the core program then it'll bite further down the line. Did you compare the object code size as well as wall clock speedup?<br>





<br>
</div>I understand the pragmas and what they do with my code. I use SPECIALIZE twice for two functions. In both functions, it was clearer to write the function as (a -> a -> a -> a), but I wanted specialized versions for the two versions that were going to be used, in which (a == Word32) or (a == Word64). This benchmarked as faster while maintaining code clarity and concision. I use INLINE in five places, each of them a SHA step function, with the understanding that it would generate ideal code for a compiler for the performance-critical parts of the algorithm: straight line, single-block code with no conditionals.<br>





<br>
When I did my original performance work, several versions of GHC ago, I did indeed consider compile time, runtime performance, and space usage. I picked what I thought was a reasonable balance at the time.<br>
<br>
I also just performed an experiment in which I took the SHA library, deleted all instances of INLINE and SPECIALIZE, and compiled it with HEAD on 32-bit Linux. You get the same crash. So my usage of SPECIALIZE and INLINE is beside the point.<br>





<div><br>
> Sadly, "valid input" isn't a well defined concept in practice. You could write a "valid" 10GB Haskell source file that obeyed the Haskell standard grammar, but I wouldn't expect that to compile either.<br>





<br>
</div>I would. I’m a little disappointed that ghc-devs does not. I wouldn’t expect it to compile quickly, but I would expect it to run.<br>
<div><br>
> You could also write small (< 1k) source programs that trigger complexity problems in Hindley-Milner style type inference. You could also use compile-time meta programming (like Template Haskell) to generate intermediate code that is well formed but much too big to compile. The fact that a program obeys a published grammar is not sufficient to expect it to compile with a particular implementation (sorry to say).<br>





<br>
</div>If I write a broken Template Haskell macro, then yes, I agree. This is not the case in this example.<br>
<div><br>
> Adding an INLINE pragma is akin to using compile-time meta programming.<br>
<br>
</div>Is it? I find that a strange point of view. Isn’t INLINE just a strong hint to the compiler that this function should be inlined? How is using INLINE any different from simply manually inserting the code at every call site?<br>





<span><font color="#888888"><br>
<br>
- Adam</font></span><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://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>