[GHC] #10698: Forall'd variable ‘$rcobox’ is not bound in RULE lhs

#10698: Forall'd variable ‘$rcobox’ is not bound in RULE lhs -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- I tried to add this rule to the code of `Data.Map`: {{{ {-# RULES "mapKeysMonotonic/coerce" mapKeysMonotonic coerce = coerce #-} }}} but it would not go through: {{{#!hs libraries/containers/Data/Map/Base.hs:1800:1: warning: Forall'd variable ‘$rcobox’ is not bound in RULE lhs Orig bndrs: [k2, a, $rcobox] Orig lhs: let { cobox_ab8H :: Coercible k2 k2 [LclId, Str=DmdType] cobox_ab8H = MkCoercible @ * @ k2 @ k2 @~ (<k2>_R :: k2 ~R# k2) } in mapKeysMonotonic @ k2 @ k2 @ a (coerce @ k2 @ k2 cobox_ab8H) optimised lhs: mapKeysMonotonic @ k2 @ k2 @ a (\ (tpl_B2 :: k2) -> case cobox_ab8H of _ [Occ=Dead] { MkCoercible tpl_B3 -> tpl_B2 }) }}} The same syntax works for mapping the second parameter, i.e. {{{ {-# RULES "map/coerce" map coerce = coerce #-} }}} (this still `Data.Map`’s `map`). This blocks https://github.com/haskell/containers/pull/163 I’ll see if I can produce a stand-alone testcase. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10698 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10698: Forall'd variable ‘$rcobox’ is not bound in RULE lhs -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by nomeata): Hmm, guess I was misguided here. Of course, `Map`’s first argument is set by the user to have role Nominal. For some reason I assumed that, as long as the constructors are in scope, I can still coerce it. But that’s not the way we went. So the whole rule is unfortunately not possible. Anyways, ghc-7.8 has a proper error message, instead of a weird warning: {{{ T10698.hs:19:53: Could not coerce from ‘Map k1 a’ to ‘Map k2 a’ because the first type argument of ‘Map’ has role Nominal, but the arguments ‘k1’ and ‘k2’ differ arising from a use of ‘coerce’ from the context (Coercible k1 k2) bound by the RULE "mapKeysMonotonic/coerce" at T10698.hs:19:1-58 In the expression: coerce When checking the transformation rule "mapKeysMonotonic/coerce" }}} so the bug is about the regression of the error message. Will commit a test case right away. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10698#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10698: Forall'd variable ‘$rcobox’ is not bound in RULE lhs
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Joachim Breitner

#10698: Forall'd variable ‘$rcobox’ is not bound in RULE lhs -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by nomeata): It can be triggered already with {{{ {-# RULES "coerce/id" coerce = id #-} }}} so my hypothesis is that the desugar creates something like {{{ Orig bndrs: [b, $rcobox] Orig lhs: let { cobox_acD :: Coercible b b [LclId, Str=DmdType] cobox_acD = MkCoercible @ * @ b @ b @~ $rcobox } in coerce @ b @ b cobox_acD }}} but since `$rcobox :: b ~_R b`, the coercion simplifier simplifies this to {{{ Orig bndrs: [b, $rcobox] Orig lhs: let { cobox_acD :: Coercible b b [LclId, Str=DmdType] cobox_acD = MkCoercible @ * @ b @ b @~ <b>_R } in coerce @ b @ b cobox_acD }}} and the “Forall'd variable ‘`$rcobox`’“ is is no longer used. One possibly sensible fix would be to remove forall’ed variables that are also not mentioned on the right hand side (I would assume that to be the case here, although I did not check), and do that before the warning is triggered. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10698#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC