From e5b789616ec4c1cbd152c5ccbefe2d27ced4a18f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 8 Jun 2026 11:26:03 +0900 Subject: feat(phase-c): resolve PHP-array-semantics phase-b TODOs Resolve category K (array_* functions, integer keys, nested mutation, sorting). Add shim variants (uasort over Vec, uasort_map for IndexMap) and delegate to existing typed variants (strtr_array, array_merge_map, array_search_in_vec). Implement PHP array semantics directly where the shape is fixed: canonical integer-key coercion (is_php_integer_key, shared by config and FilesystemRepository::dumpToPhpCode), strict array_search via trait-object pointer identity, array_reverse/array_chunk preserve_keys loops, and the installed.php nested version mutations via auto-vivify helpers. Resolving the array_merge in UpdateCommand unmasked latent borrow bugs in execute's tail (Rc input/output moved by value); fixed with .clone() to match PHP reference sharing, and resolved the tightly-coupled Intervals constraint check. composerRequire reclassified to phase-c: it depends on the $GLOBALS superglobal and PHP's require include mechanism, neither portable. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/autoload/autoload_generator.rs | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/autoload/autoload_generator.rs') diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index a0e51e9..69ecb73 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -1628,11 +1628,27 @@ impl AutoloadGenerator { }; let mut autoload = package.get_autoload(); - // PHP comparison: $package === $rootPackage (object identity). We compare by name as best-effort. - let is_root = package.get_name() == root_package.get_name(); + let is_root = package.ptr_eq(&root_package.clone().into()); if self.dev_mode.unwrap_or(false) && is_root { - // TODO(phase-b): array_merge_recursive semantics (nested merge) not preserved - autoload.extend(root_package.get_dev_autoload()); + let merged = array_merge_recursive(vec![ + PhpMixed::Array( + autoload + .into_iter() + .map(|(k, v)| (k, Box::new(v))) + .collect(), + ), + PhpMixed::Array( + root_package + .get_dev_autoload() + .into_iter() + .map(|(k, v)| (k, Box::new(v))) + .collect(), + ), + ]); + autoload = match merged { + PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(), + _ => IndexMap::new(), + }; } // skip misconfigured packages @@ -1914,7 +1930,9 @@ impl AutoloadGenerator { } pub fn composer_require(_file_identifier: &str, _file: &str) { - // TODO(phase-b): PHP GLOBALS nested array access not supported + // TODO(phase-c): unportable — depends on the $GLOBALS superglobal + // ($GLOBALS['__composer_autoload_files']) and PHP's `require $file` include + // mechanism (see also ClassLoader's include closure), neither of which is modeled. todo!() } -- cgit v1.3.1