[GHC] #14140: Better treatment for dataToTag

GHC ghc-devs at haskell.org
Fri Sep 8 09:02:18 UTC 2017


#14140: Better treatment for dataToTag
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:                    |             Keywords:  datacon-tags
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):

 hysl20 is right.  Doing stuff in `PrelRules` works if the rewrite we want
 is something like `dataToTag True --->  1`.

 But for this ticket we don't want that.  What we know is negative
 information: `dataToTag x` cannot be `16#`.  This is carried by the
 `OtherCon` uunfolding for `x`.

 So the place to implement this ticket (if that is behind your question) is
 `SimplUtils.prepareAlts`.  We want to say "if the scrutinee is `dataToTag
 x` and `x` has an unfolding of `OtherCon [A,B,C]`, then eliminate any
 alternatives that match those constructors".  Something like this in
 `prepareAlts`
 {{{
 imposs_cons = case scrut of
                 Var v -> otherCons (idUnfolding v)  -- as now
                 App dataToTag (Var v)  -> map (LitCon . conToTag)
                                               (otherCons (idUnfolding v))
                 _ -> []
 }}}
 That is,
 * If the scrutinee is `dataToTag v`
 * And v cannot be `[A,C,F]`
 * Then we know that `dataToTag v` cannot be `[1#, 3#, 6#]`
 * And so we can make a suitable `imposs_cons`

 Does that help?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14140#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list