Skip to content

Commit

Permalink
Auto merge of rust-lang#134724 - onur-ozkan:type-improvements, r=jiey…
Browse files Browse the repository at this point in the history
…ouxu

improve type mutation for certain structures

self-explanatory
  • Loading branch information
bors committed Dec 24, 2024
2 parents 32c8a9f + 6b2fd4f commit d53b0ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 53 deletions.
26 changes: 14 additions & 12 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ pub struct Std {
}

impl Std {
pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
Self { target, crates: vec![], override_build_kind: kind }
pub fn new(target: TargetSelection) -> Self {
Self { target, crates: vec![], override_build_kind: None }
}

pub fn build_kind(mut self, kind: Option<Kind>) -> Self {
self.override_build_kind = kind;
self
}
}

Expand Down Expand Up @@ -167,20 +172,17 @@ pub struct Rustc {

impl Rustc {
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
Self::new_with_build_kind(target, builder, None)
}

pub fn new_with_build_kind(
target: TargetSelection,
builder: &Builder<'_>,
kind: Option<Kind>,
) -> Self {
let crates = builder
.in_tree_crates("rustc-main", Some(target))
.into_iter()
.map(|krate| krate.name.to_string())
.collect();
Self { target, crates, override_build_kind: kind }
Self { target, crates, override_build_kind: None }
}

pub fn build_kind(mut self, build_kind: Option<Kind>) -> Self {
self.override_build_kind = build_kind;
self
}
}

Expand Down Expand Up @@ -216,7 +218,7 @@ impl Step for Rustc {
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
} else {
builder.ensure(Std::new_with_build_kind(target, self.override_build_kind));
builder.ensure(Std::new(target).build_kind(self.override_build_kind));
}

let mut cargo = builder::Cargo::new(
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Step for Rustc {
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
} else {
builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check)));
builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check)));
}

let mut cargo = builder::Cargo::new(
Expand Down Expand Up @@ -285,7 +285,7 @@ macro_rules! lint_any {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;

builder.ensure(check::Rustc::new_with_build_kind(target, builder, Some(Kind::Check)));
builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));

let cargo = prepare_tool_cargo(
builder,
Expand Down
41 changes: 10 additions & 31 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,20 @@ impl Std {
}
}

pub fn force_recompile(compiler: Compiler, target: TargetSelection) -> Self {
Self {
target,
compiler,
crates: Default::default(),
force_recompile: true,
extra_rust_args: &[],
is_for_mir_opt_tests: false,
}
pub fn force_recompile(mut self, force_recompile: bool) -> Self {
self.force_recompile = force_recompile;
self
}

pub fn new_for_mir_opt_tests(compiler: Compiler, target: TargetSelection) -> Self {
Self {
target,
compiler,
crates: Default::default(),
force_recompile: false,
extra_rust_args: &[],
is_for_mir_opt_tests: true,
}
#[allow(clippy::wrong_self_convention)]
pub fn is_for_mir_opt_tests(mut self, is_for_mir_opt_tests: bool) -> Self {
self.is_for_mir_opt_tests = is_for_mir_opt_tests;
self
}

pub fn new_with_extra_rust_args(
compiler: Compiler,
target: TargetSelection,
extra_rust_args: &'static [&'static str],
) -> Self {
Self {
target,
compiler,
crates: Default::default(),
force_recompile: false,
extra_rust_args,
is_for_mir_opt_tests: false,
}
pub fn extra_rust_args(mut self, extra_rust_args: &'static [&'static str]) -> Self {
self.extra_rust_args = extra_rust_args;
self
}

fn copy_extra_objects(
Expand Down
16 changes: 8 additions & 8 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the

// ensure that `libproc_macro` is available on the host.
if suite == "mir-opt" {
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, compiler.host).is_for_mir_opt_tests(true));
} else {
builder.ensure(compile::Std::new(compiler, compiler.host));
}
Expand All @@ -1731,7 +1731,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let mut cmd = builder.tool_cmd(Tool::Compiletest);

if suite == "mir-opt" {
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target));
builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true));
} else {
builder.ensure(compile::Std::new(compiler, target));
}
Expand Down Expand Up @@ -2737,7 +2737,7 @@ impl Step for Crate {

// Prepare sysroot
// See [field@compile::Std::force_recompile].
builder.ensure(compile::Std::force_recompile(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, compiler.host).force_recompile(true));

// If we're not doing a full bootstrap but we're testing a stage2
// version of libstd, then what we're actually testing is the libstd
Expand Down Expand Up @@ -2781,7 +2781,7 @@ impl Step for Crate {
} else {
// Also prepare a sysroot for the target.
if builder.config.build != target {
builder.ensure(compile::Std::force_recompile(compiler, target));
builder.ensure(compile::Std::new(compiler, target).force_recompile(true));
builder.ensure(RemoteCopyLibs { compiler, target });
}

Expand Down Expand Up @@ -3557,10 +3557,10 @@ impl Step for CodegenGCC {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Std::new_with_extra_rust_args(compiler, target, &[
"-Csymbol-mangling-version=v0",
"-Cpanic=abort",
]));
builder.ensure(
compile::Std::new(compiler, target)
.extra_rust_args(&["-Csymbol-mangling-version=v0", "-Cpanic=abort"]),
);

// If we're not doing a full bootstrap but we're testing a stage2
// version of libstd, then what we're actually testing is the libstd
Expand Down

0 comments on commit d53b0ff

Please sign in to comment.