[commit: ghc] wip/cheap-build-osa1: Implement cheapBuild (7a87c59)

git at git.haskell.org git at git.haskell.org
Wed Feb 21 06:50:16 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/cheap-build-osa1
Link       : http://ghc.haskell.org/trac/ghc/changeset/7a87c59c2f00248e0368999f5cd23877a04c2e28/ghc

>---------------------------------------------------------------

commit 7a87c59c2f00248e0368999f5cd23877a04c2e28
Author: David Feuer <David.Feuer at gmail.com>
Date:   Mon Jan 30 21:38:12 2017 -0500

    Implement cheapBuild
    
    Summary:
    Ben Gamari's `cheapBuild` patch with some extras
    
    Use cheapBuild for enumerating Chars
    
    Use cheapBuild for enumerating Ints
    
    Add cheapBuild rules for other consumers
    
    `GHC.List` fuses a number of functions other than `foldr` with
    `build`. Make those fuse with `cheapBuild` too.
    
    Reviewers: austin, hvr, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D3047


>---------------------------------------------------------------

7a87c59c2f00248e0368999f5cd23877a04c2e28
 libraries/base/GHC/List.hs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libraries/base/GHC/List.hs b/libraries/base/GHC/List.hs
index af50213..e177e07 100644
--- a/libraries/base/GHC/List.hs
+++ b/libraries/base/GHC/List.hs
@@ -59,6 +59,8 @@ badHead = errorEmptyList "head"
 {-# RULES
 "head/build"    forall (g::forall b.(a->b->b)->b->b) .
                 head (build g) = g (\x _ -> x) badHead
+"head/cheapBuild"    forall (g::forall b.(a->b->b)->b->b) .
+                head (cheapBuild g) = g (\x _ -> x) badHead
 "head/augment"  forall xs (g::forall b. (a->b->b) -> b -> b) .
                 head (augment g xs) = g (\x _ -> x) (head xs)
  #-}
@@ -756,6 +758,8 @@ and (x:xs)      =  x && and xs
 {-# RULES
 "and/build"     forall (g::forall b.(Bool->b->b)->b->b) .
                 and (build g) = g (&&) True
+"and/cheapBuild"     forall (g::forall b.(Bool->b->b)->b->b) .
+                     and (cheapBuild g) = g (&&) True
  #-}
 #endif
 
@@ -773,6 +777,8 @@ or (x:xs)       =  x || or xs
 {-# RULES
 "or/build"      forall (g::forall b.(Bool->b->b)->b->b) .
                 or (build g) = g (||) False
+"or/cheapBuild"      forall (g::forall b.(Bool->b->b)->b->b) .
+                     or (cheapBuild g) = g (||) False
  #-}
 #endif
 
@@ -793,6 +799,8 @@ any p (x:xs)    = p x || any p xs
 {-# RULES
 "any/build"     forall p (g::forall b.(a->b->b)->b->b) .
                 any p (build g) = g ((||) . p) False
+"any/cheapBuild"     forall p (g::forall b.(a->b->b)->b->b) .
+                     any p (cheapBuild g) = g ((||) . p) False
  #-}
 #endif
 
@@ -812,6 +820,8 @@ all p (x:xs)    =  p x && all p xs
 {-# RULES
 "all/build"     forall p (g::forall b.(a->b->b)->b->b) .
                 all p (build g) = g ((&&) . p) True
+"all/cheapBuild"     forall p (g::forall b.(a->b->b)->b->b) .
+                     all p (cheapBuild g) = g ((&&) . p) True
  #-}
 #endif
 
@@ -829,6 +839,8 @@ elem x (y:ys)   = x==y || elem x ys
 {-# RULES
 "elem/build"    forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)
    . elem x (build g) = g (\ y r -> (x == y) || r) False
+"elem/cheapBuild"    forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)
+   . elem x (cheapBuild g) = g (\ y r -> (x == y) || r) False
  #-}
 #endif
 
@@ -843,6 +855,8 @@ notElem x (y:ys)=  x /= y && notElem x ys
 {-# RULES
 "notElem/build" forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)
    . notElem x (build g) = g (\ y r -> (x /= y) && r) True
+"notElem/cheapBuild" forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)
+   . notElem x (cheapBuild g) = g (\ y r -> (x /= y) && r) True
  #-}
 #endif
 
@@ -926,6 +940,8 @@ foldr2_left  k _z  x  r (y:ys) = k x y (r ys)
 {-# RULES
 "foldr2/left"   forall k z ys (g::forall b.(a->b->b)->b->b) .
                   foldr2 k z (build g) ys = g (foldr2_left  k z) (\_ -> z) ys
+"foldr2/cheapleft"   forall k z ys (g::forall b.(a->b->b)->b->b) .
+                     foldr2 k z (cheapBuild g) ys = g (foldr2_left  k z) (\_ -> z) ys
  #-}
 -- There used to be a foldr2/right rule, allowing foldr2 to fuse with a build
 -- form on the right. However, this causes trouble if the right list ends in



More information about the ghc-commits mailing list