Skip to content

Commit 2789152

Browse files
onur-ozkanstlankes
authored andcommitted
micro-level optimizations for bootstrap
Overall optimizations for bootstrap on conditions, assertions, trait implementations, etc. Signed-off-by: onur-ozkan <[email protected]>
1 parent e8d702f commit 2789152

File tree

9 files changed

+60
-77
lines changed

9 files changed

+60
-77
lines changed

src/bootstrap/builder.rs

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

src/bootstrap/compile.rs

Lines changed: 2 additions & 4 deletions
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

Lines changed: 7 additions & 22 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
155155
"".to_owned()
156156
};
157157

158-
if &llvm_sha == "" {
158+
if llvm_sha.is_empty() {
159159
eprintln!("error: could not find commit hash for downloading LLVM");
160160
eprintln!("help: maybe your repository history is too shallow?");
161161
eprintln!("help: consider disabling `download-ci-llvm`");
@@ -208,10 +208,10 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
208208
("x86_64-unknown-netbsd", false),
209209
];
210210

211-
if !supported_platforms.contains(&(&*config.build.triple, asserts)) {
212-
if asserts == true || !supported_platforms.contains(&(&*config.build.triple, true)) {
213-
return false;
214-
}
211+
if !supported_platforms.contains(&(&*config.build.triple, asserts))
212+
&& (asserts || !supported_platforms.contains(&(&*config.build.triple, true)))
213+
{
214+
return false;
215215
}
216216

217217
if is_ci_llvm_modified(config) {
@@ -497,11 +497,11 @@ impl Step for Llvm {
497497
let mut cmd = Command::new(&res.llvm_config);
498498
let version = output(cmd.arg("--version"));
499499
let major = version.split('.').next().unwrap();
500-
let lib_name = match &llvm_version_suffix {
500+
501+
match &llvm_version_suffix {
501502
Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"),
502503
None => format!("libLLVM-{major}.{extension}"),
503-
};
504-
lib_name
504+
}
505505
};
506506

507507
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
@@ -756,13 +756,15 @@ fn configure_cmake(
756756

757757
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
758758
// We also do this if the user explicitly requested static libstdc++.
759-
if builder.config.llvm_static_stdcpp {
760-
if !target.contains("msvc") && !target.contains("netbsd") && !target.contains("solaris") {
761-
if target.contains("apple") || target.contains("windows") {
762-
ldflags.push_all("-static-libstdc++");
763-
} else {
764-
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
765-
}
759+
if builder.config.llvm_static_stdcpp
760+
&& !target.contains("msvc")
761+
&& !target.contains("netbsd")
762+
&& !target.contains("solaris")
763+
{
764+
if target.contains("apple") || target.contains("windows") {
765+
ldflags.push_all("-static-libstdc++");
766+
} else {
767+
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
766768
}
767769
}
768770

src/bootstrap/sanity.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,19 @@ pub fn check(build: &mut Build) {
9595
.unwrap_or(true)
9696
})
9797
.any(|build_llvm_ourselves| build_llvm_ourselves);
98+
9899
let need_cmake = building_llvm || build.config.any_sanitizers_enabled();
99-
if need_cmake {
100-
if cmd_finder.maybe_have("cmake").is_none() {
101-
eprintln!(
102-
"
100+
if need_cmake && cmd_finder.maybe_have("cmake").is_none() {
101+
eprintln!(
102+
"
103103
Couldn't find required command: cmake
104104
105105
You should install cmake, or set `download-ci-llvm = true` in the
106106
`[llvm]` section of `config.toml` to download LLVM rather
107107
than building it.
108108
"
109-
);
110-
crate::exit!(1);
111-
}
109+
);
110+
crate::exit!(1);
112111
}
113112

114113
build.config.python = build
@@ -202,10 +201,10 @@ than building it.
202201
.entry(*target)
203202
.or_insert_with(|| Target::from_triple(&target.triple));
204203

205-
if target.contains("-none-") || target.contains("nvptx") {
206-
if build.no_std(*target) == Some(false) {
207-
panic!("All the *-none-* and nvptx* targets are no-std targets")
208-
}
204+
if (target.contains("-none-") || target.contains("nvptx"))
205+
&& build.no_std(*target) == Some(false)
206+
{
207+
panic!("All the *-none-* and nvptx* targets are no-std targets")
209208
}
210209

211210
// Some environments don't want or need these tools, such as when testing Miri.

src/bootstrap/test.rs

Lines changed: 9 additions & 11 deletions
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

@@ -1378,7 +1376,7 @@ impl Step for MirOpt {
13781376
let run = |target| {
13791377
builder.ensure(Compiletest {
13801378
compiler: self.compiler,
1381-
target: target,
1379+
target,
13821380
mode: "mir-opt",
13831381
suite: "mir-opt",
13841382
path: "tests/mir-opt",

0 commit comments

Comments
 (0)