Skip to content

Commit 20c909f

Browse files
committed
Auto merge of #132401 - matthiaskrgr:rollup-599ieqr, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #130693 (Add `minicore` test auxiliary and support `//@ add-core-stubs` directive in ui/assembly/codegen tests) - #132316 (CI: use free runners for 3 fast windows jobs) - #132354 (Add `lp64e` RISC-V ABI) - #132395 (coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable) - #132396 (CI: use free runners for x86_64-gnu-tools and x86_64-rust-for-linux) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9ccfedf + c9584b7 commit 20c909f

File tree

19 files changed

+283
-96
lines changed

19 files changed

+283
-96
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
554554

555555
/// Extra state that is only available when coverage instrumentation is enabled.
556556
#[inline]
557+
#[track_caller]
557558
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
558559
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
559560
}

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
5454
add_unused_functions(cx);
5555
}
5656

57-
let function_coverage_map = cx.coverage_cx().take_function_coverage_map();
57+
// FIXME(#132395): Can this be none even when coverage is enabled?
58+
let function_coverage_map = match cx.coverage_cx {
59+
Some(ref cx) => cx.take_function_coverage_map(),
60+
None => return,
61+
};
5862
if function_coverage_map.is_empty() {
5963
// This module has no functions with coverage instrumentation
6064
return;

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
152152
return;
153153
};
154154

155-
let mut coverage_map = bx.coverage_cx().function_coverage_map.borrow_mut();
155+
// FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
156+
// wild, so keep this early-return until we understand why.
157+
let mut coverage_map = match bx.coverage_cx {
158+
Some(ref cx) => cx.function_coverage_map.borrow_mut(),
159+
None => return,
160+
};
156161
let func_coverage = coverage_map
157162
.entry(instance)
158163
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));

compiler/rustc_codegen_ssa/src/back/metadata.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
325325
"" | "ilp32" | "lp64" => (),
326326
"ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
327327
"ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
328-
"ilp32e" => e_flags |= elf::EF_RISCV_RVE,
328+
// Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI.
329+
"ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE,
329330
_ => bug!("unknown RISC-V ABI name"),
330331
}
331332

compiler/rustc_target/src/spec/tests/tests_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ impl Target {
165165
assert_matches!(&*self.llvm_abiname, "ilp32" | "ilp32f" | "ilp32d" | "ilp32e")
166166
}
167167
"riscv64" => {
168-
assert_matches!(&*self.llvm_abiname, "lp64" | "lp64f" | "lp64d" | "lp64q")
168+
// Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI.
169+
assert_matches!(&*self.llvm_abiname, "lp64" | "lp64f" | "lp64d" | "lp64q" | "lp64e")
169170
}
170171
_ => {}
171172
}

src/bootstrap/src/core/build_steps/test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17251725
cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
17261726
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
17271727

1728+
// Minicore auxiliary lib for `no_core` tests that need `core` stubs in cross-compilation
1729+
// scenarios.
1730+
cmd.arg("--minicore-path")
1731+
.arg(builder.src.join("tests").join("auxiliary").join("minicore.rs"));
1732+
17281733
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
17291734

