From 167350d3e99f8f430949116b1e7bcdb38f9ba26c Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Wed, 30 Oct 2024 11:28:37 +0000 Subject: [PATCH 01/16] Add `lp64e` RISC-V ABI --- compiler/rustc_codegen_ssa/src/back/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 8857fda1e9728..49365ace0e20c 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -325,7 +325,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option (), "ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE, "ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE, - "ilp32e" => e_flags |= elf::EF_RISCV_RVE, + "ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE, _ => bug!("unknown RISC-V ABI name"), } From 44b720a2d4d62c3d577b032f8a1d9241f1b94695 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Thu, 31 Oct 2024 07:36:42 +0000 Subject: [PATCH 02/16] Add a comment about `lp64e` still being unstable --- compiler/rustc_codegen_ssa/src/back/metadata.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 49365ace0e20c..4c25c85569b5d 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -325,6 +325,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option (), "ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE, "ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE, + // Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI. "ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE, _ => bug!("unknown RISC-V ABI name"), } From c1db011ccbf23de68505655b2eb0a05c37aad90d Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Thu, 31 Oct 2024 07:37:25 +0000 Subject: [PATCH 03/16] Add `lp64e` ABI to the spec tests match --- compiler/rustc_target/src/spec/tests/tests_impl.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index cc5931be860b3..bd47d12ef9ff7 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -165,7 +165,8 @@ impl Target { assert_matches!(&*self.llvm_abiname, "ilp32" | "ilp32f" | "ilp32d" | "ilp32e") } "riscv64" => { - assert_matches!(&*self.llvm_abiname, "lp64" | "lp64f" | "lp64d" | "lp64q") + // Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI. + assert_matches!(&*self.llvm_abiname, "lp64" | "lp64f" | "lp64d" | "lp64q" | "lp64e") } _ => {} } From 183599fa9943acc7730f75cc7919cbda1ab96d8a Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:38:42 +0100 Subject: [PATCH 04/16] CI: use free runners for 3 fast windows jobs --- src/ci/github-actions/jobs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index a401092a3a73f..4ad8e9ae9a904 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -488,7 +488,7 @@ auto: SCRIPT: python x.py dist bootstrap --include-default-paths DIST_REQUIRE_ALL_TOOLS: 1 CODEGEN_BACKENDS: llvm,cranelift - <<: *job-windows-8c + <<: *job-windows - image: dist-x86_64-mingw env: @@ -501,10 +501,10 @@ auto: NO_DOWNLOAD_CI_LLVM: 1 DIST_REQUIRE_ALL_TOOLS: 1 CODEGEN_BACKENDS: llvm,cranelift - <<: *job-windows-8c + <<: *job-windows - image: dist-x86_64-msvc-alt env: RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler SCRIPT: python x.py dist bootstrap --include-default-paths - <<: *job-windows-8c + <<: *job-windows From 82c2e42894a7ed5697b7152fdab754d08edd4552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Sun, 22 Sep 2024 06:37:55 +0000 Subject: [PATCH 05/16] minicore: add minimal minicore test auxiliary The initial `minicore` is intentionally super minimal and contains an incomplete subset of `core` items, and explicitly not items from `alloc` or `std`-only items. --- tests/auxiliary/minicore.rs | 77 +++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/auxiliary/minicore.rs diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs new file mode 100644 index 0000000000000..eccd170ff9830 --- /dev/null +++ b/tests/auxiliary/minicore.rs @@ -0,0 +1,77 @@ +//! Auxiliary `minicore` prelude which stubs out `core` items for `no_core` tests that need to work +//! in cross-compilation scenarios where no `core` is available (that don't want nor need to +//! `-Zbuild-std`). +//! +//! # Important notes +//! +//! - `minicore` is **only** intended for `core` items, and the stubs should match the actual `core` +//! items. +//! +//! # References +//! +//! This is partially adapted from `rustc_codegen_cranelift`: +//! . +// ignore-tidy-linelength + +#![feature(no_core, lang_items, rustc_attrs)] +#![allow(unused, improper_ctypes_definitions, internal_features)] +#![no_std] +#![no_core] + +#[lang = "sized"] +pub trait Sized {} + +#[lang = "receiver"] +pub trait Receiver {} +impl Receiver for &T {} +impl Receiver for &mut T {} + +#[lang = "copy"] +pub trait Copy {} + +impl Copy for bool {} +impl Copy for u8 {} +impl Copy for u16 {} +impl Copy for u32 {} +impl Copy for u64 {} +impl Copy for u128 {} +impl Copy for usize {} +impl Copy for i8 {} +impl Copy for i16 {} +impl Copy for i32 {} +impl Copy for isize {} +impl Copy for f32 {} +impl Copy for f64 {} +impl Copy for char {} +impl<'a, T: ?Sized> Copy for &'a T {} +impl Copy for *const T {} +impl Copy for *mut T {} + +#[lang = "phantom_data"] +pub struct PhantomData; +impl Copy for PhantomData {} + +pub enum Option { + None, + Some(T), +} +impl Copy for Option {} + +pub enum Result { + Ok(T), + Err(E), +} +impl Copy for Result {} + +#[lang = "manually_drop"] +#[repr(transparent)] +pub struct ManuallyDrop { + value: T, +} +impl Copy for ManuallyDrop {} + +#[lang = "unsafe_cell"] +#[repr(transparent)] +pub struct UnsafeCell { + value: T, +} From f9ca4201f82c31e3325887717a7e8bc0e2004dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Sun, 22 Sep 2024 07:57:35 +0000 Subject: [PATCH 06/16] bootstrap: pass minicore path when running compiletest step --- src/bootstrap/src/core/build_steps/test.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 2ad1b39a87c83..0a290a697e617 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1725,6 +1725,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target)); cmd.arg("--rustc-path").arg(builder.rustc(compiler)); + // Minicore auxiliary lib for `no_core` tests that need `core` stubs in cross-compilation + // scenarios. + cmd.arg("--minicore-path") + .arg(builder.src.join("tests").join("auxiliary").join("minicore.rs")); + let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); if mode == "run-make" { From 74c0c48858c92fa32b715faff1848f957277c4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:56:22 +0800 Subject: [PATCH 07/16] compiletest: localize `compile_test_and_save_assembly` to assembly test module --- src/tools/compiletest/src/runtest.rs | 28 ---------------- src/tools/compiletest/src/runtest/assembly.rs | 32 ++++++++++++++++++- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index a8a71c196fc02..fff4f2df5954d 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1848,34 +1848,6 @@ impl<'test> TestCx<'test> { (proc_res, output_path) } - fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) { - // This works with both `--emit asm` (as default output name for the assembly) - // and `ptx-linker` because the latter can write output at requested location. - let output_path = self.output_base_name().with_extension("s"); - let input_file = &self.testpaths.file; - - // Use the `//@ assembly-output:` directive to determine how to emit assembly. - let emit = match self.props.assembly_output.as_deref() { - Some("emit-asm") => Emit::Asm, - Some("bpf-linker") => Emit::LinkArgsAsm, - Some("ptx-linker") => Emit::None, // No extra flags needed. - Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")), - None => self.fatal("missing 'assembly-output' directive"), - }; - - let rustc = self.make_compile_args( - input_file, - TargetLocation::ThisFile(output_path.clone()), - emit, - AllowUnused::No, - LinkToAux::Yes, - Vec::new(), - ); - - let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths); - (proc_res, output_path) - } - fn verify_with_filecheck(&self, output: &Path) -> ProcRes { let mut filecheck = Command::new(self.config.llvm_filecheck.as_ref().unwrap()); filecheck.arg("--input-file").arg(output).arg(&self.testpaths.file); diff --git a/src/tools/compiletest/src/runtest/assembly.rs b/src/tools/compiletest/src/runtest/assembly.rs index 430a5534da1fd..89d7de58c203c 100644 --- a/src/tools/compiletest/src/runtest/assembly.rs +++ b/src/tools/compiletest/src/runtest/assembly.rs @@ -1,4 +1,6 @@ -use super::TestCx; +use std::path::PathBuf; + +use super::{AllowUnused, Emit, LinkToAux, ProcRes, TargetLocation, TestCx}; impl TestCx<'_> { pub(super) fn run_assembly_test(&self) { @@ -16,4 +18,32 @@ impl TestCx<'_> { self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res); } } + + fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) { + // This works with both `--emit asm` (as default output name for the assembly) + // and `ptx-linker` because the latter can write output at requested location. + let output_path = self.output_base_name().with_extension("s"); + let input_file = &self.testpaths.file; + + // Use the `//@ assembly-output:` directive to determine how to emit assembly. + let emit = match self.props.assembly_output.as_deref() { + Some("emit-asm") => Emit::Asm, + Some("bpf-linker") => Emit::LinkArgsAsm, + Some("ptx-linker") => Emit::None, // No extra flags needed. + Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")), + None => self.fatal("missing 'assembly-output' directive"), + }; + + let rustc = self.make_compile_args( + input_file, + TargetLocation::ThisFile(output_path.clone()), + emit, + AllowUnused::No, + LinkToAux::Yes, + Vec::new(), + ); + + let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths); + (proc_res, output_path) + } } From 95d01fcee95c1782151a15b803b489cf70282cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:39:08 +0800 Subject: [PATCH 08/16] compiletest: register `--minicore-path` flag and `//@ add-core-stubs` directive --- src/tools/compiletest/src/common.rs | 5 ++++ src/tools/compiletest/src/directive-list.rs | 1 + src/tools/compiletest/src/header.rs | 28 +++++++++++++++++++++ src/tools/compiletest/src/header/tests.rs | 1 + src/tools/compiletest/src/lib.rs | 7 +++++- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index e82b88eef7985..e4f2f95a91b5d 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -392,6 +392,11 @@ pub struct Config { /// Command for visual diff display, e.g. `diff-tool --color=always`. pub diff_command: Option, + + /// Path to minicore aux library, used for `no_core` tests that need `core` stubs in + /// cross-compilation scenarios that do not otherwise want/need to `-Zbuild-std`. Used in e.g. + /// ABI tests. + pub minicore_path: PathBuf, } impl Config { diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs index 4d57907f26f92..980b3f6829a81 100644 --- a/src/tools/compiletest/src/directive-list.rs +++ b/src/tools/compiletest/src/directive-list.rs @@ -3,6 +3,7 @@ /// a best-effort approximation for diagnostics. Add new headers to this list when needed. const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ // tidy-alphabetical-start + "add-core-stubs", "assembly-output", "aux-bin", "aux-build", diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index bfcdd747eb444..300a03e5f3377 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -198,6 +198,9 @@ pub struct TestProps { pub no_auto_check_cfg: bool, /// Run tests which require enzyme being build pub has_enzyme: bool, + /// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios + /// that don't otherwise want/need `-Z build-std`. + pub add_core_stubs: bool, } mod directives { @@ -243,6 +246,7 @@ mod directives { pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags"; pub const FILECHECK_FLAGS: &'static str = "filecheck-flags"; pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg"; + pub const ADD_CORE_STUBS: &'static str = "add-core-stubs"; // This isn't a real directive, just one that is probably mistyped often pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags"; } @@ -300,6 +304,7 @@ impl TestProps { filecheck_flags: vec![], no_auto_check_cfg: false, has_enzyme: false, + add_core_stubs: false, } } @@ -564,6 +569,8 @@ impl TestProps { } config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg); + + self.update_add_core_stubs(ln, config); }, ); @@ -677,6 +684,27 @@ impl TestProps { pub fn local_pass_mode(&self) -> Option { self.pass_mode } + + pub fn update_add_core_stubs(&mut self, ln: &str, config: &Config) { + let add_core_stubs = config.parse_name_directive(ln, directives::ADD_CORE_STUBS); + if add_core_stubs { + if !matches!(config.mode, Mode::Ui | Mode::Codegen | Mode::Assembly) { + panic!( + "`add-core-stubs` is currently only supported for ui, codegen and assembly test modes" + ); + } + + // FIXME(jieyouxu): this check is currently order-dependent, but we should probably + // collect all directives in one go then perform a validation pass after that. + if self.local_pass_mode().is_some_and(|pm| pm == PassMode::Run) { + // `minicore` can only be used with non-run modes, because it's `core` prelude stubs + // and can't run. + panic!("`add-core-stubs` cannot be used to run the test binary"); + } + + self.add_core_stubs = add_core_stubs; + } + } } /// If the given line begins with the appropriate comment prefix for a directive, diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 2e6effcab9868..0e735dc77c435 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -152,6 +152,7 @@ impl ConfigBuilder { "--git-repository=", "--nightly-branch=", "--git-merge-commit-email=", + "--minicore-path=", ]; let mut args: Vec = args.iter().map(ToString::to_string).collect(); diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index ccf8057bf5c57..b3ecc0b507350 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -181,7 +181,8 @@ pub fn parse_config(args: Vec) -> Config { "compiletest-diff-tool", "What custom diff tool to use for displaying compiletest tests.", "COMMAND", - ); + ) + .reqopt("", "minicore-path", "path to minicore aux library", "PATH"); let (argv0, args_) = args.split_first().unwrap(); if args.len() == 1 || args[1] == "-h" || args[1] == "--help" { @@ -371,7 +372,10 @@ pub fn parse_config(args: Vec) -> Config { git_merge_commit_email: matches.opt_str("git-merge-commit-email").unwrap(), profiler_runtime: matches.opt_present("profiler-runtime"), + diff_command: matches.opt_str("compiletest-diff-tool"), + + minicore_path: opt_path(matches, "minicore-path"), } } @@ -409,6 +413,7 @@ pub fn log_config(config: &Config) { logv(c, format!("host-linker: {:?}", config.host_linker)); logv(c, format!("verbose: {}", config.verbose)); logv(c, format!("format: {:?}", config.format)); + logv(c, format!("minicore_path: {:?}", config.minicore_path.display())); logv(c, "\n".to_string()); } From a737f75a04317b3762db8e93c229d704a48e2d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:44:40 +0800 Subject: [PATCH 09/16] compiletest: conditionally build and provide `minicore` as extern prelude when requested via `//@ add-core-stubs` directive `//@ add-core-stubs` will imply `-Cpanic=abort`. --- src/tools/compiletest/src/runtest.rs | 50 ++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index fff4f2df5954d..b337458f94359 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1150,14 +1150,20 @@ impl<'test> TestCx<'test> { } } - /// `root_testpaths` refers to the path of the original test. - /// the auxiliary and the test with an aux-build have the same `root_testpaths`. + /// `root_testpaths` refers to the path of the original test. the auxiliary and the test with an + /// aux-build have the same `root_testpaths`. fn compose_and_run_compiler( &self, mut rustc: Command, input: Option, root_testpaths: &TestPaths, ) -> ProcRes { + if self.props.add_core_stubs { + let minicore_path = self.build_minicore(); + rustc.arg("--extern"); + rustc.arg(&format!("minicore={}", minicore_path.to_str().unwrap())); + } + let aux_dir = self.aux_output_dir(); self.build_all_auxiliary(root_testpaths, &aux_dir, &mut rustc); @@ -1171,6 +1177,37 @@ impl<'test> TestCx<'test> { ) } + /// Builds `minicore`. Returns the path to the minicore rlib within the base test output + /// directory. + fn build_minicore(&self) -> PathBuf { + let output_file_path = self.output_base_dir().join("libminicore.rlib"); + let mut rustc = self.make_compile_args( + &self.config.minicore_path, + TargetLocation::ThisFile(output_file_path.clone()), + Emit::None, + AllowUnused::Yes, + LinkToAux::No, + vec![], + ); + + rustc.args(&["--crate-type", "rlib"]); + rustc.arg("-Cpanic=abort"); + + let res = + self.compose_and_run(rustc, self.config.compile_lib_path.to_str().unwrap(), None, None); + if !res.status.success() { + self.fatal_proc_rec( + &format!( + "auxiliary build of {:?} failed to compile: ", + self.config.minicore_path.display() + ), + &res, + ); + } + + output_file_path + } + /// Builds an aux dependency. fn build_auxiliary( &self, @@ -1662,6 +1699,15 @@ impl<'test> TestCx<'test> { rustc.args(&self.props.compile_flags); + // FIXME(jieyouxu): we should report a fatal error or warning if user wrote `-Cpanic=` with + // something that's not `abort`, however, by moving this last we should override previous + // `-Cpanic=`s + // + // `minicore` requires `#![no_std]` and `#![no_core]`, which means no unwinding panics. + if self.props.add_core_stubs { + rustc.arg("-Cpanic=abort"); + } + rustc } From 59cb59d74d51c3b210d81880f07169d3efeea2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:46:32 +0800 Subject: [PATCH 10/16] compiletest: stamp `minicore.rs` to rerun tests on changes --- src/tools/compiletest/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index b3ecc0b507350..5c06a39c47753 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -890,6 +890,12 @@ fn files_related_to_test( related.push(path); } + // `minicore.rs` test auxiliary: we need to make sure tests get rerun if this changes. + // + // FIXME(jieyouxu): untangle these paths, we should provide both a path to root `tests/` or + // `tests/auxiliary/` and the test suite in question. `src_base` is also a terrible name. + related.push(config.src_base.parent().unwrap().join("auxiliary").join("minicore.rs")); + related } From b115a228285676f0c11c4df7f6f3e279d2a6ec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:55:56 +0800 Subject: [PATCH 11/16] tests/assembly: add `minicore` compiletest self-test Check that `minicore` cannot be used with `run-{pass,fail}` tests. --- tests/assembly/compiletest-self-test/use-minicore-no-run.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/assembly/compiletest-self-test/use-minicore-no-run.rs diff --git a/tests/assembly/compiletest-self-test/use-minicore-no-run.rs b/tests/assembly/compiletest-self-test/use-minicore-no-run.rs new file mode 100644 index 0000000000000..0e4f05c4b3747 --- /dev/null +++ b/tests/assembly/compiletest-self-test/use-minicore-no-run.rs @@ -0,0 +1,5 @@ +//! `compiletest` self-test to check that `add-core-stubs` is incompatible with run pass modes. + +//@ add-core-stubs +//@ run-pass +//@ should-fail From a8b34f58cf7d21a822786f7b2599453b71ace5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:39:29 +0800 Subject: [PATCH 12/16] tests/codegen: add `minicore` compiletest self-test --- .../minicore-smoke-test.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/codegen/compiletest-self-test/minicore-smoke-test.rs diff --git a/tests/codegen/compiletest-self-test/minicore-smoke-test.rs b/tests/codegen/compiletest-self-test/minicore-smoke-test.rs new file mode 100644 index 0000000000000..9dd1bf29c6cfe --- /dev/null +++ b/tests/codegen/compiletest-self-test/minicore-smoke-test.rs @@ -0,0 +1,20 @@ +//! Basic smoke test for `minicore` test auxiliary. + +//@ add-core-stubs +//@ compile-flags: --target=x86_64-unknown-linux-gnu +//@ needs-llvm-components: x86 + +#![crate_type = "lib"] +#![feature(no_core)] +#![no_std] +#![no_core] + +extern crate minicore; +use minicore::*; + +struct Meow; +impl Copy for Meow {} + +// CHECK-LABEL: meow +#[no_mangle] +fn meow() {} From 0bbe07e8fff140eb2a2f1acffe5aa61fc7f4b153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:42:20 +0800 Subject: [PATCH 13/16] tests/ui: add `minicore` compiletest self-test --- .../minicore-smoke-test.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/ui/compiletest-self-test/minicore-smoke-test.rs diff --git a/tests/ui/compiletest-self-test/minicore-smoke-test.rs b/tests/ui/compiletest-self-test/minicore-smoke-test.rs new file mode 100644 index 0000000000000..ec879f2852e18 --- /dev/null +++ b/tests/ui/compiletest-self-test/minicore-smoke-test.rs @@ -0,0 +1,20 @@ +//! Basic smoke test for `minicore` test auxiliary. +//! +//! This test is duplicated between ui/codegen/assembly because they have different runtest +//! codepaths. + +//@ add-core-stubs +//@ check-pass +//@ compile-flags: --target=x86_64-unknown-linux-gnu +//@ needs-llvm-components: x86 + +#![crate_type = "lib"] +#![feature(no_core)] +#![no_std] +#![no_core] + +extern crate minicore; +use minicore::*; + +struct Meow; +impl Copy for Meow {} From adb6d4752fd00093d44e0285cfff28406dfb7229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:15:07 +0800 Subject: [PATCH 14/16] tests: use minicore in `tests/ui/abi/compatibility.rs` as an example --- tests/auxiliary/minicore.rs | 33 +++++++---------- tests/ui/abi/compatibility.rs | 69 +++++++---------------------------- 2 files changed, 28 insertions(+), 74 deletions(-) diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index eccd170ff9830..49a7580eccc8d 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -18,31 +18,26 @@ #![no_std] #![no_core] +// `core` has some exotic `marker_impls!` macro for handling the with-generics cases, but for our +// purposes, just use a simple macro_rules macro. +macro_rules! impl_marker_trait { + ($Trait:ident => [$( $ty:ident ),* $(,)?] ) => { + $( impl $Trait for $ty {} )* + } +} + #[lang = "sized"] pub trait Sized {} -#[lang = "receiver"] -pub trait Receiver {} -impl Receiver for &T {} -impl Receiver for &mut T {} +#[lang = "legacy_receiver"] +pub trait LegacyReceiver {} +impl LegacyReceiver for &T {} +impl LegacyReceiver for &mut T {} #[lang = "copy"] -pub trait Copy {} +pub trait Copy: Sized {} -impl Copy for bool {} -impl Copy for u8 {} -impl Copy for u16 {} -impl Copy for u32 {} -impl Copy for u64 {} -impl Copy for u128 {} -impl Copy for usize {} -impl Copy for i8 {} -impl Copy for i16 {} -impl Copy for i32 {} -impl Copy for isize {} -impl Copy for f32 {} -impl Copy for f64 {} -impl Copy for char {} +impl_marker_trait!(Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64 ]); impl<'a, T: ?Sized> Copy for &'a T {} impl Copy for *const T {} impl Copy for *mut T {} diff --git a/tests/ui/abi/compatibility.rs b/tests/ui/abi/compatibility.rs index 408dbea4ae834..01d90717107bb 100644 --- a/tests/ui/abi/compatibility.rs +++ b/tests/ui/abi/compatibility.rs @@ -1,4 +1,5 @@ //@ check-pass +//@ add-core-stubs //@ revisions: host //@ revisions: i686 //@[i686] compile-flags: --target i686-unknown-linux-gnu @@ -58,8 +59,10 @@ //@ revisions: nvptx64 //@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda //@[nvptx64] needs-llvm-components: nvptx -#![feature(rustc_attrs, unsized_fn_params, transparent_unions)] -#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)] +#![feature(no_core, rustc_attrs, lang_items)] +#![feature(unsized_fn_params, transparent_unions)] +#![no_std] +#![no_core] #![allow(unused, improper_ctypes_definitions, internal_features)] // FIXME: some targets are broken in various ways. @@ -67,67 +70,24 @@ // sparc64: https://github.com/rust-lang/rust/issues/115336 // mips64: https://github.com/rust-lang/rust/issues/115404 -#[cfg(host)] -use std::{ - any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc, sync::Arc, -}; +extern crate minicore; +use minicore::*; -/// To work cross-target this test must be no_core. -/// This little prelude supplies what we need. -#[cfg(not(host))] +/// To work cross-target this test must be no_core. This little prelude supplies what we need. +/// +/// Note that `minicore` provides a very minimal subset of `core` items (not yet complete). This +/// prelude contains `alloc` and non-`core` (but in `std`) items that minicore does not stub out. mod prelude { - #[lang = "sized"] - pub trait Sized {} + use minicore::*; - #[lang = "legacy_receiver"] - pub trait LegacyReceiver {} - impl LegacyReceiver for &T {} - impl LegacyReceiver for &mut T {} - - #[lang = "copy"] - pub trait Copy: Sized {} - impl Copy for i32 {} - impl Copy for f32 {} - impl Copy for &T {} - impl Copy for *const T {} - impl Copy for *mut T {} + // Trait stub, no `type_id` method. + pub trait Any: 'static {} #[lang = "clone"] pub trait Clone: Sized { fn clone(&self) -> Self; } - #[lang = "phantom_data"] - pub struct PhantomData; - impl Copy for PhantomData {} - - #[lang = "unsafe_cell"] - #[repr(transparent)] - pub struct UnsafeCell { - value: T, - } - - pub trait Any: 'static {} - - pub enum Option { - None, - Some(T), - } - impl Copy for Option {} - - pub enum Result { - Ok(T), - Err(E), - } - impl Copy for Result {} - - #[lang = "manually_drop"] - #[repr(transparent)] - pub struct ManuallyDrop { - value: T, - } - impl Copy for ManuallyDrop {} - #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] @@ -185,7 +145,6 @@ mod prelude { alloc: A, } } -#[cfg(not(host))] use prelude::*; macro_rules! test_abi_compatible { From 8dddd1ae603756ef4957320880115ecc65d706a5 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 31 Oct 2024 21:12:15 +1100 Subject: [PATCH 15/16] coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable --- compiler/rustc_codegen_llvm/src/context.rs | 1 + compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs | 6 +++++- compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 9778ff4918c0d..313957dda9642 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -554,6 +554,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// Extra state that is only available when coverage instrumentation is enabled. #[inline] + #[track_caller] pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> { self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled") } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 8edd788ee36ca..f6378199fe26e 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -54,7 +54,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) { add_unused_functions(cx); } - let function_coverage_map = cx.coverage_cx().take_function_coverage_map(); + // FIXME(#132395): Can this be none even when coverage is enabled? + let function_coverage_map = match cx.coverage_cx { + Some(ref cx) => cx.take_function_coverage_map(), + None => return, + }; if function_coverage_map.is_empty() { // This module has no functions with coverage instrumentation return; diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index a298ed86276f9..e4ff50816b97c 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -152,7 +152,12 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { return; }; - let mut coverage_map = bx.coverage_cx().function_coverage_map.borrow_mut(); + // FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the + // wild, so keep this early-return until we understand why. + let mut coverage_map = match bx.coverage_cx { + Some(ref cx) => cx.function_coverage_map.borrow_mut(), + None => return, + }; let func_coverage = coverage_map .entry(instance) .or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info)); From 3036f4f668cb5fe0abb0788034b46599a48fc1b6 Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:29:29 +0100 Subject: [PATCH 16/16] CI: use free runners for x86_64-gnu-tools and x86_64-rust-for-linux --- src/ci/github-actions/jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index a401092a3a73f..32ee63843a368 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -232,7 +232,7 @@ auto: # Tests integration with Rust for Linux. # Builds stage 1 compiler and tries to compile a few RfL examples with it. - image: x86_64-rust-for-linux - <<: *job-linux-8c + <<: *job-linux-4c - image: x86_64-gnu <<: *job-linux-4c @@ -280,7 +280,7 @@ auto: - image: x86_64-gnu-tools env: DEPLOY_TOOLSTATES_JSON: toolstates-linux.json - <<: *job-linux-8c + <<: *job-linux-4c #################### # macOS Builders #