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):
I have a first working prototype, pushed to the wip/nomeata-T2110 branch.
Comments how to do that properly and non-hacky are welcome.
I ended up implementing the first idea, and this is what works: In the
file
{{{
module Test where
import GHC.Exts
import Unsafe.Coerce
{-# RULES
"map/coerce" map coerce = coerce
#-}
newtype Age = Age Int
foo :: [Int] -> [Age]
foo = map Age
bar :: [Int] -> [Age]
bar = map coerce
baz :: [Int] -> [Age]
baz = map unsafeCoerce
}}}
the rule will be desugared to
{{{
------ Local rules for imported ids --------
"map/coerce" [ALWAYS]
forall (@ a_aET)
(@ b_aEU)
($dCoercible_aEO :: a_aET GHC.Prim.~R# b_aEU).
GHC.Base.map @ a_aET
@ b_aEU
((\ (tpl_B1 :: a_aET) -> tpl_B1)
`cast` (
participants (1)
-
GHC