Skip to content

Commit 3c7d9e7

Browse files
committed
[DependencyResolver] Clean up constraint set subscripting of unassigned identifiers.
- Conceptually these just map to a constraint of .any, which simplifies the clients.
1 parent 580d2d7 commit 3c7d9e7

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Sources/PackageGraph/DependencyResolver.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ struct PackageContainerConstraintSet<C: PackageContainer>: Collection {
238238
return AnySequence<C.Identifier>(constraints.keys)
239239
}
240240

241-
/// Get the version set associated with the given package `identifier`.
242-
subscript(identifier: Identifier) -> VersionSetSpecifier? {
243-
return constraints[identifier]
241+
/// Get the version set specifier associated with the given package `identifier`.
242+
subscript(identifier: Identifier) -> VersionSetSpecifier {
243+
return constraints[identifier] ?? .any
244244
}
245245

246246
/// Merge the given version requirement for the container `identifier`.
@@ -424,15 +424,11 @@ struct VersionAssignmentSet<C: PackageContainer>: Sequence {
424424
// A package can be excluded if there are no constraints on the
425425
// package (it has not been requested by any other package in the
426426
// assignment).
427-
return constraints[container.identifier] == nil
427+
return constraints[container.identifier] == .any
428428

429429
case .version(let version):
430-
// A version is valid if it is contained in the constraints, or there are no constraints.
431-
if let versionSet = constraints[container.identifier] {
432-
return versionSet.contains(version)
433-
} else {
434-
return true
435-
}
430+
// A version is valid if it is contained in the constraints.
431+
return constraints[container.identifier].contains(version)
436432
}
437433
}
438434

@@ -604,7 +600,7 @@ public class DependencyResolver<
604600
excluding allExclusions: [Identifier: Set<Version>]
605601
) throws -> AssignmentSet? {
606602
func validVersions(_ container: Container) -> AnyIterator<Version> {
607-
let constraints = allConstraints[container.identifier] ?? .any
603+
let constraints = allConstraints[container.identifier]
608604
let exclusions = allExclusions[container.identifier] ?? Set()
609605
var it = container.versions.reversed().makeIterator()
610606
return AnyIterator { () -> Version? in

Tests/PackageGraphTests/DependencyResolverTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ where C.Identifier == String
402402
{
403403
var actual = [String: VersionSetSpecifier]()
404404
for identifier in constraints.containerIdentifiers {
405-
actual[identifier] = constraints[identifier]!
405+
actual[identifier] = constraints[identifier]
406406
}
407407
XCTAssertEqual(actual, expected, file: file, line: line)
408408
}

0 commit comments

Comments
 (0)