add CvEVAL_COMPILED() flag and fix closure bug. #22097
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[NB: I'm not expecting to merge this until after 5.40. Too much chance that something subtle changes in closure behaviour.]
EVAL CVs are treated a bit weirdly: their CvROOT() and CvSTART() fields don't get populated; instead the current values are stored in the PL_eval_root and PL_eval_start variables while they are being executed.
This caused a bug in closures and nested evals when an inner eval was repeated twice. The first inner eval accessed an outer lexical, which caused a fake cache entry to be added to the outer eval's pad. The second inner eval finds this cached entry, but incorrectly concludes that the outer eval is in fact an anon sub prototype and issues a 'variable is not available' warning. This is due to this simplistic definition in pad.c:
This commit adds a new flag, CvEVAL_COMPILED(), to indicate a fully-compiled EVAL CV. This allows us to work around the limitation.
In an ideal world this would have been fixed instead by making EVAL CVs first-class citizens with CvROOT() etc, but plenty of stuff seems to assume otherwise. So I took the path of least resistance.
See https://www.perlmonks.org/?node_id=11158351