[Haskell-cafe] INLINABLE and SPECIALIZE, GHC 8.0.1

Jyotirmoy Bhattacharya jyotirmoy at jyotirmoy.net
Fri Jun 17 11:01:40 UTC 2016

I'm trying to write a mutable hash table library that would work both in
the IO and ST monads, so I'm using the PrimMonad typeclass [see
JmoyHash.hs  in the attached archive].

For efficiency, I would like the functions to be specialized to the
concrete monad at the call site. According to Section of the GHC
User's Guide

The optimiser *also* considers each *imported* INLINABLE overloaded
function, and specialises it for the different types at which it is called
in M.

So I marked all the functions in my library as INLINABLE. Yet adding a
SPECIALIZE pragma in Main.hs (currently commented out) for an imported
function improves runtime performance by 3x, which should not be happening
since, if I understand the manual right, the function should have been
specialized anyway since it is marked INLINABLE.

I am writing to this list rather than filing a bug since I'm not sure if
I'm reading the manual right and I have not explicitly verified that the
specialization is not happening. I would greatly appreciate any help on
both counts.

I'm using GHC 8.0.1 with the -O2 flag.

Marking the function as INLINE might solve the problem but that's something
I don't want to do as it seems to me that specialization and not inlining
is what's appropriate here.

Jyotirmoy Bhattacharya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160617/b2fb466d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-specialize.tar.bz2
Type: application/x-bzip2
Size: 172157 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160617/b2fb466d/attachment-0001.bin>

More information about the Haskell-Cafe mailing list