Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/solver/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ type PendingTask<'cache, D> = LocalBoxFuture<'cache, Result<TaskResult<'cache, D

type RequirementCondition<'a, S> = Option<(ConditionId, Vec<Vec<DisjunctionComplement<'a, S>>>)>;

/// Fetches each version set's sorted candidates while avoiding `try_join_all`'s
/// per-future bookkeeping for the overwhelmingly common single-version-set case.
/// Union members remain concurrent for dependency providers whose futures yield.
async fn get_requirement_candidates<D: DependencyProvider>(
cache: &SolverCache<D>,
requirement: Requirement,
) -> Result<Vec<&[D::SolvableId]>, Box<dyn Any>> {
match requirement {
Requirement::Single(version_set) => Ok(vec![
cache
.get_or_cache_sorted_candidates_for_version_set(version_set)
.await?,
]),
Requirement::Union(version_set_union) => {
futures::future::try_join_all(
cache
.provider()
.version_sets_in_union(version_set_union)
.map(|version_set| {
cache.get_or_cache_sorted_candidates_for_version_set(version_set)
}),
)
.await
}
}
}

/// An object that is responsible for encoding information from the dependency
/// provider into rules and variables that are used by the solver.
///
Expand Down Expand Up @@ -853,15 +880,7 @@ impl<'a, 'cache, D: DependencyProvider> Encoder<'a, 'cache, D> {
) {
let cache = self.cache;
self.queue_future(async move {
let candidates = futures::future::try_join_all(
requirement
.requirement
.version_sets(cache.provider())
.map(|version_set| {
cache.get_or_cache_sorted_candidates_for_version_set(version_set)
}),
)
.await?;
let candidates = get_requirement_candidates(cache, requirement.requirement).await?;

Ok(TaskResult::RequirementCandidates(
RequirementCandidatesAvailable {
Expand Down Expand Up @@ -1039,15 +1058,7 @@ impl<'a, 'cache, D: DependencyProvider> Encoder<'a, 'cache, D> {
}))
.await?;

let candidates = futures::future::try_join_all(
requirement
.requirement
.version_sets(cache.provider())
.map(|version_set| {
cache.get_or_cache_sorted_candidates_for_version_set(version_set)
}),
)
.await?;
let candidates = get_requirement_candidates(cache, requirement.requirement).await?;

Ok(TaskResult::RequirementCandidates(
RequirementCandidatesAvailable {
Expand Down
2 changes: 1 addition & 1 deletion tools/solve-snapshot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Opts {

/// The timeout to use for solving requirements in seconds. If a solve takes
/// longer if will be cancelled.
#[clap(long, default_value = "60")]
#[clap(long, default_value = "10")]
timeout: u64,

/// The random seed to use for generating the requirements.
Expand Down