Skip Menu |

This queue is for tickets about the constant-defer CPAN distribution.

Report information
The Basics
Id: 61380
Status: resolved
Priority: 0/
Queue: constant-defer

People
Owner: Nobody in particular
Requestors: adamk [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Clarify if this module does optree culling
One of the biggest benefits of Perl constants is that they can be optimised in branches at compile time, removing code that can't be reached and making it faster. use constant WIN32 => ($^O' eq Win32'); while ( 1 ) { if ( WIN32 ) { # This is optimised away # This is run } else { # This is compiled away } } While the code used to produce the constant is compiled away in the constant::defer case, the documentation does not make it clear if this optree-culling/currying of the rest of your code occurs in the same way as for normal constants. Clarifying this in the documentation would be appreciated.
Show quoted text
> While the code used to produce the constant is compiled away in the > constant::defer case, the documentation does not make it clear if this > optree-culling/currying of the rest of your code occurs in the same way > as for normal constants.
Alas, the short answer is no. The long answer is that after the first call it's a plain constant. Too late for the defining module or script normally, but might be seen by later loaded stuff. I didn't think much about folding when I wrote the code. I wanted mainly to defer some object creation, module loading, and/or slow calculations. I imagine it's not feasible to go back over previously compiled code and revisit inlining and folding, but getting it in subsequently loaded code is better than nothing. I hope I can keep at least that much inlining, though I'm not sure I want to promise just yet. Show quoted text
> Clarifying this in the documentation would be appreciated.
Yep, beaut, new version uploaded just now.