Skip to content

Commit 8e873c3

Browse files
committed
Make librustc_query_system compile.
1 parent 5b8dac3 commit 8e873c3

File tree

8 files changed

+57
-785
lines changed

8 files changed

+57
-785
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,12 +4042,15 @@ version = "0.0.0"
40424042
dependencies = [
40434043
"log",
40444044
"parking_lot 0.9.0",
4045+
"rustc-rayon-core",
40454046
"rustc_ast",
40464047
"rustc_data_structures",
40474048
"rustc_errors",
40484049
"rustc_hir",
40494050
"rustc_index",
40504051
"rustc_macros",
4052+
"rustc_session",
4053+
"rustc_span",
40514054
"serialize",
40524055
"smallvec 1.0.0",
40534056
]

src/librustc_query_system/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ doctest = false
1111

1212
[dependencies]
1313
log = { version = "0.4", features = ["release_max_level_info", "std"] }
14+
rustc-rayon-core = "0.3.0"
1415
rustc_ast = { path = "../librustc_ast" }
1516
rustc_data_structures = { path = "../librustc_data_structures" }
1617
rustc_errors = { path = "../librustc_errors" }
1718
rustc_hir = { path = "../librustc_hir" }
1819
rustc_index = { path = "../librustc_index" }
1920
rustc_macros = { path = "../librustc_macros" }
2021
rustc_serialize = { path = "../libserialize", package = "serialize" }
22+
rustc_session = { path = "../librustc_session" }
23+
rustc_span = { path = "../librustc_span" }
2124
parking_lot = "0.9"
2225
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_query_system/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
#![feature(bool_to_option)]
12
#![feature(const_fn)]
23
#![feature(const_if_match)]
34
#![feature(const_panic)]
45
#![feature(core_intrinsics)]
6+
#![feature(hash_raw_entry)]
57
#![feature(specialization)]
68
#![feature(stmt_expr_attributes)]
9+
#![feature(vec_remove_item)]
710

811
#[macro_use]
912
extern crate log;
13+
#[macro_use]
14+
extern crate rustc_data_structures;
1015

1116
pub mod dep_graph;
17+
pub mod query;
1218

1319
pub trait HashStableContext {
1420
fn debug_dep_tasks(&self) -> bool;

src/librustc_query_system/query/caches.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use crate::dep_graph::DepNodeIndex;
2-
use crate::ty::query::config::QueryContext;
3-
use crate::ty::query::plumbing::{QueryLookup, QueryState, QueryStateShard};
2+
use crate::query::config::QueryContext;
3+
use crate::query::plumbing::{QueryLookup, QueryState, QueryStateShard};
44

55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::sharded::Sharded;
77
use std::default::Default;
88
use std::hash::Hash;
99
use std::marker::PhantomData;
1010

11-
pub(crate) trait CacheSelector<CTX: QueryContext, K, V> {
11+
pub trait CacheSelector<CTX: QueryContext, K, V> {
1212
type Cache: QueryCache<CTX, Key = K, Value = V>;
1313
}
1414

15-
pub(crate) trait QueryCache<CTX: QueryContext>: Default {
15+
pub trait QueryCache<CTX: QueryContext>: Default {
1616
type Key;
1717
type Value;
1818
type Sharded: Default;

src/librustc_query_system/query/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Query configuration and description traits.
22
33
use crate::dep_graph::SerializedDepNodeIndex;
4-
use crate::ty::query::caches::QueryCache;
5-
use crate::ty::query::job::{QueryJobId, QueryJobInfo};
6-
use crate::ty::query::plumbing::CycleError;
7-
use crate::ty::query::QueryState;
4+
use crate::dep_graph::{DepContext, DepGraph, DepNode};
5+
use crate::query::caches::QueryCache;
6+
use crate::query::job::{QueryJobId, QueryJobInfo};
7+
use crate::query::plumbing::CycleError;
8+
use crate::query::QueryState;
89
use rustc_data_structures::profiling::ProfileCategory;
910
use rustc_hir::def_id::DefId;
1011

@@ -14,7 +15,6 @@ use rustc_data_structures::stable_hasher::HashStable;
1415
use rustc_data_structures::sync::Lock;
1516
use rustc_data_structures::thin_vec::ThinVec;
1617
use rustc_errors::Diagnostic;
17-
use rustc_query_system::dep_graph::{DepContext, DepGraph, DepNode};
1818
use rustc_session::Session;
1919
use std::borrow::Cow;
2020
use std::fmt::Debug;
@@ -58,7 +58,7 @@ pub trait QueryContext: DepContext {
5858
) -> R;
5959
}
6060

61-
pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
61+
pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
6262
const ANON: bool;
6363
const EVAL_ALWAYS: bool;
6464
const DEP_KIND: CTX::DepKind;
@@ -81,7 +81,7 @@ pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
8181
fn handle_cycle_error(tcx: CTX, error: CycleError<CTX::Query>) -> Self::Value;
8282
}
8383

84-
pub(crate) trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
84+
pub trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
8585
fn describe(tcx: CTX, key: Self::Key) -> Cow<'static, str>;
8686

8787
#[inline]
@@ -90,7 +90,7 @@ pub(crate) trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
9090
}
9191

9292
fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
93-
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
93+
panic!("QueryDescription::load_from_disk() called for an unsupported query.")
9494
}
9595
}
9696

