Skip to content

Commit f471219

Browse files
committed
Auto merge of #56765 - Zoxc:pq-test, r=<try>
[do not merge] Test parallel queries Let's see if I have more luck r? @michaelwoerister
2 parents ddab10a + 9ff6e14 commit f471219

File tree

17 files changed

+484
-500
lines changed

17 files changed

+484
-500
lines changed

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl Config {
553553
set(&mut config.lld_enabled, rust.lld);
554554
set(&mut config.lldb_enabled, rust.lldb);
555555
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
556-
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
556+
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(true);
557557
config.rustc_default_linker = rust.default_linker.clone();
558558
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
559559
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);

src/librustc/dep_graph/dep_node.rs

-11
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,6 @@ impl DefId {
434434
}
435435
}
436436

437-
impl DepKind {
438-
#[inline]
439-
pub fn fingerprint_needed_for_crate_hash(self) -> bool {
440-
match self {
441-
DepKind::HirBody |
442-
DepKind::Krate => true,
443-
_ => false,
444-
}
445-
}
446-
}
447-
448437
define_dep_nodes!( <'tcx>
449438
// We use this for most things when incr. comp. is turned off.
450439
[] Null,

src/librustc/dep_graph/graph.rs

+267-218
Large diffs are not rendered by default.

src/librustc/dep_graph/prev.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ impl PreviousDepGraph {
2929
}
3030

3131
#[inline]
32-
pub fn edges_from(&self,
33-
dep_node: &DepNode)
34-
-> Option<(&[SerializedDepNodeIndex], SerializedDepNodeIndex)> {
35-
self.index
36-
.get(dep_node)
37-
.map(|&node_index| {
38-
(self.data.edge_targets_from(node_index), node_index)
39-
})
32+
pub fn edge_targets_from(
33+
&self,
34+
dep_node_index: SerializedDepNodeIndex
35+
) -> &[SerializedDepNodeIndex] {
36+
self.data.edge_targets_from(dep_node_index)
4037
}
4138

4239
#[inline]

src/librustc/hir/map/collector.rs

+85-44
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,69 @@ pub(super) struct NodeCollector<'a, 'hir> {
5151

5252
// We are collecting DepNode::HirBody hashes here so we can compute the
5353
// crate hash from then later on.
54-
hir_body_nodes: Vec<(DefPathHash, DepNodeIndex)>,
54+
hir_body_nodes: Vec<(DefPathHash, Fingerprint)>,
55+
}
56+
57+
fn input_dep_node_and_hash<'a, I>(
58+
dep_graph: &DepGraph,
59+
hcx: &mut StableHashingContext<'a>,
60+
def_node: DepNode,
61+
input: I,
62+
) -> (DepNodeIndex, Fingerprint)
63+
where
64+
I: HashStable<StableHashingContext<'a>>,
65+
{
66+
let dep_node_index = dep_graph.input_task(def_node, &mut *hcx, &input).1;
67+
68+
let hash = if dep_graph.is_fully_enabled() {
69+
dep_graph.fingerprint_of(dep_node_index)
70+
} else {
71+
let mut stable_hasher = StableHasher::new();
72+
input.hash_stable(hcx, &mut stable_hasher);
73+
stable_hasher.finish()
74+
};
75+
76+
(dep_node_index, hash)
77+
}
78+
79+
fn hir_dep_nodes<'a, I>(
80+
dep_graph: &DepGraph,
81+
hcx: &mut StableHashingContext<'a>,
82+
def_path_hash: DefPathHash,
83+
item_like: I,
84+
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
85+
) -> (DepNodeIndex, DepNodeIndex)
86+
where
87+
I: HashStable<StableHashingContext<'a>>,
88+
{
89+
let sig = dep_graph.input_task(
90+
def_path_hash.to_dep_node(DepKind::Hir),
91+
&mut *hcx,
92+
HirItemLike { item_like: &item_like, hash_bodies: false },
93+
).1;
94+
let (full, hash) = input_dep_node_and_hash(
95+
dep_graph,
96+
hcx,
97+
def_path_hash.to_dep_node(DepKind::HirBody),
98+
HirItemLike { item_like: &item_like, hash_bodies: true },
99+
);
100+
hir_body_nodes.push((def_path_hash, hash));
101+
(sig, full)
55102
}
56103

