Skip to content

Commit 5206827

Browse files
committed
Address comments
1 parent 5de82b9 commit 5206827

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/librustc/ty/query/job.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::ty::tls;
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_span::Span;
99

10+
use std::convert::TryFrom;
1011
use std::marker::PhantomData;
1112
use std::num::NonZeroU32;
1213

@@ -52,6 +53,10 @@ pub struct QueryJobId {
5253
}
5354

5455
impl QueryJobId {
56+
pub fn new(job: QueryShardJobId, shard: usize, kind: DepKind) -> Self {
57+
QueryJobId { job, shard: u16::try_from(shard).unwrap(), kind }
58+
}
59+
5560
fn query<'tcx>(self, map: &QueryMap<'tcx>) -> Query<'tcx> {
5661
map.get(&self).unwrap().info.query.clone()
5762
}

src/librustc/ty/query/plumbing.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
2121
use rustc_span::source_map::DUMMY_SP;
2222
use rustc_span::Span;
2323
use std::collections::hash_map::Entry;
24-
use std::convert::TryFrom;
2524
use std::hash::{Hash, Hasher};
2625
use std::mem;
2726
use std::num::NonZeroU32;
@@ -150,37 +149,30 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
150149
}
151150

152151
// Create the id of the job we're waiting for
153-
let id = QueryJobId {
154-
job: job.id,
155-
shard: u16::try_from(shard).unwrap(),
156-
kind: Q::dep_kind(),
157-
};
152+
let id = QueryJobId::new(job.id, shard, Q::dep_kind());
158153

159154
job.latch(id)
160155
}
161156
QueryResult::Poisoned => FatalError.raise(),
162157
}
163158
}
164159
Entry::Vacant(entry) => {
165-
let jobs = &mut lock.jobs;
166-
167160
// No job entry for this query. Return a new one to be started later.
168-
return tls::with_related_context(tcx, |icx| {
169-
// Generate an id unique within this shard.
170-
let id = jobs.checked_add(1).unwrap();
171-
*jobs = id;
172-
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());
173-
174-
let global_id = QueryJobId {
175-
job: id,
176-
shard: u16::try_from(shard).unwrap(),
177-
kind: Q::dep_kind(),
178-
};
179-
let job = QueryJob::new(id, span, icx.query);
180-
let owner = JobOwner { cache, id: global_id, key: (*key).clone() };
181-
entry.insert(QueryResult::Started(job));
182-
TryGetJob::NotYetStarted(owner)
183-
});
161+
162+
// Generate an id unique within this shard.
163+
let id = lock.jobs.checked_add(1).unwrap();
164+
lock.jobs = id;
165+
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());
166+
167+
let global_id = QueryJobId::new(id, shard, Q::dep_kind());
168+
169+
let job =
170+
tls::with_related_context(tcx, |icx| QueryJob::new(id, span, icx.query));
171+
172+
entry.insert(QueryResult::Started(job));
173+
174+
let owner = JobOwner { cache, id: global_id, key: (*key).clone() };
175+
return TryGetJob::NotYetStarted(owner);
184176
}
185177
};
186178
mem::drop(lock_guard);

0 commit comments

Comments
 (0)