Skip to content

Commit 83bd6b7

Browse files
committed
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.
1 parent 8f359be commit 83bd6b7

File tree

12 files changed

+127
-139
lines changed

12 files changed

+127
-139
lines changed

src/bootstrap/src/core/build_steps/check.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ use crate::core::builder::{
88
self, crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step,
99
};
1010
use crate::core::config::TargetSelection;
11-
use crate::utils::cache::Interned;
12-
use crate::INTERNER;
1311
use crate::{Compiler, Mode, Subcommand};
1412
use std::path::{Path, PathBuf};
1513

16-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
14+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1715
pub struct Std {
1816
pub target: TargetSelection,
1917
/// Whether to build only a subset of crates.
2018
///
2119
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
2220
///
2321
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
24-
crates: Interned<Vec<String>>,
22+
crates: Vec<String>,
2523
}
2624

2725
/// Returns args for the subcommand itself (not for cargo)
@@ -89,7 +87,7 @@ fn cargo_subcommand(kind: Kind) -> &'static str {
8987

9088
impl Std {
9189
pub fn new(target: TargetSelection) -> Self {
92-
Self { target, crates: INTERNER.intern_list(vec![]) }
90+
Self { target, crates: vec![] }
9391
}
9492
}
9593

@@ -204,15 +202,15 @@ impl Step for Std {
204202
}
205203
}
206204

207-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
208206
pub struct Rustc {
209207
pub target: TargetSelection,
210208
/// Whether to build only a subset of crates.
211209
///
212210
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
213211
///
214212
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
215-
crates: Interned<Vec<String>>,
213+
crates: Vec<String>,
216214
}
217215

218216
impl Rustc {
@@ -222,7 +220,7 @@ impl Rustc {
222220
.into_iter()
223221
.map(|krate| krate.name.to_string())
224222
.collect();
225-
Self { target, crates: INTERNER.intern_list(crates) }
223+
Self { target, crates }
226224
}
227225
}
228226

@@ -305,10 +303,10 @@ impl Step for Rustc {
305303
}
306304
}
307305

308-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
306+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
309307
pub struct CodegenBackend {
310308
pub target: TargetSelection,
311-
pub backend: Interned<String>,
309+
pub backend: &'static str,
312310
}
313311

