RE: [commit: ghc] master: Add rule mapFB c (λx.x) = c (2fa4421)

Simon Peyton Jones simonpj at microsoft.com
Wed Mar 8 12:22:55 UTC 2017


Joachim

Please, I beg you, add a comment to explain why this rule is useful. I'm sure you had a good reason for adding it, but it's not apparent from the code.

Thanks

Simon

|  -----Original Message-----
|  From: ghc-commits [mailto:ghc-commits-bounces at haskell.org] On Behalf
|  Of git at git.haskell.org
|  Sent: 06 March 2017 23:52
|  To: ghc-commits at haskell.org
|  Subject: [commit: ghc] master: Add rule mapFB c (λx.x) = c (2fa4421)
|  
|  Repository : ssh://git@git.haskell.org/ghc
|  
|  On branch  : master
|  Link       :
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fghc.ha
|  skell.org%2Ftrac%2Fghc%2Fchangeset%2F2fa44217c1d9722227297eefb0d6c6aed
|  7e128ca%2Fghc&data=02%7C01%7Csimonpj%40microsoft.com%7Cc5db3687da004cd
|  11d0f08d464ebc6ca%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6362444
|  11212143808&sdata=KMHS17MUXQUkBOaMbFiRxXiRM8gIvlEMGz%2FDw7F7Njo%3D&res
|  erved=0
|  
|  >---------------------------------------------------------------
|  
|  commit 2fa44217c1d9722227297eefb0d6c6aed7e128ca
|  Author: Joachim Breitner <mail at joachim-breitner.de>
|  Date:   Mon Mar 6 17:30:52 2017 -0500
|  
|      Add rule mapFB c (λx.x) = c
|  
|      Test Plan: exended T2110 with a case for that.
|  
|      Reviewers: austin, hvr, dfeuer, bgamari
|  
|      Reviewed By: dfeuer
|  
|      Subscribers: dfeuer, thomie
|  
|      Differential Revision: https://phabricator.haskell.org/D3275
|  
|  
|  >---------------------------------------------------------------
|  
|  2fa44217c1d9722227297eefb0d6c6aed7e128ca
|   libraries/base/GHC/Base.hs                        | 1 +
|   testsuite/tests/simplCore/should_run/T2110.hs     | 3 +++
|   testsuite/tests/simplCore/should_run/T2110.stdout | 1 +
|   3 files changed, 5 insertions(+)
|  
|  diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
|  index 2f155c6..6f9d454 100644
|  --- a/libraries/base/GHC/Base.hs
|  +++ b/libraries/base/GHC/Base.hs
|  @@ -973,6 +973,7 @@ mapFB c f = \x ys -> c (f x) ys
|   "map"       [~1] forall f xs.   map f xs                = build (\c n
|  -> foldr (mapFB c f) n xs)
|   "mapList"   [1]  forall f.      foldr (mapFB (:) f) []  = map f
|   "mapFB"     forall c f g.       mapFB (mapFB c f) g     = mapFB c
|  (f.g)
|  +"mapFB/id"  forall c.           mapFB c (\x -> x)       = c
|     #-}
|  
|   -- See Breitner, Eisenberg, Peyton Jones, and Weirich, "Safe Zero-
|  cost diff --git a/testsuite/tests/simplCore/should_run/T2110.hs
|  b/testsuite/tests/simplCore/should_run/T2110.hs
|  index 610be09..d945fac 100644
|  --- a/testsuite/tests/simplCore/should_run/T2110.hs
|  +++ b/testsuite/tests/simplCore/should_run/T2110.hs
|  @@ -5,6 +5,8 @@ import Unsafe.Coerce
|  
|   newtype Age = Age Int
|  
|  +foo :: [Int] -> [Int]
|  +foo = map id
|   fooAge :: [Int] -> [Age]
|   fooAge = map Age
|   fooCoerce :: [Int] -> [Age]
|  @@ -19,6 +21,7 @@ same x y = case reallyUnsafePtrEquality#
|  (unsafeCoerce x) y of
|  
|   main = do
|       let l = [1,2,3]
|  +    same (foo l) l
|       same (fooAge l) l
|       same (fooCoerce l) l
|       same (fooUnsafeCoerce l) l
|  diff --git a/testsuite/tests/simplCore/should_run/T2110.stdout
|  b/testsuite/tests/simplCore/should_run/T2110.stdout
|  index 55f7ebb..4ff957b 100644
|  --- a/testsuite/tests/simplCore/should_run/T2110.stdout
|  +++ b/testsuite/tests/simplCore/should_run/T2110.stdout
|  @@ -1,3 +1,4 @@
|   yes
|   yes
|   yes
|  +yes
|  
|  _______________________________________________
|  ghc-commits mailing list
|  ghc-commits at haskell.org
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  commits&data=02%7C01%7Csimonpj%40microsoft.com%7Cc5db3687da004cd11d0f0
|  8d464ebc6ca%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6362444112121
|  43808&sdata=y%2BRYDSeV9k2Uj%2BlPtE%2BeIeG05mQvE97QV0B0wgl7cx4%3D&reser
|  ved=0


More information about the ghc-devs mailing list