Skip to content

Commit d1dba66

Browse files
committed
[Pubgrub] Kill Solution.versionIntersection(for:)
This is no longer required because the postive dictionary already contains the intersections.
1 parent bf2c603 commit d1dba66

File tree

3 files changed

+8
-35
lines changed

3 files changed

+8
-35
lines changed

Sources/PackageGraph/Pubgrub.swift

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,8 @@ final class PartialSolution<Identifier: PackageContainerIdentifier> {
480480

481481
/// A list of all packages that have been assigned, but are not yet satisfied.
482482
var undecided: [Term<Identifier>] {
483-
let decisionTerms = assignments
484-
.filter { $0.isDecision }
485-
.map { $0.term }
486-
487483
// FIXME: Should we sort this so we have a deterministic results?
488-
return _positive.values.filter { !decisionTerms.contains($0) }
484+
return _positive.values.filter { !decisions.keys.contains($0.package) }
489485
}
490486

491487
/// Create a new derivation assignment and add it to the partial solution's
@@ -572,25 +568,6 @@ final class PartialSolution<Identifier: PackageContainerIdentifier> {
572568
}
573569
}
574570

575-
/// Create an intersection of the versions of all assignments referring to
576-
/// a given package.
577-
/// - Returns: nil if no assignments exist or intersection of versions is
578-
/// invalid.
579-
func versionIntersection(for package: Identifier) -> Term<Identifier>? {
580-
let packageAssignments = assignments.filter { $0.term.package == package }
581-
let firstTerm = packageAssignments.first?.term
582-
guard let intersection = packageAssignments.reduce(firstTerm, { result, assignment in
583-
guard let res = result?.intersect(with: assignment.term) else {
584-
return nil
585-
}
586-
return res
587-
})
588-
else {
589-
return nil
590-
}
591-
return intersection
592-
}
593-
594571
/// Does the solution contain a decision for every derivation meaning
595572
/// that all necessary packages have been found?
596573
var isFinished: Bool {
@@ -1092,11 +1069,7 @@ public final class PubgrubDependencyResolver<
10921069

10931070
// FIXME: We should choose a package with least available versions for the
10941071
// constraints that we have so far on the package.
1095-
let candidate = undecided.first!
1096-
1097-
guard let pkgTerm = solution.versionIntersection(for: candidate.package) else {
1098-
fatalError("failed to create version intersection for \(candidate.package)")
1099-
}
1072+
let pkgTerm = undecided.first!
11001073

11011074
// Get the best available version for this package.
11021075
guard let version = try getBestAvailableVersion(for: pkgTerm) else {
@@ -1125,10 +1098,10 @@ public final class PubgrubDependencyResolver<
11251098

11261099
// Decide this version if there was no conflict with its dependencies.
11271100
if !haveConflict {
1128-
decide(candidate.package, version: version, location: .decisionMaking)
1101+
decide(pkgTerm.package, version: version, location: .decisionMaking)
11291102
}
11301103

1131-
return candidate.package
1104+
return pkgTerm.package
11321105
}
11331106

11341107
// MARK: - Error Reporting

Tests/PackageGraphTests/PubgrubTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,18 @@ final class PubgrubTests: XCTestCase {
411411
XCTAssertEqual(solution.decisionLevel, 1)
412412
}
413413

414-
func testSolutionVersionIntersection() {
414+
func testPositiveTerms() {
415415
let s1 = PartialSolution(assignments: [
416416
.derivation("a^1.0.0", cause: _cause, decisionLevel: 0),
417417
])
418-
XCTAssertEqual(s1.versionIntersection(for: "a")?.requirement,
418+
XCTAssertEqual(s1._positive["a"]?.requirement,
419419
.versionSet(.range("1.0.0"..<"2.0.0")))
420420

421421
let s2 = PartialSolution(assignments: [
422422
.derivation("a^1.0.0", cause: _cause, decisionLevel: 0),
423423
.derivation("a^1.5.0", cause: _cause, decisionLevel: 0)
424424
])
425-
XCTAssertEqual(s2.versionIntersection(for: "a")?.requirement,
425+
XCTAssertEqual(s2._positive["a"]?.requirement,
426426
.versionSet(.range("1.5.0"..<"2.0.0")))
427427
}
428428

Tests/PackageGraphTests/XCTestManifests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extension PubgrubTests {
5656
static let __allTests__PubgrubTests = [
5757
("testIncompatibilityNormalizeTermsOnInit", testIncompatibilityNormalizeTermsOnInit),
5858
("testMissingVersion", testMissingVersion),
59+
("testPositiveTerms", testPositiveTerms),
5960
("testResolutionAvoidingConflictResolutionDuringDecisionMaking", testResolutionAvoidingConflictResolutionDuringDecisionMaking),
6061
("testResolutionConflictResolutionWithAPartialSatisfier", testResolutionConflictResolutionWithAPartialSatisfier),
6162
("testResolutionNoConflicts", testResolutionNoConflicts),
@@ -69,7 +70,6 @@ extension PubgrubTests {
6970
("testSolutionIsFinished", testSolutionIsFinished),
7071
("testSolutionPositive", testSolutionPositive),
7172
("testSolutionUndecided", testSolutionUndecided),
72-
("testSolutionVersionIntersection", testSolutionVersionIntersection),
7373
("testTermIntersection", testTermIntersection),
7474
("testTermInverse", testTermInverse),
7575
("testTermIsValidDecision", testTermIsValidDecision),

0 commit comments

Comments
 (0)