[GHC] #13750: GHC produces incorrect coercions in hairy code

#13750: GHC produces incorrect coercions in hairy code
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.3
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: Runtime crash
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Andres Löh has been working with an optimized version of generics-sop, and
ran into segfaults. He was able to reduce the test case to the attached
(still not tiny) one, and could reduce it no further. He discovered the
following utterly bogus definition in `-ddump-simpl` (with -O):
{{{
Main.gshowP_$dAll :: All MyShow GHC.Exts.Any
[GblId,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
WorkFree=False, Expandable=True, Guidance=IF_ARGS [] 20 0}]
Main.gshowP_$dAll
= ghc-prim-0.5.0.0:GHC.Classes.$p1(%,%)
@ (All MyShow GHC.Exts.Any)
@ (All (All MyShow) GHC.Exts.Any)
(ghc-prim-0.5.0.0:GHC.Classes.C:(%%)
`cast` (Sub (Sym (Main.D:R:AllFk_c[][0] <[*]>_N <All MyShow>_N))
; Sym (Main.N:All[0] <[*]>_N <All MyShow>_N <'[]>_N)
; Sub
(Nth:1
(Sub
(Sym
(Main.D:R:AllFkc:[0] <[*]>_N <All MyShow>_N
<'[Char]>_N <'[]>_N))
; (AllF
<[*]>_N
<All MyShow>_N
((':)
<[*]>_N
(UnsafeCo nominal '[Char] GHC.Exts.Any)
(UnsafeCo nominal '[] GHC.Exts.Any))_N)_R
; Sub
(Main.D:R:AllFkc:[0]
<[*]>_N <All MyShow>_N

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * Attachment "segfault-investigation.cabal" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * Attachment "SegfaultAllInOne.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * Attachment "NS.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): This is a regression, as it works in 8.0.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * version: 8.3 => 8.2.1-rc2 * milestone: 8.4.1 => 8.2.2 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * priority: normal => highest -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: simonpj (added) * related: => #13429 Comment: Commit a920404fb12fb52a59e4f728cce4d662a418c5f8 (Fix TcSimplify.decideQuantification for kind variables) caused this regression. On a related note, that same commit also caused another class of program to loop at runtime in https://ghc.haskell.org/trac/ghc/ticket/13429#comment:16, so there's definitely something fishy with this commit. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by edsko): * cc: edsko (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Well this is embarrassing. I did take a quick look. The test program is littered with `unsafeCoerce` which makes it harder to determine where things actually go wrong. I still think the "decideQuantification" patch is fine; I think it is just exposing bugs elsewhere. I discovered that (like #13429), adding `-fno-specialise` (to switch off the specialiser) makes it work again. So that may be a workaround for Andres. I'm not against reverting the "decideQauntification" patch as an expedient way to make the release work; but that would re-introduce the bugs that the patch cured. I'm on holiday now for a week, I'm afraid. It'd be great if someone was able to characterise more precisely what is going wrong. At the moment I have no clue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by kosmikus): Simon, thanks for taking a look, and sorry for the "bad" test program. Yes, this very much originated in code littered with unsafeCoerce, which was an experiment, and I already spent several hours to condense it down to the size it currently has. The code compiles and behaves ok with older GHCs. Many further attempts at simplification just make it work (such as reducing to a single module, or simplifying seemingly unrelated functions). I'm fully aware that this is nowhere near a simple and easy to reproduce example. If it helps, I can invest more time to do so. On the other hand, if you have a reasonably clear idea what's going wrong, I'd prefer not to. In the meantime, I'll try the workaround you suggest. All this is in a codebase that's currently just an experiment. If it doesn't work reliably, I cannot move forward with the experiment, but it's not mission critical to me. My main worry is that it looks like it's a regression that might also affect arbitrary other things in subtle ways. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by kosmikus): I can confirm that `-fno-specialise` also works in the full example as a workaround (but it seems it has to be applied at each use site of one of the critical functions, so it's not an extremely viable workaround for a library). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Commit 2b74bd9d8b4c6b20f3e8d9ada12e7db645cc3c19 (Stop the specialiser generating loopy code), the fix for #13429, also fixed this bug! Hooray! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:9 RyanGlScott]:
Commit 2b74bd9d8b4c6b20f3e8d9ada12e7db645cc3c19 (Stop the specialiser generating loopy code), the fix for #13429, also fixed this bug! Hooray!
It would be very nice if one of the type gurus could come up with a story about why that change fixed this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I'm no "type guru", but I find this development quite unsurprising. The "utterly bogus definition" that you pointed out in the original comment concerns the `All` type class, which has `AllF` as a superclass. The nub of #13429 concerns improper specialization of dictionary functions with superclasses, and `All` falls into the category. Combine incorrect specialization with `unsafeCoerce`, and segfaults are just around the corner. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: (none)
Type: bug | Status: new
Priority: highest | Milestone: 8.2.2
Component: Compiler | Version: 8.2.1-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #13429 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): You may not be surprised, but I am. But I'm also delighted -- I was not looking forward to discovering what was happening. I hope that it's actually fixed, not just masked. But let's see if Andres's original problem is fixed. If it is, let's declare victory and close. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by kosmikus): This is good news. Thanks a lot. I will test my original program as soon as I have a GHC with this patch available. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by kosmikus): Looks good. I built from git master, and it works for me now. Feel free to close. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13750: GHC produces incorrect coercions in hairy code -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: closed Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: #13429 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => fixed Comment: Hurrah. Thanks. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13750#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC