Skip to content

Commit a7444d8

Browse files
committed
distinguish FINAL phase from CHECK phase
CHECK phase is always after the parsing of the current compilation unit. FINAL phase is after the main application's CHECK phase, when the application as a whole commits to optimization policies. In other words, a FINAL block defined in a module is not run when the module is compiled (that would be a CHECK instead), but rather when the application using the module is completing its compilation and linking.
1 parent 14e9ce6 commit a7444d8

File tree

6 files changed

+31
-23
lines changed

6 files changed

+31
-23
lines changed

S02-bits.pod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Synopsis 2: Bits and Pieces
1313

1414
Created: 10 Aug 2004
1515

16-
Last Modified: 13 May 2013
17-
Version: 273
16+
Last Modified: 15 May 2013
17+
Version: 274
1818

1919
This document summarizes Apocalypse 2, which covers small-scale
2020
lexical items and typological issues. (These Synopses also contain
@@ -4175,7 +4175,8 @@ such a declaration will occur by the end of the current compilation unit:
41754175
foo $x:; # not a provisional call; it's a method call on $x
41764176
foo $x: $y; # not a provisional call; it's a method call on $x
41774177

4178-
If a postdeclaration is not seen, the compile fails at C<CHECK> time.
4178+
If a postdeclaration is not seen, the compile fails at C<CHECK> time,
4179+
that is, at the end of compilation for this compilation unit.
41794180
(You are still free to predeclare subroutines explicitly, of course.)
41804181
The postdeclaration may be in any lexical or package scope that
41814182
could have made the declaration visible to the provisional call had the

S04-control.pod

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Synopsis 4: Blocks and Statements
1313
Created: 19 Aug 2004
1414

1515
Last Modified: 15 May 2013
16-
Version: 122
16+
Version: 123
1717

1818
This document summarizes Apocalypse 4, which covers the block and
1919
statement syntax of Perl.
@@ -1349,6 +1349,7 @@ them respond to various control exceptions and exit values:
13491349

13501350
BEGIN {...}* at compile time, ASAP, only ever runs once
13511351
CHECK {...}* at compile time, ALAP, only ever runs once
1352+
FINAL {...}* at link time, ALAP, only ever runs once
13521353
INIT {...}* at run time, ASAP, only ever runs once
13531354
END {...} at run time, ALAP, only ever runs once
13541355

@@ -1369,6 +1370,8 @@ them respond to various control exceptions and exit values:
13691370
CATCH {...} catch exceptions, before LEAVE
13701371
CONTROL {...} catch control exceptions, before LEAVE
13711372

1373+
COMPOSE {...} when a role is composed into a class
1374+
13721375
Those marked with a C<*> can also be used within an expression:
13731376

13741377
my $compiletime = BEGIN { now };
@@ -1417,6 +1420,9 @@ Code that is generated at run time can still fire off C<CHECK>
14171420
and C<INIT> phasers, though of course those phasers can't do things that
14181421
would require travel back in time. You need a wormhole for that.
14191422

1423+
The compiler is free to ignore C<FINAL> phasers compiled at run time
1424+
since they're too late for the application-wide linking decisions.
1425+
14201426
Some of these phasers also have corresponding traits that can be set on variables.
14211427
These have the advantage of passing the variable in question into
14221428
the closure as its topic:
@@ -1433,7 +1439,8 @@ a list of phasers rather than a single phaser. In general, initializing
14331439
phasers execute in order declared, while finalizing phasers execute in
14341440
the opposite order. When phasers are in different modules, the
14351441
C<INIT> and C<END> phasers are treated as if declared at C<use> time in
1436-
the using module.
1442+
the using module. (It is erroneous to depend on this order if the
1443+
module is used more than once, however.)
14371444

14381445
The semantics of C<INIT> and C<START> are not equivalent to each
14391446
other in the case of cloned closures. An C<INIT> only runs once for
@@ -1506,7 +1513,7 @@ any C<CATCH> and C<CONTROL> phasers. This includes
15061513
the C<LEAVE> variants, C<KEEP> and C<UNDO>. C<POST> phasers are evaluated after
15071514
everything else, to guarantee that even C<LEAVE> phasers can't violate postconditions.
15081515
Likewise C<PRE> phasers fire off before any C<ENTER> or C<FIRST> (though not
1509-
before C<BEGIN>, C<CHECK>, or C<INIT>, since those are done at compile or
1516+
before C<BEGIN>, C<CHECK>, C<FINAL>, or C<INIT>, since those are done at compile or
15101517
process initialization time).
15111518

15121519
The C<POST> block can be defined in one of two ways. Either the
@@ -1823,7 +1830,7 @@ that can carry the info lazily. Neither approach is pretty.]
18231830

18241831
Some closures produce C<Block> objects at compile time that cannot be
18251832
cloned, because they're not attached to any runtime code that can
1826-
actually clone them. C<BEGIN>, C<CHECK>, C<INIT>, and C<END> blocks
1833+
actually clone them. C<BEGIN>, C<CHECK>, C<FINAL>, C<INIT>, and C<END> blocks
18271834
fall into this category. Therefore you can't reliably refer to
18281835
run-time variables from these closures even if they appear to be in the
18291836
scope. (The compile-time closure may, in fact, see some kind of permanent

S06-routines.pod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Synopsis 6: Subroutines
1616

1717
Created: 21 Mar 2003
1818

19-
Last Modified: 23 Feb 2013
20-
Version: 157
19+
Last Modified: 15 May 2013
20+
Version: 158
2121

2222
This document summarizes Apocalypse 6, which covers subroutines and the
2323
new type system.
@@ -2955,7 +2955,7 @@ to be able to handle various unforeseen conditions (perhaps).
29552955

29562956
Note that all routines are (by default) considered to be candidates
29572957
for inlining and constant folding. The optimizer is allowed to start
2958-
making these optimizations after the main program's C<CHECK> time,
2958+
making these optimizations after the main program's C<FINAL> time,
29592959
but not before. After any routine is "hard" inlined or constant
29602960
folded, it is explicitly retyped as immutable; any attempt to
29612961
wrap an immutable routine will result in failure of the wrap call.
@@ -2964,14 +2964,14 @@ a subclass of C<Routine>.
29642964

29652965
On the other hand, it is also possible to explicitly mark a routine
29662966
as mutable, and then the ability to wrap it must be preserved even
2967-
after C<CHECK> time. This is done by recasting to C<SoftRoutine>.
2967+
after C<FINAL> time. This is done by recasting to C<SoftRoutine>.
29682968
Explicitly marking a routine as either mutable or immutable should
29692969
be considered permanent. It is still possible to inline soft
29702970
routines, but only if the possibility of indirection is detected
29712971
inline as well, and provision made (either inline or via external
29722972
rewriting) for dealing with any wrappers.
29732973

2974-
Hence, any routine marked as soft before C<CHECK> time is exempt
2974+
Hence, any routine marked as soft before C<FINAL> time is exempt
29752975
from hard inlining or folding. There are several methods of
29762976
marking a routine as soft, however no method is provided for marking
29772977
routines as hard, since that is the job of the optimizer.
@@ -3005,7 +3005,7 @@ your optimizer into more of a "pessimizer".
30053005

30063006
For any normal standalone application, any C<use soft> pragma applies
30073007
to the entire program in which it participates, provided it is
3008-
performed before C<CHECK> time. The optimizer may then harden
3008+
performed before C<FINAL> time. The optimizer may then harden
30093009
anything that was not requested to remain soft.
30103010

30113011
A plug-in system, such as for a web server, may choose either to allow
@@ -3014,9 +3014,9 @@ optimizer harden individual plug-ins independently, or treat all
30143014
plug-ins as a part of the same program by softening all plug-ins.
30153015
(Similar considerations apply to optimizing classes to closed/final.)
30163016

3017-
Note that installing a wrapper before C<CHECK> time is specifically
3017+
Note that installing a wrapper before C<FINAL> time is specifically
30183018
I<not> one of the ways to mark a routine as soft. Such a routine
3019-
may still be hardened at C<CHECK> time despite being wrapped during
3019+
may still be hardened at C<FINAL> time despite being wrapped during
30203020
compile time.
30213021

30223022
=head2 The C<&?ROUTINE> object

S10-packages.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ to run at all if the result of some previous compilation's run has
107107
been cached.)
108108

109109
If it is desired to have code that varies in meaning from run to run,
110-
then you should put such code into an INIT block. (Likewise, you
111-
could put code into a CHECK block that has inconsistent semantics
110+
then you should put such code into an C<INIT> block. (Likewise, you
111+
could put code into a C<CHECK> block that has inconsistent semantics
112112
from compilation to compilation, but that's probably a bad idea.)
113113

114114
In any case, it is erroneous for any external module to depend

S12-objects.pod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Synopsis 12: Objects
1313

1414
Created: 27 Oct 2004
1515

16-
Last Modified: 8 Mar 2013
17-
Version: 128
16+
Last Modified: 15 May 2013
17+
Version: 129
1818

1919
=head1 Overview
2020

@@ -2191,7 +2191,7 @@ the command line or from a mouse click.
21912191

21922192
These pragmatics (whether explicit or assumed) merely change the application's
21932193
default to closed and final,
2194-
which means that at the end of the main compilation (C<CHECK> time)
2194+
which means that at the end of the main compilation (C<FINAL> time)
21952195
the optimizer is allowed to look for candidate classes to close or
21962196
finalize. But anyone (including the main application) can request
21972197
that any class stay open or nonfinal, and the class closer/finalizer
@@ -2238,7 +2238,7 @@ must specifically pessimize the class:
22382238
class Mammal is repr(*) {...}
22392239

22402240
An C<augment> is allowed to do this as long as it is before the
2241-
main C<CHECK> time, at which point the compiler commits to its
2241+
main C<FINAL> time, at which point the compiler commits to its
22422242
optimization strategies. Compilers are not required to support
22432243
run-time pessimizations (though they may). Compilers may also generate
22442244
both optimal and pessimal code paths and choose which to run based

S19-commandline.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,12 @@ argument list.
404404

405405
=item --check-syntax, -c
406406

407-
Check syntax, then exit. Desugars to C<-e 'CHECK{ compiles_ok(); exit; }'>.
407+
Check syntax, then exit. Desugars to C<-e 'CHECK { compiles_ok(); exit; }'>.
408408

409409
=item --doc
410410

411411
Lookup Perl documentation in Pod format. Desugars to
412-
C<-e 'CHECK{ compiles_ok(); dump_perldoc(); }'>. C<$*ARGS> contains the
412+
C<-e 'CHECK { compiles_ok(); dump_perldoc(); }'>. C<$*ARGS> contains the
413413
arguments passed to C<perl6>, and is available at C<CHECK> time, so
414414
C<dump_perldoc()> can respond to command-line options.
415415

0 commit comments

Comments
 (0)