Re: [GHC] #2110: Rules to eliminate casted id's

#2110: Rules to eliminate casted id's
-------------------------------------+------------------------------------
Reporter: igloo | Owner:
Type: feature request | Status: new
Priority: lowest | Milestone: 7.6.2
Component: Compiler | Version: 6.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:
-------------------------------------+------------------------------------
Comment (by nomeata):
Please allow me to use this as a notepad; this way I (or someone else) can
easily find the thoughts later.
With `Coercible` in GHC, one might want that
{{{
{-# RULES
"myMap/coerce" myMap coerce = coerce
#-}
}}}
will be a usable rule that would also fire in
{{{
foo :: [Int] -> [Age]
foo = myMap Age
}}}
At the moment, it does not do that yet. Here is the rule (as shown by
`-ddump-rules`, with `-O`):
{{{
==================== Tidy Core rules ====================
"myMap/coerce" [ALWAYS]
forall (@ t) (@ t1) ($dCoercible :: GHC.Types.Coercible t t1).
Test.myMap @ t @ t1 (GHC.Prim.coerce @ t @ t1 $dCoercible)
= GHC.Prim.coerce
@ [t]
@ [t1]
(case $dCoercible of _ { GHC.Types.MkCoercible ds ->
GHC.Types.MkCoercible @ [t] @ [t1] @~ [ds]_R
})
}}}
and here is the Core code the rule needs to match (`-ddump-simpl`, with
`-O`):
{{{
Test.foo1 :: GHC.Types.Int -> GHC.Types.Int
[GblId,
Arity=1,
Caf=NoCafRefs,
Str=DmdType m,
Unf=Unf{Src=InlineStable, TopLvl=True, Arity=1, Value=True,
ConLike=True, WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=True)
Tmpl= \ (tpl_B1 [Occ=Once] :: GHC.Types.Int) -> tpl_B1}]
Test.foo1 = \ (tpl_B1 :: GHC.Types.Int) -> tpl_B1
Test.foo :: [GHC.Types.Int] -> [Test.Age]
[GblId,
Arity=1,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=0, Value=True,
ConLike=True, WorkFree=True, Expandable=True,
Guidance=IF_ARGS [] 20 60}]
Test.foo =
Test.foo_myMap
@ GHC.Types.Int
@ Test.Age
(Test.foo1
`cast` (
participants (1)
-
GHC