[GHC] #14363: :type hangs on coerce

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This works {{{ ghci -ignore-dot-ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Prelude> import Data.Coerce Prelude Data.Coerce> :t [fmap, coerce] <interactive>:1:8: error: • Occurs check: cannot construct the infinite type: b ~ f b arising from a use of ‘coerce’ • In the expression: coerce In the expression: [fmap, coerce] }}} But doing it with `contra` {{{ Prelude Data.Coerce> contra = undefined :: Functor f => (b -> a) -> (f a -> f b) }}} it hangs {{{ Prelude Data.Coerce> :t [coerce, contra] ^CInterrupted. Prelude Data.Coerce> :t [contra, coerce] ^CInterrupted. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: Old description:
This works
{{{ ghci -ignore-dot-ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Prelude> import Data.Coerce Prelude Data.Coerce> :t [fmap, coerce]
<interactive>:1:8: error: • Occurs check: cannot construct the infinite type: b ~ f b arising from a use of ‘coerce’ • In the expression: coerce In the expression: [fmap, coerce]
}}}
But doing it with `contra`
{{{ Prelude Data.Coerce> contra = undefined :: Functor f => (b -> a) -> (f a -> f b) }}}
it hangs
{{{ Prelude Data.Coerce> :t [coerce, contra] ^CInterrupted. Prelude Data.Coerce> :t [contra, coerce] ^CInterrupted. }}}
New description: This works {{{ $ ghci -ignore-dot-ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Prelude> import Data.Coerce Prelude Data.Coerce> :t [fmap, coerce] <interactive>:1:8: error: • Occurs check: cannot construct the infinite type: b ~ f b arising from a use of ‘coerce’ • In the expression: coerce In the expression: [fmap, coerce] }}} But doing it with `contra` {{{ Prelude Data.Coerce> contra = undefined :: Functor f => (b -> a) -> (f a -> f b) }}} it hangs {{{ Prelude Data.Coerce> :t [coerce, contra] ^CInterrupted. Prelude Data.Coerce> :t [contra, coerce] ^CInterrupted. }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): `Functor` constraint not needed to make it hang {{{ Prelude Data.Coerce> contra = undefined :: (a -> b) -> (f b -> f a) Prelude Data.Coerce> :t [contra, coerce] ^CInterrupted. }}} Giving it a concrete type gives an actual failure {{{ Prelude Data.Coerce> contra = undefined :: (a -> b) -> (Maybe b -> Maybe a) Prelude Data.Coerce> :t [contra, coerce] <interactive>:1:10: error: • Occurs check: cannot construct the infinite type: b ~ Maybe (Maybe b) arising from a use of ‘coerce’ • In the expression: coerce In the expression: [contra, coerce] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Gah! How has this bug survived so long? I see this {{{ Inert set: [G] co1: a ~R# f b Work item: [B] co2: b ~R# f a }}} We can't rewrite the work item `co2` with the inert `co1`, because the role of f's argument is Nominal, sot`co1` can't rewrite it. So we add `co2` to the inert set. Alas we then kick out `co1` becuase it has a free `b`, thinking that it might be rewritten by `co2`. But of course it can't and we get an infinite loop instead. Sigh! What's wrong? I think that `anyRewritableTyVar` needs to beecome role- aware. Richard do you agree? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * keywords: => Roles -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Yes, `anyRewritableTyVar` needs to become role-aware. It should pass a role to the predicate function, I think. But I'm not sure why the "occurs check" failure in the original post is correct. IIUC, we're trying to check `coerce :: (a -> b) -> (f a -> f b)`. In other words, we want to prove `Coercible (a -> b) (f a -> f b)`, which decomposes to `Coercible a (f a)` and `Coercible b (f b)`. These aren't insoluble, and I don't think we should report an occurs-check problem. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
Resolution: | Keywords: Roles
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_compile/T14363, | T14363a Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * testcase: => typecheck/should_compile/T14363, T14363a * resolution: => fixed Comment: My patch fixes the loop. The occurs-check problem was already fixed, perhaps by my `wc_insol` changes. I've added tests for both. Richard I'd appreciate a quick look at the patch, but I'm pretty confident (following our discussion) hence committing. Perhaps you can then close. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_compile/T14363, | T14363a Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Thank you Simon. A coworker of mine met you at yesterday's Papers We Love, she said you were working on a patch fixing a loop in the type checker :] I'm curious if this was it -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14363: :type hangs on coerce -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_compile/T14363, | T14363a Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Yes, that was it :-). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14363#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC