[GHC] #15845: TH eta-reduces away explicit foralls in data family instances
#15845: TH eta-reduces away explicit foralls in data family instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Template | Version: 8.7 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #9692, #14179 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Consider the following code: {{{#!hs {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} module Bug where import Language.Haskell.TH data family F1 a b data instance F1 [a] b = MkF1 data family F2 a data instance F2 a = MkF2 $(do i1 <- reify ''F1 i2 <- reify ''F2 runIO $ mapM_ (putStrLn . pprint) [i1, i2] pure []) }}} {{{ $ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive Bug.hs GHCi, version 8.7.20181101: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) data family Bug.F1 (a_0 :: *) (b_1 :: *) :: * data instance forall (a_2 :: *). Bug.F1 ([a_2]) b_3 = Bug.MkF1 data family Bug.F2 (a_0 :: *) :: * data instance Bug.F2 a_1 = Bug.MkF2 }}} The output here is quite baffling: * In the `F1` instance, we have an explicit `forall` which quantifies `a_2` but not `b_3`! * In the `F2` instance, there isn't an explicit `forall` at all despite the fact that there ought to be one, since there is a type variable `a_1` in this instance. The culprit in both of the bullet points above is the fact that GHC eta- reduces its internal representation of data family instance axioms. This is the same thing which caused #9692 and #14179, in fact. Luckily, the same fix for those tickets will also work here. Patch incoming. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15845> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15845: TH eta-reduces away explicit foralls in data family instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Template Haskell | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9692, #14179 | Differential Rev(s): Phab:D5294 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D5294 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15845#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15845: TH eta-reduces away explicit foralls in data family instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Template Haskell | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9692, #14179 | Differential Rev(s): Phab:D5294 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"63a817074a8d49798bfd46a6545906fff143e924/ghc" 63a81707/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="63a817074a8d49798bfd46a6545906fff143e924" Fix #15845 by defining etaExpandFamInstLHS and using it Summary: Both #9692 and #14179 were caused by GHC being careless about using eta-reduced data family instance axioms. Each of those tickets were fixed by manually whipping up some code to eta-expand the axioms. The same sort of issue has now caused #15845, so I figured it was high time to factor out the code that each of these fixes have in common. This patch introduces the `etaExpandFamInstLHS` function, which takes a family instance's type variables, LHS types, and RHS type, and returns type variables and LHS types that have been eta-expanded if necessary, in the case of a data family instance. (If it's a type family instance, `etaExpandFamInstLHS` just returns the supplied type variables and LHS types unchanged). Along the way, I noticed that many references to `Note [Eta reduction for data families]` (in `FamInstEnv`) had slightly bitrotted (they either referred to a somewhat different name, or claimed that the Note lived in a different module), so I took the liberty of cleaning those up. Test Plan: make test TEST="T9692 T15845" Reviewers: goldfire, bgamari Reviewed By: goldfire Subscribers: rwbarton, carter GHC Trac Issues: #15845 Differential Revision: https://phabricator.haskell.org/D5294 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15845#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15845: TH eta-reduces away explicit foralls in data family instances -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Template Haskell | Version: 8.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T15845 Blocked By: | Blocking: Related Tickets: #9692, #14179 | Differential Rev(s): Phab:D5294 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => th/T15845 * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15845#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC