Skip to content

Commit fe29028

Browse files
committed
Use async for registry network operations
Converts Poll into async. Some error messages are impacted due to slightly different code paths being taken. This is a major change to the sparse registry backend in http_remote.rs.
1 parent 0e9c1a0 commit fe29028

29 files changed

Lines changed: 1219 additions & 1610 deletions

File tree

crates/resolver-tests/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::cell::RefCell;
1111
use std::cmp::{max, min};
1212
use std::collections::{BTreeMap, HashSet};
1313
use std::fmt;
14-
use std::task::Poll;
1514
use std::time::Instant;
1615

1716
use cargo::core::Resolve;
@@ -135,12 +134,12 @@ pub fn resolve_with_global_context_raw(
135134
used: RefCell<HashSet<PackageId>>,
136135
}
137136
impl<'a> Registry for MyRegistry<'a> {
138-
fn query(
137+
async fn query(
139138
&self,
140139
dep: &Dependency,
141140
kind: QueryKind,
142141
f: &mut dyn FnMut(IndexSummary),
143-
) -> Poll<CargoResult<()>> {
142+
) -> CargoResult<()> {
144143
for summary in self.list.iter() {
145144
let matched = match kind {
146145
QueryKind::Exact => dep.matches(summary),
@@ -153,7 +152,7 @@ pub fn resolve_with_global_context_raw(
153152
f(IndexSummary::Candidate(summary.clone()));
154153
}
155154
}
156-
Poll::Ready(Ok(()))
155+
Ok(())
157156
}
158157

159158
fn describe_source(&self, _src: SourceId) -> String {
@@ -163,10 +162,6 @@ pub fn resolve_with_global_context_raw(
163162
fn is_replaced(&self, _src: SourceId) -> bool {
164163
false
165164
}
166-
167-
fn block_until_ready(&self) -> CargoResult<()> {
168-
Ok(())
169-
}
170165
}
171166
impl<'a> Drop for MyRegistry<'a> {
172167
fn drop(&mut self) {

crates/xtask-bump-check/src/xtask.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use std::collections::HashMap;
1616
use std::fmt::Write;
1717
use std::fs;
18-
use std::task;
1918

2019
use cargo::CargoResult;
2120
use cargo::core::Package;
@@ -444,15 +443,9 @@ fn check_crates_io<'a>(
444443
let current = member.version();
445444
let version_req = format!(">={current}");
446445
let query = Dependency::parse(*name, Some(&version_req), source_id)?;
447-
let possibilities = loop {
448-
// Exact to avoid returning all for path/git
449-
match registry.query_vec(&query, QueryKind::Exact) {
450-
task::Poll::Ready(res) => {
451-
break res?;
452-
}
453-
task::Poll::Pending => registry.block_until_ready()?,
454-
}
455-
};
446+
// Exact to avoid returning all for path/git
447+
let possibilities =
448+
futures::executor::block_on(registry.query_vec(&query, QueryKind::Exact))?;
456449
if possibilities.is_empty() {
457450
tracing::trace!("dep `{name}` has no version greater than or equal to `{current}`");
458451
} else {

src/cargo/core/compiler/future_incompat.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ use crate::sources::source::QueryKind;
4040
use crate::util::CargoResult;
4141
use crate::util::cache_lock::CacheLockMode;
4242
use anyhow::{Context, bail, format_err};
43+
use futures::stream::FuturesUnordered;
4344
use serde::{Deserialize, Serialize};
4445
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
4546
use std::fmt::Write as _;
4647
use std::io::{Read, Write};
47-
use std::task::Poll;
4848

4949
pub const REPORT_PREAMBLE: &str = "\
5050
The following warnings were discovered during the build. These warnings are an
@@ -308,7 +308,7 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
308308
.ok()?;
309309
// Create a set of updated registry sources.
310310
let map = SourceConfigMap::new(ws.gctx()).ok()?;
311-
let mut package_ids: BTreeSet<_> = package_ids
311+
let package_ids: BTreeSet<_> = package_ids
312312
.iter()
313313
.filter(|pkg_id| pkg_id.source_id().is_registry())
314314
.collect();
@@ -325,28 +325,18 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
325325
.collect();
326326

327327
// Query the sources for new versions, mapping `package_ids` into `summaries`.
328-
let mut summaries = Vec::new();
329-
while !package_ids.is_empty() {
330-
package_ids.retain(|&pkg_id| {
331-
let Some(source) = sources.get(&pkg_id.source_id()) else {
332-
return false;
333-
};
334-
let Ok(dep) = Dependency::parse(pkg_id.name(), None, pkg_id.source_id()) else {
335-
return false;
336-
};
337-
match source.query_vec(&dep, QueryKind::Exact) {
338-
Poll::Ready(Ok(sum)) => {
339-
summaries.push((pkg_id, sum));
340-
false
341-
}
342-
Poll::Ready(Err(_)) => false,
343-
Poll::Pending => true,
344-
}
345-
});
346-
for (_, source) in sources.iter() {
347-
source.block_until_ready().ok()?;
328+
let pending = FuturesUnordered::new();
329+
for pkg_id in package_ids {
330+
if let Some(source) = sources.get(&pkg_id.source_id())
331+
&& let Ok(dep) = Dependency::parse(pkg_id.name(), None, pkg_id.source_id())
332+
{
333+
pending.push(async move {
334+
let sum = source.query_vec(&dep, QueryKind::Exact).await.ok()?;
335+
Some((pkg_id, sum))
336+
});
348337
}
349338
}
339+
let summaries = crate::util::block_on_stream(pending).flatten();
350340

351341
let mut updates = String::new();
352342
for (pkg_id, summaries) in summaries {

0 commit comments

Comments
 (0)