Skip to content

Interpreter fixes: lvalue assignment and JFFI warnings#289

Merged
fglock merged 8 commits intomasterfrom
suppress-jffi-warnings
Mar 9, 2026
Merged

Interpreter fixes: lvalue assignment and JFFI warnings#289
fglock merged 8 commits intomasterfrom
suppress-jffi-warnings

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Mar 9, 2026

Summary

  • Suppress JFFI sun.misc.Unsafe deprecation warnings in launchers
  • Fix interpreter RHS context for array/hash element assignment
  • Fix interpreter: compile hash literal elements in LIST context
  • Fix interpreter: ARRAY_SET and HASH_SET return lvalue for chained operations

Details

JFFI Warnings

Added --sun-misc-unsafe-memory-access=allow to jperl and jperl.bat launchers to suppress the sun.misc.Unsafe deprecation warnings from JFFI library.

Lvalue Assignment Fix

Modified ARRAY_SET and HASH_SET opcodes to return the lvalue (the actual container element) in a destination register. This fixes operations like:

($hash{KEY} = $value) =~ s/pattern/replacement/;
($array[0] = $value) =~ s/pattern/replacement/;

Previously, the substitution would modify a copy of the value instead of the actual hash/array element.

Hash Literal Context Fix

Fixed hash literal elements like { @list } being compiled in the wrong context - arrays were returning their count instead of their elements.

Test Results

  • All 156 unit tests pass
  • ExifTool.t interpreter tests improved from 8/35 to 16/35 passing

Generated with Devin

fglock and others added 8 commits March 9, 2026 14:40
Add --sun-misc-unsafe-memory-access=allow JVM option to jperl and jperl.bat
to suppress warnings from JFFI library about deprecated sun.misc.Unsafe methods.
Also add comments explaining both JVM options and when they can be removed.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Use LValueVisitor.getContext() to properly determine RHS context for all
LHS patterns including $array[index] and $hash{key} assignments.

Previously, the interpreter used manual checks that only covered simple
scalar assignments ($x = ...) but not array/hash element assignments.
This caused `$_[0] = <$fh>` to incorrectly use LIST context for readline,
reading all lines instead of one line respecting $/.

This fix improves ExifTool.t in interpreter mode from ~3/35 to 8/35 passing.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
When compiling hash literals like { @list }, elements must be compiled
in LIST context so arrays are flattened to their elements. Previously,
the current context was used, which could be SCALAR, causing @list to
return its count instead of its elements.

This fixes "Odd number of elements in anonymous hash" warnings in
ExifTool tests.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Modified ARRAY_SET and HASH_SET opcodes to return the lvalue (the actual
container element) in a destination register. This fixes operations like:

  ($hash{KEY} = $value) =~ s/pattern/replacement/;
  ($array[0] = $value) =~ s/pattern/replacement/;

Previously, the substitution would modify a copy of the value instead of
the actual hash/array element, because the assignment returned the original
RHS value rather than the stored element.

Changes:
- ARRAY_SET format: rd arrayReg indexReg valueReg (returns element in rd)
- HASH_SET format: rd hashReg keyReg valueReg (returns element in rd)
- Updated InlineOpcodeHandler, Disassemble, CompileAssignment, Opcodes

This improves ExifTool.t interpreter tests from 8/35 to 16/35 passing.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Comprehensive plan for unifying backend compilation through a shared
AST transformation pass that annotates:

- Context resolution (scalar/list/void for each node)
- Call context (wantarray propagation to subroutine calls)
- Operator argument contexts (per-argument context requirements)
- Lvalue detection (for s///, tr///, ++, etc.)
- Variable binding (links uses to declarations, same $x detection)
- Closure capture (collected captured variables)
- Label resolution (goto/next/last/redo targets)
- Pragma tracking (strict/warnings/features per scope)
- Constant folding integration (existing ConstantFoldingVisitor)
- Compile-time warnings

Includes 10-milestone implementation plan with differential testing
against native Perl at each step.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Point implementers to relevant skills for debugging and testing:
- interpreter-parity (primary skill for this work)
- debug-perlonjava (general debugging)
- debug-exiftool (real-world module testing)
- profile-perlonjava (performance validation)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Added Phase 3.5: BlockAnalyzer that integrates existing visitors:
- FindDeclarationVisitor for 'local' operator tracking
- RegexUsageDetector for regex state save/restore optimization

This enables:
- Correct dynamic scoping (save/restore at block boundaries)
- Optimized regex state handling (only save when regex is used)
- Both backends read annotations instead of duplicating detection

Also added annotations: containsLocal, localDeclarations, containsRegex

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
- Create AGENTS.md with project rules including progress tracking requirement
- Expand shared_ast_transformer.md with:
  - Existing AbstractNode annotation infrastructure analysis
  - Inventory of all 12 existing visitors (categorized as shared vs JVM-specific)
  - LValueVisitor integration notes for LvalueResolver phase
  - Progress Tracking section with current status and next steps
- Mark DepthFirstLiteralRefactorVisitor as obsolete (compiler falls back to interpreter)
- Update .gitignore to allow AGENTS.md

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 472fee6 into master Mar 9, 2026
2 checks passed
@fglock fglock deleted the suppress-jffi-warnings branch March 9, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant