Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1f28a2

Browse files
authoredMar 9, 2024
Rollup merge of rust-lang#121567 - Nilstrieb:less-interning, r=albertlarsan68
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.
2 parents 9d272a1 + fbb97ed commit f1f28a2

File tree

13 files changed

+128
-140
lines changed

13 files changed

+128
-140
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,
@@ -559,13 +558,13 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
559558
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
560559
}
561560

562-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
561+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
563562
struct StdLink {
564563
pub compiler: Compiler,
565564
pub target_compiler: Compiler,
566565
pub target: TargetSelection,
567566
/// Not actually used; only present to make sure the cache invalidation is correct.
568-
crates: Interned<Vec<String>>,
567+
crates: Vec<String>,
569568
/// See [`Std::force_recompile`].
570569
force_recompile: bool,
571570
}
@@ -612,7 +611,7 @@ impl Step for StdLink {
612611
});
613612
let libdir = sysroot.join(lib).join("rustlib").join(target.triple).join("lib");
614613
let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host.triple).join("lib");
615-
(INTERNER.intern_path(libdir), INTERNER.intern_path(hostdir))
614+
(libdir, hostdir)
616615
} else {
617616
let libdir = builder.sysroot_libdir(target_compiler, target);
618617
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
@@ -818,7 +817,7 @@ fn cp_rustc_component_to_ci_sysroot(
818817
}
819818
}
820819

821-
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
820+
#[derive(Debug, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)]
822821
pub struct Rustc {
823822
pub target: TargetSelection,
824823
pub compiler: Compiler,
@@ -827,7 +826,7 @@ pub struct Rustc {
827826
/// This should only be requested by the user, not used within rustbuild itself.
828827
/// Using it within rustbuild can lead to confusing situation where lints are replayed
829828
/// in two different steps.
830-
crates: Interned<Vec<String>>,
829+
crates: Vec<String>,
831830
}
832831

833832
impl Rustc {
@@ -1220,13 +1219,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12201219
}
12211220
}
12221221

1223-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1222+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12241223
struct RustcLink {
12251224
pub compiler: Compiler,
12261225
pub target_compiler: Compiler,
12271226
pub target: TargetSelection,
12281227
/// Not actually used; only present to make sure the cache invalidation is correct.
1229-
crates: Interned<Vec<String>>,
1228+
crates: Vec<String>,
12301229
}
12311230

12321231
impl RustcLink {
@@ -1261,11 +1260,11 @@ impl Step for RustcLink {
12611260
}
12621261
}
12631262

1264-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1263+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12651264
pub struct CodegenBackend {
12661265
pub target: TargetSelection,
12671266
pub compiler: Compiler,
1268-
pub backend: Interned<String>,
1267+
pub backend: String,
12691268
}
12701269

