Skip to content

Commit a46f059

Browse files
committed
Disable optimization fuel when using multiple threads
1 parent a23e90a commit a46f059

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/librustc/session/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,13 @@ pub fn build_session_options_and_crate_config(
18591859
);
18601860
}
18611861

1862+
if debugging_opts.query_threads.unwrap_or(1) > 1 && debugging_opts.fuel.is_some() {
1863+
early_error(
1864+
error_format,
1865+
"Optimization fuel is incompatible with multiple query threads",
1866+
);
1867+
}
1868+
18621869
if codegen_units == Some(0) {
18631870
early_error(
18641871
error_format,

src/librustc/session/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
2727
use util::common::ProfileQueriesMsg;
2828

29-
use rustc_data_structures::sync::{Lrc, Lock, OneThread, Once};
29+
use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once};
3030

3131
use syntax::ast::NodeId;
3232
use errors::{self, DiagnosticBuilder, DiagnosticId};
@@ -146,15 +146,15 @@ pub struct Session {
146146
/// If -zfuel=crate=n is specified, Some(crate).
147147
optimization_fuel_crate: Option<String>,
148148
/// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
149-
optimization_fuel_limit: Cell<u64>,
149+
optimization_fuel_limit: LockCell<u64>,
150150
/// We're rejecting all further optimizations.
151-
out_of_fuel: Cell<bool>,
151+
out_of_fuel: LockCell<bool>,
152152

153153
// The next two are public because the driver needs to read them.
154154
/// If -zprint-fuel=crate, Some(crate).
155155
pub print_fuel_crate: Option<String>,
156156
/// Always set to zero and incremented so that we can print fuel expended by a crate.
157-
pub print_fuel: Cell<u64>,
157+
pub print_fuel: LockCell<u64>,
158158

159159
/// Loaded up early on in the initialization of this `Session` to avoid
160160
/// false positives about a job server in our environment.
@@ -846,6 +846,7 @@ impl Session {
846846
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
847847
/// This expends fuel if applicable, and records fuel if applicable.
848848
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
849+
assert!(self.query_threads() == 1);
849850
let mut ret = true;
850851
match self.optimization_fuel_crate {
851852
Some(ref c) if c == crate_name => {
@@ -1075,9 +1076,9 @@ pub fn build_session_(
10751076

10761077
let optimization_fuel_crate = sopts.debugging_opts.fuel.as_ref().map(|i| i.0.clone());
10771078
let optimization_fuel_limit =
1078-
Cell::new(sopts.debugging_opts.fuel.as_ref().map(|i| i.1).unwrap_or(0));
1079+
LockCell::new(sopts.debugging_opts.fuel.as_ref().map(|i| i.1).unwrap_or(0));
10791080
let print_fuel_crate = sopts.debugging_opts.print_fuel.clone();
1080-
let print_fuel = Cell::new(0);
1081+
let print_fuel = LockCell::new(0);
10811082

10821083
let working_dir = match env::current_dir() {
10831084
Ok(dir) => dir,
@@ -1132,7 +1133,7 @@ pub fn build_session_(
11321133
optimization_fuel_limit,
11331134
print_fuel_crate,
11341135
print_fuel,
1135-
out_of_fuel: Cell::new(false),
1136+
out_of_fuel: LockCell::new(false),
11361137
// Note that this is unsafe because it may misinterpret file descriptors
11371138
// on Unix as jobserver file descriptors. We hopefully execute this near
11381139
// the beginning of the process though to ensure we don't get false

0 commit comments

Comments
 (0)