aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/dependency_resolver/transaction.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-08 11:26:03 +0900
committernsfisis <nsfisis@gmail.com>2026-06-08 11:26:03 +0900
commite5b789616ec4c1cbd152c5ccbefe2d27ced4a18f (patch)
tree7a713cf1bcec30a1c69d5c434d8df6a7525dcbc2 /crates/shirabe/src/dependency_resolver/transaction.rs
parent7439cdb08afe0882186a34f70c1e8878fcb7dca5 (diff)
downloadphp-shirabe-e5b789616ec4c1cbd152c5ccbefe2d27ced4a18f.tar.gz
php-shirabe-e5b789616ec4c1cbd152c5ccbefe2d27ced4a18f.tar.zst
php-shirabe-e5b789616ec4c1cbd152c5ccbefe2d27ced4a18f.zip
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<T>, 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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/dependency_resolver/transaction.rs')
-rw-r--r--crates/shirabe/src/dependency_resolver/transaction.rs22
1 files changed, 7 insertions, 15 deletions
diff --git a/crates/shirabe/src/dependency_resolver/transaction.rs b/crates/shirabe/src/dependency_resolver/transaction.rs
index 3450815..d20659c 100644
--- a/crates/shirabe/src/dependency_resolver/transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/transaction.rs
@@ -4,6 +4,7 @@ use indexmap::IndexMap;
use indexmap::IndexSet;
use shirabe_php_shim::{
PhpMixed, array_filter, array_intersect, array_keys, array_pop, array_unshift, strcmp, uasort,
+ uasort_map,
};
use crate::dependency_resolver::operation::InstallOperation;
@@ -70,9 +71,7 @@ impl Transaction {
/// @param PackageInterface[] $resultPackages
fn set_result_package_maps(&mut self, result_packages: Vec<PackageInterfaceHandle>) {
- // PHP: static function (PackageInterface $a, PackageInterface $b): int { ... };
- // TODO(phase-b): bridge the closure to uasort's argument type
- let _package_sort = |a: &PackageInterfaceHandle, b: &PackageInterfaceHandle| -> i64 {
+ let package_sort = |a: &PackageInterfaceHandle, b: &PackageInterfaceHandle| -> i64 {
// sort alias packages by the same name behind their non alias version
if a.get_name() == b.get_name() {
let a_is_alias = a.as_alias().is_some();
@@ -100,17 +99,12 @@ impl Transaction {
.insert(package.ptr_id().to_string(), package);
}
- // TODO(phase-b): uasort signature mismatch — needs to operate on the IndexMap with a PackageInterface comparator
- uasort(
- todo!("&mut self.result_package_map"),
- |_a: &str, _b: &str| -> i64 { todo!("package_sort") },
- );
+ uasort_map(&mut self.result_package_map, package_sort);
let names: Vec<String> = self.result_packages_by_name.keys().cloned().collect();
- for _name in &names {
- uasort(
- todo!("&mut self.result_packages_by_name[name]"),
- |_a: &str, _b: &str| -> i64 { todo!("package_sort") },
- );
+ for name in &names {
+ if let Some(packages) = self.result_packages_by_name.get_mut(name) {
+ uasort(packages, package_sort);
+ }
}
}
@@ -297,8 +291,6 @@ impl Transaction {
let mut plugins_with_deps: Vec<std::rc::Rc<dyn OperationInterface>> = vec![];
let mut plugin_requires: Vec<String> = vec![];
- // PHP: foreach (array_reverse($operations, true) as $idx => $op)
- // TODO(phase-b): array_reverse preserves keys (true); iterate indices in reverse to mimic
let mut to_remove: Vec<usize> = vec![];
for idx in (0..operations.len()).rev() {
let op = &operations[idx];