12711270
fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
@@ -1284,7 +1283,7 @@ pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
12841283
fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
12851284
if path.path.to_str().unwrap().contains(CODEGEN_BACKEND_PREFIX) {
12861285
let mut needs_codegen_backend_config = true;
1287-
for &backend in run.builder.config.codegen_backends(run.target) {
1286+
for backend in run.builder.config.codegen_backends(run.target) {
12881287
if path
12891288
.path
12901289
.to_str()
@@ -1321,15 +1320,15 @@ impl Step for CodegenBackend {
13211320
return;
13221321
}
13231322

1324-
for &backend in run.builder.config.codegen_backends(run.target) {
1323+
for backend in run.builder.config.codegen_backends(run.target) {
13251324
if backend == "llvm" {
13261325
continue; // Already built as part of rustc
13271326
}
13281327

13291328
run.builder.ensure(CodegenBackend {
13301329
target: run.target,
13311330
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
1332-
backend,
1331+
backend: backend.clone(),
13331332
});
13341333
}
13351334
}
@@ -1394,7 +1393,7 @@ impl Step for CodegenBackend {
13941393
f.display()
13951394
);
13961395
}
1397-
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
1396+
let stamp = codegen_backend_stamp(builder, compiler, target, &backend);
13981397
let codegen_backend = codegen_backend.to_str().unwrap();
13991398
t!(fs::write(stamp, codegen_backend));
14001399
}
@@ -1433,7 +1432,7 @@ fn copy_codegen_backends_to_sysroot(
14331432
continue; // Already built as part of rustc
14341433
}
14351434

1436-
let stamp = codegen_backend_stamp(builder, compiler, target, *backend);
1435+
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
14371436
let dylib = t!(fs::read_to_string(&stamp));
14381437
let file = Path::new(&dylib);
14391438
let filename = file.file_name().unwrap().to_str().unwrap();
@@ -1470,7 +1469,7 @@ fn codegen_backend_stamp(
14701469
builder: &Builder<'_>,
14711470
compiler: Compiler,
14721471
target: TargetSelection,
1473-
backend: Interned<String>,
1472+
backend: &str,
14741473
) -> PathBuf {
14751474
builder
14761475
.cargo_out(compiler, Mode::Codegen, target)
@@ -1508,7 +1507,7 @@ impl Sysroot {
15081507
}
15091508

15101509
impl Step for Sysroot {
1511-
type Output = Interned<PathBuf>;
1510+
type Output = PathBuf;
15121511

15131512
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
15141513
run.never()
@@ -1520,7 +1519,7 @@ impl Step for Sysroot {
15201519
/// That is, the sysroot for the stage0 compiler is not what the compiler
15211520
/// thinks it is by default, but it's the same as the default for stages
15221521
/// 1-3.
1523-
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
1522+
fn run(self, builder: &Builder<'_>) -> PathBuf {
15241523
let compiler = self.compiler;
15251524
let host_dir = builder.out.join(compiler.host.triple);
15261525

@@ -1652,7 +1651,7 @@ impl Step for Sysroot {
16521651
);
16531652
}
16541653

1655-
INTERNER.intern_path(sysroot)
1654+
sysroot
16561655
}
16571656
}
16581657

@@ -1735,15 +1734,15 @@ impl Step for Assemble {
17351734
// to not fail while linking the artifacts.
17361735
build_compiler.stage = actual_stage;
17371736

1738-
for &backend in builder.config.codegen_backends(target_compiler.host) {
1737+
for backend in builder.config.codegen_backends(target_compiler.host) {
17391738
if backend == "llvm" {
17401739
continue; // Already built as part of rustc
17411740
}
17421741

17431742
builder.ensure(CodegenBackend {
17441743
compiler: build_compiler,
17451744
target: target_compiler.host,
1746-
backend,
1745+
backend: backend.clone(),
17471746
});
17481747
}
17491748

‎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};
@@ -489,8 +488,7 @@ impl Step for Rustc {
489488
}
490489

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

495493
// Misc license info
496494
let cp = |file: &str| {
@@ -504,9 +502,9 @@ impl Step for Rustc {
504502
}
505503
}
506504

507-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
505+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
508506
pub struct DebuggerScripts {
509-
pub sysroot: Interned<PathBuf>,
507+
pub sysroot: PathBuf,
510508
pub host: TargetSelection,
511509
}
512510

@@ -1264,10 +1262,10 @@ impl Step for Miri {
12641262
}
12651263
}
12661264

1267-
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
1265+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
12681266
pub struct CodegenBackend {
12691267
pub compiler: Compiler,
1270-
pub backend: Interned<String>,
1268+
pub backend: String,
12711269
}
12721270

12731271
impl Step for CodegenBackend {
@@ -1280,14 +1278,14 @@ impl Step for CodegenBackend {
12801278
}
12811279

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

12881286
run.builder.ensure(CodegenBackend {
12891287
compiler: run.builder.compiler(run.builder.top_stage, run.target),
1290-
backend,
1288+
backend: backend.clone(),
12911289
});
12921290
}
12931291
}
@@ -1304,7 +1302,8 @@ impl Step for CodegenBackend {
13041302
return None;
13051303
}
13061304

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.