Skip to content

Commit a77ed9b

Browse files
committed
Auto merge of #10064 - arlosi:poll, r=Eh2406
Registry functions return Poll to enable parallel fetching of index data Adds `Poll` as a return type for several registry functions to enable parallel fetching of crate metadata with a future http-based registry. Work is scheduled by calling the `query` and related functions, then waited on with `block_until_ready`. This PR is based on the draft PR started by eh2406 here [#8985](#8985). r? `@Eh2406` cc `@alexcrichton` cc `@jonhoo`
2 parents 19f3188 + 0c07056 commit a77ed9b

File tree

21 files changed

+708
-316
lines changed

21 files changed

+708
-316
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
77
use std::fmt;
88
use std::fmt::Write;
99
use std::rc::Rc;
10+
use std::task::Poll;
1011
use std::time::Instant;
1112

1213
use cargo::core::dependency::DepKind;
@@ -129,14 +130,14 @@ pub fn resolve_with_config_raw(
129130
dep: &Dependency,
130131
f: &mut dyn FnMut(Summary),
131132
fuzzy: bool,
132-
) -> CargoResult<()> {
133+
) -> Poll<CargoResult<()>> {
133134
for summary in self.list.iter() {
134135
if fuzzy || dep.matches(summary) {
135136
self.used.insert(summary.package_id());
136137
f(summary.clone());
137138
}
138139
}
139-
Ok(())
140+
Poll::Ready(Ok(()))
140141
}
141142

142143
fn describe_source(&self, _src: SourceId) -> String {
@@ -146,6 +147,10 @@ pub fn resolve_with_config_raw(
146147
fn is_replaced(&self, _src: SourceId) -> bool {
147148
false
148149
}
150+
151+
fn block_until_ready(&mut self) -> CargoResult<()> {
152+
Ok(())
153+
}
149154
}
150155
impl<'a> Drop for MyRegistry<'a> {
151156
fn drop(&mut self) {

src/cargo/core/compiler/future_incompat.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
99
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
1010
use std::fmt::Write as _;
1111
use std::io::{Read, Write};
12+
use std::task::Poll;
1213

1314
pub const REPORT_PREAMBLE: &str = "\
1415
The following warnings were discovered during the build. These warnings are an
@@ -264,7 +265,7 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
264265
let _lock = ws.config().acquire_package_cache_lock().ok()?;
265266
// Create a set of updated registry sources.
266267
let map = SourceConfigMap::new(ws.config()).ok()?;
267-
let package_ids: BTreeSet<_> = package_ids
268+
let mut package_ids: BTreeSet<_> = package_ids
268269
.iter()
269270
.filter(|pkg_id| pkg_id.source_id().is_registry())
270271
.collect();
@@ -279,15 +280,35 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
279280
Some((sid, source))
280281
})
281282
.collect();
282-
// Query the sources for new versions.
283+
284+
// Query the sources for new versions, mapping `package_ids` into `summaries`.
285+
let mut summaries = Vec::new();
286+
while !package_ids.is_empty() {
287+
package_ids.retain(|&pkg_id| {
288+
let source = match sources.get_mut(&pkg_id.source_id()) {
289+
Some(s) => s,
290+
None => return false,
291+
};
292+
let dep = match Dependency::parse(pkg_id.name(), None, pkg_id.source_id()) {
293+
Ok(dep) => dep,
294+
Err(_) => return false,
295+
};
296+
match source.query_vec(&dep) {
297+
Poll::Ready(Ok(sum)) => {
298+
summaries.push((pkg_id, sum));
299+
false
300+
}
301+
Poll::Ready(Err(_)) => false,
302+
Poll::Pending => true,
303+
}
304+
});
305+
for (_, source) in sources.iter_mut() {
306+
source.block_until_ready().ok()?;
307+
}
308+
}
309+
283310
let mut updates = String::new();
284-
for pkg_id in package_ids {
285-
let source = match sources.get_mut(&pkg_id.source_id()) {
286-
Some(s) => s,
287-
None => continue,
288-
};
289-
let dep = Dependency::parse(pkg_id.name(), None, pkg_id.source_id()).ok()?;
290-
let summaries = source.query_vec(&dep).ok()?;
311+
for (pkg_id, summaries) in summaries {
291312
let mut updated_versions: Vec<_> = summaries
292313
.iter()
293314
.map(|summary| summary.version())

0 commit comments

Comments
 (0)