[GHC] #15426: `elemIndex` and `findIndex` still can't fuse

GHC ghc-devs at haskell.org
Sat Aug 11 20:57:23 UTC 2018


#15426: `elemIndex` and `findIndex` still can't fuse
-------------------------------------+-------------------------------------
        Reporter:  kabuhr            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.8.1
       Component:  libraries/base    |              Version:  8.4.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by kabuhr):

 Okay, I'm working on a patch/test case, but I need some advice.  The issue
 seems to be that because `findIndices` is marked `INLINE` instead of
 merely `INLINABLE`, the unfolding in the interface file for the function:
 {{{
 #!haskell
 findIndex       :: (a -> Bool) -> [a] -> Maybe Int
 findIndex p     = listToMaybe . findIndices p
 }}}
 has already been turned into an unfusible version.  I can fix this in one
 of two ways, either by marking `findIndex` as `INLINABLE` which puts a
 fusible version of `findIndex` (with `findIndices` already inlined) into
 the interface file **OR** by demoting `findIndices` from `INLINE` to
 merely `INLINABLE`.  (It must be marked `INLINABLE` to keep a fusible
 version in the interface file; if it's unmarked, an unfusible unfolding is
 included instead.)

 I favor the second option, because it seems cleaner and also seems more
 likely to generate better code when `findIndices` is used directly in user
 code (i.e., because it will help avoid the same situation we currently
 have with `findIndex` and `elemIndex`).

 Is there any drawback to switching `findIndices` from `INLINE` to
 `INLINABLE`?  In other words, what is the motivation in the first place
 for marking `findIndices` as `INLINE` instead of just `INLINABLE`.  I've
 run the normal test suite (`make test`) before and after the change and
 didn't observe any performance regressions.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15426#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list