Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#11344 closed bug (duplicate)

Rule "and/build" not firing

Reported by: j.waldmann Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9848 Differential Rev(s):
Wiki Page:

Description

For this function

isprime_1 :: Int -> Bool
isprime_1 n = n >= 2 &&
  ( and $ map (\t -> 0 < mod n t) $
       [2 .. truncate $ sqrt $ fromIntegral n] )

rule "and/build" is not firing with ghc-7.10.3.

ghc-7.8.4 does fire the rule and produces much better (that is, non-allocating) code.

I can get good code with 7.10 if I replace "and" by

import GHC.Base (build)

{-# RULES
"und/build"  forall (g::forall b.(Bool->b->b)->b->b) .
                und (build g) = g (&&) True
 #-}

{-# NOINLINE und #-}
und :: [Bool] -> Bool
und = foldr (&&) True

Change History (3)

comment:1 Changed 3 years ago by nomeata

Resolution: duplicate
Status: newclosed

This is a regression due to BBP: and no longer is GHC.OldList.and (if you import that, it works), but rather

and :: Foldable t => t Bool -> Bool
and = getAll #. foldMap All

foldMap has been modified to fuse better since then, see #9848.

comment:2 Changed 3 years ago by simonpj

Can someone check if the fix to #9848 fixes this ticket too? ANd add a regression test?

Thanks

Simon

comment:3 Changed 3 years ago by nomeata

I did check, it fixes this (that’s why I closed it). Also, that ticket has a regression test for and. I think we are fine (besides slightly shamed that it is broken in 7.10).

Note: See TracTickets for help on using tickets.