17301735
if mode == "run-make" {

src/ci/github-actions/jobs.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ auto:
232232
# Tests integration with Rust for Linux.
233233
# Builds stage 1 compiler and tries to compile a few RfL examples with it.
234234
- image: x86_64-rust-for-linux
235-
<<: *job-linux-8c
235+
<<: *job-linux-4c
236236

237237
- image: x86_64-gnu
238238
<<: *job-linux-4c
@@ -280,7 +280,7 @@ auto:
280280
- image: x86_64-gnu-tools
281281
env:
282282
DEPLOY_TOOLSTATES_JSON: toolstates-linux.json
283-
<<: *job-linux-8c
283+
<<: *job-linux-4c
284284

285285
####################
286286
# macOS Builders #
@@ -488,7 +488,7 @@ auto:
488488
SCRIPT: python x.py dist bootstrap --include-default-paths
489489
DIST_REQUIRE_ALL_TOOLS: 1
490490
CODEGEN_BACKENDS: llvm,cranelift
491-
<<: *job-windows-8c
491+
<<: *job-windows
492492

493493
- image: dist-x86_64-mingw
494494
env:
@@ -501,10 +501,10 @@ auto:
501501
NO_DOWNLOAD_CI_LLVM: 1
502502
DIST_REQUIRE_ALL_TOOLS: 1
503503
CODEGEN_BACKENDS: llvm,cranelift
504-
<<: *job-windows-8c
504+
<<: *job-windows
505505

506506
- image: dist-x86_64-msvc-alt
507507
env:
508508
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler
509509
SCRIPT: python x.py dist bootstrap --include-default-paths
510-
<<: *job-windows-8c
510+
<<: *job-windows

src/tools/compiletest/src/common.rs

+5
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ pub struct Config {
392392

393393
/// Command for visual diff display, e.g. `diff-tool --color=always`.
394394
pub diff_command: Option<String>,
395+
396+
/// Path to minicore aux library, used for `no_core` tests that need `core` stubs in
397+
/// cross-compilation scenarios that do not otherwise want/need to `-Zbuild-std`. Used in e.g.
398+
/// ABI tests.
399+
pub minicore_path: PathBuf,
395400
}
396401

397402
impl Config {

src/tools/compiletest/src/directive-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// a best-effort approximation for diagnostics. Add new headers to this list when needed.
44
const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
55
// tidy-alphabetical-start
6+
"add-core-stubs",
67
"assembly-output",
78
"aux-bin",
89
"aux-build",

src/tools/compiletest/src/header.rs

+28
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ pub struct TestProps {
198198
pub no_auto_check_cfg: bool,
199199
/// Run tests which require enzyme being build
200200
pub has_enzyme: bool,
201+
/// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios
202+
/// that don't otherwise want/need `-Z build-std`.
203+
pub add_core_stubs: bool,
201204
}
202205

203206
mod directives {
@@ -243,6 +246,7 @@ mod directives {
243246
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
244247
pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
245248
pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg";
249+
pub const ADD_CORE_STUBS: &'static str = "add-core-stubs";
246250
// This isn't a real directive, just one that is probably mistyped often
247251
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
248252
}
@@ -300,6 +304,7 @@ impl TestProps {
300304
filecheck_flags: vec![],
301305
no_auto_check_cfg: false,
302306
has_enzyme: false,
307+
add_core_stubs: false,
303308
}
304309
}
305310

@@ -564,6 +569,8 @@ impl TestProps {
564569
}
565570

566571
config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
572+
573+
self.update_add_core_stubs(ln, config);
567574
},
568575
);
569576

@@ -677,6 +684,27 @@ impl TestProps {
677684
pub fn local_pass_mode(&self) -> Option<PassMode> {
678685
self.pass_mode
679686
}
687+
688+
pub fn update_add_core_stubs(&mut self, ln: &str, config: &Config) {
689+
let add_core_stubs = config.parse_name_directive(ln, directives::ADD_CORE_STUBS);
690+
if add_core_stubs {
691+
if !matches!(config.mode, Mode::Ui | Mode::Codegen | Mode::Assembly) {
692+
panic!(
693+
"`add-core-stubs` is currently only supported for ui, codegen and assembly test modes"
694+
);
695+
}
696+
697+
// FIXME(jieyouxu): this check is currently order-dependent, but we should probably
698+
// collect all directives in one go then perform a validation pass after that.
699+
if self.local_pass_mode().is_some_and(|pm| pm == PassMode::Run) {
700+
// `minicore` can only be used with non-run modes, because it's `core` prelude stubs
701+
// and can't run.
702+
panic!("`add-core-stubs` cannot be used to run the test binary");
703+
}
704+
705+
self.add_core_stubs = add_core_stubs;
706+
}
707+
}
680708
}
681709

682710
/// If the given line begins with the appropriate comment prefix for a directive,

src/tools/compiletest/src/header/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl ConfigBuilder {
152152
"--git-repository=",
153153
"--nightly-branch=",
154154
"--git-merge-commit-email=",
155+
"--minicore-path=",
155156
];
156157
let mut args: Vec<String> = args.iter().map(ToString::to_string).collect();
157158

