Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Feb 12, 2020
1 parent 5de82b9 commit 5206827
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/librustc/ty/query/job.rs
Expand Up @@ -7,6 +7,7 @@ use crate::ty::tls;
use rustc_data_structures::fx::FxHashMap;
use rustc_span::Span;

use std::convert::TryFrom;
use std::marker::PhantomData;
use std::num::NonZeroU32;

Expand Down Expand Up @@ -52,6 +53,10 @@ pub struct QueryJobId {
}

impl QueryJobId {
pub fn new(job: QueryShardJobId, shard: usize, kind: DepKind) -> Self {
QueryJobId { job, shard: u16::try_from(shard).unwrap(), kind }
}

fn query<'tcx>(self, map: &QueryMap<'tcx>) -> Query<'tcx> {
map.get(&self).unwrap().info.query.clone()
}
Expand Down
40 changes: 16 additions & 24 deletions src/librustc/ty/query/plumbing.rs
Expand Up @@ -21,7 +21,6 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
use rustc_span::source_map::DUMMY_SP;
use rustc_span::Span;
use std::collections::hash_map::Entry;
use std::convert::TryFrom;
use std::hash::{Hash, Hasher};
use std::mem;
use std::num::NonZeroU32;
Expand Down Expand Up @@ -150,37 +149,30 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
}

// Create the id of the job we're waiting for
let id = QueryJobId {
job: job.id,
shard: u16::try_from(shard).unwrap(),
kind: Q::dep_kind(),
};
let id = QueryJobId::new(job.id, shard, Q::dep_kind());

job.latch(id)
}
QueryResult::Poisoned => FatalError.raise(),
}
}
Entry::Vacant(entry) => {
let jobs = &mut lock.jobs;

// No job entry for this query. Return a new one to be started later.
return tls::with_related_context(tcx, |icx| {
// Generate an id unique within this shard.
let id = jobs.checked_add(1).unwrap();
*jobs = id;
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());

let global_id = QueryJobId {
job: id,
shard: u16::try_from(shard).unwrap(),
kind: Q::dep_kind(),
};
let job = QueryJob::new(id, span, icx.query);
let owner = JobOwner { cache, id: global_id, key: (*key).clone() };
entry.insert(QueryResult::Started(job));
TryGetJob::NotYetStarted(owner)
});

// Generate an id unique within this shard.
let id = lock.jobs.checked_add(1).unwrap();
lock.jobs = id;
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());

let global_id = QueryJobId::new(id, shard, Q::dep_kind());

let job =
tls::with_related_context(tcx, |icx| QueryJob::new(id, span, icx.query));

entry.insert(QueryResult::Started(job));

let owner = JobOwner { cache, id: global_id, key: (*key).clone() };
return TryGetJob::NotYetStarted(owner);
}
};
mem::drop(lock_guard);
Expand Down

0 comments on commit 5206827

Please sign in to comment.