Proposal: EPHEMERAL pragma

Ryan Trinkle ryan.trinkle at gmail.com
Thu Oct 25 16:08:25 CEST 2012


On a related note, it would be nice to have a little more tooling for
ensuring that SPECIALIZE pragmas take full effect.  In particular, it's
nice to write generic code over numeric types (Double, Float), but if it
doesn't get specialized away, performance really tanks.  Going through a
codebase and manually annotating all uses of the class can be really
laborious, and it's a brittle solution.  It would be nice to indicate to
the compiler that a particular instance or even a particular class should
always be specialized away, and to get some warnings when this isn't
possible.

Of course, I have no idea what the ramifications of this would be; I just
thought I'd file the idea under this thread.


Ryan

On Thu, Oct 25, 2012 at 9:56 AM, José Pedro Magalhães <jpm at cs.uu.nl> wrote:

> Hi all,
>
> Following up on a chat with Simon Peyton Jones at ICFP, I would like to
> discuss the
> possible introduction of a EPHEMERAL pragma. For example:
>
> {-# EPHEMERAL Rep #-}
>> data Rep = ...
>>
>
> This pragma would indicate that the programmer intends the Rep datatype
> not to
> be present in the final generated core code. Its proposed semantics are
> the following:
>
> 1. Make the compiler very keen to inline any functions that produce or
> consume Rep.
>
> 2. If Rep is exported, make all functions that operate on Rep INLINABLE
> (that is, make
> their code available for inlining in other modules).
>
> 3. Emit a warning if the generated core code still contains uses of Rep.
>
> My main use case for such a pragma is in the generic representation of
> datatypes in
> GHC.Generics. It's clear that we don't want sums and products lying around
> in user
> code, and in most cases we can get rid of them by inlining aggressively.
> Hopefully
> such a pragma can simplify or entirely replace the use of INLINE/INLINABLE
> pragmas
> in some cases.
>
> However, I'm not sure how well this can work in practice. Regarding (3),
> for instance,
> it's clear that functions that operate on Rep will be around in the final
> core code;
> perhaps only functions which do not directly produce or consume Rep, yet
> end up
> having values of Rep within them, should trigger a warning.
>
> (1) is hard to do well, in general. In particular when there are rewriting
> rules involving
> values of Rep, or functions that produce/consume Rep, the order in which
> they are
> inlined might affect the elimination of Rep values.
>
> In any case, I thought I'd share this with this list, in the hope to get
> feedback regarding
> how to improve the inliner (and the feedback programmers get regarding
> inlining).
>
>
> Cheers,
> Pedro
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20121025/b4c80f3a/attachment.htm>


More information about the Glasgow-haskell-users mailing list