[GHC] #13581: UNPACK should allow recursion that obviously terminates

#13581: UNPACK should allow recursion that obviously terminates -------------------------------------+------------------------------------- Reporter: ryanreich | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 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: -------------------------------------+------------------------------------- I want to do this: {{{ {-# LANGUAGE TypeFamilies MagicHash KindSignatures #-} data Peano = Zero | Succ Peano data family BigWord (n :: Peano) data instance BigWord Zero = MachineWord# Word# data instance BigWord (Succ n) = BigWord {-# UNPACK #-}(BigWord n) {-# UNPACK #-}(BigWord n) }}} However, the compiler tells me that it is ignoring the UNPACKs, and the only reason I can see is that they are apparently recursive. This exact type of recursion is handled just fine in instance declarations because the recursive instance has fewer type constructors than the head; can't UNPACK do the same thing? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13581 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13581: UNPACK should allow recursion that obviously terminates -------------------------------------+------------------------------------- Reporter: ryanreich | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 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): No, the reason that GHC can't act on the unpacks is that it processes each `data instance` declaration, once and for all, when it encounters it. So it bahveas much as if it saw {{{ type instance BigWord (Succ n) = BigWord_Succ n data BigWord_Succ n = BigWord {-# UNPACK #-}(BigWord n} {-# UNPACK #-}(BigWord n) }}} At this point it can't unpack those fields because it has no idea what `n` is. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13581#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13581: UNPACK should allow recursion that obviously terminates -------------------------------------+------------------------------------- Reporter: ryanreich | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 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 ryanreich): When you say that it has no idea what `n` is, do you mean that it can't figure out if it is `Zero` or not, or that it can't unpack `BigWord n` at all simply because `n` is polymorphic? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13581#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13581: UNPACK should allow recursion that obviously terminates -------------------------------------+------------------------------------- Reporter: ryanreich | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 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): I mean that given {{{ data BigWord_Succ n = BigWord {-# UNPACK #-}(BigWord n} {-# UNPACK #-}(BigWord n) }}} `n` is clearly polymorphic, so GHC can't simplify `(BigWord n)`. And if it can't simplify it, it can't unpack it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13581#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC