Skip to content

Commit 9971008

Browse files
committed
micro-level optimizations for bootstrap
Overall optimizations for bootstrap on conditions, assertions, trait implementations, etc. Signed-off-by: onur-ozkan <[email protected]>
1 parent 12b1784 commit 9971008

File tree

9 files changed

+60
-77
lines changed

9 files changed

+60
-77
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'a> ShouldRun<'a> {
523523
.iter()
524524
.map(|p| {
525525
// assert only if `p` isn't submodule
526-
if !submodules_paths.iter().find(|sm_p| p.contains(*sm_p)).is_some() {
526+
if submodules_paths.iter().find(|sm_p| p.contains(*sm_p)).is_none() {
527527
assert!(
528528
self.builder.src.join(p).exists(),
529529
"`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}",

src/bootstrap/compile.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,8 @@ impl Step for Rustc {
876876
cargo.rustflag("-Clto=off");
877877
}
878878
}
879-
} else {
880-
if builder.config.rust_lto == RustcLto::Off {
881-
cargo.rustflag("-Clto=off");
882-
}
879+
} else if builder.config.rust_lto == RustcLto::Off {
880+
cargo.rustflag("-Clto=off");
883881
}
884882

885883
for krate in &*self.crates {

src/bootstrap/config.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -322,33 +322,23 @@ pub struct RustfmtMetadata {
322322
pub version: String,
323323
}
324324

325-
#[derive(Clone, Debug)]
325+
#[derive(Clone, Debug, Default)]
326326
pub enum RustfmtState {
327327
SystemToolchain(PathBuf),
328328
Downloaded(PathBuf),
329329
Unavailable,
330+
#[default]
330331
LazyEvaluated,
331332
}
332333

333-
impl Default for RustfmtState {
334-
fn default() -> Self {
335-
RustfmtState::LazyEvaluated
336-
}
337-
}
338-
339-
#[derive(Debug, Clone, Copy, PartialEq)]
334+
#[derive(Debug, Default, Clone, Copy, PartialEq)]
340335
pub enum LlvmLibunwind {
336+
#[default]
341337
No,
342338
InTree,
343339
System,
344340
}
345341

346-
impl Default for LlvmLibunwind {
347-
fn default() -> Self {
348-
Self::No
349-
}
350-
}
351-
352342
impl FromStr for LlvmLibunwind {
353343
type Err = String;
354344

@@ -362,19 +352,14 @@ impl FromStr for LlvmLibunwind {
362352
}
363353
}
364354

365-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
355+
#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
366356
pub enum SplitDebuginfo {
367357
Packed,
368358
Unpacked,
359+
#[default]
369360
Off,
370361
}
371362

372-
impl Default for SplitDebuginfo {
373-
fn default() -> Self {
374-
SplitDebuginfo::Off
375-
}
376-
}
377-
378363
impl std::str::FromStr for SplitDebuginfo {
379364
type Err = ();
380365

@@ -1529,7 +1514,7 @@ impl Config {
15291514
let asserts = llvm_assertions.unwrap_or(false);
15301515
config.llvm_from_ci = match llvm.download_ci_llvm {
15311516
Some(StringOrBool::String(s)) => {
1532-
assert!(s == "if-available", "unknown option `{s}` for download-ci-llvm");
1517+
assert_eq!(s, "if-available", "unknown option `{s}` for download-ci-llvm");
15331518
crate::llvm::is_ci_llvm_available(&config, asserts)
15341519
}
15351520
Some(StringOrBool::Bool(b)) => b,

src/bootstrap/config/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ build-config = {}
136136
"setting string value without quotes"
137137
);
138138
assert_eq!(config.gdb, Some("bar".into()), "setting string value with quotes");
139-
assert_eq!(config.deny_warnings, false, "setting boolean value");
139+
assert!(!config.deny_warnings, "setting boolean value");
140140
assert_eq!(
141141
config.tools,
142142
Some(["cargo".to_string()].into_iter().collect()),
@@ -181,13 +181,13 @@ fn profile_user_dist() {
181181

182182
#[test]
183183
fn rust_optimize() {
184-
assert_eq!(parse("").rust_optimize.is_release(), true);
185-
assert_eq!(parse("rust.optimize = false").rust_optimize.is_release(), false);
186-
assert_eq!(parse("rust.optimize = true").rust_optimize.is_release(), true);
187-
assert_eq!(parse("rust.optimize = 0").rust_optimize.is_release(), false);
188-
assert_eq!(parse("rust.optimize = 1").rust_optimize.is_release(), true);
184+
assert!(parse("").rust_optimize.is_release());
185+
assert!(!parse("rust.optimize = false").rust_optimize.is_release());
186+
assert!(parse("rust.optimize = true").rust_optimize.is_release());
187+
assert!(!parse("rust.optimize = 0").rust_optimize.is_release());
188+
assert!(parse("rust.optimize = 1").rust_optimize.is_release());
189+
assert!(parse("rust.optimize = \"s\"").rust_optimize.is_release());
189190
assert_eq!(parse("rust.optimize = 1").rust_optimize.get_opt_level(), Some("1".to_string()));
190-
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.is_release(), true);
191191
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.get_opt_level(), Some("s".to_string()));
192192
}
193193

src/bootstrap/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl Config {
441441
}
442442

443443
pub(crate) fn download_beta_toolchain(&self) {
444-
self.verbose(&format!("downloading stage0 beta artifacts"));
444+
self.verbose("downloading stage0 beta artifacts");
445445

446446
let date = &self.stage0_metadata.compiler.date;
447447
let version = &self.stage0_metadata.compiler.version;

src/bootstrap/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub const VERSION: usize = 2;
116116

117117
/// Extra --check-cfg to add when building
118118
/// (Mode restriction, config name, config values (if any))
119-
const EXTRA_CHECK_CFGS: &[(Option<Mode>, &'static str, Option<&[&'static str]>)] = &[
119+
const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
120120
(None, "bootstrap", None),
121121
(Some(Mode::Rustc), "parallel_compiler", None),
122122
(Some(Mode::ToolRustc), "parallel_compiler", None),
@@ -1757,10 +1757,11 @@ to download LLVM rather than building it.
17571757
//
17581758
// In these cases we automatically enable Ninja if we find it in the
17591759
// environment.
1760-
if !self.config.ninja_in_file && self.config.build.contains("msvc") {
1761-
if cmd_finder.maybe_have("ninja").is_some() {
1762-
return true;
1763-
}
1760+
if !self.config.ninja_in_file
1761+
&& self.config.build.contains("msvc")
1762+
&& cmd_finder.maybe_have("ninja").is_some()
1763+
{
1764+
return true;
17641765
}
17651766

17661767
self.config.ninja_in_file

src/bootstrap/llvm.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
148148
"".to_owned()
149149
};
150150

151-
if &llvm_sha == "" {
151+
if llvm_sha.is_empty() {
152152
eprintln!("error: could not find commit hash for downloading LLVM");
153153
eprintln!("help: maybe your repository history is too shallow?");
154154
eprintln!("help: consider disabling `download-ci-llvm`");
@@ -201,10 +201,10 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
201201
("x86_64-unknown-netbsd", false),
202202
];
203203

204-
if !supported_platforms.contains(&(&*config.build.triple, asserts)) {
205-
if asserts == true || !supported_platforms.contains(&(&*config.build.triple, true)) {
206-
return false;
207-
}
204+
if !supported_platforms.contains(&(&*config.build.triple, asserts))
205+
&& (asserts || !supported_platforms.contains(&(&*config.build.triple, true)))
206+
{
207+
return false;
208208
}
209209

210210
if is_ci_llvm_modified(config) {
@@ -490,11 +490,11 @@ impl Step for Llvm {
490490
let mut cmd = Command::new(&res.llvm_config);
491491
let version = output(cmd.arg("--version"));
492492
let major = version.split('.').next().unwrap();
493-
let lib_name = match &llvm_version_suffix {
493+
494+
match &llvm_version_suffix {
494495
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
495496
None => format!("libLLVM-{major}.{extension}"),
496-
};
497-
lib_name
497+
}
498498
};
499499

500500
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
@@ -749,13 +749,15 @@ fn configure_cmake(
749749

750750
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
751751
// We also do this if the user explicitly requested static libstdc++.
752-
if builder.config.llvm_static_stdcpp {
753-
if !target.contains("msvc") && !target.contains("netbsd") && !target.contains("solaris") {
754-
if target.contains("apple") || target.contains("windows") {
755-
ldflags.push_all("-static-libstdc++");
756-
} else {
757-
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
758-
}
752+
if builder.config.llvm_static_stdcpp
753+
&& !target.contains("msvc")
754+
&& !target.contains("netbsd")
755+
&& !target.contains("solaris")
756+
{
757+
if target.contains("apple") || target.contains("windows") {
758+
ldflags.push_all("-static-libstdc++");
759+
} else {
760+
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
759761
}
760762
}
761763

src/bootstrap/sanity.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,19 @@ pub fn check(build: &mut Build) {
9292
.unwrap_or(true)
9393
})
9494
.any(|build_llvm_ourselves| build_llvm_ourselves);
95+
9596
let need_cmake = building_llvm || build.config.any_sanitizers_enabled();
96-
if need_cmake {
97-
if cmd_finder.maybe_have("cmake").is_none() {
98-
eprintln!(
99-
"
97+
if need_cmake && cmd_finder.maybe_have("cmake").is_none() {
98+
eprintln!(
99+
"
100100
Couldn't find required command: cmake
101101
102102
You should install cmake, or set `download-ci-llvm = true` in the
103103
`[llvm]` section of `config.toml` to download LLVM rather
104104
than building it.
105105
"
106-
);
107-
crate::exit!(1);
108-
}
106+
);
107+
crate::exit!(1);
109108
}
110109

111110
build.config.python = build
@@ -199,10 +198,10 @@ than building it.
199198
.entry(*target)
200199
.or_insert_with(|| Target::from_triple(&target.triple));
201200

202-
if target.contains("-none-") || target.contains("nvptx") {
203-
if build.no_std(*target) == Some(false) {
204-
panic!("All the *-none-* and nvptx* targets are no-std targets")
205-
}
201+
if (target.contains("-none-") || target.contains("nvptx"))
202+
&& build.no_std(*target) == Some(false)
203+
{
204+
panic!("All the *-none-* and nvptx* targets are no-std targets")
206205
}
207206

208207
// Make sure musl-root is valid

src/bootstrap/test.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1139,16 +1139,14 @@ help: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
11391139
.map(|filename| builder.src.join("src/etc/completions").join(filename));
11401140
if builder.config.cmd.bless() {
11411141
builder.ensure(crate::run::GenerateCompletions);
1142-
} else {
1143-
if crate::flags::get_completion(shells::Bash, &bash).is_some()
1144-
|| crate::flags::get_completion(shells::Fish, &fish).is_some()
1145-
|| crate::flags::get_completion(shells::PowerShell, &powershell).is_some()
1146-
{
1147-
eprintln!(
1148-
"x.py completions were changed; run `x.py run generate-completions` to update them"
1149-
);
1150-
crate::exit!(1);
1151-
}
1142+
} else if crate::flags::get_completion(shells::Bash, &bash).is_some()
1143+
|| crate::flags::get_completion(shells::Fish, &fish).is_some()
1144+
|| crate::flags::get_completion(shells::PowerShell, &powershell).is_some()
1145+
{
1146+
eprintln!(
1147+
"x.py completions were changed; run `x.py run generate-completions` to update them"
1148+
);
1149+
crate::exit!(1);
11521150
}
11531151
}
11541152

@@ -1372,7 +1370,7 @@ impl Step for MirOpt {
13721370
let run = |target| {
13731371
builder.ensure(Compiletest {
13741372
compiler: self.compiler,
1375-
target: target,
1373+
target,
13761374
mode: "mir-opt",
13771375
suite: "mir-opt",
13781376
path: "tests/mir-opt",

0 commit comments

Comments
 (0)