Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a49916b

Browse files
authored
Unrolled build for rust-lang#134251
Rollup merge of rust-lang#134251 - bjorn3:various_cleanups2, r=oli-obk A bunch of cleanups (part 2) Just like rust-lang#133567 these were all found while looking at the respective code, but are not blocking any other changes I want to make in the short term.
2 parents 4a204be + 3198496 commit a49916b

File tree

18 files changed

+43
-71
lines changed

18 files changed

+43
-71
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,6 @@ dependencies = [
35073507
"cc",
35083508
"either",
35093509
"itertools",
3510-
"jobserver",
35113510
"libc",
35123511
"object 0.36.5",
35133512
"pathdiff",

compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::sync::{Arc, Condvar, Mutex};
22

3-
use jobserver::HelperThread;
3+
use rustc_data_structures::jobserver::{self, HelperThread};
44
use rustc_errors::DiagCtxtHandle;
5-
use rustc_session::Session;
65

76
// FIXME don't panic when a worker thread panics
87

@@ -14,14 +13,13 @@ pub(super) struct ConcurrencyLimiter {
1413
}
1514

1615
impl ConcurrencyLimiter {
17-
pub(super) fn new(sess: &Session, pending_jobs: usize) -> Self {
16+
pub(super) fn new(pending_jobs: usize) -> Self {
1817
let state = Arc::new(Mutex::new(state::ConcurrencyLimiterState::new(pending_jobs)));
1918
let available_token_condvar = Arc::new(Condvar::new());
2019

2120
let state_helper = state.clone();
2221
let available_token_condvar_helper = available_token_condvar.clone();
23-
let helper_thread = sess
24-
.jobserver
22+
let helper_thread = jobserver::client()
2523
.clone()
2624
.into_helper_thread(move |token| {
2725
let mut state = state_helper.lock().unwrap();
@@ -113,7 +111,7 @@ impl Drop for ConcurrencyLimiterToken {
113111
}
114112

115113
mod state {
116-
use jobserver::Acquired;
114+
use rustc_data_structures::jobserver::Acquired;
117115

118116
#[derive(Debug)]
119117
pub(super) struct ConcurrencyLimiterState {

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ pub(crate) fn run_aot(
679679
metadata_module: None,
680680
metadata,
681681
crate_info: CrateInfo::new(tcx, target_cpu),
682-
concurrency_limiter: ConcurrencyLimiter::new(tcx.sess, 0),
682+
concurrency_limiter: ConcurrencyLimiter::new(0),
683683
});
684684
};
685685

@@ -711,7 +711,7 @@ pub(crate) fn run_aot(
711711
CguReuse::PreLto | CguReuse::PostLto => false,
712712
});
713713

714-
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(tcx.sess, todo_cgus.len()));
714+
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(todo_cgus.len()));
715715

716716
let modules = tcx.sess.time("codegen mono items", || {
717717
let mut modules: Vec<_> = par_map(todo_cgus, |(_, cgu)| {

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,7 @@ fn dep_symbol_lookup_fn(
287287

288288
let mut dylib_paths = Vec::new();
289289

290-
let data = &crate_info
291-
.dependency_formats
292-
.iter()
293-
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)
294-
.unwrap()
295-
.1;
290+
let data = &crate_info.dependency_formats[&rustc_session::config::CrateType::Executable].1;
296291
// `used_crates` is in reverse postorder in terms of dependencies. Reverse the order here to
297292
// get a postorder which ensures that all dependencies of a dylib are loaded before the dylib
298293
// itself. This helps the dynamic linker to find dylibs not in the regular dynamic library

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![warn(unused_lifetimes)]
1313
// tidy-alphabetical-end
1414

15-
extern crate jobserver;
1615
#[macro_use]
1716
extern crate rustc_middle;
1817
extern crate rustc_abi;

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ bitflags = "2.4.1"
1111
cc = "1.1.23"
1212
either = "1.5.0"
1313
itertools = "0.12"
14-
jobserver = "0.1.28"
1514
pathdiff = "0.2.0"
1615
regex = "1.4"
1716
rustc_abi = { path = "../rustc_abi" }

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ pub fn each_linked_rlib(
236236
) -> Result<(), errors::LinkRlibError> {
237237
let crates = info.used_crates.iter();
238238

239-
let fmts = if crate_type.is_none() {
239+
let fmts = if let Some(crate_type) = crate_type {
240+
let Some(fmts) = info.dependency_formats.get(&crate_type) else {
241+
return Err(errors::LinkRlibError::MissingFormat);
242+
};
243+
244+
fmts
245+
} else {
240246
for combination in info.dependency_formats.iter().combinations(2) {
241247
let (ty1, list1) = &combination[0];
242248
let (ty2, list2) = &combination[1];
@@ -252,18 +258,7 @@ pub fn each_linked_rlib(
252258
if info.dependency_formats.is_empty() {
253259
return Err(errors::LinkRlibError::MissingFormat);
254260
}
255-
&info.dependency_formats[0].1
256-
} else {
257-
let fmts = info
258-
.dependency_formats
259-
.iter()
260-
.find_map(|&(ty, ref list)| if Some(ty) == crate_type { Some(list) } else { None });
261-
262-
let Some(fmts) = fmts else {
263-
return Err(errors::LinkRlibError::MissingFormat);
264-
};
265-
266-
fmts
261+
info.dependency_formats.first().unwrap().1
267262
};
268263

269264
for &cnum in crates {
@@ -624,8 +619,7 @@ fn link_staticlib(
624619
let fmts = codegen_results
625620
.crate_info
626621
.dependency_formats
627-
.iter()
628-
.find_map(|&(ty, ref list)| if ty == CrateType::Staticlib { Some(list) } else { None })
622+
.get(&CrateType::Staticlib)
629623
.expect("no dependency formats for staticlib");
630624

631625
let mut all_rust_dylibs = vec![];
@@ -2355,11 +2349,10 @@ fn linker_with_args(
23552349
// they are used within inlined functions or instantiated generic functions. We do this *after*
23562350
// handling the raw-dylib symbols in the current crate to make sure that those are chosen first
23572351
// by the linker.
2358-
let (_, dependency_linkage) = codegen_results
2352+
let dependency_linkage = codegen_results
23592353
.crate_info
23602354
.dependency_formats
2361-
.iter()
2362-
.find(|(ty, _)| *ty == crate_type)
2355+
.get(&crate_type)
23632356
.expect("failed to find crate type in dependency format list");
23642357

23652358
// We sort the libraries below
@@ -2738,11 +2731,10 @@ fn add_upstream_rust_crates(
27382731
// Linking to a rlib involves just passing it to the linker (the linker
27392732
// will slurp up the object files inside), and linking to a dynamic library
27402733
// involves just passing the right -l flag.
2741-
let (_, data) = codegen_results
2734+
let data = codegen_results
27422735
.crate_info
27432736
.dependency_formats
2744-
.iter()
2745-
.find(|(ty, _)| *ty == crate_type)
2737+
.get(&crate_type)
27462738
.expect("failed to find crate type in dependency format list");
27472739

27482740
if sess.target.is_like_aix {

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ fn for_each_exported_symbols_include_dep<'tcx>(
17491749
}
17501750

17511751
let formats = tcx.dependency_formats(());
1752-
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
1752+
let deps = &formats[&crate_type];
17531753

17541754
for (index, dep_format) in deps.iter().enumerate() {
17551755
let cnum = CrateNum::new(index + 1);

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::sync::Arc;
66
use std::sync::mpsc::{Receiver, Sender, channel};
77
use std::{fs, io, mem, str, thread};
88

9-
use jobserver::{Acquired, Client};
109
use rustc_ast::attr;
1110
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
11+
use rustc_data_structures::jobserver::{self, Acquired};
1212
use rustc_data_structures::memmap::Mmap;
1313
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1414
use rustc_errors::emitter::Emitter;
@@ -456,7 +456,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
456456
metadata_module: Option<CompiledModule>,
457457
) -> OngoingCodegen<B> {
458458
let (coordinator_send, coordinator_receive) = channel();
459-
let sess = tcx.sess;
460459

461460
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
462461
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
@@ -477,7 +476,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
477476
shared_emitter,
478477
codegen_worker_send,
479478
coordinator_receive,
480-
sess.jobserver.clone(),
481479
Arc::new(regular_config),
482480
Arc::new(metadata_config),
483481
Arc::new(allocator_config),
@@ -1093,7 +1091,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
10931091
shared_emitter: SharedEmitter,
10941092
codegen_worker_send: Sender<CguMessage>,
10951093
coordinator_receive: Receiver<Box<dyn Any + Send>>,
1096-
jobserver: Client,
10971094
regular_config: Arc<ModuleConfig>,
10981095
metadata_config: Arc<ModuleConfig>,
10991096
allocator_config: Arc<ModuleConfig>,
@@ -1145,7 +1142,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11451142
// get tokens on `coordinator_receive` which will
11461143
// get managed in the main loop below.
11471144
let coordinator_send2 = coordinator_send.clone();
1148-
let helper = jobserver
1145+
let helper = jobserver::client()
11491146
.into_helper_thread(move |token| {
11501147
drop(coordinator_send2.send(Box::new(Message::Token::<B>(token))));
11511148
})

compiler/rustc_data_structures/src/jobserver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::{LazyLock, OnceLock};
22

3-
pub use jobserver_crate::Client;
3+
pub use jobserver_crate::{Acquired, Client, HelperThread};
44
use jobserver_crate::{FromEnv, FromEnvErrorKind};
55

66
// We can only call `from_env_ext` once per process

0 commit comments

Comments
 (0)