diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:04:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:04:27 +0900 |
| commit | da0d38a8e16ebefd59ef5291b5788e6238cc78ba (patch) | |
| tree | c6a4cb9f2444beeb84b2d30133053867acb46741 /crates/shirabe/src/dependency_resolver/pool_optimizer.rs | |
| parent | c0879ab4a02b257cb0bd416dbdfa07784c8e3809 (diff) | |
| download | php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.tar.gz php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.tar.zst php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.zip | |
refactor(semver): replace Constraint's OP_*/STR_OP_* with CmpOp
PHP's version_compare takes its operator as a string, so the shim's port
did too, and Constraint carried two families of operator constants plus
translation tables to convert between the string form and its own int
codes. Five copies of those tables had accumulated across Constraint,
CompilingMatcher and the plugin value bridge.
version_compare now takes a CmpOp, which makes an invalid operator
unrepresentable and removes the tables' reason to exist. Constraint
stores a CmpOp and keeps only the string parsing its constructor needs;
getOperator, compile and CompilingMatcher::match speak CmpOp as well.
PHP's OP_* numbering stays observable: a plugin reads the raw integer off
the Constraint object over RPC, so get_operator_constant and its new
inverse hold that 0..5 mapping.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/dependency_resolver/pool_optimizer.rs')
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/pool_optimizer.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs index 972d2f21..5aca700e 100644 --- a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs +++ b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs @@ -6,7 +6,7 @@ use crate::dependency_resolver::Request; use crate::package::BasePackageHandle; use crate::package::version::VersionParser; use indexmap::IndexMap; -use shirabe_php_shim::{implode, ksort}; +use shirabe_php_shim::{CmpOp, implode, ksort}; use shirabe_semver::CompilingMatcher; use shirabe_semver::Intervals; use shirabe_semver::constraint::AnyConstraint; @@ -156,11 +156,7 @@ impl PoolOptimizer { let constraint = irremovable_package_constraints .get(&package.get_name()) .unwrap(); - if CompilingMatcher::r#match( - constraint, - SimpleConstraint::OP_EQ, - package.get_version().to_string(), - ) { + if CompilingMatcher::r#match(constraint, CmpOp::Eq, package.get_version().to_string()) { self.mark_package_irremovable(package.clone()); } } @@ -252,7 +248,7 @@ impl PoolOptimizer { if CompilingMatcher::r#match( require_constraint, - SimpleConstraint::OP_EQ, + CmpOp::Eq, package.get_version().to_string(), ) { group_hash_parts.push(format!( @@ -265,7 +261,7 @@ impl PoolOptimizer { for (_, link) in package.get_replaces() { if CompilingMatcher::r#match( link.get_constraint(), - SimpleConstraint::OP_EQ, + CmpOp::Eq, package.get_version().to_string(), ) { // Use the same hash part as the regular require hash because that's what the replacement does @@ -283,7 +279,7 @@ impl PoolOptimizer { for (_, conflict_constraint) in conflict_constraints { if CompilingMatcher::r#match( conflict_constraint, - SimpleConstraint::OP_EQ, + CmpOp::Eq, package.get_version().to_string(), ) { group_hash_parts.push(format!( @@ -605,11 +601,7 @@ impl PoolOptimizer { .and_then(|m| m.get(&id)) .map(|p| p.get_version()); if let Some(version_str) = version_str - && !CompilingMatcher::r#match( - link_constraint, - SimpleConstraint::OP_EQ, - version_str, - ) + && !CompilingMatcher::r#match(link_constraint, CmpOp::Eq, version_str) { self.mark_package_for_removal(id); if let Some(map) = package_index.get_mut(require) { |
