fix(tie,MakeMaker): AUTOLOAD fallback + INST_ARCHLIBDIR expansion#530
Merged
fix(tie,MakeMaker): AUTOLOAD fallback + INST_ARCHLIBDIR expansion#530
Conversation
Two fixes surfaced while running `jcpan -t AI::Prolog`:
1. tie: Do not fall through to AUTOLOAD for UNTIE/DESTROY.
Retying an already-tied hash (as Regexp::Common does when its
import loads sub-modules that themselves `use Regexp::Common`)
triggers an implicit untie. The untie path calls tiedUntie()
which, via tieCallIfExists("UNTIE"), was using
InheritanceResolver.findMethodInHierarchy — which transparently
falls back to AUTOLOAD. That invoked Regexp::Common's AUTOLOAD
with an unset $AUTOLOAD, producing the cryptic error
`Can't at .../balanced.pm line 9.` and breaking loading of
Regexp::Common entirely.
tie special methods (UNTIE, DESTROY) are "if exists" only: they
should not trigger AUTOLOAD dispatch. Reject AUTOLOAD-resolved
matches (detected via code.autoloadVariableName != null) in all
four tieCallIfExists helpers: TiedVariableBase, TieHash,
TieArray, TieHandle.
2. MakeMaker: Expand $(INST_ARCHLIBDIR)/$(INST_AUTODIR) and tolerate
missing generated sources.
Term::ReadKey's Makefile.PL sets
`PM => { 'ReadKey.pm' => '$(INST_ARCHLIBDIR)/ReadKey.pm' }`.
PerlOnJava's MakeMaker only expanded INST_LIB/INST_ARCHLIB/
INST_LIBDIR, leaving INST_ARCHLIBDIR literal which produced
`mkdir: : No such file or directory`.
- Derive <parent> and <full> paths from NAME and expand
INST_LIBDIR, INST_ARCHLIBDIR, INST_AUTODIR, INST_ARCHAUTODIR
(both $(...) and ${...} forms).
- Make `_shell_cp` tolerant of missing source files. Some
distributions (Term::ReadKey) generate .pm via a .pm.PL that
requires XS bootstrap; we cannot run that, but the install
should still succeed so dependent modules can proceed.
Result:
`jcpan -t AI::Prolog`: 460/460 tests pass (previously 14/19 test
files failed to load at all).
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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 bugs surfaced while running
jcpan -t AI::Prolog. Before: 14 of 19 test files failed to load at all. After: 460/460 tests pass.1. Tie — Do not fall through to AUTOLOAD for
UNTIE/DESTROYRetying an already-tied hash (as
Regexp::Commondoes in itsimportwhen loading sub-modules that themselvesuse Regexp::Common) triggers an implicituntie.TiedVariableBase::tieCallIfExists,TieHash::tieCallIfExists,TieArray::tieCallIfExists, andTieHandle::tieCallIfExistsusedInheritanceResolver.findMethodInHierarchy, which transparently falls back toAUTOLOADwhen the method doesn't exist.That invoked
Regexp::Common'ssub AUTOLOAD { _croak "Can't $AUTOLOAD" }with an unset$AUTOLOAD, producing the cryptic errorCan't at .../balanced.pm line 9.and breaking every module that depends onRegexp::Common.Per Perl semantics,
UNTIE/DESTROYon tied variables are "if exists" only and must not trigger AUTOLOAD dispatch. Fix: reject AUTOLOAD-resolved matches (detected viacode.autoloadVariableName != null) in all fourtieCallIfExistshelpers.Minimal repro:
2. MakeMaker — Expand
$(INST_ARCHLIBDIR)/$(INST_AUTODIR)+ tolerate missing generated sourcesTerm::ReadKey'sMakefile.PLusesPM => { 'ReadKey.pm' => '$(INST_ARCHLIBDIR)/ReadKey.pm' }. PerlOnJava's MakeMaker only expandedINST_LIB/INST_ARCHLIB/INST_LIBDIR, leavingINST_ARCHLIBDIRliteral →mkdir: : No such file or directory.<parent>/<full>paths fromNAMEand expandINST_LIBDIR,INST_ARCHLIBDIR,INST_AUTODIR,INST_ARCHAUTODIR(both$(...)and${...}forms) per standard EUMM conventions._shell_cptolerant of missing source files. Some distributions (likeTerm::ReadKey) generate.pmfrom a.pm.PLthat requires XS bootstrap; PerlOnJava can't run that, but the install should still succeed so dependent modules can proceed.Test plan
make— all unit tests passjcpan -t AI::Prolog— 460/460 tests pass (was 14/19 files failing)jcpan -i Term::ReadKey— installs (with graceful skip of the missing generated.pm)tie; tierepro now matchesperlbehavior (TIEHASH runs on re-tie; DESTROY is dispatched via AUTOLOAD with$AUTOLOADcorrectly set)Generated with Devin