Skip to content

feat: typed lexical declarations + POSIX low-level FD operations for IPC::Run#499

Merged
fglock merged 2 commits intomasterfrom
feature/typed-lexical-declarations
Apr 13, 2026
Merged

feat: typed lexical declarations + POSIX low-level FD operations for IPC::Run#499
fglock merged 2 commits intomasterfrom
feature/typed-lexical-declarations

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 13, 2026

Summary

Two sets of changes that unblock IPC::Run and other CPAN modules:

1. Parser fixes (commit e9bda61)

  • Qualified function calls without parens: Carp::carp join " ", ... was misparsed as indirect method call syntax when the sub was unknown at compile time. Fixed by treating :: names as function calls regardless of compile-time sub resolution.
  • Typed lexical declarations: my IPC::Run::IO $pipe failed with "Not implemented: my". Fixed the parser to accept type names when unambiguously followed by a sigil ($@%\(), and emit a runtime checkClassExists call matching Perl's "No such class TYPE" error.
  • POSIX.pm: Added use Carp since real Perl's POSIX transitively loads it but PerlOnJava's Java-backed POSIX did not.

2. POSIX low-level FD operations (commit b0798fb)

Implemented native file descriptor functions needed by IPC::Run:

  • pipe(), dup(), open(), close(), read(), write(), lseek(), fcntl(), isatty()
  • Fcntl constants: F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_SETFL, FD_CLOEXEC

Cross-platform implementation using Java FFM API:

  • Linux/macOS: Native libc calls via FFMPosixLinux (macOS inherits)
  • Windows: MSVCRT calls (_pipe, _dup, _open, etc.) via FFMPosixWindows using ucrtbase.dll

IPC::Run test results

Metric Before After
Passing tests ~7 341
Failing tests ~339 1
Skipped (fork) 0 39

The 39 skips are expected — IPC::Run tests that require fork() now properly detect its absence and skip instead of crashing. The 1 remaining failure is a minor edge case in t/io.t (write on closed FD).

Test plan

  • make passes (all unit tests)
  • jcpan -t IPC::Run — 341/342 pass, 39 skip
  • Smoke tests: POSIX::pipe, POSIX::dup, POSIX::open, POSIX::close, POSIX::read, POSIX::write, POSIX::fcntl
  • my No::Such $x produces "No such class" error
  • require Carp; my Carp $x works
  • use IPC::Run; print "ok" works

Generated with Devin

…ut parens

Two parser bugs were preventing IPC::Run from loading:

1. Qualified function calls without parentheses (e.g. Carp::carp join " ", ...)
   were misparsed as indirect method call syntax when the sub was unknown at
   compile time. Fix: treat qualified names (containing ::) as function calls
   regardless of compile-time sub resolution.

2. Typed lexical declarations with qualified type names (e.g. my IPC::Run::IO $pipe)
   failed with "Not implemented: my" because the parser required the package to
   be loaded. Fix: accept type names when unambiguously followed by a sigil
   ($, @, %, \, (), and emit a runtime checkClassExists call matching Perl
   behavior ("No such class TYPE").

Also adds `use Carp` to POSIX.pm since real Perl POSIX transitively loads Carp
but PerlOnJava Java-backed POSIX did not.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock force-pushed the feature/typed-lexical-declarations branch from b0798fb to 582f968 Compare April 13, 2026 11:10
…, read, write, lseek, fcntl)

Add native implementations of POSIX file descriptor functions needed by
IPC::Run and other CPAN modules:

- pipe() - create OS-level pipes
- dup() - duplicate file descriptors
- open() - open files returning raw FDs
- close() - close file descriptors
- read() - read from FDs into buffers
- write() - write buffers to FDs
- lseek() - seek on FDs
- fcntl() - file control operations
- isatty() - terminal detection (Perl wrapper)
- F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_SETFL, FD_CLOEXEC constants

Implementation uses Java FFM (Foreign Function & Memory) API:
- Linux/macOS: native libc calls (pipe, dup, open, close, read, write,
  lseek, fcntl) via FFMPosixLinux (macOS inherits)
- Windows: MSVCRT calls (_pipe, _dup, _open, _close, _read, _write,
  _lseek) via FFMPosixWindows using ucrtbase.dll

IPC::Run test results improved from ~7 passing tests to 341 passing,
1 failing, 39 skipped (fork() limitation).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock force-pushed the feature/typed-lexical-declarations branch from 582f968 to 3b7ac54 Compare April 13, 2026 11:53
@fglock fglock merged commit 8436c31 into master Apr 13, 2026
2 checks passed
@fglock fglock deleted the feature/typed-lexical-declarations branch April 13, 2026 12:05
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