Consider the following two programs:
unit module Comp;
say 'Hello, world!'
and
unit module Comp;
CHECK { if $*DISTRO.is-win { say 'compiling on Windows' }}
say 'Hello, world!'
Naively, I would have expected both programs to compile to exactly the same bytecode: the CHECK
block specifies code to run at the end of compilation; checking a variable and then doing nothing has no effect on the run-time behavior of the program, and thus (I would have thought) shouldn't need to be included in the compiled bytecode.
However, compiling these two programs does not result in the same bytecode. Specifically, compiling the version without the CHECK
block creates 24K of bytecode versus 60K for the version with it. Why is the bytecode different for these two versions? Does this difference in bytecode have (or potentially have) a runtime cost? (It seems like it must, but I want to be sure).
And one more related question: how do DOC CHECK
blocks fit in with the above? My understanding is that even the compiler skips DOC CHECK
blocks when it's not run with the --doc
flag. Consistent with that, the bytecode for a hello-world program does not increase in size when given a DOC CHECK
block like the one above. However, it does increase in size if the block includes a use
statement. From that, I conclude that use
is somehow special-cased and gets executed even in DOC CHECK
blocks. Is that correct? If so, are there other simillarly special-cased forms I should know about?