Skip to content

Commit

Permalink
bootstrap: use internment instead of hand-rolled interning
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Sep 14, 2024
1 parent 5fe0e40 commit 585ee32
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 203 deletions.
64 changes: 64 additions & 0 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# It is not intended for manual editing.
version = 3

[[package]]
name = "ahash"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
"zerocopy",
]

[[package]]
name = "aho-corasick"
version = "1.1.3"
Expand All @@ -11,6 +23,12 @@ dependencies = [
"memchr",
]

[[package]]
name = "allocator-api2"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"

[[package]]
name = "anstyle"
version = "1.0.8"
Expand Down Expand Up @@ -44,6 +62,7 @@ dependencies = [
"fd-lock",
"home",
"ignore",
"internment",
"junction",
"libc",
"object",
Expand Down Expand Up @@ -272,6 +291,16 @@ dependencies = [
"regex-syntax",
]

[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [
"ahash",
"allocator-api2",
]

[[package]]
name = "heck"
version = "0.5.0"
Expand Down Expand Up @@ -303,6 +332,15 @@ dependencies = [
"winapi-util",
]

[[package]]
name = "internment"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f54d755e2513c46a29d3c06fed25aa5d2008252469266055797f331a71aa42"
dependencies = [
"hashbrown",
]

[[package]]
name = "itoa"
version = "1.0.11"
Expand Down Expand Up @@ -383,6 +421,12 @@ dependencies = [
"memchr",
]

[[package]]
name = "once_cell"
version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe"

[[package]]
name = "opener"
version = "0.5.2"
Expand Down Expand Up @@ -827,3 +871,23 @@ name = "yansi"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"

[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive",
]

[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
1 change: 1 addition & 0 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ clap = { version = "4.4", default-features = false, features = ["std", "usage",
clap_complete = "4.4"
fd-lock = "4.0"
home = "0.5"
internment = "0.8.5"
ignore = "0.4"
libc = "0.2"
object = { version = "0.36.3", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
Expand Down
30 changes: 16 additions & 14 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
use crate::core::build_steps::llvm;
pub use crate::core::config::flags::Subcommand;
use crate::core::config::flags::{Color, Flags, Warnings};
use crate::utils::cache::{Interned, INTERNER};
use crate::utils::cache::Interned;
use crate::utils::channel::{self, GitInfo};
use crate::utils::helpers::{self, exe, output, t};

Expand Down Expand Up @@ -446,15 +446,21 @@ impl std::str::FromStr for RustcLto {
}
}

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

impl Default for TargetSelection {
fn default() -> Self {
Self { triple: "".into(), file: Default::default(), synthetic: Default::default() }
}
}

/// Newtype over `Vec<TargetSelection>` so we can implement custom parsing logic
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct TargetSelectionList(Vec<TargetSelection>);
Expand All @@ -481,18 +487,14 @@ impl TargetSelection {
(selection, None)
};

let triple = INTERNER.intern_str(triple);
let file = file.map(|f| INTERNER.intern_str(f));
let triple: Interned<str> = triple.into();
let file: Option<Interned<str>> = file.map(|f| f.into());

Self { triple, file, synthetic: false }
}

pub fn create_synthetic(triple: &str, file: &str) -> Self {
Self {
triple: INTERNER.intern_str(triple),
file: Some(INTERNER.intern_str(file)),
synthetic: true,
}
Self { triple: triple.into(), file: Some(file.into()), synthetic: true }
}

pub fn rustc_target_arg(&self) -> &str {
Expand Down Expand Up @@ -552,15 +554,15 @@ impl fmt::Debug for TargetSelection {

impl PartialEq<&str> for TargetSelection {
fn eq(&self, other: &&str) -> bool {
self.triple == *other
&*self.triple == *other
}
}

// Targets are often used as directory names throughout bootstrap.
// This impl makes it more ergonomics to use them as such.
impl AsRef<Path> for TargetSelection {
fn as_ref(&self) -> &Path {
self.triple.as_ref()
(*self.triple).as_ref()
}
}

Expand Down Expand Up @@ -2067,7 +2069,7 @@ impl Config {
// thus, disabled
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
// when the config sets `rust.lld = false`
if config.build.triple == "x86_64-unknown-linux-gnu"
if &*config.build.triple == "x86_64-unknown-linux-gnu"
&& config.hosts == [config.build]
&& (config.channel == "dev" || config.channel == "nightly")
{
Expand Down
Loading

0 comments on commit 585ee32

Please sign in to comment.