[GHC] #15928: Reduction stack overflow when using "coerce"

GHC ghc-devs at haskell.org
Sat Nov 24 02:44:19 UTC 2018


#15928: Reduction stack overflow when using "coerce"
-------------------------------------+-------------------------------------
        Reporter:  harendra          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.3
       Component:  Compiler          |              Version:  8.6.2
      Resolution:                    |             Keywords:
Operating System:  MacOS X           |         Architecture:
 Type of failure:  Compile-time      |  Unknown/Multiple
  crash or panic                     |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by harendra):

 I think GHC needs to move on from "by GHC developers for GHC developers"
 to "by GHC developers for mortal Haskell programmers". You have a lot more
 context here than a Haskell programmer at large would have. The error
 needs to be resolved quickly, in a few seconds or perhaps minutes would be
 fine too. The error message and the documentation does not serve that
 purpose, it (Data.Coerce) refers to the paper and the roles wiki page
 (referring to papers is common theme for GHC and Haskell libraries), the
 paper is accessible to only a very small population, and we should not
 expect a large population of programmers to go read the paper and spend
 hours or even days or weeks trying to understand it and having to learning
 a lot of other things in the process. For that one error message, which
 can be explained better in just a few more words, it becomes a big
 digression.

 I am sorry about that rant, GHC devs are doing a terrific job, it is a
 wonderful technology but it has a potential to become much more usable by
 a lot more ordinary programmers like me if the error messages and the
 documentation become a little better.

 Keeping that aside, I still have a few questions about the issue at hand,
 I suspect there is a bug here:

 1) Why a and a0 are treated as different types in the first version of the
 code? If a ~ a0 then there won't be a loop. In fact, this code is coercing
 a type into itself, which should be trivial. In the second version of the
 code where it works, the two types have been explicitly forced to be the
 same via a type signature.

 2) This code works fine if the "Stream" type is defined using "data"
 instead of a "newtype". It puzzles me, why in that case we are not going
 into a loop? Why in that case the types a and a0 are the same?

 About the error message, I think it can be improved. First of all, a
 regular programmer won't have any idea what a "reduction stack" is, they
 can just guess, it is possibly a GHC internal thing. The error message is
 for GHC developers, not for users. The flag "-freduction-depth" is only
 mentioned in "Undecidable Instances section" of the guide, nowhere else.
 If the programmer is supposed to know about the reduction stack then it
 should be documented and the concept should be explained. But I guess we
 can do better even without doing that. The error message can perhaps be
 phrased something like this, it might be inaccurate, but just to give an
 idea:

 {{{
 When trying to determine that the representation of type x is the
 same as that of type y, we expanded the types n times but still
 could not determine that they are equal, we can go on but we
 are limited by the reduction stack size which can be changed by
 using the -freduction-depth option. In some cases where the
 types are recursively defined, it is possible that the expansion
 forms an infinite loop that never terminates. For more details
 and examples see this manual page.
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15928#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list