@@ -490,9 +490,7 @@ public struct PubGrubDependencyResolver {
490
490
491
491
// If decision making determines that no more decisions are to be
492
492
// made, it returns nil to signal that version solving is done.
493
- next = try await withCheckedThrowingContinuation {
494
- self . makeDecision ( state: state, completion: $0. resume ( with: ) )
495
- }
493
+ next = try await self . makeDecision ( state: state)
496
494
}
497
495
}
498
496
@@ -691,77 +689,70 @@ public struct PubGrubDependencyResolver {
691
689
}
692
690
693
691
internal func makeDecision(
694
- state: State ,
695
- completion: @escaping ( Result < DependencyResolutionNode ? , Error > ) -> Void
696
- ) {
692
+ state: State
693
+ ) async throws -> DependencyResolutionNode ? {
697
694
// If there are no more undecided terms, version solving is complete.
698
695
let undecided = state. solution. undecided
699
696
guard !undecided. isEmpty else {
700
- return completion ( . success ( nil ) )
697
+ return nil
701
698
}
702
699
703
700
// Prefer packages with least number of versions that fit the current requirements so we
704
701
// get conflicts (if any) sooner.
705
- Task {
706
- do {
707
- let start = DispatchTime . now ( )
708
- let counts = try await self . computeCounts ( for: undecided)
709
- // forced unwraps safe since we are testing for count and errors above
710
- let pkgTerm = undecided. min {
711
- // Prefer packages that don't allow pre-release versions
712
- // to allow propagation logic to find dependencies that
713
- // limit the range before making any decisions. This means
714
- // that we'd always prefer release versions.
715
- if $0. supportsPrereleases != $1. supportsPrereleases {
716
- return !$0. supportsPrereleases
717
- }
718
-
719
- return counts [ $0] ! < counts [ $1] !
720
- } !
721
- self . delegate? . willResolve ( term: pkgTerm)
722
- // at this point the container is cached
723
- let container = try self . provider. getCachedContainer ( for: pkgTerm. node. package )
724
-
725
- // Get the best available version for this package.
726
- guard let version = try await container. getBestAvailableVersion ( for: pkgTerm) else {
727
- state. addIncompatibility ( try Incompatibility ( pkgTerm, root: state. root, cause: . noAvailableVersion) , at: . decisionMaking)
728
- return completion ( . success( pkgTerm. node) )
729
- }
730
-
731
- // Add all of this version's dependencies as incompatibilities.
732
- let depIncompatibilities = try await container. incompatibilites (
733
- at: version,
734
- node: pkgTerm. node,
735
- overriddenPackages: state. overriddenPackages,
736
- root: state. root
737
- )
702
+ let start = DispatchTime . now ( )
703
+ let counts = try await self . computeCounts ( for: undecided)
704
+ // forced unwraps safe since we are testing for count and errors above
705
+ let pkgTerm = undecided. min {
706
+ // Prefer packages that don't allow pre-release versions
707
+ // to allow propagation logic to find dependencies that
708
+ // limit the range before making any decisions. This means
709
+ // that we'd always prefer release versions.
710
+ if $0. supportsPrereleases != $1. supportsPrereleases {
711
+ return !$0. supportsPrereleases
712
+ }
713
+
714
+ return counts [ $0] ! < counts [ $1] !
715
+ } !
716
+ self . delegate? . willResolve ( term: pkgTerm)
717
+ // at this point the container is cached
718
+ let container = try self . provider. getCachedContainer ( for: pkgTerm. node. package )
719
+
720
+ // Get the best available version for this package.
721
+ guard let version = try await container. getBestAvailableVersion ( for: pkgTerm) else {
722
+ state. addIncompatibility ( try Incompatibility ( pkgTerm, root: state. root, cause: . noAvailableVersion) , at: . decisionMaking)
723
+ return pkgTerm. node
724
+ }
738
725
739
- var haveConflict = false
740
- for incompatibility in depIncompatibilities {
741
- // Add the incompatibility to our partial solution.
742
- state. addIncompatibility ( incompatibility, at: . decisionMaking)
743
-
744
- // Check if this incompatibility will satisfy the solution.
745
- haveConflict = haveConflict || incompatibility. terms. allSatisfy {
746
- // We only need to check if the terms other than this package
747
- // are satisfied because we _know_ that the terms matching
748
- // this package will be satisfied if we make this version
749
- // as a decision.
750
- $0. node == pkgTerm. node || state. solution. satisfies ( $0)
751
- }
752
- }
726
+ // Add all of this version's dependencies as incompatibilities.
727
+ let depIncompatibilities = try await container. incompatibilites (
728
+ at: version,
729
+ node: pkgTerm. node,
730
+ overriddenPackages: state. overriddenPackages,
731
+ root: state. root
732
+ )
753
733
754
- // Decide this version if there was no conflict with its dependencies.
755
- if !haveConflict {
756
- self . delegate? . didResolve ( term: pkgTerm, version: version, duration: start. distance ( to: . now( ) ) )
757
- state. decide ( pkgTerm. node, at: version)
758
- }
734
+ var haveConflict = false
735
+ for incompatibility in depIncompatibilities {
736
+ // Add the incompatibility to our partial solution.
737
+ state. addIncompatibility ( incompatibility, at: . decisionMaking)
759
738
760
- completion ( . success( pkgTerm. node) )
761
- } catch {
762
- completion ( . failure( error) )
739
+ // Check if this incompatibility will satisfy the solution.
740
+ haveConflict = haveConflict || incompatibility. terms. allSatisfy {
741
+ // We only need to check if the terms other than this package
742
+ // are satisfied because we _know_ that the terms matching
743
+ // this package will be satisfied if we make this version
744
+ // as a decision.
745
+ $0. node == pkgTerm. node || state. solution. satisfies ( $0)
763
746
}
764
747
}
748
+
749
+ // Decide this version if there was no conflict with its dependencies.
750
+ if !haveConflict {
751
+ self . delegate? . didResolve ( term: pkgTerm, version: version, duration: start. distance ( to: . now( ) ) )
752
+ state. decide ( pkgTerm. node, at: version)
753
+ }
754
+
755
+ return pkgTerm. node
765
756
}
766
757
}
767
758
0 commit comments