The issue of having an :init pragma for subs came up again during today's #parrotsketch meeting, and I volunteered to summarize the discussion for ticket #39926 and the mailing list.
The :init pragma is intended to make it easier for automatically generated modules to make sure that initializations are performed prior to execution of :main. By way of review -- the :main pragma designates the entry point for a module when it is given to parrot on the command line. If the module contains multiple subs marked :main, then the last such sub is used. However, sometimes the module given to parrot on the command line actually comes from several sources, such as when using pbcmerge, or when a compiler includes automatically generated files coming from pgc or tgc. These external sources may need to have various initializations performed prior to executing :main. The easy way to do this is to allow such external sources to create subs marked :init that are to be executed prior to :main. Without something like :init, it then becomes the responsibility of the :main sub to explicitly call any needed initialization subs, and given that some of these initialization subs may be coming from other sources, it's often difficult to know what should be called. It's easy to confuse :init with the existing :load pragma, but as :load is currently written it only executes subs when a module is loaded via the load_bytecode op. Subs marked :load are not loaded when a .pbc/.pir file comes from the parrot command line. While we could conceivably add the "execute before :main" behavior to the :load pragma, there may be times when we want to differentiate "execute as program" from "load as library module", so having a separate :init pragma would allow us to do that. Also, previous messages in RT #39926 had indicated that :init would also designate subs to be executed when loaded as a module, but today we felt that complete orthogonality might be better. A sub that needs to be executed in both situations can simply specify both pragmas (":init :load"). In ticket #39926 both Allison and Chip have already given their approval for an :init pragma, so this message is just a summary of where things stand. More importantly, it's an invitation for people to contribute tests and code to bring the :init pragma to life. I know that several of the compiler authors will greatly benefit from having it available (which is why it came up in today's #parrotsketch). Thanks! Pm