Rollup merge of #138682 - Alexendoo:extra-symbols, r=fee1-dead
Allow drivers to supply a list of extra symbols to intern
Allows adding new symbols as `const`s in external drivers, desirable in Clippy so we can use them in patterns to replace code like 75530e9f72/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs (L66)
The Clippy change adds a couple symbols as a demo, the exact `clippy_utils` API and replacing other usages can be done on the Clippy side to minimise sync conflicts
---
try-job: aarch64-gnu
This commit is contained in:
@@ -117,6 +117,7 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
|
||||
thread_stack_size: usize,
|
||||
edition: Edition,
|
||||
sm_inputs: SourceMapInputs,
|
||||
extra_symbols: &[&'static str],
|
||||
f: F,
|
||||
) -> R {
|
||||
// The "thread pool" is a single spawned thread in the non-parallel
|
||||
@@ -134,9 +135,12 @@ fn run_in_thread_with_globals<F: FnOnce(CurrentGcx) -> R + Send, R: Send>(
|
||||
// name contains null bytes.
|
||||
let r = builder
|
||||
.spawn_scoped(s, move || {
|
||||
rustc_span::create_session_globals_then(edition, Some(sm_inputs), || {
|
||||
f(CurrentGcx::new())
|
||||
})
|
||||
rustc_span::create_session_globals_then(
|
||||
edition,
|
||||
extra_symbols,
|
||||
Some(sm_inputs),
|
||||
|| f(CurrentGcx::new()),
|
||||
)
|
||||
})
|
||||
.unwrap()
|
||||
.join();
|
||||
@@ -152,6 +156,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
|
||||
thread_builder_diag: &EarlyDiagCtxt,
|
||||
edition: Edition,
|
||||
threads: usize,
|
||||
extra_symbols: &[&'static str],
|
||||
sm_inputs: SourceMapInputs,
|
||||
f: F,
|
||||
) -> R {
|
||||
@@ -168,12 +173,18 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
|
||||
let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());
|
||||
|
||||
if !sync::is_dyn_thread_safe() {
|
||||
return run_in_thread_with_globals(thread_stack_size, edition, sm_inputs, |current_gcx| {
|
||||
// Register the thread for use with the `WorkerLocal` type.
|
||||
registry.register();
|
||||
return run_in_thread_with_globals(
|
||||
thread_stack_size,
|
||||
edition,
|
||||
sm_inputs,
|
||||
extra_symbols,
|
||||
|current_gcx| {
|
||||
// Register the thread for use with the `WorkerLocal` type.
|
||||
registry.register();
|
||||
|
||||
f(current_gcx)
|
||||
});
|
||||
f(current_gcx)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let current_gcx = FromDyn::from(CurrentGcx::new());
|
||||
@@ -230,7 +241,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce(CurrentGcx) -> R + Send,
|
||||
// pool. Upon creation, each worker thread created gets a copy of the
|
||||
// session globals in TLS. This is possible because `SessionGlobals` impls
|
||||
// `Send` in the parallel compiler.
|
||||
rustc_span::create_session_globals_then(edition, Some(sm_inputs), || {
|
||||
rustc_span::create_session_globals_then(edition, extra_symbols, Some(sm_inputs), || {
|
||||
rustc_span::with_session_globals(|session_globals| {
|
||||
let session_globals = FromDyn::from(session_globals);
|
||||
builder
|
||||
|
||||
Reference in New Issue
Block a user