From: Roderick Schertler Date: Tue, 7 Jan 1997 20:27:50 +0000 (-0500) Subject: Re: constant function inlining X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f0893e72a8aa916a77953ff2f1847494d1527fb8;p=p5sagit%2Fp5-mst-13.2.git Re: constant function inlining On Tue, 7 Jan 1997 18:21:28 +0000, Tim Bunce said: > > A few words about redefining [constant] functions would be worthwhile. Right, patch attached. p5p-msgid: --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index a9bdb9b..fb0a2d7 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -812,6 +812,12 @@ to 01411. Octal constants are introduced with a leading 0 in Perl, as in C. (W) You tried to do a connect on a closed socket. Did you forget to check the return value of your socket() call? See L. +=item Constant subroutine %s redefined + +(S) You redefined a subroutine which had previously been eligible for +inlining. See L for commentary and +workarounds. + =item Corrupt malloc ptr 0x%lx at 0x%lx (P) The malloc package that comes with Perl had an internal failure. diff --git a/pod/perlsub.pod b/pod/perlsub.pod index 6bd3fe8..fa14a7f 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -752,7 +752,22 @@ in @foo. And the split() gets called in a scalar context and starts scribbling on your @_ parameter list. This is all very powerful, of course, and should be used only in moderation -to make the world a better place. +to make the world a better place. + +If you redefine a subroutine which was eligible for inlining you'll get +a mandatory warning. (You can use this warning to tell whether or not a +particular subroutine is considered constant.) The warning is +considered severe enough not to be optional because previously compiled +invocations of the function will still be using the old value of the +function. If you need to be able to redefine the subroutine you need to +ensure that it isn't inlined, either by dropping the C<()> prototype +(which changes the calling semantics, so beware) or by thwarting the +inlining mechanism in some other way, such as + + my $dummy; + sub not_inlined () { + $dummy || 23 + } =head2 Overriding Builtin Functions