[GHC] #9137: A way to match RULES only for literals
GHC
ghc-devs at haskell.org
Fri May 23 11:08:23 UTC 2014
#9137: A way to match RULES only for literals
-------------------------------------+------------------------------------
Reporter: nomeata | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Description changed by nomeata:
Old description:
> In `GHC/Enum` we have
> {{{
> {-# RULES
> "enumDeltaToInteger1" [0] forall c n x . enumDeltaToIntegerFB c n x 1 =
> up_fb c n x 1
> #-}
> -- This rule ensures that in the common case (delta = 1), we do not do
> the check here,
> -- and also that we have the chance to inline up_fb, which would allow
> the constructor to be
> -- inlined and good things to happen.
> -- We do not do it for Int this way because hand-tuned code already
> exists, and
> -- the special case varies more from the general case, due to the issue
> of overflows.
> }}}
> This rule would be useful for all literals, not just for `1`.
>
> I remember a discussion that such a rule would be more useful if we had a
> way to specify that, for example (random syntax).
> {-# RULES
> "enumDeltaToInteger1" [0] forall c n x d . isLiteral d =>
> enumDeltaToIntegerFB c n x d = up_fb c n x d
> #-}
> I’m reporting this now to be able to link to it from #9136, where this
> feature might also help.
New description:
In `GHC/Enum` we have
{{{
{-# RULES
"enumDeltaToInteger1" [0] forall c n x . enumDeltaToIntegerFB c n x 1 =
up_fb c n x 1
#-}
-- This rule ensures that in the common case (delta = 1), we do not do the
check here,
-- and also that we have the chance to inline up_fb, which would allow the
constructor to be
-- inlined and good things to happen.
-- We do not do it for Int this way because hand-tuned code already
exists, and
-- the special case varies more from the general case, due to the issue of
overflows.
}}}
This rule would be useful for all literals, not just for `1`.
I remember a discussion that such a rule would be more useful if we had a
way to specify that, for example (random syntax).
{{{
{-# RULES
"enumDeltaToInteger1" [0] forall c n x d . isLiteral d =>
enumDeltaToIntegerFB c n x d = up_fb c n x d
#-}
}}}
I’m reporting this now to be able to link to it from #9136, where this
feature might also help.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9137#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list