[commit: ghc] master: Document missing dataToTag# . tagToEnum# rule (517c194)

git at git.haskell.org git at git.haskell.org
Tue Feb 20 04:53:35 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/517c194095064c123b18b779c96c0866e0b3a6d9/ghc

>---------------------------------------------------------------

commit 517c194095064c123b18b779c96c0866e0b3a6d9
Author: David Feuer <david.feuer at gmail.com>
Date:   Mon Feb 19 23:48:22 2018 -0500

    Document missing dataToTag# . tagToEnum# rule
    
    Explain why we don't have a rule to optimize `dataToTag# (tagToEnum# x)`
    to `x`.
    
    [skip ci]
    
    Reviewers: bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #14282
    
    Differential Revision: https://phabricator.haskell.org/D4375


>---------------------------------------------------------------

517c194095064c123b18b779c96c0866e0b3a6d9
 compiler/prelude/PrelRules.hs | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/compiler/prelude/PrelRules.hs b/compiler/prelude/PrelRules.hs
index c9a3bc7..73484b7 100644
--- a/compiler/prelude/PrelRules.hs
+++ b/compiler/prelude/PrelRules.hs
@@ -909,6 +909,19 @@ dataToTagRule = a `mplus` b
       guard $ ty1 `eqType` ty2
       return tag
 
+    -- Why don't we simplify tagToEnum# (dataToTag# x) to x? We would
+    -- like to, but it seems tricky. See #14282. The trouble is that
+    -- we never actually see tagToEnum# (dataToTag# x). Because dataToTag#
+    -- is can_fail, this expression is immediately transformed into
+    --
+    --   case dataToTag# @T x of wild
+    --     { __DEFAULT -> tagToEnum# @T wild }
+    --
+    -- and wild has no unfolding. Simon Peyton Jones speculates one way around
+    -- might be to arrange to give unfoldings to case binders of CONLIKE
+    -- applications and mark dataToTag# CONLIKE, but he doubts it's really
+    -- worth the trouble.
+
     -- dataToTag (K e1 e2)  ==>   tag-of K
     -- This also works (via exprIsConApp_maybe) for
     --   dataToTag x



More information about the ghc-commits mailing list