More aggressive dictionary removal?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

More aggressive dictionary removal?

Conal Elliott
I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: More aggressive dictionary removal?

Johan Tibell-2
The best way I know is to put INLINABLE on all functions with dictionaries that you want removed. That's what we do in e.g. containers. The pragma is perhaps a bit misnamed, as it doesn't only imply that we make the source of the function available for inlining, but also that we specialize the dictionary arguments at every call site, when known.

On Thu, Jan 28, 2016 at 1:04 AM, Conal Elliott <[hidden email]> wrote:
I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: More aggressive dictionary removal?

Simon Peyton Jones
In reply to this post by Conal Elliott

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: [hidden email]
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: More aggressive dictionary removal?

Johan Tibell-2
I think the difference between the inlinable and specialize pragma is whether the specialization needs to be driven by the call site or not. If you have a handful of known types you want to specialize for up front, you can use the specialize pragma. If the set is large or unknown (like in the case of container keys/value, the inlinable pragma does the right thing.)

On Thu, Jan 28, 2016 at 1:54 PM, Simon Peyton Jones <[hidden email]> wrote:

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: [hidden email]
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: More aggressive dictionary removal?

Simon Peyton Jones

I think the difference between the inlinable and specialize pragma is whether the specialization needs to be driven by the call site or not. If you have a handful of known types you want to specialize for up front, you can use the specialize pragma. If the set is large or unknown (like in the case of container keys/value, the inlinable pragma does the right thing.)

Correct!  And not well described anywhere.  

 

If someone writes something, I’ll willingly review

 

S

 

From: Johan Tibell [mailto:[hidden email]]
Sent: 28 January 2016 13:40
To: Simon Peyton Jones <[hidden email]>
Cc: Conal Elliott <[hidden email]>; [hidden email]
Subject: Re: More aggressive dictionary removal?

 

I think the difference between the inlinable and specialize pragma is whether the specialization needs to be driven by the call site or not. If you have a handful of known types you want to specialize for up front, you can use the specialize pragma. If the set is large or unknown (like in the case of container keys/value, the inlinable pragma does the right thing.)

 

On Thu, Jan 28, 2016 at 1:54 PM, Simon Peyton Jones <[hidden email]> wrote:

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: [hidden email]
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

 


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: More aggressive dictionary removal?

Conal Elliott
In reply to this post by Simon Peyton Jones
Hah! I had misread the signatures in the Core output. I'm getting exactly the dictionary removal I wanted. Fantastic!

I'm attaching my sample source code and the Core it produces.

Sorry for the misdirection, and kudos for specialis/zation in GHC!

-- Conal

On Thu, Jan 28, 2016 at 4:54 AM, Simon Peyton Jones <[hidden email]> wrote:

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: [hidden email]
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal



_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

SpecT.dump-simpl (26K) Download Attachment
SpecT.hs (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: More aggressive dictionary removal?

Conal Elliott
I just split the "library code" (data types and instances) and the client code (type-specialized use) into two modules. Same great results, as long as both modules are compiled with -O (not even -O2). Sweet!

On Thu, Jan 28, 2016 at 10:12 AM, Conal Elliott <[hidden email]> wrote:
Hah! I had misread the signatures in the Core output. I'm getting exactly the dictionary removal I wanted. Fantastic!

I'm attaching my sample source code and the Core it produces.

Sorry for the misdirection, and kudos for specialis/zation in GHC!

-- Conal

On Thu, Jan 28, 2016 at 4:54 AM, Simon Peyton Jones <[hidden email]> wrote:

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: [hidden email]
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal




_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: More aggressive dictionary removal?

Carter Schonwald
In reply to this post by Simon Peyton Jones
Wait, inlinable creates a new specialization automatically at each new instances / use site? I always thought it just allows invoking specialize pragma in client modules.  

On Thursday, January 28, 2016, Simon Peyton Jones <[hidden email]> wrote:

I think the difference between the inlinable and specialize pragma is whether the specialization needs to be driven by the call site or not. If you have a handful of known types you want to specialize for up front, you can use the specialize pragma. If the set is large or unknown (like in the case of container keys/value, the inlinable pragma does the right thing.)

Correct!  And not well described anywhere.  

 

If someone writes something, I’ll willingly review

 

S

 

From: Johan Tibell [mailto:<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;johan.tibell@gmail.com&#39;);" target="_blank">johan.tibell@...]
Sent: 28 January 2016 13:40
To: Simon Peyton Jones <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;simonpj@microsoft.com&#39;);" target="_blank">simonpj@...>
Cc: Conal Elliott <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;conal@conal.net&#39;);" target="_blank">conal@...>; <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;ghc-devs@haskell.org&#39;);" target="_blank">ghc-devs@...
Subject: Re: More aggressive dictionary removal?

 

I think the difference between the inlinable and specialize pragma is whether the specialization needs to be driven by the call site or not. If you have a handful of known types you want to specialize for up front, you can use the specialize pragma. If the set is large or unknown (like in the case of container keys/value, the inlinable pragma does the right thing.)

 

On Thu, Jan 28, 2016 at 1:54 PM, Simon Peyton Jones <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;simonpj@microsoft.com&#39;);" target="_blank">simonpj@...> wrote:

Aggressive inlining is one way, but specialisation ought to get a long way, and makes fewer copies of the specialised code.

 

It’s hard to help without a concrete example

 

Simon

 

From: ghc-devs [mailto:<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;ghc-devs-bounces@haskell.org&#39;);" target="_blank">ghc-devs-bounces@...] On Behalf Of Conal Elliott
Sent: 28 January 2016 00:05
To: <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;ghc-devs@haskell.org&#39;);" target="_blank">ghc-devs@...
Subject: More aggressive dictionary removal?

 

I'm looking for pointers on getting GHC to eliminate more overloading & polymorphism. I think this sort of thing mainly happens in the Specialise module. The default GHC flag settings get me a couple levels of monomorphization and dictionary removal, but I want to go further. I've tried -fspecialise-aggressively, but it didn't seem to make a difference, and I haven't found this flag described in the GHC user's guide. Anyone have pointers to more information?

Thanks, - Conal


_______________________________________________
ghc-devs mailing list
<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;ghc-devs@haskell.org&#39;);" target="_blank">ghc-devs@...
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

 


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs