From 83bd6b73952ff34d261e2127347e25fd483510cc Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:35:19 +0100 Subject: [PATCH] Avoid some interning in bootstrap This interning is pointless and only makes the code more complex. The only remaining use of interning is `TargetSelection`, for which I left a comment. --- src/bootstrap/src/core/build_steps/check.rs | 24 ++++----- src/bootstrap/src/core/build_steps/clean.rs | 5 +- src/bootstrap/src/core/build_steps/compile.rs | 45 ++++++++--------- src/bootstrap/src/core/build_steps/dist.rs | 21 ++++---- src/bootstrap/src/core/build_steps/doc.rs | 41 ++++++++------- src/bootstrap/src/core/build_steps/install.rs | 3 +- src/bootstrap/src/core/build_steps/test.rs | 50 +++++++++++-------- src/bootstrap/src/core/builder.rs | 20 ++++---- src/bootstrap/src/core/config/config.rs | 18 ++++--- src/bootstrap/src/core/metadata.rs | 9 ++-- src/bootstrap/src/lib.rs | 19 ++++--- src/bootstrap/src/utils/cache.rs | 11 ---- 12 files changed, 127 insertions(+), 139 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 3ac60f15ef67e..c01832a99ac7b 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -8,12 +8,10 @@ use crate::core::builder::{ self, crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step, }; use crate::core::config::TargetSelection; -use crate::utils::cache::Interned; -use crate::INTERNER; use crate::{Compiler, Mode, Subcommand}; use std::path::{Path, PathBuf}; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Std { pub target: TargetSelection, /// Whether to build only a subset of crates. @@ -21,7 +19,7 @@ pub struct Std { /// This shouldn't be used from other steps; see the comment on [`compile::Rustc`]. /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc - crates: Interned>, + crates: Vec, } /// Returns args for the subcommand itself (not for cargo) @@ -89,7 +87,7 @@ fn cargo_subcommand(kind: Kind) -> &'static str { impl Std { pub fn new(target: TargetSelection) -> Self { - Self { target, crates: INTERNER.intern_list(vec![]) } + Self { target, crates: vec![] } } } @@ -204,7 +202,7 @@ impl Step for Std { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Rustc { pub target: TargetSelection, /// Whether to build only a subset of crates. @@ -212,7 +210,7 @@ pub struct Rustc { /// This shouldn't be used from other steps; see the comment on [`compile::Rustc`]. /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc - crates: Interned>, + crates: Vec, } impl Rustc { @@ -222,7 +220,7 @@ impl Rustc { .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { target, crates: INTERNER.intern_list(crates) } + Self { target, crates } } } @@ -305,10 +303,10 @@ impl Step for Rustc { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CodegenBackend { pub target: TargetSelection, - pub backend: Interned, + pub backend: &'static str, } impl Step for CodegenBackend { @@ -321,14 +319,14 @@ impl Step for CodegenBackend { } fn make_run(run: RunConfig<'_>) { - for &backend in &[INTERNER.intern_str("cranelift"), INTERNER.intern_str("gcc")] { + for &backend in &["cranelift", "gcc"] { run.builder.ensure(CodegenBackend { target: run.target, backend }); } } fn run(self, builder: &Builder<'_>) { // FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved - if builder.build.config.vendor && &self.backend == "gcc" { + if builder.build.config.vendor && self.backend == "gcc" { println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled."); return; } @@ -552,7 +550,7 @@ fn codegen_backend_stamp( builder: &Builder<'_>, compiler: Compiler, target: TargetSelection, - backend: Interned, + backend: &str, ) -> PathBuf { builder .cargo_out(compiler, Mode::Codegen, target) diff --git a/src/bootstrap/src/core/build_steps/clean.rs b/src/bootstrap/src/core/build_steps/clean.rs index 4b993945f19fc..f263ebb349f98 100644 --- a/src/bootstrap/src/core/build_steps/clean.rs +++ b/src/bootstrap/src/core/build_steps/clean.rs @@ -10,7 +10,6 @@ use std::io::{self, ErrorKind}; use std::path::Path; use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step}; -use crate::utils::cache::Interned; use crate::utils::helpers::t; use crate::{Build, Compiler, Mode, Subcommand}; @@ -44,10 +43,10 @@ impl Step for CleanAll { macro_rules! clean_crate_tree { ( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $( - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct $name { compiler: Compiler, - crates: Interned>, + crates: Vec, } impl Step for $name { diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index d349cd67fed2c..72c7ee9987dc1 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -27,7 +27,6 @@ use crate::core::builder::crate_description; use crate::core::builder::Cargo; use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath}; use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection}; -use crate::utils::cache::{Interned, INTERNER}; use crate::utils::helpers::{ exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date, }; @@ -35,14 +34,14 @@ use crate::LLVM_TOOLS; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; use filetime::FileTime; -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Std { pub target: TargetSelection, pub compiler: Compiler, /// Whether to build only a subset of crates in the standard library. /// /// This shouldn't be used from other steps; see the comment on [`Rustc`]. - crates: Interned>, + crates: Vec, /// When using download-rustc, we need to use a new build of `std` for running unit tests of Std itself, /// but we need to use the downloaded copy of std for linking to rustdoc. Allow this to be overriden by `builder.ensure` from other steps. force_recompile: bool, @@ -556,13 +555,13 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)"); } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] struct StdLink { pub compiler: Compiler, pub target_compiler: Compiler, pub target: TargetSelection, /// Not actually used; only present to make sure the cache invalidation is correct. - crates: Interned>, + crates: Vec, /// See [`Std::force_recompile`]. force_recompile: bool, } @@ -609,7 +608,7 @@ impl Step for StdLink { }); let libdir = sysroot.join(lib).join("rustlib").join(target.triple).join("lib"); let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host.triple).join("lib"); - (INTERNER.intern_path(libdir), INTERNER.intern_path(hostdir)) + (libdir, hostdir) } else { let libdir = builder.sysroot_libdir(target_compiler, target); let hostdir = builder.sysroot_libdir(target_compiler, compiler.host); @@ -815,7 +814,7 @@ fn cp_rustc_component_to_ci_sysroot( } } -#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)] pub struct Rustc { pub target: TargetSelection, pub compiler: Compiler, @@ -824,7 +823,7 @@ pub struct Rustc { /// This should only be requested by the user, not used within rustbuild itself. /// Using it within rustbuild can lead to confusing situation where lints are replayed /// in two different steps. - crates: Interned>, + crates: Vec, } impl Rustc { @@ -1217,13 +1216,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] struct RustcLink { pub compiler: Compiler, pub target_compiler: Compiler, pub target: TargetSelection, /// Not actually used; only present to make sure the cache invalidation is correct. - crates: Interned>, + crates: Vec, } impl RustcLink { @@ -1258,11 +1257,11 @@ impl Step for RustcLink { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CodegenBackend { pub target: TargetSelection, pub compiler: Compiler, - pub backend: Interned, + pub backend: String, } fn needs_codegen_config(run: &RunConfig<'_>) -> bool { @@ -1281,7 +1280,7 @@ pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_"; fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool { if path.path.to_str().unwrap().contains(CODEGEN_BACKEND_PREFIX) { let mut needs_codegen_backend_config = true; - for &backend in run.builder.config.codegen_backends(run.target) { + for backend in run.builder.config.codegen_backends(run.target) { if path .path .to_str() @@ -1318,7 +1317,7 @@ impl Step for CodegenBackend { return; } - for &backend in run.builder.config.codegen_backends(run.target) { + for backend in run.builder.config.codegen_backends(run.target) { if backend == "llvm" { continue; // Already built as part of rustc } @@ -1326,7 +1325,7 @@ impl Step for CodegenBackend { run.builder.ensure(CodegenBackend { target: run.target, compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), - backend, + backend: backend.clone(), }); } } @@ -1391,7 +1390,7 @@ impl Step for CodegenBackend { f.display() ); } - let stamp = codegen_backend_stamp(builder, compiler, target, backend); + let stamp = codegen_backend_stamp(builder, compiler, target, &backend); let codegen_backend = codegen_backend.to_str().unwrap(); t!(fs::write(stamp, codegen_backend)); } @@ -1430,7 +1429,7 @@ fn copy_codegen_backends_to_sysroot( continue; // Already built as part of rustc } - let stamp = codegen_backend_stamp(builder, compiler, target, *backend); + let stamp = codegen_backend_stamp(builder, compiler, target, backend); let dylib = t!(fs::read_to_string(&stamp)); let file = Path::new(&dylib); let filename = file.file_name().unwrap().to_str().unwrap(); @@ -1467,7 +1466,7 @@ fn codegen_backend_stamp( builder: &Builder<'_>, compiler: Compiler, target: TargetSelection, - backend: Interned, + backend: &str, ) -> PathBuf { builder .cargo_out(compiler, Mode::Codegen, target) @@ -1505,7 +1504,7 @@ impl Sysroot { } impl Step for Sysroot { - type Output = Interned; + type Output = PathBuf; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.never() @@ -1517,7 +1516,7 @@ impl Step for Sysroot { /// That is, the sysroot for the stage0 compiler is not what the compiler /// thinks it is by default, but it's the same as the default for stages /// 1-3. - fn run(self, builder: &Builder<'_>) -> Interned { + fn run(self, builder: &Builder<'_>) -> PathBuf { let compiler = self.compiler; let host_dir = builder.out.join(compiler.host.triple); @@ -1649,7 +1648,7 @@ impl Step for Sysroot { ); } - INTERNER.intern_path(sysroot) + sysroot } } @@ -1732,7 +1731,7 @@ impl Step for Assemble { // to not fail while linking the artifacts. build_compiler.stage = actual_stage; - for &backend in builder.config.codegen_backends(target_compiler.host) { + for backend in builder.config.codegen_backends(target_compiler.host) { if backend == "llvm" { continue; // Already built as part of rustc } @@ -1740,7 +1739,7 @@ impl Step for Assemble { builder.ensure(CodegenBackend { compiler: build_compiler, target: target_compiler.host, - backend, + backend: backend.clone(), }); } diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index d9ab18e7250b0..45b9b04e46a6e 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -25,7 +25,6 @@ use crate::core::build_steps::llvm; use crate::core::build_steps::tool::{self, Tool}; use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; use crate::core::config::TargetSelection; -use crate::utils::cache::{Interned, INTERNER}; use crate::utils::channel; use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit}; use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball}; @@ -488,8 +487,7 @@ impl Step for Rustc { } // Debugger scripts - builder - .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host }); + builder.ensure(DebuggerScripts { sysroot: image.to_owned(), host }); // Misc license info let cp = |file: &str| { @@ -503,9 +501,9 @@ impl Step for Rustc { } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct DebuggerScripts { - pub sysroot: Interned, + pub sysroot: PathBuf, pub host: TargetSelection, } @@ -1263,10 +1261,10 @@ impl Step for Miri { } } -#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)] pub struct CodegenBackend { pub compiler: Compiler, - pub backend: Interned, + pub backend: String, } impl Step for CodegenBackend { @@ -1279,14 +1277,14 @@ impl Step for CodegenBackend { } fn make_run(run: RunConfig<'_>) { - for &backend in run.builder.config.codegen_backends(run.target) { + for backend in run.builder.config.codegen_backends(run.target) { if backend == "llvm" { continue; // Already built as part of rustc } run.builder.ensure(CodegenBackend { compiler: run.builder.compiler(run.builder.top_stage, run.target), - backend, + backend: backend.clone(), }); } } @@ -1303,7 +1301,8 @@ impl Step for CodegenBackend { return None; } - if !builder.config.codegen_backends(self.compiler.host).contains(&self.backend) { + if !builder.config.codegen_backends(self.compiler.host).contains(&self.backend.to_string()) + { return None; } @@ -1528,7 +1527,7 @@ impl Step for Extended { add_component!("analysis" => Analysis { compiler, target }); add_component!("rustc-codegen-cranelift" => CodegenBackend { compiler: builder.compiler(stage, target), - backend: INTERNER.intern_str("cranelift"), + backend: "cranelift".to_string(), }); let etc = builder.src.join("src/etc/installer"); diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 7a122a8676ba7..b4a91fecfa90e 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -16,7 +16,6 @@ use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool} use crate::core::builder::{self, crate_description}; use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; use crate::core::config::{Config, TargetSelection}; -use crate::utils::cache::{Interned, INTERNER}; use crate::utils::helpers::{dir_is_empty, symlink_dir, t, up_to_date}; use crate::Mode; @@ -59,8 +58,8 @@ macro_rules! book { )? builder.ensure(RustbookSrc { target: self.target, - name: INTERNER.intern_str($book_name), - src: INTERNER.intern_path(builder.src.join($path)), + name: $book_name.to_owned(), + src: builder.src.join($path), parent: Some(self), }) } @@ -108,18 +107,18 @@ impl Step for UnstableBook { builder.ensure(UnstableBookGen { target: self.target }); builder.ensure(RustbookSrc { target: self.target, - name: INTERNER.intern_str("unstable-book"), - src: INTERNER.intern_path(builder.md_doc_out(self.target).join("unstable-book")), + name: "unstable-book".to_owned(), + src: builder.md_doc_out(self.target).join("unstable-book"), parent: Some(self), }) } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq)] struct RustbookSrc { target: TargetSelection, - name: Interned, - src: Interned, + name: String, + src: PathBuf, parent: Option

, } @@ -141,7 +140,7 @@ impl Step for RustbookSrc