@@ -112,6 +112,6 @@ where
112112
}
113113

114114
default fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option<Self::Value> {
115-
bug!("QueryDescription::load_from_disk() called for an unsupported query.")
115+
panic!("QueryDescription::load_from_disk() called for an unsupported query.")
116116
}
117117
}

src/librustc_query_system/query/job.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use crate::ty::query::config::QueryContext;
2-
use crate::ty::query::plumbing::CycleError;
3-
#[cfg(parallel_compiler)]
4-
use crate::ty::tls;
1+
use crate::dep_graph::{DepKind, DepContext};
2+
use crate::query::config::QueryContext;
3+
use crate::query::plumbing::CycleError;
54

65
use rustc_data_structures::fx::FxHashMap;
7-
use rustc_query_system::dep_graph::DepContext;
86
use rustc_span::Span;
97

108
use std::convert::TryFrom;
@@ -22,7 +20,7 @@ use {
2220
rustc_rayon_core as rayon_core,
2321
rustc_span::DUMMY_SP,
2422
std::iter::FromIterator,
25-
std::{mem, process, thread},
23+
std::{mem, process},
2624
};
2725

2826
/// Represents a span and a query key.
@@ -52,7 +50,7 @@ pub struct QueryJobId<K> {
5250
pub kind: K,
5351
}
5452

55-
impl<K: rustc_query_system::dep_graph::DepKind> QueryJobId<K> {
53+
impl<K: DepKind> QueryJobId<K> {
5654
pub fn new(job: QueryShardJobId, shard: usize, kind: K) -> Self {
5755
QueryJobId { job, shard: u16::try_from(shard).unwrap(), kind }
5856
}
@@ -529,38 +527,13 @@ fn remove_cycle<CTX: QueryContext>(
529527
}
530528
}
531529

532-
/// Creates a new thread and forwards information in thread locals to it.
533-
/// The new thread runs the deadlock handler.
534-
/// Must only be called when a deadlock is about to happen.
535-
#[cfg(parallel_compiler)]
536-
pub unsafe fn handle_deadlock() {
537-
let registry = rayon_core::Registry::current();
538-
539-
let gcx_ptr = tls::GCX_PTR.with(|gcx_ptr| gcx_ptr as *const _);
540-
let gcx_ptr = &*gcx_ptr;
541-
542-
let rustc_span_globals =
543-
rustc_span::GLOBALS.with(|rustc_span_globals| rustc_span_globals as *const _);
544-
let rustc_span_globals = &*rustc_span_globals;
545-
let syntax_globals = rustc_ast::attr::GLOBALS.with(|syntax_globals| syntax_globals as *const _);
546-
let syntax_globals = &*syntax_globals;
547-
thread::spawn(move || {
548-
tls::GCX_PTR.set(gcx_ptr, || {
549-
rustc_ast::attr::GLOBALS.set(syntax_globals, || {
550-
rustc_span::GLOBALS
551-
.set(rustc_span_globals, || tls::with_global(|tcx| deadlock(tcx, &registry)))
552-
});
553-
})
554-
});
555-
}
556-
557530
/// Detects query cycles by using depth first search over all active query jobs.
558531
/// If a query cycle is found it will break the cycle by finding an edge which
559532
/// uses a query latch and then resuming that waiter.
560533
/// There may be multiple cycles involved in a deadlock, so this searches
561534
/// all active queries for cycles before finally resuming all the waiters at once.
562535
#[cfg(parallel_compiler)]
563-
fn deadlock<CTX: QueryContext>(tcx: CTX, registry: &rayon_core::Registry) {
536+
pub fn deadlock<CTX: QueryContext>(tcx: CTX, registry: &rayon_core::Registry) {
564537
let on_panic = OnDrop(|| {
565538
eprintln!("deadlock handler panicked, aborting process");
566539
process::abort();

0 commit comments

Comments
 (0)