Open martinmcclure opened 3 years ago
Yes, good catch. Probably making the change and letting the CI run is enough?
Although in a random image I took I see 53 senders and all of them are using the optimised version and never going through this one...
Describe the problem
whileTrue:
and related messages are optimized by the bytecode compiler when the receiver (and argument, where applicable) are literal blocks. When this condition is not met, a normal message send is compiled and at runtime the corresponding method (such asBlockClosure>>whileTrue:
) is evaluated. These methods are implemented in a tail-recursive manner. Since Pharo does not currently have tail-call elimination, this consumes stack space. For example, you can try this doit:and watch Pharo rapidly consume memory until
ctrl-.
This expression should consume CPU, but there is no need for it to consume significant memory.Classes involved BlockClosure
Proposal
BlockClosure>>whileTrue
is currently implemented asit could avoid consuming stack if implemented as
Similar changes are needed for at least
whileFalse
,whileFalse:
,whileTrue
, andwhileTrue:
.Version information:
Expected development cost This one's fairly simple. Perhaps a day to write tests, make the changes, run regression tests, and so on. Alas, I don't have a day to spare right now.
Also, it is conceivable that the non-optimized implementations are needed for the bootstrapping process. If so, the fix would involve replacing the initial implementations later in the build process, and in that case this should be done by or with consultation from someone familiar with the bootstrap/build process.