Fix caller() returning incorrect frames in interpreter mode#307
Closed
fglock wants to merge 1 commit into
Closed
Conversation
The interpreter's caller() function was returning incorrect stack frames in two scenarios: 1. For regular subroutine calls (main calls outer() calls inner()), caller() returned no frames because all BytecodeInterpreter.execute frames were consecutive and the previous fix treated them as one call. 2. For use/require with import(), the stack order was wrong - the CallerStack entry (from parseUseDeclaration) was being added after interpreter frames instead of at the correct position. Fix: Use InterpretedCode.apply as the boundary marker. Each apply() call marks the END of a Perl subroutine execution. Multiple execute() frames within an apply() share one interpreter frame. Key changes to ExceptionFormatter.formatException(): - Track addedFrameForCurrentLevel flag - Only add one interpreter frame per call level - When we see InterpretedCode.apply, increment to next frame index - For innermost frame (index 0), use runtime currentPackage to reflect package declarations that executed at runtime Now both test cases work correctly: - Regular sub calls: caller(0)=main, caller(1)=main, depth=1 - use/import: caller(0)=NestedInstance, caller(1)=main Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
Owner
Author
|
Merged into PR #306 which contains both fixes |
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
Fix the interpreter's
caller()function which was returning incorrect stack frames in two scenarios:Regular subroutine calls (main calls outer() calls inner()):
caller()returned no frames because allBytecodeInterpreter.executeframes were consecutive and were treated as one call.use/require with import(): The stack order was wrong - the CallerStack entry was being added after interpreter frames instead of at the correct position.
Root Cause
The previous fix removed the use of
InterpreterState.currentPackage.get()for the innermost frame, which broke Exporter'scaller()calls. This caused@EXPORT_OKto be populated in the wrong package, making all ExifTool tests fail with "Symbol not allowed for export" errors.Fix
InterpretedCode.applyas the boundary marker for Perl call levelsaddedFrameForCurrentLevelflag to add only one interpreter frame per call levelcurrentPackageto reflectpackage Foo;declarations that executed at runtimeTest Plan
./gradlew testpassescaller(0)=main, caller(1)=main, depth=1use Image::ExifTool qw(ImageInfo)Generated with Devin