RE: [commit: ghc] wip/T9732: Generate two versions of pattern synonym matcher: * one where the continuation is lifted, * one where the continuation is unlifted. (423e9b2)

No no! Let's not do that. It's grotesque to generate identical code twice. We must find a better way.
Simon
| -----Original Message-----
| From: ghc-commits [mailto:ghc-commits-bounces@haskell.org] On Behalf
| Of git@git.haskell.org
| Sent: 30 October 2014 15:40
| To: ghc-commits@haskell.org
| Subject: [commit: ghc] wip/T9732: Generate two versions of pattern
| synonym matcher: * one where the continuation is lifted, * one where
| the continuation is unlifted. (423e9b2)
|
| Repository : ssh://git@git.haskell.org/ghc
|
| On branch : wip/T9732
| Link :
| http://ghc.haskell.org/trac/ghc/changeset/423e9b28930fb9e6dfcd4a20dd60
| 4ec488a2bb1d/ghc
|
| >---------------------------------------------------------------
|
| commit 423e9b28930fb9e6dfcd4a20dd604ec488a2bb1d
| Author: Dr. ERDI Gergo

On Thu, 30 Oct 2014, Simon Peyton Jones wrote:
No no! Let's not do that. It's grotesque to generate identical code twice. We must find a better way.
So the type of an open-kinded matcher function, for a pattern of type pattern type P :: [T a] would need to be something like $m?P :: forall (r :: ?) a. [T a] -> R(r) -> R(r) -> r where R(r) = Void# -> r if r :: # , r otherwise Is there a way to do that? I couldn't think of anything better than to generate two versions: $mP :: forall r a. [T a] -> r -> r -> r $m#P :: forall (r :: #) a. [T a] -> (Void# -> r) -> (Void# -> r) -> r Now, to cut down on the amount of code generated, I guess we could have $m?P :: forall (r :: ?) a. [T a] -> (Void# -> r) -> (Void# -> r) -> r and always compile pattern synonym match continuations into lambdas over this dummy Void#, but I thought we also wanted to avoid that... Note that if P were to have arguments, the same problem would still be present with the fail continuation (but not the success one).

| $m?P :: forall (r :: ?) a. [T a] -> R(r) -> R(r) -> r | | where R(r) = Void# -> r if r :: # | , r otherwise | | Is there a way to do that? No indeed. | Now, to cut down on the amount of code generated, I guess we could | have | | $m?P :: forall (r :: ?) a. [T a] -> (Void# -> r) -> (Void# -> r) -> r | | and always compile pattern synonym match continuations into lambdas | over this dummy Void#, but I thought we also wanted to avoid that... I think that's fine. These matchers will usually be inlined and all the clutter will go away. | Note that if P were to have arguments, the same problem would still be | present with the fail continuation (but not the success one). Yes, let's take advantage of that S
participants (2)
-
Dr. ERDI Gergo
-
Simon Peyton Jones