src/tools/compiletest/src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
181181
"compiletest-diff-tool",
182182
"What custom diff tool to use for displaying compiletest tests.",
183183
"COMMAND",
184-
);
184+
)
185+
.reqopt("", "minicore-path", "path to minicore aux library", "PATH");
185186

186187
let (argv0, args_) = args.split_first().unwrap();
187188
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -371,7 +372,10 @@ pub fn parse_config(args: Vec<String>) -> Config {
371372
git_merge_commit_email: matches.opt_str("git-merge-commit-email").unwrap(),
372373

373374
profiler_runtime: matches.opt_present("profiler-runtime"),
375+
374376
diff_command: matches.opt_str("compiletest-diff-tool"),
377+
378+
minicore_path: opt_path(matches, "minicore-path"),
375379
}
376380
}
377381

@@ -409,6 +413,7 @@ pub fn log_config(config: &Config) {
409413
logv(c, format!("host-linker: {:?}", config.host_linker));
410414
logv(c, format!("verbose: {}", config.verbose));
411415
logv(c, format!("format: {:?}", config.format));
416+
logv(c, format!("minicore_path: {:?}", config.minicore_path.display()));
412417
logv(c, "\n".to_string());
413418
}
414419

@@ -885,6 +890,12 @@ fn files_related_to_test(
885890
related.push(path);
886891
}
887892

893+
// `minicore.rs` test auxiliary: we need to make sure tests get rerun if this changes.
894+
//
895+
// FIXME(jieyouxu): untangle these paths, we should provide both a path to root `tests/` or
896+
// `tests/auxiliary/` and the test suite in question. `src_base` is also a terrible name.
897+
related.push(config.src_base.parent().unwrap().join("auxiliary").join("minicore.rs"));
898+
888899
related
889900
}
890901

src/tools/compiletest/src/runtest.rs

+48-30
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,20 @@ impl<'test> TestCx<'test> {
11501150
}
11511151
}
11521152

1153-
/// `root_testpaths` refers to the path of the original test.
1154-
/// the auxiliary and the test with an aux-build have the same `root_testpaths`.
1153+
/// `root_testpaths` refers to the path of the original test. the auxiliary and the test with an
1154+
/// aux-build have the same `root_testpaths`.
11551155
fn compose_and_run_compiler(
11561156
&self,
11571157
mut rustc: Command,
11581158
input: Option<String>,
11591159
root_testpaths: &TestPaths,
11601160
) -> ProcRes {
1161+
if self.props.add_core_stubs {
1162+
let minicore_path = self.build_minicore();
1163+
rustc.arg("--extern");
1164+
rustc.arg(&format!("minicore={}", minicore_path.to_str().unwrap()));
1165+
}
1166+
11611167
let aux_dir = self.aux_output_dir();
11621168
self.build_all_auxiliary(root_testpaths, &aux_dir, &mut rustc);
11631169

@@ -1171,6 +1177,37 @@ impl<'test> TestCx<'test> {
11711177
)
11721178
}
11731179

