Skip to content

Commit 72770ef

Browse files
authored
Rollup merge of #93787 - klensy:really-not-a-features, r=wesleywiser
parallel_compiler: hide dependencies behind feature Separate dependencies for `parallel_compiler` feature, so they will not be compiled if feature not selected, reducing number of compiled crates from 238 to 224.
2 parents 600ec28 + 008fc79 commit 72770ef

File tree

10 files changed

+63
-39
lines changed

10 files changed

+63
-39
lines changed

compiler/rustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ features = ['unprefixed_malloc_on_supported_platforms']
1919
jemalloc = ['tikv-jemalloc-sys']
2020
llvm = ['rustc_driver/llvm']
2121
max_level_info = ['rustc_driver/max_level_info']
22+
rustc_use_parallel_compiler = ['rustc_driver/rustc_use_parallel_compiler']

compiler/rustc_codegen_ssa/src/base.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCode
1414
use rustc_attr as attr;
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
17+
18+
#[cfg(parallel_compiler)]
1719
use rustc_data_structures::sync::{par_iter, ParallelIterator};
1820
use rustc_hir as hir;
1921
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
@@ -622,34 +624,34 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
622624
// This likely is a temporary measure. Once we don't have to support the
623625
// non-parallel compiler anymore, we can compile CGUs end-to-end in
624626
// parallel and get rid of the complicated scheduling logic.
627+
#[cfg(parallel_compiler)]
625628
let pre_compile_cgus = |cgu_reuse: &[CguReuse]| {
626-
if cfg!(parallel_compiler) {
627-
tcx.sess.time("compile_first_CGU_batch", || {
628-
// Try to find one CGU to compile per thread.
629-
let cgus: Vec<_> = cgu_reuse
630-
.iter()
631-
.enumerate()
632-
.filter(|&(_, reuse)| reuse == &CguReuse::No)
633-
.take(tcx.sess.threads())
634-
.collect();
635-
636-
// Compile the found CGUs in parallel.
637-
let start_time = Instant::now();
638-
639-
let pre_compiled_cgus = par_iter(cgus)
640-
.map(|(i, _)| {
641-
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
642-
(i, module)
643-
})
644-
.collect();
645-
646-
(pre_compiled_cgus, start_time.elapsed())
647-
})
648-
} else {
649-
(FxHashMap::default(), Duration::new(0, 0))
650-
}
629+
tcx.sess.time("compile_first_CGU_batch", || {
630+
// Try to find one CGU to compile per thread.
631+
let cgus: Vec<_> = cgu_reuse
632+
.iter()
633+
.enumerate()
634+
.filter(|&(_, reuse)| reuse == &CguReuse::No)
635+
.take(tcx.sess.threads())
636+
.collect();
637+
638+
// Compile the found CGUs in parallel.
639+
let start_time = Instant::now();
640+
641+
let pre_compiled_cgus = par_iter(cgus)
642+
.map(|(i, _)| {
643+
let module = backend.compile_codegen_unit(tcx, codegen_units[i].name());
644+
(i, module)
645+
})
646+
.collect();
647+
648+
(pre_compiled_cgus, start_time.elapsed())
649+
})
651650
};
652651

652+
#[cfg(not(parallel_compiler))]
653+
let pre_compile_cgus = |_: &[CguReuse]| (FxHashMap::default(), Duration::new(0, 0));
654+
653655
let mut cgu_reuse = Vec::new();
654656
let mut pre_compiled_cgus: Option<FxHashMap<usize, _>> = None;
655657
let mut total_codegen_time = Duration::new(0, 0);

compiler/rustc_data_structures/Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ doctest = false
99
[dependencies]
1010
arrayvec = { version = "0.7", default-features = false }
1111
ena = "0.14"
12-
indexmap = { version = "1.8.0", features = ["rustc-rayon"] }
12+
indexmap = { version = "1.8.0" }
1313
tracing = "0.1"
1414
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_macros = { path = "../rustc_macros" }
1717
rustc_graphviz = { path = "../rustc_graphviz" }
1818
cfg-if = "0.1.2"
1919
stable_deref_trait = "1.0.0"
20-
rayon = { version = "0.3.2", package = "rustc-rayon" }
21-
rayon-core = { version = "0.3.2", package = "rustc-rayon-core" }
20+
rayon = { version = "0.3.2", package = "rustc-rayon", optional = true }
21+
rayon-core = { version = "0.3.2", package = "rustc-rayon-core", optional = true }
2222
rustc-hash = "1.1.0"
2323
smallvec = { version = "1.6.1", features = ["const_generics", "union", "may_dangle"] }
2424
rustc_index = { path = "../rustc_index", package = "rustc_index" }
@@ -36,3 +36,6 @@ winapi = { version = "0.3", features = ["fileapi", "psapi", "winerror"] }
3636

3737
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3838
memmap2 = "0.2.1"
39+
40+
[features]
41+
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rayon", "rayon-core"]

compiler/rustc_driver/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"]
3939
[features]
4040
llvm = ['rustc_interface/llvm']
4141
max_level_info = ['rustc_log/max_level_info']
42+
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler',
43+
'rustc_middle/rustc_use_parallel_compiler']

