]> git.lizzy.rs Git - rust.git/commitdiff
Address comments
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Wed, 12 Feb 2020 13:24:38 +0000 (14:24 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Wed, 12 Feb 2020 13:37:50 +0000 (14:37 +0100)
src/librustc/ty/query/job.rs
src/librustc/ty/query/plumbing.rs

index a3c2bb2f1f557faad5a534b16e7a7854c95d85b7..8aae57e72cd527b4239a662b87ff6318f0d61618 100644 (file)
@@ -7,6 +7,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use rustc_span::Span;
 
+use std::convert::TryFrom;
 use std::marker::PhantomData;
 use std::num::NonZeroU32;
 
@@ -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()
     }
index 4e7a23be3837475d02c08518d003c58e772012d1..8b787915de605e56f4cdb7512ea0a2e1f18d47a3 100644 (file)
@@ -21,7 +21,6 @@
 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;
@@ -150,11 +149,7 @@ pub(super) fn try_get(tcx: TyCtxt<'tcx>, span: Span, key: &Q::Key) -> TryGetJob<
                             }
 
                             // 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)
                         }
@@ -162,25 +157,22 @@ pub(super) fn try_get(tcx: TyCtxt<'tcx>, span: Span, key: &Q::Key) -> TryGetJob<
                     }
                 }
                 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);