From 9a25fcfc82b72f60facd381786ca5490acca032c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Jun 2026 02:42:02 +0900 Subject: feat(dependency-resolver): share operations via Rc, drop clone_box OperationInterface::clone_box (a todo!() trait-object clone stub) is removed in favor of Rc shared ownership. All its methods are &self, so operations are immutable value objects that Rc can share; pushing the same operation into multiple lists (installer's install/uninstall splits) becomes a cheap Rc clone instead of clone_box. Box is replaced with Rc across Transaction (and its Lock/LocalRepo wrappers), Installer, PackageEvent, InstallationManager and EventDispatcher; Box::new operation constructions become Rc::new. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../dependency_resolver/local_repo_transaction.rs | 2 +- .../src/dependency_resolver/lock_transaction.rs | 2 +- .../operation/operation_interface.rs | 4 --- .../shirabe/src/dependency_resolver/transaction.rs | 41 +++++++++++----------- 4 files changed, 23 insertions(+), 26 deletions(-) (limited to 'crates/shirabe/src/dependency_resolver') diff --git a/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs b/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs index 5d9c0d5..dc71562 100644 --- a/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs +++ b/crates/shirabe/src/dependency_resolver/local_repo_transaction.rs @@ -24,7 +24,7 @@ impl LocalRepoTransaction { pub fn get_operations( &self, - ) -> Vec> { + ) -> Vec> { // TODO(phase-b): delegate to inner transaction once operations are typed. Vec::new() } diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs index aa7ae25..61f5b39 100644 --- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs +++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs @@ -209,7 +209,7 @@ impl LockTransaction { pub fn get_operations( &self, - ) -> &Vec> { + ) -> &Vec> { self.inner.get_operations() } } diff --git a/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs b/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs index 3c24ff4..51b150c 100644 --- a/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs +++ b/crates/shirabe/src/dependency_resolver/operation/operation_interface.rs @@ -13,10 +13,6 @@ pub trait OperationInterface: std::fmt::Debug { fn to_string(&self) -> String; - fn clone_box(&self) -> Box { - todo!() - } - fn as_install_operation(&self) -> Option<&InstallOperation> { None } diff --git a/crates/shirabe/src/dependency_resolver/transaction.rs b/crates/shirabe/src/dependency_resolver/transaction.rs index 8cf5d5b..a693356 100644 --- a/crates/shirabe/src/dependency_resolver/transaction.rs +++ b/crates/shirabe/src/dependency_resolver/transaction.rs @@ -19,7 +19,7 @@ use crate::repository::PlatformRepository; #[derive(Debug)] pub struct Transaction { /// @var OperationInterface[] - pub(crate) operations: Vec>, + pub(crate) operations: Vec>, /// Packages present at the beginning of the transaction /// @var PackageInterface[] @@ -63,7 +63,7 @@ impl Transaction { } /// @return OperationInterface[] - pub fn get_operations(&self) -> &Vec> { + pub fn get_operations(&self) -> &Vec> { &self.operations } @@ -114,8 +114,8 @@ impl Transaction { } /// @return OperationInterface[] - pub(crate) fn calculate_operations(&mut self) -> Vec> { - let mut operations: Vec> = vec![]; + pub(crate) fn calculate_operations(&mut self) -> Vec> { + let mut operations: Vec> = vec![]; let mut present_package_map: IndexMap = IndexMap::new(); let mut remove_map: IndexMap = IndexMap::new(); @@ -170,7 +170,7 @@ impl Transaction { remove_alias_map.shift_remove(&alias_key); } else { // TODO(phase-b): MarkAliasInstalledOperation::new expects AliasPackage by value - operations.push(Box::new(MarkAliasInstalledOperation::new(todo!( + operations.push(std::rc::Rc::new(MarkAliasInstalledOperation::new(todo!( "package as AliasPackage by value" )))); } @@ -196,14 +196,14 @@ impl Transaction { || package.get_source_reference() != present.get_source_reference() || abandoned_or_replacement_changed { - operations.push(Box::new(UpdateOperation::new( + operations.push(std::rc::Rc::new(UpdateOperation::new( source.clone(), package.clone(), ))); } remove_map.shift_remove(&package.get_name()); } else { - operations.push(Box::new(InstallOperation::new(package.clone()))); + operations.push(std::rc::Rc::new(InstallOperation::new(package.clone()))); remove_map.shift_remove(&package.get_name()); } } @@ -213,12 +213,13 @@ impl Transaction { // PHP: array_unshift($operations, new Operation\UninstallOperation($package)); array_unshift( &mut operations, - Box::new(UninstallOperation::new(package)) as Box, + std::rc::Rc::new(UninstallOperation::new(package)) + as std::rc::Rc, ); } for (_name_version, _package) in remove_alias_map { // TODO(phase-b): MarkAliasUninstalledOperation::new expects AliasPackage by value - operations.push(Box::new(MarkAliasUninstalledOperation::new(todo!( + operations.push(std::rc::Rc::new(MarkAliasUninstalledOperation::new(todo!( "package as AliasPackage by value" )))); } @@ -292,13 +293,13 @@ impl Transaction { /// @return OperationInterface[] reordered operation list fn move_plugins_to_front( &self, - mut operations: Vec>, - ) -> Vec> { - let mut dl_modifying_plugins_no_deps: Vec> = vec![]; - let mut dl_modifying_plugins_with_deps: Vec> = vec![]; + mut operations: Vec>, + ) -> Vec> { + let mut dl_modifying_plugins_no_deps: Vec> = vec![]; + let mut dl_modifying_plugins_with_deps: Vec> = vec![]; let mut dl_modifying_plugin_requires: Vec = vec![]; - let mut plugins_no_deps: Vec> = vec![]; - let mut plugins_with_deps: Vec> = vec![]; + let mut plugins_no_deps: Vec> = vec![]; + let mut plugins_with_deps: Vec> = vec![]; let mut plugin_requires: Vec = vec![]; // PHP: foreach (array_reverse($operations, true) as $idx => $op) @@ -392,7 +393,7 @@ impl Transaction { } // PHP: array_merge($dlModifyingPluginsNoDeps, $dlModifyingPluginsWithDeps, $pluginsNoDeps, $pluginsWithDeps, $operations) - let mut result: Vec> = vec![]; + let mut result: Vec> = vec![]; result.extend(dl_modifying_plugins_no_deps); result.extend(dl_modifying_plugins_with_deps); result.extend(plugins_no_deps); @@ -408,9 +409,9 @@ impl Transaction { /// @return OperationInterface[] reordered operation list fn move_uninstalls_to_front( &self, - mut operations: Vec>, - ) -> Vec> { - let mut uninst_ops: Vec> = vec![]; + mut operations: Vec>, + ) -> Vec> { + let mut uninst_ops: Vec> = vec![]; let mut to_remove: Vec = vec![]; for (idx, op) in operations.iter().enumerate() { let is_uninstall = op @@ -435,7 +436,7 @@ impl Transaction { operations.remove(idx); } - let mut result: Vec> = vec![]; + let mut result: Vec> = vec![]; result.extend(uninst_ops); result.extend(operations); result -- cgit v1.3.1