From d3bc3354c9705dfc6dc5e9b9adb5eb64d41e4c49 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 30 Aug 2026 23:01:25 +0900 Subject: feat(plugin): serve ProcessExecutor as a proxy stub Composer reaches this class two ways: the object graph hands one out through Composer::getLoop()->getProcessExecutor(), and plugins write `new ProcessExecutor($io)` freely. Both bind to a Rust-side entity, so the timeout the run shares -- seeded from process-timeout and rewritten while the run is in flight -- has one value instead of one per world, and the executor can still be passed to the classes that take one (`new Filesystem($process)`). Three things the stub generator was missing came with it: - By-ref parameters. The call carries their positions and the answer carries what each holds afterwards; a position the answer omits was never assigned to, which is what PHP does with an untouched by-ref parameter. ProcessExecutor::execute is the only one on a proxied class. - Argument arity, reproduced where the real body reads func_num_args(). execute($cmd) forwards the child's output and execute($cmd, $out) captures it, and nothing but the argument count separates the two. - Static methods that cannot run in the worker. One that reads a static property the Rust side owns, or that reaches a guarded class, forwards through __shirabeCallStatic instead of being materialized. That also fixes Filesystem::isLocalPath and getPlatformPath, whose materialized bodies called the guarded Composer\Util\Platform. The async surface stays an explicit error. executeAsync resolves its promise with a Symfony Process, whose proc_open() resource and pipes belong to whichever process called start(), so a Rust-side spawn has none to hand back; running the real start() in the worker needs a promise representation that crosses the boundary unresolved. The fixture project drives the whole synchronous surface from plugin code and compares the trace against upstream Composer byte for byte. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-rpc/php/worker.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'crates/shirabe-php-rpc/php/worker.php') diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php index 6ed5df40..bc10c2de 100644 --- a/crates/shirabe-php-rpc/php/worker.php +++ b/crates/shirabe-php-rpc/php/worker.php @@ -295,15 +295,29 @@ final class ShirabeRpcRuntime return array_map([self::class, 'fromWire'], $value); } - /** Sends a CallRustMethod request and drives the cooperative loop until its Return. */ - public static function callRust(int $rhandle, string $method, array $args) - { + /** + * Sends a CallRustMethod request and drives the cooperative loop until its Return. + * + * `$outParamPositions` names the by-ref parameters of the called method; the Rust side + * answers with the value each of them holds afterwards, and the caller (a generated stub) + * assigns those back to its own by-ref parameters. + * + * @param list $outParamPositions + * @param array|null $outParams + */ + public static function callRust( + int $rhandle, + string $method, + array $args, + array $outParamPositions = [], + ?array &$outParams = null + ) { $corrId = self::$nextCorrId; self::$nextCorrId += 2; self::writeFrame( SHIRABE_TAG_CALL_RUST_METHOD, $corrId, - serialize([$rhandle, $method, self::toWire($args), []]) + serialize([$rhandle, $method, self::toWire($args), $outParamPositions]) ); while (true) { $frame = self::readFrame(); @@ -320,6 +334,7 @@ final class ShirabeRpcRuntime self::fail('protocol violation: unparseable response payload'); } if ($tag === SHIRABE_TAG_RETURN) { + $outParams = self::fromWire($fields[1] ?? []); return self::fromWire($fields[0]); } [$class, $message, $code] = $fields; -- cgit v1.3.1-4-g156e