[commit: ghc] wip/cheap-build: Implement cheapBuild (f95f7a7)

git at git.haskell.org git at git.haskell.org
Thu Mar 16 17:21:06 UTC 2017


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

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

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

commit f95f7a7afc07bc545aec7758b10a7931b1dc0381
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


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

f95f7a7afc07bc545aec7758b10a7931b1dc0381
 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 018c0a7..8906a91 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)
  #-}
@@ -730,6 +732,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
 
@@ -747,6 +751,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
 
@@ -767,6 +773,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
 
@@ -786,6 +794,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
 
@@ -803,6 +813,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
 
@@ -817,6 +829,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
 
@@ -900,6 +914,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