57104
impl<'a, 'hir> NodeCollector<'a, 'hir> {
58105
pub(super) fn root(krate: &'hir Crate,
59106
dep_graph: &'a DepGraph,
60107
definitions: &'a definitions::Definitions,
61-
hcx: StableHashingContext<'a>,
108+
mut hcx: StableHashingContext<'a>,
62109
source_map: &'a SourceMap)
63110
-> NodeCollector<'a, 'hir> {
64111
let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX);
65112

113+
let mut hir_body_nodes = Vec::new();
114+
66115
// Allocate DepNodes for the root module
67-
let (root_mod_sig_dep_index, root_mod_full_dep_index);
68-
{
116+
let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
69117
let Crate {
70118
ref module,
71119
// Crate attributes are not copied over to the root `Mod`, so hash
@@ -83,28 +131,23 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
83131
body_ids: _,
84132
} = *krate;
85133

86-
root_mod_sig_dep_index = dep_graph.input_task(
87-
root_mod_def_path_hash.to_dep_node(DepKind::Hir),
88-
&hcx,
89-
HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
90-
).1;
91-
root_mod_full_dep_index = dep_graph.input_task(
92-
root_mod_def_path_hash.to_dep_node(DepKind::HirBody),
93-
&hcx,
94-
HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
95-
).1;
96-
}
134+
hir_dep_nodes(
135+
dep_graph,
136+
&mut hcx,
137+
root_mod_def_path_hash,
138+
(module, attrs, span),
139+
&mut hir_body_nodes,
140+
)
141+
};
97142

98143
{
99144
dep_graph.input_task(
100145
DepNode::new_no_params(DepKind::AllLocalTraitImpls),
101-
&hcx,
146+
&mut hcx,
102147
&krate.trait_impls,
103148
);
104149
}
105150

106-
let hir_body_nodes = vec![(root_mod_def_path_hash, root_mod_full_dep_index)];
107-
108151
let mut collector = NodeCollector {
109152
krate,
110153
source_map,
@@ -139,9 +182,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
139182
let node_hashes = self
140183
.hir_body_nodes
141184
.iter()
142-
.fold(Fingerprint::ZERO, |fingerprint, &(def_path_hash, dep_node_index)| {
185+
.fold(Fingerprint::ZERO, |fingerprint, &(def_path_hash, hash)| {
143186
fingerprint.combine(
144-
def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
187+
def_path_hash.0.combine(hash)
145188
)
146189
});
147190

@@ -169,17 +212,19 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
169212

170213
source_file_names.sort_unstable();
171214

172-
let (_, crate_dep_node_index) = self
173-
.dep_graph
174-
.input_task(DepNode::new_no_params(DepKind::Krate),
175-
&self.hcx,
176-
(((node_hashes, upstream_crates), source_file_names),
177-
(commandline_args_hash,
178-
crate_disambiguator.to_fingerprint())));
179-
180-
let svh = Svh::new(self.dep_graph
181-
.fingerprint_of(crate_dep_node_index)
182-
.to_smaller_hash());
215+
let crate_hash_input = (
216+
((node_hashes, upstream_crates), source_file_names),
217+
(commandline_args_hash, crate_disambiguator.to_fingerprint())
218+
);
219+
220+
let (_, crate_hash) = input_dep_node_and_hash(
221+
self.dep_graph,
222+
&mut self.hcx,
223+
DepNode::new_no_params(DepKind::Krate),
224+
crate_hash_input,
225+
);
226+
227+
let svh = Svh::new(crate_hash.to_smaller_hash());
183228
(self.map, svh)
184229
}
185230

@@ -261,19 +306,15 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
261306

262307
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
263308

264-
self.current_signature_dep_index = self.dep_graph.input_task(
265-
def_path_hash.to_dep_node(DepKind::Hir),
266-
&self.hcx,
267-
HirItemLike { item_like, hash_bodies: false },
268-
).1;
269-
270-
self.current_full_dep_index = self.dep_graph.input_task(
271-
def_path_hash.to_dep_node(DepKind::HirBody),
272-
&self.hcx,
273-
HirItemLike { item_like, hash_bodies: true },
274-
).1;
275-
276-
self.hir_body_nodes.push((def_path_hash, self.current_full_dep_index));
309+
let (signature_dep_index, full_dep_index) = hir_dep_nodes(
310+
self.dep_graph,
311+
&mut self.hcx,
312+
def_path_hash,
313+
item_like,
314+
&mut self.hir_body_nodes,
315+
);
316+
self.current_signature_dep_index = signature_dep_index;
317+
self.current_full_dep_index = full_dep_index;
277318

278319
self.current_dep_node_owner = dep_node_owner;
279320
self.currently_in_body = false;

src/librustc/session/mod.rs

+31-18
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use util::common::{duration_to_secs_str, ErrorReported};
2626
use util::common::ProfileQueriesMsg;
2727

2828
use rustc_data_structures::base_n;
29-
use rustc_data_structures::sync::{self, Lrc, Lock, LockCell, OneThread, Once, RwLock};
29+
use rustc_data_structures::sync::{
30+
self, Lrc, Lock, OneThread, Once, RwLock, AtomicU64, AtomicUsize, AtomicBool, Ordering,
31+
Ordering::SeqCst,
32+
};
3033

3134
use errors::{self, DiagnosticBuilder, DiagnosticId, Applicability};
3235
use errors::emitter::{Emitter, EmitterWriter};
@@ -51,7 +54,6 @@ use std::io::Write;
5154
use std::path::PathBuf;
5255
use std::time::Duration;
5356
use std::sync::mpsc;
54-
use std::sync::atomic::{AtomicUsize, Ordering};
5557

5658
mod code_stats;
5759
pub mod config;
@@ -148,15 +150,15 @@ pub struct Session {
148150
/// If -zfuel=crate=n is specified, Some(crate).
149151
optimization_fuel_crate: Option<String>,
150152
/// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
151-
optimization_fuel_limit: LockCell<u64>,
153+
optimization_fuel_limit: AtomicU64,
152154
/// We're rejecting all further optimizations.
153-
out_of_fuel: LockCell<bool>,
155+
out_of_fuel: AtomicBool,
154156

155157
// The next two are public because the driver needs to read them.
156158
/// If -zprint-fuel=crate, Some(crate).
157159
pub print_fuel_crate: Option<String>,
158160
/// Always set to zero and incremented so that we can print fuel expended by a crate.
159-
pub print_fuel: LockCell<u64>,
161+
pub print_fuel: AtomicU64,
160162

161163
/// Loaded up early on in the initialization of this `Session` to avoid
162164
/// false positives about a job server in our environment.
@@ -835,7 +837,7 @@ impl Session {
835837

836838
#[inline(always)]
837839
pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) {
838-
if unlikely!(self.self_profiling_active) {
840+
if unlikely!(false) {
839841
self.profiler_active(f)
840842
}
841843
}
@@ -867,36 +869,47 @@ impl Session {
867869
self.perf_stats.normalize_projection_ty.load(Ordering::Relaxed));
868870
}
869871

870-
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
871-
/// This expends fuel if applicable, and records fuel if applicable.
872-
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
872+
#[inline(never)]
873+
#[cold]
874+
pub fn consider_optimizing_cold<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
873875
let mut ret = true;
874876
if let Some(ref c) = self.optimization_fuel_crate {
875877
if c == crate_name {
876878
assert_eq!(self.query_threads(), 1);
877-
let fuel = self.optimization_fuel_limit.get();
879+
let fuel = self.optimization_fuel_limit.load(SeqCst);
878880
ret = fuel != 0;
879-
if fuel == 0 && !self.out_of_fuel.get() {
881+
if fuel == 0 && !self.out_of_fuel.load(SeqCst) {
880882
eprintln!("optimization-fuel-exhausted: {}", msg());
881-
self.out_of_fuel.set(true);
883+
self.out_of_fuel.store(true, SeqCst);
882884
} else if fuel > 0 {
883-
self.optimization_fuel_limit.set(fuel - 1);
885+
self.optimization_fuel_limit.store(fuel - 1, SeqCst);
884886
}
885887
}
886888
}
887889
if let Some(ref c) = self.print_fuel_crate {
888890
if c == crate_name {
889891
assert_eq!(self.query_threads(), 1);
890-
self.print_fuel.set(self.print_fuel.get() + 1);
892+
self.print_fuel.store(self.print_fuel.load(SeqCst) + 1, SeqCst);
891893
}
892894
}
893895
ret
894896
}
895897

898+
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
899+
/// This expends fuel if applicable, and records fuel if applicable.
900+
#[inline(always)]
901+
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
902+
if likely!(self.optimization_fuel_crate.is_none() && self.print_fuel_crate.is_none()) {
903+
true
904+
} else {
905+
self.consider_optimizing_cold(crate_name, msg)
906+
}
907+
}
908+
896909
/// Returns the number of query threads that should be used for this
897910
/// compilation
898911
pub fn query_threads_from_opts(opts: &config::Options) -> usize {
899-
opts.debugging_opts.query_threads.unwrap_or(1)
912+
opts.debugging_opts.query_threads.unwrap_or(4)
900913
}
901914

902915
/// Returns the number of query threads that should be used for this
@@ -1138,9 +1151,9 @@ pub fn build_session_(
11381151

11391152
let optimization_fuel_crate = sopts.debugging_opts.fuel.as_ref().map(|i| i.0.clone());
11401153
let optimization_fuel_limit =
1141-
LockCell::new(sopts.debugging_opts.fuel.as_ref().map(|i| i.1).unwrap_or(0));
1154+
AtomicU64::new(sopts.debugging_opts.fuel.as_ref().map(|i| i.1).unwrap_or(0));
11421155
let print_fuel_crate = sopts.debugging_opts.print_fuel.clone();
1143-
let print_fuel = LockCell::new(0);
1156+
let print_fuel = AtomicU64::new(0);
11441157

11451158
let working_dir = env::current_dir().unwrap_or_else(|e|
11461159
p_s.span_diagnostic
@@ -1205,7 +1218,7 @@ pub fn build_session_(
12051218
optimization_fuel_limit,
12061219
print_fuel_crate,
12071220
print_fuel,
1208-
out_of_fuel: LockCell::new(false),
1221+
out_of_fuel: AtomicBool::new(false),
12091222
// Note that this is unsafe because it may misinterpret file descriptors
12101223
// on Unix as jobserver file descriptors. We hopefully execute this near
12111224
// the beginning of the process though to ensure we don't get false

0 commit comments

Comments
 (0)