1180+
/// Builds `minicore`. Returns the path to the minicore rlib within the base test output
1181+
/// directory.
1182+
fn build_minicore(&self) -> PathBuf {
1183+
let output_file_path = self.output_base_dir().join("libminicore.rlib");
1184+
let mut rustc = self.make_compile_args(
1185+
&self.config.minicore_path,
1186+
TargetLocation::ThisFile(output_file_path.clone()),
1187+
Emit::None,
1188+
AllowUnused::Yes,
1189+
LinkToAux::No,
1190+
vec![],
1191+
);
1192+
1193+
rustc.args(&["--crate-type", "rlib"]);
1194+
rustc.arg("-Cpanic=abort");
1195+
1196+
let res =
1197+
self.compose_and_run(rustc, self.config.compile_lib_path.to_str().unwrap(), None, None);
1198+
if !res.status.success() {
1199+
self.fatal_proc_rec(
1200+
&format!(
1201+
"auxiliary build of {:?} failed to compile: ",
1202+
self.config.minicore_path.display()
1203+
),
1204+
&res,
1205+
);
1206+
}
1207+
1208+
output_file_path
1209+
}
1210+
11741211
/// Builds an aux dependency.
11751212
fn build_auxiliary(
11761213
&self,
@@ -1662,6 +1699,15 @@ impl<'test> TestCx<'test> {
16621699

16631700
rustc.args(&self.props.compile_flags);
16641701

1702+
// FIXME(jieyouxu): we should report a fatal error or warning if user wrote `-Cpanic=` with
1703+
// something that's not `abort`, however, by moving this last we should override previous
1704+
// `-Cpanic=`s
1705+
//
1706+
// `minicore` requires `#![no_std]` and `#![no_core]`, which means no unwinding panics.
1707+
if self.props.add_core_stubs {
1708+
rustc.arg("-Cpanic=abort");
1709+
}
1710+
16651711
rustc
16661712
}
16671713

@@ -1848,34 +1894,6 @@ impl<'test> TestCx<'test> {
18481894
(proc_res, output_path)
18491895
}
18501896

1851-
fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
1852-
// This works with both `--emit asm` (as default output name for the assembly)
1853-
// and `ptx-linker` because the latter can write output at requested location.
1854-
let output_path = self.output_base_name().with_extension("s");
1855-
let input_file = &self.testpaths.file;
1856-
1857-
// Use the `//@ assembly-output:` directive to determine how to emit assembly.
1858-
let emit = match self.props.assembly_output.as_deref() {
1859-
Some("emit-asm") => Emit::Asm,
1860-
Some("bpf-linker") => Emit::LinkArgsAsm,
1861-
Some("ptx-linker") => Emit::None, // No extra flags needed.
1862-
Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")),
1863-
None => self.fatal("missing 'assembly-output' directive"),
1864-
};
1865-
1866-
let rustc = self.make_compile_args(
1867-
input_file,
1868-
TargetLocation::ThisFile(output_path.clone()),
1869-
emit,
1870-
AllowUnused::No,
1871-
LinkToAux::Yes,
1872-
Vec::new(),
1873-
);
1874-
1875-
let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
1876-
(proc_res, output_path)
1877-
}
1878-
18791897
fn verify_with_filecheck(&self, output: &Path) -> ProcRes {
18801898
let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap());
18811899
filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file);

src/tools/compiletest/src/runtest/assembly.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use super::TestCx;
1+
use std::path::PathBuf;
2+
3+
use super::{AllowUnused, Emit, LinkToAux, ProcRes, TargetLocation, TestCx};
24

35
impl TestCx<'_> {
46
pub(super) fn run_assembly_test(&self) {
@@ -16,4 +18,32 @@ impl TestCx<'_> {
1618
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
1719
}
1820
}
21+
22+
fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
23+
// This works with both `--emit asm` (as default output name for the assembly)
24+
// and `ptx-linker` because the latter can write output at requested location.
25+
let output_path = self.output_base_name().with_extension("s");
26+
let input_file = &self.testpaths.file;
27+
28+
// Use the `//@ assembly-output:` directive to determine how to emit assembly.
29+
let emit = match self.props.assembly_output.as_deref() {
30+
Some("emit-asm") => Emit::Asm,
31+
Some("bpf-linker") => Emit::LinkArgsAsm,
32+
Some("ptx-linker") => Emit::None, // No extra flags needed.
33+
Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")),
34+
None => self.fatal("missing 'assembly-output' directive"),
35+
};
36+
37+
let rustc = self.make_compile_args(
38+
input_file,
39+
TargetLocation::ThisFile(output_path.clone()),
40+
emit,
41+
AllowUnused::No,
42+
LinkToAux::Yes,
43+
Vec::new(),
44+
);
45+
46+
let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
47+
(proc_res, output_path)
48+
}
1949
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! `compiletest` self-test to check that `add-core-stubs` is incompatible with run pass modes.
2+
3+
//@ add-core-stubs
4+
//@ run-pass
5+
//@ should-fail

0 commit comments

Comments
 (0)