{ let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); - let out = out.join(name); + let out = out.join(&name); let index = out.join("index.html"); let rustbook = builder.tool_exe(Tool::Rustbook); let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook); @@ -211,8 +210,8 @@ impl Step for TheBook { // build book builder.ensure(RustbookSrc { target, - name: INTERNER.intern_str("book"), - src: INTERNER.intern_path(absolute_path.clone()), + name: "book".to_owned(), + src: absolute_path.clone(), parent: Some(self), }); @@ -220,8 +219,8 @@ impl Step for TheBook { for edition in &["first-edition", "second-edition", "2018-edition"] { builder.ensure(RustbookSrc { target, - name: INTERNER.intern_string(format!("book/{edition}")), - src: INTERNER.intern_path(absolute_path.join(edition)), + name: format!("book/{edition}"), + src: absolute_path.join(edition), // There should only be one book that is marked as the parent for each target, so // treat the other editions as not having a parent. parent: Option::::None, @@ -526,12 +525,12 @@ impl Step for SharedAssets { } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Std { pub stage: u32, pub target: TargetSelection, pub format: DocumentationFormat, - crates: Interned>, + crates: Vec, } impl Std { @@ -546,7 +545,7 @@ impl Std { .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Std { stage, target, format, crates: INTERNER.intern_list(crates) } + Std { stage, target, format, crates } } } @@ -721,11 +720,11 @@ fn doc_std( builder.cp_r(&out_dir, out); } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct Rustc { pub stage: u32, pub target: TargetSelection, - crates: Interned>, + crates: Vec, } impl Rustc { @@ -735,7 +734,7 @@ impl Rustc { .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { stage, target, crates: INTERNER.intern_list(crates) } + Self { stage, target, crates } } } @@ -1189,8 +1188,8 @@ impl Step for RustcBook { // Run rustbook/mdbook to generate the HTML pages. builder.ensure(RustbookSrc { target: self.target, - name: INTERNER.intern_str("rustc"), - src: INTERNER.intern_path(out_base), + name: "rustc".to_owned(), + src: out_base, parent: Some(self), }); } diff --git a/src/bootstrap/src/core/build_steps/install.rs b/src/bootstrap/src/core/build_steps/install.rs index 29238b90225af..bbb697c0a18c7 100644 --- a/src/bootstrap/src/core/build_steps/install.rs +++ b/src/bootstrap/src/core/build_steps/install.rs @@ -13,7 +13,6 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::core::config::{Config, TargetSelection}; use crate::utils::helpers::t; use crate::utils::tarball::GeneratedTarball; -use crate::INTERNER; use crate::{Compiler, Kind}; #[cfg(target_os = "illumos")] @@ -291,7 +290,7 @@ install!((self, builder, _config), RustcCodegenCranelift, alias = "rustc-codegen-cranelift", Self::should_build(_config), only_hosts: true, { if let Some(tarball) = builder.ensure(dist::CodegenBackend { compiler: self.compiler, - backend: INTERNER.intern_str("cranelift"), + backend: "cranelift".to_string(), }) { install_sh(builder, "rustc-codegen-cranelift", self.compiler.stage, Some(self.target), &tarball); } else { diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 791f847a8661a..50750e6b8d32f 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -26,7 +26,6 @@ use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; use crate::core::config::flags::get_completion; use crate::core::config::flags::Subcommand; use crate::core::config::TargetSelection; -use crate::utils::cache::{Interned, INTERNER}; use crate::utils::exec::BootstrapCommand; use crate::utils::helpers::{ self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var, @@ -38,9 +37,9 @@ use crate::{envify, CLang, DocTests, GitRepo, Mode}; const ADB_TEST_DIR: &str = "/data/local/tmp/work"; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CrateBootstrap { - path: Interned, + path: PathBuf, host: TargetSelection, } @@ -58,7 +57,7 @@ impl Step for CrateBootstrap { fn make_run(run: RunConfig<'_>) { for path in run.paths { - let path = INTERNER.intern_path(path.assert_single_path().path.clone()); + let path = path.assert_single_path().path.clone(); run.builder.ensure(CrateBootstrap { host: run.target, path }); } } @@ -623,7 +622,7 @@ impl Step for Miri { // miri tests need to know about the stage sysroot cargo.env("MIRI_SYSROOT", &miri_sysroot); - cargo.env("MIRI_HOST_SYSROOT", sysroot); + cargo.env("MIRI_HOST_SYSROOT", &sysroot); cargo.env("MIRI", &miri); if builder.config.locked_deps { // enforce lockfiles @@ -1567,8 +1566,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the } if suite == "debuginfo" { - builder - .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target }); + builder.ensure(dist::DebuggerScripts { + sysroot: builder.sysroot(compiler).to_path_buf(), + host: target, + }); } // Also provide `rust_test_helpers` for the host. @@ -2299,7 +2300,7 @@ impl Step for RustcGuide { pub struct CrateLibrustc { compiler: Compiler, target: TargetSelection, - crates: Vec>, + crates: Vec, } impl Step for CrateLibrustc { @@ -2315,8 +2316,11 @@ impl Step for CrateLibrustc { let builder = run.builder; let host = run.build_triple(); let compiler = builder.compiler_for(builder.top_stage, host, host); - let crates = - run.paths.iter().map(|p| builder.crate_paths[&p.assert_single_path().path]).collect(); + let crates = run + .paths + .iter() + .map(|p| builder.crate_paths[&p.assert_single_path().path].clone()) + .collect(); builder.ensure(CrateLibrustc { compiler, target: run.target, crates }); } @@ -2339,7 +2343,7 @@ impl Step for CrateLibrustc { fn run_cargo_test<'a>( cargo: impl Into, libtest_args: &[&str], - crates: &[Interned], + crates: &[String], primary_crate: &str, description: impl Into>, compiler: Compiler, @@ -2370,7 +2374,7 @@ fn run_cargo_test<'a>( fn prepare_cargo_test( cargo: impl Into, libtest_args: &[&str], - crates: &[Interned], + crates: &[String], primary_crate: &str, compiler: Compiler, target: TargetSelection, @@ -2398,7 +2402,7 @@ fn prepare_cargo_test( DocTests::No => { let krate = &builder .crates - .get(&INTERNER.intern_str(primary_crate)) + .get(primary_crate) .unwrap_or_else(|| panic!("missing crate {primary_crate}")); if krate.has_lib { cargo.arg("--lib"); @@ -2408,7 +2412,7 @@ fn prepare_cargo_test( DocTests::Yes => {} } - for &krate in crates { + for krate in crates { cargo.arg("-p").arg(krate); } @@ -2450,7 +2454,7 @@ pub struct Crate { pub compiler: Compiler, pub target: TargetSelection, pub mode: Mode, - pub crates: Vec>, + pub crates: Vec, } impl Step for Crate { @@ -2465,8 +2469,11 @@ impl Step for Crate { let builder = run.builder; let host = run.build_triple(); let compiler = builder.compiler_for(builder.top_stage, host, host); - let crates = - run.paths.iter().map(|p| builder.crate_paths[&p.assert_single_path().path]).collect(); + let crates = run + .paths + .iter() + .map(|p| builder.crate_paths[&p.assert_single_path().path].clone()) + .collect(); builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, crates }); } @@ -2628,7 +2635,7 @@ impl Step for CrateRustdoc { run_cargo_test( cargo, &[], - &[INTERNER.intern_str("rustdoc:0.0.0")], + &["rustdoc:0.0.0".to_string()], "rustdoc", "rustdoc", compiler, @@ -2689,7 +2696,7 @@ impl Step for CrateRustdocJsonTypes { run_cargo_test( cargo, libtest_args, - &[INTERNER.intern_str("rustdoc-json-types")], + &["rustdoc-json-types".to_string()], "rustdoc-json-types", "rustdoc-json-types", compiler, @@ -3115,8 +3122,7 @@ impl Step for CodegenCranelift { return; } - if !builder.config.codegen_backends(run.target).contains(&INTERNER.intern_str("cranelift")) - { + if !builder.config.codegen_backends(run.target).contains(&"cranelift".to_owned()) { builder.info("cranelift not in rust.codegen-backends. skipping"); return; } @@ -3240,7 +3246,7 @@ impl Step for CodegenGCC { return; } - if !builder.config.codegen_backends(run.target).contains(&INTERNER.intern_str("gcc")) { + if !builder.config.codegen_backends(run.target).contains(&"gcc".to_owned()) { builder.info("gcc not in rust.codegen-backends. skipping"); return; } diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 0ec5e16de1da5..d68c5f4dffc8e 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -19,7 +19,7 @@ use crate::core::build_steps::{check, clean, compile, dist, doc, install, run, s use crate::core::config::flags::{Color, Subcommand}; use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection}; use crate::prepare_behaviour_dump_dir; -use crate::utils::cache::{Cache, Interned, INTERNER}; +use crate::utils::cache::Cache; use crate::utils::helpers::{self, add_dylib_path, add_link_lib_path, exe, linker_args}; use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, output, t, LldThreads}; use crate::EXTRA_CHECK_CFGS; @@ -102,7 +102,7 @@ impl RunConfig<'_> { /// Return a list of crate names selected by `run.paths`. #[track_caller] - pub fn cargo_crates_in_set(&self) -> Interned> { + pub fn cargo_crates_in_set(&self) -> Vec { let mut crates = Vec::new(); for krate in &self.paths { let path = krate.assert_single_path(); @@ -111,7 +111,7 @@ impl RunConfig<'_> { }; crates.push(crate_name.to_string()); } - INTERNER.intern_list(crates) + crates } /// Given an `alias` selected by the `Step` and the paths passed on the command line, @@ -120,7 +120,7 @@ impl RunConfig<'_> { /// Normally, people will pass *just* `library` if they pass it. /// But it's possible (although strange) to pass something like `library std core`. /// Build all crates anyway, as if they hadn't passed the other args. - pub fn make_run_crates(&self, alias: Alias) -> Interned> { + pub fn make_run_crates(&self, alias: Alias) -> Vec { let has_alias = self.paths.iter().any(|set| set.assert_single_path().path.ends_with(alias.as_str())); if !has_alias { @@ -133,7 +133,7 @@ impl RunConfig<'_> { }; let crate_names = crates.into_iter().map(|krate| krate.name.to_string()).collect(); - INTERNER.intern_list(crate_names) + crate_names } } @@ -1062,26 +1062,26 @@ impl<'a> Builder<'a> { } } - pub fn sysroot(&self, compiler: Compiler) -> Interned { + pub fn sysroot(&self, compiler: Compiler) -> PathBuf { self.ensure(compile::Sysroot::new(compiler)) } /// Returns the libdir where the standard library and other artifacts are /// found for a compiler's sysroot. - pub fn sysroot_libdir(&self, compiler: Compiler, target: TargetSelection) -> Interned { + pub fn sysroot_libdir(&self, compiler: Compiler, target: TargetSelection) -> PathBuf { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] struct Libdir { compiler: Compiler, target: TargetSelection, } impl Step for Libdir { - type Output = Interned; + type Output = PathBuf; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.never() } - fn run(self, builder: &Builder<'_>) -> Interned { + fn run(self, builder: &Builder<'_>) -> PathBuf { let lib = builder.sysroot_libdir_relative(self.compiler); let sysroot = builder .sysroot(self.compiler) @@ -1110,7 +1110,7 @@ impl<'a> Builder<'a> { ); } - INTERNER.intern_path(sysroot) + sysroot } } self.ensure(Libdir { compiler, target }) diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 834025c81887e..5407b7cea6629 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -263,7 +263,7 @@ pub struct Config { pub rustc_default_linker: Option, pub rust_optimize_tests: bool, pub rust_dist_src: bool, - pub rust_codegen_backends: Vec>, + pub rust_codegen_backends: Vec, pub rust_verify_llvm_ir: bool, pub rust_thin_lto_import_instr_limit: Option, pub rust_remap_debuginfo: bool, @@ -457,6 +457,8 @@ impl std::str::FromStr for RustcLto { } #[derive(Copy, Clone, Default, 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, file: Option>, @@ -579,7 +581,7 @@ pub struct Target { pub wasi_root: Option, pub qemu_rootfs: Option, pub no_std: bool, - pub codegen_backends: Option>>, + pub codegen_backends: Option>, } impl Target { @@ -1161,7 +1163,7 @@ impl Config { channel: "dev".to_string(), codegen_tests: true, rust_dist_src: true, - rust_codegen_backends: vec![INTERNER.intern_str("llvm")], + rust_codegen_backends: vec!["llvm".to_owned()], deny_warnings: true, bindir: "bin".into(), dist_include_mingw_linker: true, @@ -1680,7 +1682,7 @@ impl Config { } } - INTERNER.intern_str(s) + s.clone() }).collect(); } @@ -1867,7 +1869,7 @@ impl Config { } } - INTERNER.intern_str(s) + s.clone() }).collect()); } @@ -2254,7 +2256,7 @@ impl Config { } pub fn llvm_enabled(&self, target: TargetSelection) -> bool { - self.codegen_backends(target).contains(&INTERNER.intern_str("llvm")) + self.codegen_backends(target).contains(&"llvm".to_owned()) } pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind { @@ -2273,14 +2275,14 @@ impl Config { self.submodules.unwrap_or(rust_info.is_managed_git_subrepository()) } - pub fn codegen_backends(&self, target: TargetSelection) -> &[Interned] { + pub fn codegen_backends(&self, target: TargetSelection) -> &[String] { self.target_config .get(&target) .and_then(|cfg| cfg.codegen_backends.as_deref()) .unwrap_or(&self.rust_codegen_backends) } - pub fn default_codegen_backend(&self, target: TargetSelection) -> Option> { + pub fn default_codegen_backend(&self, target: TargetSelection) -> Option { self.codegen_backends(target).first().cloned() } diff --git a/src/bootstrap/src/core/metadata.rs b/src/bootstrap/src/core/metadata.rs index 5802082326a88..08a96407a6917 100644 --- a/src/bootstrap/src/core/metadata.rs +++ b/src/bootstrap/src/core/metadata.rs @@ -3,7 +3,6 @@ use std::process::Command; use serde_derive::Deserialize; -use crate::utils::cache::INTERNER; use crate::utils::helpers::output; use crate::{t, Build, Crate}; @@ -43,19 +42,19 @@ struct Target { pub fn build(build: &mut Build) { for package in workspace_members(build) { if package.source.is_none() { - let name = INTERNER.intern_string(package.name); + let name = package.name; let mut path = PathBuf::from(package.manifest_path); path.pop(); let deps = package .dependencies .into_iter() .filter(|dep| dep.source.is_none()) - .map(|dep| INTERNER.intern_string(dep.name)) + .map(|dep| dep.name) .collect(); let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib")); - let krate = Crate { name, deps, path, has_lib }; + let krate = Crate { name: name.clone(), deps, path, has_lib }; let relative_path = krate.local_path(build); - build.crates.insert(name, krate); + build.crates.insert(name.clone(), krate); let existing_path = build.crate_paths.insert(relative_path, name); assert!( existing_path.is_none(), diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 965d788bb8371..693bdbfa3652b 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -41,7 +41,6 @@ use crate::core::builder::Kind; use crate::core::config::{flags, LldMode}; use crate::core::config::{DryRun, Target}; use crate::core::config::{LlvmLibunwind, TargetSelection}; -use crate::utils::cache::{Interned, INTERNER}; use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, OutputMode}; use crate::utils::helpers::{self, dir_is_empty, exe, libdir, mtime, output, symlink_dir}; @@ -191,8 +190,8 @@ pub struct Build { ranlib: RefCell>, // Miscellaneous // allow bidirectional lookups: both name -> path and path -> name - crates: HashMap, Crate>, - crate_paths: HashMap>, + crates: HashMap, + crate_paths: HashMap, is_sudo: bool, ci_env: CiEnv, delayed_failures: RefCell>, @@ -204,8 +203,8 @@ pub struct Build { #[derive(Debug, Clone)] struct Crate { - name: Interned, - deps: HashSet>, + name: String, + deps: HashSet, path: PathBuf, has_lib: bool, } @@ -829,8 +828,8 @@ impl Build { } /// Output directory for some generated md crate documentation for a target (temporary) - fn md_doc_out(&self, target: TargetSelection) -> Interned { - INTERNER.intern_path(self.out.join(&*target.triple).join("md-doc")) + fn md_doc_out(&self, target: TargetSelection) -> PathBuf { + self.out.join(&*target.triple).join("md-doc") } /// Returns `true` if this is an external version of LLVM not managed by bootstrap. @@ -1538,7 +1537,7 @@ impl Build { /// "local" crates (those in the local source tree, not from a registry). fn in_tree_crates(&self, root: &str, target: Option) -> Vec<&Crate> { let mut ret = Vec::new(); - let mut list = vec![INTERNER.intern_str(root)]; + let mut list = vec![root.to_owned()]; let mut visited = HashSet::new(); while let Some(krate) = list.pop() { let krate = self @@ -1564,11 +1563,11 @@ impl Build { && (dep != "rustc_codegen_llvm" || self.config.hosts.iter().any(|host| self.config.llvm_enabled(*host))) { - list.push(*dep); + list.push(dep.clone()); } } } - ret.sort_unstable_by_key(|krate| krate.name); // reproducible order needed for tests + ret.sort_unstable_by_key(|krate| krate.name.clone()); // reproducible order needed for tests ret } diff --git a/src/bootstrap/src/utils/cache.rs b/src/bootstrap/src/utils/cache.rs index 2b86585a9d3c0..e18dcbb47bea0 100644 --- a/src/bootstrap/src/utils/cache.rs +++ b/src/bootstrap/src/utils/cache.rs @@ -194,17 +194,6 @@ impl Interner { pub fn intern_str(&self, s: &str) -> Interned { self.strs.lock().unwrap().intern_borrow(s) } - pub fn intern_string(&self, s: String) -> Interned { - self.strs.lock().unwrap().intern(s) - } - - pub fn intern_path(&self, s: PathBuf) -> Interned { - self.paths.lock().unwrap().intern(s) - } - - pub fn intern_list(&self, v: Vec) -> Interned> { - self.lists.lock().unwrap().intern(v) - } } pub static INTERNER: Lazy = Lazy::new(Interner::default);