compiler/rustc_interface/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ doctest = false
1010
libc = "0.2"
1111
libloading = "0.7.1"
1212
tracing = "0.1"
13-
rustc-rayon-core = "0.3.2"
14-
rayon = { version = "0.3.2", package = "rustc-rayon" }
13+
rustc-rayon-core = { version = "0.3.2", optional = true }
14+
rayon = { version = "0.3.2", package = "rustc-rayon", optional = true }
1515
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
1616
rustc_ast = { path = "../rustc_ast" }
1717
rustc_attr = { path = "../rustc_attr" }
@@ -57,3 +57,4 @@ rustc_target = { path = "../rustc_target" }
5757

5858
[features]
5959
llvm = ['rustc_codegen_llvm']
60+
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler']

compiler/rustc_middle/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ bitflags = "1.2.1"
1212
either = "1.5.0"
1313
gsgdt = "0.1.2"
1414
tracing = "0.1"
15-
rustc-rayon = "0.3.2"
16-
rustc-rayon-core = "0.3.2"
15+
rustc-rayon = { version = "0.3.2", optional = true }
16+
rustc-rayon-core = { version = "0.3.2", optional = true }
1717
polonius-engine = "0.13.0"
1818
rustc_apfloat = { path = "../rustc_apfloat" }
1919
rustc_attr = { path = "../rustc_attr" }
@@ -35,3 +35,6 @@ rustc_session = { path = "../rustc_session" }
3535
rustc_type_ir = { path = "../rustc_type_ir" }
3636
rand = "0.8.4"
3737
rand_xoshiro = "0.6.0"
38+
39+
[features]
40+
rustc_use_parallel_compiler = ["rustc-rayon", "rustc-rayon-core"]

compiler/rustc_query_impl/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ doctest = false
88

99
[dependencies]
1010
measureme = "10.0.0"
11-
rustc-rayon-core = "0.3.2"
11+
rustc-rayon-core = { version = "0.3.2", optional = true }
1212
rustc_ast = { path = "../rustc_ast" }
1313
rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_errors = { path = "../rustc_errors" }
@@ -20,3 +20,6 @@ rustc_query_system = { path = "../rustc_query_system" }
2020
rustc_serialize = { path = "../rustc_serialize" }
2121
rustc_session = { path = "../rustc_session" }
2222
rustc_span = { path = "../rustc_span" }
23+
24+
[features]
25+
rustc_use_parallel_compiler = ["rustc-rayon-core", "rustc_query_system/rustc_use_parallel_compiler"]

compiler/rustc_query_system/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ doctest = false
99
[dependencies]
1010
rustc_arena = { path = "../rustc_arena" }
1111
tracing = "0.1"
12-
rustc-rayon-core = "0.3.2"
12+
rustc-rayon-core = { version = "0.3.2", optional = true }
1313
rustc_ast = { path = "../rustc_ast" }
1414
rustc_data_structures = { path = "../rustc_data_structures" }
1515
rustc_errors = { path = "../rustc_errors" }
@@ -23,3 +23,6 @@ rustc_span = { path = "../rustc_span" }
2323
rustc_target = { path = "../rustc_target" }
2424
parking_lot = "0.11"
2525
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
26+
27+
[features]
28+
rustc_use_parallel_compiler = ["rustc-rayon-core"]

src/bootstrap/compile.rs

+2
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
689689
}
690690

691691
if builder.config.rustc_parallel {
692+
// keep in sync with `bootstrap/lib.rs:Build::rustc_features`
693+
// `cfg` option for rustc, `features` option for cargo, for conditional compilation
692694
cargo.rustflag("--cfg=parallel_compiler");
693695
cargo.rustdocflag("--cfg=parallel_compiler");
694696
}

src/bootstrap/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,16 @@ impl Build {
729729

730730
/// Gets the space-separated set of activated features for the compiler.
731731
fn rustc_features(&self, kind: Kind) -> String {
732-
let mut features = String::new();
732+
let mut features = vec![];
733733
if self.config.jemalloc {
734-
features.push_str("jemalloc");
734+
features.push("jemalloc");
735735
}
736736
if self.config.llvm_enabled() || kind == Kind::Check {
737-
features.push_str(" llvm");
737+
features.push("llvm");
738+
}
739+
// keep in sync with `bootstrap/compile.rs:rustc_cargo_env`
740+
if self.config.rustc_parallel {
741+
features.push("rustc_use_parallel_compiler");
738742
}
739743

740744
// If debug logging is on, then we want the default for tracing:
@@ -743,10 +747,10 @@ impl Build {
743747
// if its unset, if debug_assertions is on, then debug_logging will also be on
744748
// as well as tracing *ignoring* this feature when debug_assertions is on
745749
if !self.config.rust_debug_logging {
746-
features.push_str(" max_level_info");
750+
features.push("max_level_info");
747751
}
748752

749-
features
753+
features.join(" ")
750754
}
751755

752756
/// Component directory that Cargo will produce output into (e.g.

0 commit comments

Comments
 (0)