Skip to content

Language: JIT support for non-void function return types #55

Description

@PurHur

Category

language

Problem

User-defined functions with non-void return types (: string, : ?int, etc.) must compile in JIT and AOT, not only VM. docs/capabilities-syntax.md still lists Method return types: JIT = no (#55).

MiniWebApp Router helpers, template functions, and self-host lib/ code rely on typed returns:

function greet(string $name): string { return 'Hello '.$name; }
function route(string $path): ?string { return null; }

php-src reference

  • Zend/zend_compile.czend_compile_return, return type enforcement
  • Zend/zend_execute.cZEND_RETURN, ZEND_RETURN_VALUE
  • Zend/zend_type.c — return type validation

Repro (today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "function f(): string { return \"ok\"; } echo f();"
php bin/jit.php -r "function f(): string { return \"ok\"; } echo f();"
'

Zend / VM target: prints ok. JIT gap: confirm whether bin/jit.php prints ok, fatals, or segfaults; this issue closes when JIT + AOT match VM.

AOT slice:

# Write /tmp/ret.php with greet() above, then:
php bin/compile.php /tmp/ret.php /tmp/ret-out && /tmp/ret-out

Scope (this repo)

Layer Files Notes
Compiler lib/Compiler.php TYPE_RETURN value operand for user functions
VM lib/VM.php Already supports returns for many paths — regression guard
JIT lib/JIT.php, lib/JIT.pre OpCode::TYPE_RETURN LLVM ret with boxed __value__* per type
AOT lib/AOT/ Same ABI as JIT
Caps script/capability-syntax.php Flip JIT row for method return types
Tests test/compliance/cases/function_return_*.phpt string, int, bool, null, array

v1 types: void, string, int, bool, float, array, ?T for same. Defer: object, union/intersection returns.

Done when

  • JIT repro prints ok for : string return (no LogicException / segfault)
  • Compliance PHPTs for VM + JIT (@group llvm) on return types above
  • AOT linked binary runs return-type fixture
  • docs/capabilities-syntax.md — method return types JIT = yes (subset documented)
  • examples/003-MiniWebApp JIT project gate unblocked where blocked only by returns (Testing: JIT smoke for phpc build --project on 003-MiniWebApp #587)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter function_return'
make test-harness ARGS='--filter function_return'  # LLVM hosts

Dependencies

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions