Skip to content

Commit 21ea254

Browse files
committed
Remove the Vec<Job> from DependencyQueue
I... don't think this needed any more! Doing some digging looks like this was originally added in 79768eb. That was so early it didn't even use a PR and was almost 5 years ago. Since then we've had a huge number of changes to the backend and `Unit` nowadays does all the deduplication we need, so no need to store a `Vec` here and we can just have a mapping of `Key` to `Job` and that's it.
1 parent 6be1265 commit 21ea254

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,17 @@ use crate::util::{Progress, ProgressStyle};
3232
/// actual compilation step of each package. Packages enqueue units of work and
3333
/// then later on the entire graph is processed and compiled.
3434
pub struct JobQueue<'a, 'cfg> {
35-
queue: DependencyQueue<Key<'a>, Vec<Job>>,
35+
queue: DependencyQueue<Key<'a>, Job>,
3636
tx: Sender<Message<'a>>,
3737
rx: Receiver<Message<'a>>,
3838
active: Vec<Key<'a>>,
39-
pending: HashMap<Key<'a>, PendingBuild>,
4039
compiled: HashSet<PackageId>,
4140
documented: HashSet<PackageId>,
4241
counts: HashMap<PackageId, usize>,
4342
is_release: bool,
4443
progress: Progress<'cfg>,
4544
}
4645

47-
/// A helper structure for metadata about the state of a building package.
48-
struct PendingBuild {
49-
/// The number of jobs currently active.
50-
amt: usize,
51-
}
52-
5346
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
5447
struct Key<'a> {
5548
pkg: PackageId,
@@ -140,7 +133,6 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
140133
tx,
141134
rx,
142135
active: Vec::new(),
143-
pending: HashMap::new(),
144136
compiled: HashSet::new(),
145137
documented: HashSet::new(),
146138
counts: HashMap::new(),
@@ -157,7 +149,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
157149
) -> CargoResult<()> {
158150
let key = Key::new(unit);
159151
let deps = key.dependencies(cx)?;
160-
self.queue.queue(&key, Vec::new(), &deps).push(job);
152+
self.queue.queue(&key, job, &deps);
161153
*self.counts.entry(key.pkg).or_insert(0) += 1;
162154
Ok(())
163155
}
@@ -236,13 +228,10 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
236228
// possible that can run. Note that this is also the point where we
237229
// start requesting job tokens. Each job after the first needs to
238230
// request a token.
239-
while let Some((key, jobs)) = self.queue.dequeue() {
240-
self.pending.insert(key, PendingBuild { amt: jobs.len() });
241-
for job in jobs {
242-
queue.push((key, job));
243-
if !self.active.is_empty() || !queue.is_empty() {
244-
jobserver_helper.request_token();
245-
}
231+
while let Some((key, job)) = self.queue.dequeue() {
232+
queue.push((key, job));
233+
if !self.active.is_empty() || !queue.is_empty() {
234+
jobserver_helper.request_token();
246235
}
247236
}
248237

@@ -463,12 +452,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
463452
if key.mode.is_run_custom_build() && cx.bcx.show_warnings(key.pkg) {
464453
self.emit_warnings(None, &key, cx)?;
465454
}
466-
467-
let state = self.pending.get_mut(&key).unwrap();
468-
state.amt -= 1;
469-
if state.amt == 0 {
470-
self.queue.finish(&key);
471-
}
455+
self.queue.finish(&key);
472456
Ok(())
473457
}
474458

src/cargo/util/dependency_queue.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! This structure is used to store the dependency graph and dynamically update
55
//! it to figure out when a dependency should be built.
66
7-
use std::collections::hash_map::Entry::{Occupied, Vacant};
87
use std::collections::{HashMap, HashSet};
98
use std::hash::Hash;
109

@@ -53,11 +52,8 @@ impl<K: Hash + Eq + Clone, V> DependencyQueue<K, V> {
5352
///
5453
/// It is assumed that any dependencies of this package will eventually also
5554
/// be added to the dependency queue.
56-
pub fn queue(&mut self, key: &K, value: V, dependencies: &[K]) -> &mut V {
57-
let slot = match self.dep_map.entry(key.clone()) {
58-
Occupied(v) => return &mut v.into_mut().1,
59-
Vacant(v) => v,
60-
};
55+
pub fn queue(&mut self, key: &K, value: V, dependencies: &[K]) {
56+
assert!(!self.dep_map.contains_key(key));
6157

6258
let mut my_dependencies = HashSet::new();
6359
for dep in dependencies {
@@ -68,7 +64,7 @@ impl<K: Hash + Eq + Clone, V> DependencyQueue<K, V> {
6864
.or_insert_with(HashSet::new);
6965
rev.insert(key.clone());
7066
}
71-
&mut slot.insert((my_dependencies, value)).1
67+
self.dep_map.insert(key.clone(), (my_dependencies, value));
7268
}
7369

7470
/// All nodes have been added, calculate some internal metadata and prepare

0 commit comments

Comments
 (0)