Skip to content

Commit aeb7d64

Browse files
committed
bootstrap: use internment instead of hand-rolled interning
1 parent a772336 commit aeb7d64

File tree

4 files changed

+82
-203
lines changed

4 files changed

+82
-203
lines changed

src/bootstrap/Cargo.lock

+64
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# It is not intended for manual editing.
33
version = 3
44

5+
[[package]]
6+
name = "ahash"
7+
version = "0.8.11"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
10+
dependencies = [
11+
"cfg-if",
12+
"once_cell",
13+
"version_check",
14+
"zerocopy",
15+
]
16+
517
[[package]]
618
name = "aho-corasick"
719
version = "1.1.3"
@@ -11,6 +23,12 @@ dependencies = [
1123
"memchr",
1224
]
1325

26+
[[package]]
27+
name = "allocator-api2"
28+
version = "0.2.18"
29+
source = "registry+https://github.com/rust-lang/crates.io-index"
30+
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
31+
1432
[[package]]
1533
name = "anstyle"
1634
version = "1.0.8"
@@ -44,6 +62,7 @@ dependencies = [
4462
"fd-lock",
4563
"home",
4664
"ignore",
65+
"internment",
4766
"junction",
4867
"libc",
4968
"object",
@@ -275,6 +294,16 @@ dependencies = [
275294
"regex-syntax",
276295
]
277296

297+
[[package]]
298+
name = "hashbrown"
299+
version = "0.14.5"
300+
source = "registry+https://github.com/rust-lang/crates.io-index"
301+
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
302+
dependencies = [
303+
"ahash",
304+
"allocator-api2",
305+
]
306+
278307
[[package]]
279308
name = "heck"
280309
version = "0.5.0"
@@ -306,6 +335,15 @@ dependencies = [
306335
"winapi-util",
307336
]
308337

338+
[[package]]
339+
name = "internment"
340+
version = "0.8.5"
341+
source = "registry+https://github.com/rust-lang/crates.io-index"
342+
checksum = "d7f54d755e2513c46a29d3c06fed25aa5d2008252469266055797f331a71aa42"
343+
dependencies = [
344+
"hashbrown",
345+
]
346+
309347
[[package]]
310348
name = "itoa"
311349
version = "1.0.11"
@@ -386,6 +424,12 @@ dependencies = [
386424
"memchr",
387425
]
388426

427+
[[package]]
428+
name = "once_cell"
429+
version = "1.20.0"
430+
source = "registry+https://github.com/rust-lang/crates.io-index"
431+
checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe"
432+
389433
[[package]]
390434
name = "opener"
391435
version = "0.5.2"
@@ -836,3 +880,23 @@ name = "yansi"
836880
version = "0.5.1"
837881
source = "registry+https://github.com/rust-lang/crates.io-index"
838882
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
883+
884+
[[package]]
885+
name = "zerocopy"
886+
version = "0.7.35"
887+
source = "registry+https://github.com/rust-lang/crates.io-index"
888+
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
889+
dependencies = [
890+
"zerocopy-derive",
891+
]
892+
893+
[[package]]
894+
name = "zerocopy-derive"
895+
version = "0.7.35"
896+
source = "registry+https://github.com/rust-lang/crates.io-index"
897+
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
898+
dependencies = [
899+
"proc-macro2",
900+
"quote",
901+
"syn",
902+
]

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ clap = { version = "4.4", default-features = false, features = ["std", "usage",
4545
clap_complete = "4.4"
4646
fd-lock = "4.0"
4747
home = "0.5"
48+
internment = "0.8.5"
4849
ignore = "0.4"
4950
libc = "0.2"
5051
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }

src/bootstrap/src/core/config/config.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
2222
use crate::core::build_steps::llvm;
2323
pub use crate::core::config::flags::Subcommand;
2424
use crate::core::config::flags::{Color, Flags, Warnings};
25-
use crate::utils::cache::{INTERNER, Interned};
25+
use crate::utils::cache::Interned;
2626
use crate::utils::channel::{self, GitInfo};
2727
use crate::utils::helpers::{self, exe, output, t};
2828

@@ -447,15 +447,21 @@ impl std::str::FromStr for RustcLto {
447447
}
448448
}
449449

450-
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
450+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
451451
// N.B.: This type is used everywhere, and the entire codebase relies on it being Copy.
452452
// Making !Copy is highly nontrivial!
453453
pub struct TargetSelection {
454-
pub triple: Interned<String>,
455-
file: Option<Interned<String>>,
454+
pub triple: Interned<str>,
455+
file: Option<Interned<str>>,
456456
synthetic: bool,
457457
}
458458

459+
impl Default for TargetSelection {
460+
fn default() -> Self {
461+
Self { triple: "".into(), file: Default::default(), synthetic: Default::default() }
462+
}
463+
}
464+
459465
/// Newtype over `Vec<TargetSelection>` so we can implement custom parsing logic
460466
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
461467
pub struct TargetSelectionList(Vec<TargetSelection>);
@@ -482,18 +488,14 @@ impl TargetSelection {
482488
(selection, None)
483489
};
484490

485-
let triple = INTERNER.intern_str(triple);
486-
let file = file.map(|f| INTERNER.intern_str(f));
491+
let triple: Interned<str> = triple.into();
492+
let file: Option<Interned<str>> = file.map(|f| f.into());
487493

488494
Self { triple, file, synthetic: false }
489495
}
490496

491497
pub fn create_synthetic(triple: &str, file: &str) -> Self {
492-
Self {
493-
triple: INTERNER.intern_str(triple),
494-
file: Some(INTERNER.intern_str(file)),
495-
synthetic: true,
496-
}
498+
Self { triple: triple.into(), file: Some(file.into()), synthetic: true }
497499
}
498500

499501
pub fn rustc_target_arg(&self) -> &str {
@@ -553,15 +555,15 @@ impl fmt::Debug for TargetSelection {
553555

554556
impl PartialEq<&str> for TargetSelection {
555557
fn eq(&self, other: &&str) -> bool {
556-
self.triple == *other
558+
&*self.triple == *other
557559
}
558560
}
559561

560562
// Targets are often used as directory names throughout bootstrap.
561563
// This impl makes it more ergonomics to use them as such.
562564
impl AsRef<Path> for TargetSelection {
563565
fn as_ref(&self) -> &Path {
564-
self.triple.as_ref()
566+
(*self.triple).as_ref()
565567
}
566568
}
567569

@@ -2072,7 +2074,7 @@ impl Config {
20722074
// thus, disabled
20732075
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
20742076
// when the config sets `rust.lld = false`
2075-
if config.build.triple == "x86_64-unknown-linux-gnu"
2077+
if &*config.build.triple == "x86_64-unknown-linux-gnu"
20762078
&& config.hosts == [config.build]
20772079
&& (config.channel == "dev" || config.channel == "nightly")
20782080
{

0 commit comments

Comments
 (0)