314312
impl Step for CodegenBackend {
@@ -321,14 +319,14 @@ impl Step for CodegenBackend {
321319
}
322320

323321
fn make_run(run: RunConfig<'_>) {
324-
for &backend in &[INTERNER.intern_str("cranelift"), INTERNER.intern_str("gcc")] {
322+
for &backend in &["cranelift", "gcc"] {
325323
run.builder.ensure(CodegenBackend { target: run.target, backend });
326324
}
327325
}
328326

329327
fn run(self, builder: &Builder<'_>) {
330328
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
331-
if builder.build.config.vendor && &self.backend == "gcc" {
329+
if builder.build.config.vendor && self.backend == "gcc" {
332330
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
333331
return;
334332
}
@@ -552,7 +550,7 @@ fn codegen_backend_stamp(
552550
builder: &Builder<'_>,
553551
compiler: Compiler,
554552
target: TargetSelection,
555-
backend: Interned<String>,
553+
backend: &str,
556554
) -> PathBuf {
557555
builder
558556
.cargo_out(compiler, Mode::Codegen, target)

src/bootstrap/src/core/build_steps/clean.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

1212
use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
13-
use crate::utils::cache::Interned;
1413
use crate::utils::helpers::t;
1514
use crate::{Build, Compiler, Mode, Subcommand};
1615

@@ -44,10 +43,10 @@ impl Step for CleanAll {
4443

4544
macro_rules! clean_crate_tree {
4645
( $( $name:ident, $mode:path, $root_crate:literal);+ $(;)? ) => { $(
47-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
46+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4847
pub struct $name {
4948
compiler: Compiler,
50-
crates: Interned<Vec<String>>,
49+
crates: Vec<String>,
5150
}
5251

5352
impl Step for $name {

src/bootstrap/src/core/build_steps/compile.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ use crate::core::builder::crate_description;
2727
use crate::core::builder::Cargo;
2828
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
2929
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
30-
use crate::utils::cache::{Interned, INTERNER};
3130
use crate::utils::helpers::{
3231
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date,
3332
};
3433
use crate::LLVM_TOOLS;
3534
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
3635
use filetime::FileTime;
3736

38-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
37+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3938
pub struct Std {
4039
pub target: TargetSelection,
4140
pub compiler: Compiler,
4241
/// Whether to build only a subset of crates in the standard library.
4342
///
4443
/// This shouldn't be used from other steps; see the comment on [`Rustc`].
45-
crates: Interned<Vec<String>>,
44+
crates: Vec<String>,
4645
/// When using download-rustc, we need to use a new build of `std` for running unit tests of Std itself,
4746
/// 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.
4847
force_recompile: bool,
@@ -556,13 +555,13 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
556555
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
557556
}
558557

559-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
558+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
560559
struct StdLink {
561560
pub compiler: Compiler,
562561
pub target_compiler: Compiler,
563562
pub target: TargetSelection,
564563
/// Not actually used; only present to make sure the cache invalidation is correct.
565-
crates: Interned<Vec<String>>,
564+
crates: Vec<String>,
566565
/// See [`Std::force_recompile`].
567566
force_recompile: bool,
568567
}
@@ -609,7 +608,7 @@ impl Step for StdLink {
609608
});
610609
let libdir = sysroot.join(lib).join("rustlib").join(target.triple).join("lib");
611610
let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host.triple).join("lib");
612-
(INTERNER.intern_path(libdir), INTERNER.intern_path(hostdir))
611+
(libdir, hostdir)
613612
} else {
614613
let libdir = builder.sysroot_libdir(target_compiler, target);
615614
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
@@ -815,7 +814,7 @@ fn cp_rustc_component_to_ci_sysroot(
815814
}
816815
}
817816

818-
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
817+
#[derive(Debug, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)]
819818
pub struct Rustc {
820819
pub target: TargetSelection,
821820
pub compiler: Compiler,
@@ -824,7 +823,7 @@ pub struct Rustc {
824823
/// This should only be requested by the user, not used within rustbuild itself.
825824
/// Using it within rustbuild can lead to confusing situation where lints are replayed
826825
/// in two different steps.
827-
crates: Interned<Vec<String>>,
826+
crates: Vec<String>,
828827
}
829828

830829
impl Rustc {
@@ -1217,13 +1216,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12171216
}
12181217
}
12191218

1220-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1219+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12211220
struct RustcLink {
12221221
pub compiler: Compiler,
12231222
pub target_compiler: Compiler,
12241223
pub target: TargetSelection,
12251224
/// Not actually used; only present to make sure the cache invalidation is correct.
1226-
crates: Interned<Vec<String>>,
1225+
crates: Vec<String>,
12271226
}
12281227

12291228
impl RustcLink {
@@ -1258,11 +1257,11 @@ impl Step for RustcLink {
12581257
}
12591258
}
12601259

1261-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1260+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12621261
pub struct CodegenBackend {
12631262
pub target: TargetSelection,
12641263
pub compiler: Compiler,
1265-
pub backend: Interned<String>,
1264+
pub backend: String,
12661265
}
12671266

12681267
fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
@@ -1281,7 +1280,7 @@ pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
12811280
fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
12821281
if path.path.to_str().unwrap().contains(CODEGEN_BACKEND_PREFIX) {
12831282
let mut needs_codegen_backend_config = true;
1284-
for &backend in run.builder.config.codegen_backends(run.target) {
1283+
for backend in run.builder.config.codegen_backends(run.target) {
12851284
if path
12861285
.path
12871286
.to_str()
@@ -1318,15 +1317,15 @@ impl Step for CodegenBackend {
13181317
return;
13191318
}
13201319

1321-
for &backend in run.builder.config.codegen_backends(run.target) {
1320+
for backend in run.builder.config.codegen_backends(run.target) {
13221321
if backend == "llvm" {
13231322
continue; // Already built as part of rustc
13241323
}
13251324

13261325
run.builder.ensure(CodegenBackend {
13271326
target: run.target,
13281327
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
1329-
backend,
1328+
backend: backend.clone(),
13301329
});
13311330
}
13321331
}
@@ -1391,7 +1390,7 @@ impl Step for CodegenBackend {
13911390
f.display()
13921391
);
13931392
}
1394-
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
1393+
let stamp = codegen_backend_stamp(builder, compiler, target, &backend);
13951394
let codegen_backend = codegen_backend.to_str().unwrap();
13961395
t!(fs::write(stamp, codegen_backend));
13971396
}
@@ -1430,7 +1429,7 @@ fn copy_codegen_backends_to_sysroot(
14301429
continue; // Already built as part of rustc
14311430
}
14321431

1433-
let stamp = codegen_backend_stamp(builder, compiler, target, *backend);
1432+
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
14341433
let dylib = t!(fs::read_to_string(&stamp));
14351434
let file = Path::new(&dylib);
14361435
let filename = file.file_name().unwrap().to_str().unwrap();
@@ -1467,7 +1466,7 @@ fn codegen_backend_stamp(
14671466
builder: &Builder<'_>,
14681467
compiler: Compiler,
14691468
target: TargetSelection,
1470-
backend: Interned<String>,
1469+
backend: &str,
14711470
) -> PathBuf {
14721471
builder
14731472
.cargo_out(compiler, Mode::Codegen, target)
@@ -1505,7 +1504,7 @@ impl Sysroot {
15051504
}
15061505

15071506
impl Step for Sysroot {
1508-
type Output = Interned<PathBuf>;
1507+
type Output = PathBuf;
15091508

15101509
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
15111510
run.never()
@@ -1517,7 +1516,7 @@ impl Step for Sysroot {
15171516
/// That is, the sysroot for the stage0 compiler is not what the compiler
15181517
/// thinks it is by default, but it's the same as the default for stages
15191518
/// 1-3.
1520-
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
1519+
fn run(self, builder: &Builder<'_>) -> PathBuf {
15211520
let compiler = self.compiler;
15221521
let host_dir = builder.out.join(compiler.host.triple);
15231522

@@ -1649,7 +1648,7 @@ impl Step for Sysroot {
16491648
);
16501649
}
16511650

1652-
INTERNER.intern_path(sysroot)
1651+
sysroot
16531652
}
16541653
}
16551654

@@ -1732,15 +1731,15 @@ impl Step for Assemble {
17321731
// to not fail while linking the artifacts.
17331732
build_compiler.stage = actual_stage;
17341733

1735-
for &backend in builder.config.codegen_backends(target_compiler.host) {
1734+
for backend in builder.config.codegen_backends(target_compiler.host) {
17361735
if backend == "llvm" {
17371736
continue; // Already built as part of rustc
17381737
}
17391738

17401739
builder.ensure(CodegenBackend {
17411740
compiler: build_compiler,
17421741
target: target_compiler.host,
1743-
backend,
1742+
backend: backend.clone(),
17441743
});
17451744
}
17461745

src/bootstrap/src/core/build_steps/dist.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::core::build_steps::llvm;
2525
use crate::core::build_steps::tool::{self, Tool};
2626
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2727
use crate::core::config::TargetSelection;
28-
use crate::utils::cache::{Interned, INTERNER};
2928
use crate::utils::channel;
3029
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
3130
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
@@ -488,8 +487,7 @@ impl Step for Rustc {
488487
}
489488

490489
// Debugger scripts
491-
builder
492-
.ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host });
490+
builder.ensure(DebuggerScripts { sysroot: image.to_owned(), host });
493491

494492
// Misc license info
495493
let cp = |file: &str| {
@@ -503,9 +501,9 @@ impl Step for Rustc {
503501
}
504502
}
505503

506-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
504+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
507505
pub struct DebuggerScripts {
508-
pub sysroot: Interned<PathBuf>,
506+
pub sysroot: PathBuf,
509507
pub host: TargetSelection,
510508
}
511509

@@ -1263,10 +1261,10 @@ impl Step for Miri {
12631261
}
12641262
}
12651263

1266-
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1264+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
12671265
pub struct CodegenBackend {
12681266
pub compiler: Compiler,
1269-
pub backend: Interned<String>,
1267+
pub backend: String,
12701268
}
12711269

12721270
impl Step for CodegenBackend {
@@ -1279,14 +1277,14 @@ impl Step for CodegenBackend {
12791277
}
12801278

12811279
fn make_run(run: RunConfig<'_>) {
1282-
for &backend in run.builder.config.codegen_backends(run.target) {
1280+
for backend in run.builder.config.codegen_backends(run.target) {
12831281
if backend == "llvm" {
12841282
continue; // Already built as part of rustc
12851283
}
12861284

12871285
run.builder.ensure(CodegenBackend {
12881286
compiler: run.builder.compiler(run.builder.top_stage, run.target),
1289-
backend,
1287+
backend: backend.clone(),
12901288
});
12911289
}
12921290
}
@@ -1303,7 +1301,8 @@ impl Step for CodegenBackend {
13031301
return None;
13041302
}
13051303

1306-
if !builder.config.codegen_backends(self.compiler.host).contains(&self.backend) {
1304+
if !builder.config.codegen_backends(self.compiler.host).contains(&self.backend.to_string())
1305+
{
13071306
return None;
13081307
}
13091308

@@ -1528,7 +1527,7 @@ impl Step for Extended {
15281527
add_component!("analysis" => Analysis { compiler, target });
15291528
add_component!("rustc-codegen-cranelift" => CodegenBackend {
15301529
compiler: builder.compiler(stage, target),
1531-
backend: INTERNER.intern_str("cranelift"),
1530+
backend: "cranelift".to_string(),
15321531
});
15331532

15341533
let etc = builder.src.join("src/etc/installer");

0 commit comments

Comments
 (0)