diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-29 03:42:14 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-29 03:42:14 +0900 |
| commit | 86fcc80b348a3f00ab81e5447924aa10202d95e8 (patch) | |
| tree | 0bdb4f7bd11aab799230a97500a380401a93b77e /crates/shirabe/src/repository | |
| parent | 7f83e785a77fbdbcada9c6714703d4e5801af82a (diff) | |
| download | php-shirabe-86fcc80b348a3f00ab81e5447924aa10202d95e8.tar.gz php-shirabe-86fcc80b348a3f00ab81e5447924aa10202d95e8.tar.zst php-shirabe-86fcc80b348a3f00ab81e5447924aa10202d95e8.zip | |
refactor(repository): introduce typed LockArrayRepositoryHandle
Share LockArrayRepository via Rc<RefCell<_>> while preserving the PHP
?LockArrayRepository type strength: Request.locked_repository, Locker
::get_locked_repository, and the installer create_* helpers now thread
the typed handle instead of an owned LockArrayRepository, and pool
builder identity check becomes a strict ptr_eq via widening into
RepositoryInterfaceHandle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
| -rw-r--r-- | crates/shirabe/src/repository/handle.rs | 63 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/repository_set.rs | 6 |
2 files changed, 64 insertions, 5 deletions
diff --git a/crates/shirabe/src/repository/handle.rs b/crates/shirabe/src/repository/handle.rs index f7a4104..a4225f7 100644 --- a/crates/shirabe/src/repository/handle.rs +++ b/crates/shirabe/src/repository/handle.rs @@ -10,8 +10,8 @@ use shirabe_semver::constraint::AnyConstraint; use crate::package::BasePackageHandle; use crate::package::PackageInterfaceHandle; use crate::repository::{ - FindPackageConstraint, InstalledRepositoryInterface, LoadPackagesResult, ProviderInfo, - RepositoryInterface, SearchResult, WritableRepositoryInterface, + FindPackageConstraint, InstalledRepositoryInterface, LoadPackagesResult, LockArrayRepository, + ProviderInfo, RepositoryInterface, SearchResult, WritableRepositoryInterface, }; /// Shared reference to a repository. Corresponds to PHP `RepositoryInterface`. @@ -172,3 +172,62 @@ impl std::hash::Hash for RepositoryInterfaceHandle { self.ptr_id().hash(state); } } + +/// Typed shared handle over `LockArrayRepository`. Preserves the PHP `?LockArrayRepository` +/// typing where a `RepositoryInterfaceHandle` would be too wide. +#[derive(Debug, Clone)] +pub struct LockArrayRepositoryHandle(Rc<RefCell<LockArrayRepository>>); + +impl LockArrayRepositoryHandle { + pub fn new(repository: LockArrayRepository) -> Self { + let rc: Rc<RefCell<LockArrayRepository>> = Rc::new(RefCell::new(repository)); + let rc_dyn: Rc<RefCell<dyn RepositoryInterface>> = rc.clone(); + rc.borrow().set_self_handle(Rc::downgrade(&rc_dyn)); + Self(rc) + } + + pub fn from_rc(rc: Rc<RefCell<LockArrayRepository>>) -> Self { + Self(rc) + } + + pub fn as_rc(&self) -> &Rc<RefCell<LockArrayRepository>> { + &self.0 + } + + pub fn borrow(&self) -> Ref<'_, LockArrayRepository> { + self.0.borrow() + } + + pub fn borrow_mut(&self) -> RefMut<'_, LockArrayRepository> { + self.0.borrow_mut() + } + + pub fn ptr_eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.0, &other.0) + } + + pub fn ptr_id(&self) -> usize { + Rc::as_ptr(&self.0) as *const () as usize + } +} + +impl From<LockArrayRepositoryHandle> for RepositoryInterfaceHandle { + fn from(h: LockArrayRepositoryHandle) -> Self { + let rc: Rc<RefCell<dyn RepositoryInterface>> = h.0; + RepositoryInterfaceHandle::from_rc(rc) + } +} + +impl PartialEq for LockArrayRepositoryHandle { + fn eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.0, &other.0) + } +} + +impl Eq for LockArrayRepositoryHandle {} + +impl std::hash::Hash for LockArrayRepositoryHandle { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + self.ptr_id().hash(state); + } +} diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index f4a4057..843af80 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -32,7 +32,7 @@ use crate::package::version::StabilityFilter; use crate::repository::CompositeRepository; use crate::repository::InstalledRepository; use crate::repository::InstalledRepositoryInterface; -use crate::repository::LockArrayRepository; +use crate::repository::LockArrayRepositoryHandle; use crate::repository::PlatformRepository; use crate::repository::{AdvisoryProviderInterface, PartialOrSecurityAdvisory}; use crate::repository::{FindPackageConstraint, RepositoryInterface, RepositoryInterfaceHandle}; @@ -573,7 +573,7 @@ impl RepositorySet { pub fn create_pool_for_package( &mut self, package_name: &str, - locked_repo: Option<LockArrayRepository>, + locked_repo: Option<LockArrayRepositoryHandle>, ) -> Result<Pool> { // TODO unify this with above in some simpler version without "request"? self.create_pool_for_packages(vec![package_name.to_string()], locked_repo) @@ -583,7 +583,7 @@ impl RepositorySet { pub fn create_pool_for_packages( &mut self, package_names: Vec<String>, - locked_repo: Option<LockArrayRepository>, + locked_repo: Option<LockArrayRepositoryHandle>, ) -> Result<Pool> { let mut request = Request::new(locked_repo); |
