[GHC] #10769: Yet another crash from type holes

#10769: Yet another crash from type holes -----------------------------------------+------------------------------- Reporter: rpglover64 | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.3 Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: GHCi crash Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -----------------------------------------+------------------------------- {{{#!hs {-# OPTIONS_GHC -fdefer-typed-holes #-} hylo a b = h where h = b . fmap h . a foo a b = hylo a' b' where a' x = _ b' = _ bar :: [Int] bar = [] main = print bar }}} Loading this up in ghci and attempting to run main prints: {{{ GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help unknown option: 'c' [1 of 1] Compiling Main ( bad.hs, interpreted ) bad.hs:6:16: Warning: Found hole ‘_’ with type: t4 Where: ‘t4’ is a rigid type variable bound by the inferred type of a' :: t3 -> t4 at bad.hs:6:9 Relevant bindings include x :: t3 (bound at bad.hs:6:12) a' :: t3 -> t4 (bound at bad.hs:6:9) b' :: forall t. t (bound at bad.hs:7:9) b :: t1 (bound at bad.hs:5:7) a :: t (bound at bad.hs:5:5) foo :: t -> t1 -> t2 -> b (bound at bad.hs:5:1) In the expression: _ In an equation for ‘a'’: a' x = _ In an equation for ‘foo’: foo a b = hylo a' b' where a' x = _ b' = _ bad.hs:7:14: Warning: Found hole ‘_’ with type: t3 Where: ‘t3’ is a rigid type variable bound by the inferred type of b' :: t3 at bad.hs:7:9 Relevant bindings include b' :: t3 (bound at bad.hs:7:9) b :: t1 (bound at bad.hs:5:7) a :: t (bound at bad.hs:5:5) foo :: t -> t1 -> t2 -> b (bound at bad.hs:5:1) In the expression: _ In an equation for ‘b'’: b' = _ In an equation for ‘foo’: foo a b = hylo a' b' where a' x = _ b' = _ Ok, modules loaded: Main. *Main> main ghc: panic! (the 'impossible' happened) (GHC version 7.10.2 for x86_64-unknown-linux): nameModule $dFunctor_aKj Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} Compiling with ghc and then running the resulting binary works. Attempting to replicate with a recent version of GHC HEAD gives {{{ GHCi, version 7.11.20150812: http://www.haskell.org/ghc/ :? for help unknown option: 'c' [1 of 1] Compiling Main ( bad.hs, interpreted ) bad.hs:5:11: error: No instance for (Functor f0) arising from a use of ‘hylo’ The type variable ‘f0’ is ambiguous Note: there are several potential instances: instance Functor Maybe -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Functor ((->) r) -- Defined in ‘GHC.Base’ ...plus two others In the expression: hylo a' b' In an equation for ‘foo’: foo a b = hylo a' b' where a' x = _ b' = _ Failed, modules loaded: none. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10769 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10769: Yet another crash from typed holes -------------------------------+----------------------------------------- Reporter: rpglover64 | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.3 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------+----------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10769#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10769: Yet another crash from typed holes -------------------------------+----------------------------------------- Reporter: rpglover64 | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.3 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------+----------------------------------------- Comment (by bgamari): I would probably say that the bug was that GHC 7.10.2 didn't realize it needed a `Functor` instance (hence crashing at runtime as it had no dictionary to provide). This appears to be fixed in `master`. The problem here is that you program is ambiguous; GHC has no way of knowing which functor you mean here. GHC will gladly help you fill in the holes of an unambiguous program, but it won't make decisions on your behalf. This can be resolved by telling GHC which functor `a'` is supposed to be. For instance, perhaps you want `a` and `a'` to be values of the same functor, {{{#!hs {-# OPTIONS_GHC -fdefer-typed-holes #-} {-# LANGUAGE ScopedTypeVariables #-} hylo :: Functor f => (a -> f a) -> (f b -> b) -> a -> b hylo a b = h where h = b . fmap h . a foo :: forall f a b. Functor f => (a -> f a) -> (f b -> b) -> a -> b foo a b = hylo a' b' where a' x = _ b' :: f b -> b b' = _ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10769#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10769: Yet another crash from typed holes -------------------------------+----------------------------------------- Reporter: rpglover64 | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.3 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------+----------------------------------------- Comment (by rpglover64): Interestingly, also passing `-fdefer-type-errors` makes ghc 7.10.2 both warn about "No instance for Functor" and run successfully. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10769#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10769: Yet another crash from typed holes
-------------------------------+-----------------------------------------
Reporter: rpglover64 | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 7.10.3
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64 (amd64)
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------+-----------------------------------------
Comment (by Ben Gamari

#10769: Yet another crash from typed holes -------------------------------+-------------------------------------- Reporter: rpglover64 | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------+-------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: 7.10.3 => 8.0.1 Comment: Fix won't be present in 7.10.3 but this should work in 8.0. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10769#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC