Skip to content

Commit 0309953

Browse files
committed
Auto merge of #84833 - Mark-Simulacrum:thread-local-consts, r=varkor
"const" initialized thread locals in rustc This appears to give a slight speedup on many of our benchmarks.
2 parents 14f863c + 5065144 commit 0309953

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#![feature(control_flow_enum)]
5151
#![feature(associated_type_defaults)]
5252
#![feature(iter_zip)]
53+
#![feature(thread_local_const_init)]
5354
#![recursion_limit = "512"]
5455

5556
#[macro_use]

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ pub mod tls {
17051705
#[cfg(not(parallel_compiler))]
17061706
thread_local! {
17071707
/// A thread local variable that stores a pointer to the current `ImplicitCtxt`.
1708-
static TLV: Cell<usize> = Cell::new(0);
1708+
static TLV: Cell<usize> = const { Cell::new(0) };
17091709
}
17101710

17111711
/// Sets TLV to `value` during the call to `f`.

compiler/rustc_middle/src/ty/print/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ macro_rules! define_scoped_cx {
5555
}
5656

5757
thread_local! {
58-
static FORCE_IMPL_FILENAME_LINE: Cell<bool> = Cell::new(false);
59-
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = Cell::new(false);
60-
static NO_TRIMMED_PATH: Cell<bool> = Cell::new(false);
61-
static NO_QUERIES: Cell<bool> = Cell::new(false);
58+
static FORCE_IMPL_FILENAME_LINE: Cell<bool> = const { Cell::new(false) };
59+
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
60+
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
61+
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
6262
}
6363

6464
/// Avoids running any queries during any prints that occur

compiler/rustc_span/src/hygiene.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ fn update_disambiguator(expn_id: ExpnId) {
13301330
// This cache is only used by `DummyHashStableContext`,
13311331
// so we won't pollute the cache values of the normal `StableHashingContext`
13321332
thread_local! {
1333-
static CACHE: ExpnIdCache = Default::default();
1333+
static CACHE: ExpnIdCache = const { ExpnIdCache::new(Vec::new()) };
13341334
}
13351335

13361336
&CACHE

compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(negative_impls)]
2121
#![feature(nll)]
2222
#![feature(min_specialization)]
23+
#![feature(thread_local_const_init)]
2324

2425
#[macro_use]
2526
extern crate rustc_macros;

0 commit comments

Comments
 (0)