fix: preserve @_ aliasing across goto &SUB tail calls#643
Merged
Conversation
84d7ff4 to
9dc1be9
Compare
Two issues exposed by `jcpan -t JSON::Validator::Ref`:
1. `goto &SUB` was emitted as `argsValue.getList().getArrayOfAlias()`.
`RuntimeArray.getList()` deep-copies each element via
`new RuntimeScalar(element)`, which destroys aliasing of the caller's
`@_`. After the tail call, `$_[N] = ...` in the target sub no longer
propagated to the caller's variable. JSON::Validator's
`_validate_type_boolean` (and many similar helpers) rely on this Perl
semantic to coerce values in place. Fix: skip `getList()` and call
`getArrayOfAlias()` directly on the `RuntimeBase` value, matching the
pattern already used by `EmitBlock` for `for` loops. Applied to both
`handleGotoSubroutine` (`goto &NAME` / `goto \&NAME`) and
`handleGotoSubroutineBlock` (`goto &{expr}` / `goto &$var`).
2. CPAN.pm's `_allow_installing` early-stop check was running before the
test phase (`$run_allow_installing_within_test = 1`), so
`jcpan -t Module::Name` could not test older releases that contain
modules no longer indexed under the same distribution (e.g.
`JSON::Validator::Ref` only exists in JSON-Validator-4.25 even though
the indexed `JSON::Validator` dist is now 5.15). Defer the check to
the install phase. For full installs the prompt still fires.
Effect on `jcpan -t JSON::Validator::Ref`: failing subtests drop from
65/824 to 14/824 (e.g. coerce.t goes 0/48 → 48/48; jv-array.t 33/35 →
35/35). Remaining failures are unrelated (Mojo::IOLoop shim, YAML::XS
checksum, openapiv3 explode) and out of scope for this PR.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
9dc1be9 to
d28ab2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two issues exposed by
./jcpan -t JSON::Validator::Ref:goto &SUBno longer preserves@_aliasing.The bytecode for tail calls was emitting
argsValue.getList().getArrayOfAlias().RuntimeArray.getList()deep-copies every element vianew RuntimeScalar(element), so by the time the target sub sees@_the elements are no longer aliased to the caller's variables. As a result$_[N] = ...in the target sub silently failed to mutate the caller, even though direct (non-goto) calls work fine. JSON::Validator's coerce/boolean validators (and many other CPAN modules) depend on this. Fix: skipgetList()and callgetArrayOfAlias()directly on theRuntimeBasevalue, matching the pattern already used byEmitBlockforforloops. Applied to bothhandleGotoSubroutineandhandleGotoSubroutineBlock.jcpan -t Module::Namecouldn't test older releases._allow_installingwas running before the test phase ($run_allow_installing_within_test = 1), sojcpan -taborted with a "downgrade / outdated dist" stop for any module whose only available release is older than what's already installed (e.g.JSON::Validator::Refonly exists in JSON-Validator-4.25 even thoughJSON::Validatoris now indexed at 5.15). The check is now deferred to the install phase; full installs still prompt.Effect on
jcpan -t JSON::Validator::Refcoerce.tjv-array.tjv-boolean.tRemaining failures are unrelated root causes (Mojo::IOLoop shim returning undef for
io/timer, YAML::XS checksum, openapiv3 explode edge case) and out of scope.Test plan
sub bar { $_[0] = "X" } sub foo { goto &bar } my $x = "orig"; foo($x); print $xprintedorigbefore,Xafter.make(full unit-test suite) passes.t/coerce.t,t/jv-array.tfrom JSON-Validator-4.25 now fully pass;t/jv-boolean.timproved.Generated with Devin