From f91bd7882f311a86cf8005af00f55dc55c744c73 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:20:23 +0000 Subject: [PATCH 01/13] Merge commit 'fbda869b4e230c788b6bce426038ba8419956f2d' into sync_cg_clif-2024-04-05 --- .cirrus.yml | 3 ++ .github/workflows/abi-cafe.yml | 2 + .github/workflows/main.yml | 68 ++++++++++++++-------------------- .github/workflows/rustc.yml | 2 + Readme.md | 22 +---------- build_system/build_backend.rs | 16 +++----- build_system/build_sysroot.rs | 4 +- build_system/main.rs | 13 ++----- build_system/prepare.rs | 1 - build_system/tests.rs | 17 ++++----- build_system/utils.rs | 18 --------- docs/rustc_testing.md | 23 ++++++++++++ example/mini_core.rs | 4 +- rust-toolchain | 2 +- scripts/filter_profile.rs | 9 ++--- src/num.rs | 2 +- 16 files changed, 85 insertions(+), 121 deletions(-) create mode 100644 docs/rustc_testing.md diff --git a/.cirrus.yml b/.cirrus.yml index aa1a2bad2cf2a..97c2f45d31e22 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -13,4 +13,7 @@ task: - ./y.sh prepare test_script: - . $HOME/.cargo/env + # Disabling incr comp reduces cache size and incr comp doesn't save as much + # on CI anyway. + - export CARGO_BUILD_INCREMENTAL=false - ./y.sh test diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml index e6bf944f5527b..a745f2801cc4e 100644 --- a/.github/workflows/abi-cafe.yml +++ b/.github/workflows/abi-cafe.yml @@ -3,6 +3,8 @@ name: Abi-cafe on: - push +permissions: {} + jobs: abi_cafe: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 526871d0c05f4..913a5c5a8500c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,20 @@ on: - push - pull_request +defaults: + run: + shell: bash + +permissions: {} + +env: + # Disabling incr comp reduces cache size and incr comp doesn't save as much + # on CI anyway. + CARGO_BUILD_INCREMENTAL: false + # Rust's CI denies warnings. Deny them here too to ensure subtree syncs don't + # fail because of warnings. + RUSTFLAGS: "-Dwarnings" + jobs: rustfmt: runs-on: ubuntu-latest @@ -23,15 +37,15 @@ jobs: cargo fmt --check rustfmt --check build_system/main.rs rustfmt --check example/* + rustfmt --check scripts/*.rs test: runs-on: ${{ matrix.os }} timeout-minutes: 60 - defaults: - run: - shell: bash + env: + CG_CLIF_EXPENSIVE_CHECKS: 1 strategy: fail-fast: false @@ -47,15 +61,19 @@ jobs: - os: ubuntu-latest env: TARGET_TRIPLE: x86_64-pc-windows-gnu + apt_deps: gcc-mingw-w64-x86-64 wine-stable - os: ubuntu-latest env: TARGET_TRIPLE: aarch64-unknown-linux-gnu + apt_deps: gcc-aarch64-linux-gnu qemu-user - os: ubuntu-latest env: TARGET_TRIPLE: s390x-unknown-linux-gnu + apt_deps: gcc-s390x-linux-gnu qemu-user - os: ubuntu-latest env: TARGET_TRIPLE: riscv64gc-unknown-linux-gnu + apt_deps: gcc-riscv64-linux-gnu qemu-user - os: windows-latest env: TARGET_TRIPLE: x86_64-pc-windows-msvc @@ -80,29 +98,11 @@ jobs: if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - - name: Install MinGW toolchain and wine - if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' - run: | - sudo apt-get update - sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable - - - name: Install AArch64 toolchain and qemu - if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' - run: | - sudo apt-get update - sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user - - - name: Install s390x toolchain and qemu - if: matrix.env.TARGET_TRIPLE == 's390x-unknown-linux-gnu' + - name: Install toolchain and emulator + if: matrix.apt_deps != null run: | sudo apt-get update - sudo apt-get install -y gcc-s390x-linux-gnu qemu-user - - - name: Install riscv64gc toolchain and qemu - if: matrix.env.TARGET_TRIPLE == 'riscv64gc-unknown-linux-gnu' - run: | - sudo apt-get update - sudo apt-get install -y gcc-riscv64-linux-gnu qemu-user + sudo apt-get install -y ${{ matrix.apt_deps }} - name: Prepare dependencies run: ./y.sh prepare @@ -142,10 +142,6 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 - defaults: - run: - shell: bash - steps: - uses: actions/checkout@v4 @@ -168,10 +164,6 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 - defaults: - run: - shell: bash - steps: - uses: actions/checkout@v4 @@ -193,20 +185,16 @@ jobs: run: ./y.sh prepare - name: Build - run: CI_OPT=1 ./y.sh build --sysroot none + run: ./y.sh build --sysroot none - name: Benchmark - run: CI_OPT=1 ./y.sh bench + run: ./y.sh bench dist: runs-on: ${{ matrix.os }} timeout-minutes: 60 - defaults: - run: - shell: bash - strategy: fail-fast: false matrix: @@ -252,10 +240,10 @@ jobs: run: ./y.sh prepare - name: Build backend - run: CI_OPT=1 ./y.sh build --sysroot none + run: ./y.sh build --sysroot none - name: Build sysroot - run: CI_OPT=1 ./y.sh build + run: ./y.sh build - name: Package prebuilt cg_clif run: tar cvfJ cg_clif.tar.xz dist diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index 930d025b73edc..75ea94ee79790 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -3,6 +3,8 @@ name: Various rustc tests on: - push +permissions: {} + jobs: bootstrap_rustc: runs-on: ubuntu-latest diff --git a/Readme.md b/Readme.md index a297b22326f37..00ea15cb38cc2 100644 --- a/Readme.md +++ b/Readme.md @@ -101,27 +101,7 @@ For additional ways to use rustc_codegen_cranelift like the JIT mode see [usage. ## Building and testing with changes in rustc code -This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/). -This can happen, for example, when you are implementing a new compiler intrinsic. - -Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository. - -You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code: - -1. `cd $RustCheckoutDir` -2. Run `python x.py setup` and choose option for compiler (`b`). -3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt` - * (Optional) You can also build cargo by adding `src/tools/cargo` to previous command. -4. Copy cargo from a nightly toolchain: `cp $(rustup +nightly which cargo) ./build/host/stage2/bin/cargo`. Note that you would need to do this every time you rebuilt `rust` repository. -5. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`. -6. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`. -7. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc. - * `rustup run stage2 ./y.sh prepare` - * `rustup run stage2 ./y.sh build` - * (Optional) run tests: `rustup run stage2 ./y.sh test` -8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`. - -You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes. +See [rustc_testing.md](docs/rustc_testing.md). ## Not yet supported diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index d90111adf7761..129713e574ad0 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,9 +1,10 @@ +use std::env; use std::path::PathBuf; use crate::path::{Dirs, RelPath}; use crate::rustc_info::get_file_name; use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env}; -use crate::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup}; +use crate::utils::{CargoProject, Compiler, LogGroup}; pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); @@ -16,20 +17,15 @@ pub(crate) fn build_backend( let _group = LogGroup::guard("Build backend"); let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs); - maybe_incremental(&mut cmd); let mut rustflags = rustflags_from_env("RUSTFLAGS"); rustflags.push("-Zallow-features=rustc_private".to_owned()); - if is_ci() { - // Deny warnings on CI - rustflags.push("-Dwarnings".to_owned()); - - if !is_ci_opt() { - cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true"); - cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true"); - } + if env::var("CG_CLIF_EXPENSIVE_CHECKS").is_ok() { + // Enabling debug assertions implicitly enables the clif ir verifier + cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true"); + cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true"); } if use_unstable_features { diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 1ed896c6bf0e4..10c3f9cfa2ce3 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -6,8 +6,7 @@ use std::process::Command; use crate::path::{Dirs, RelPath}; use crate::rustc_info::get_file_name; use crate::utils::{ - maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, - LogGroup, + remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup, }; use crate::{config, CodegenBackend, SysrootKind}; @@ -270,7 +269,6 @@ fn build_clif_sysroot_for_triple( } compiler.rustflags.extend(rustflags); let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); - maybe_incremental(&mut build_cmd); if channel == "release" { build_cmd.arg("--release"); } diff --git a/build_system/main.rs b/build_system/main.rs index e8cf486e966ed..cdd2bae03f8f1 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -6,7 +6,7 @@ use std::env; use std::path::PathBuf; use std::process; -use self::utils::{is_ci, is_ci_opt, Compiler}; +use self::utils::Compiler; mod abi_cafe; mod bench; @@ -60,14 +60,9 @@ fn main() { } env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); - if is_ci() { - // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway - env::set_var("CARGO_BUILD_INCREMENTAL", "false"); - - if !is_ci_opt() { - // Enable the Cranelift verifier - env::set_var("CG_CLIF_ENABLE_VERIFIER", "1"); - } + // Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled + if env::var_os("CARGO_BUILD_INCREMENTAL").is_none() { + env::set_var("CARGO_BUILD_INCREMENTAL", "true"); } let mut args = env::args().skip(1); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 3677d0a7d3607..5525a5f63e93b 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -15,7 +15,6 @@ pub(crate) fn prepare(dirs: &Dirs) { RelPath::DOWNLOAD.ensure_exists(dirs); crate::tests::RAND_REPO.fetch(dirs); crate::tests::REGEX_REPO.fetch(dirs); - crate::tests::PORTABLE_SIMD_REPO.fetch(dirs); } pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { diff --git a/build_system/tests.rs b/build_system/tests.rs index 1c3e615c7aba2..9efb6ed715ca7 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -130,16 +130,10 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github( pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target"); -pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( - "rust-lang", - "portable-simd", - "5794c837bc605c4cd9dbb884285976dfdb293cce", - "a64d8fdd0ed0d9c4", - "portable-simd", -); +pub(crate) static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("coretests"); pub(crate) static PORTABLE_SIMD: CargoProject = - CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable-simd_target"); + CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target"); static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests"); @@ -221,7 +215,12 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::custom("test.portable-simd", &|runner| { - PORTABLE_SIMD_REPO.patch(&runner.dirs); + apply_patches( + &runner.dirs, + "portable-simd", + &runner.stdlib_source.join("library/portable-simd"), + &PORTABLE_SIMD_SRC.to_path(&runner.dirs), + ); PORTABLE_SIMD.clean(&runner.dirs); diff --git a/build_system/utils.rs b/build_system/utils.rs index 149f1618f5c0e..9f95122b341c5 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -254,14 +254,6 @@ pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) { } } -pub(crate) fn is_ci() -> bool { - env::var("CI").is_ok() -} - -pub(crate) fn is_ci_opt() -> bool { - env::var("CI_OPT").is_ok() -} - static IN_GROUP: AtomicBool = AtomicBool::new(false); pub(crate) struct LogGroup { is_gha: bool, @@ -288,13 +280,3 @@ impl Drop for LogGroup { IN_GROUP.store(false, Ordering::SeqCst); } } - -pub(crate) fn maybe_incremental(cmd: &mut Command) { - if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") { - // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway - cmd.env("CARGO_BUILD_INCREMENTAL", "false"); - } else { - // Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled - cmd.env("CARGO_BUILD_INCREMENTAL", "true"); - } -} diff --git a/docs/rustc_testing.md b/docs/rustc_testing.md new file mode 100644 index 0000000000000..88c555572318b --- /dev/null +++ b/docs/rustc_testing.md @@ -0,0 +1,23 @@ +# Building and testing with changes in rustc code + +This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/). +This can happen, for example, when you are implementing a new compiler intrinsic. + +Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository. + +You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code: + +1. `cd $RustCheckoutDir` +2. Run `python x.py setup` and choose option for compiler (`b`). +3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt` + * (Optional) You can also build cargo by adding `src/tools/cargo` to previous command. +4. Copy cargo from a nightly toolchain: `cp $(rustup +nightly which cargo) ./build/host/stage2/bin/cargo`. Note that you would need to do this every time you rebuilt `rust` repository. +5. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`. +6. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`. +7. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc. + * `rustup run stage2 ./y.sh prepare` + * `rustup run stage2 ./y.sh build` + * (Optional) run tests: `rustup run stage2 ./y.sh test` +8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`. + +You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes. diff --git a/example/mini_core.rs b/example/mini_core.rs index 1cee513190784..e45c16ee280a7 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -90,8 +90,9 @@ unsafe impl Sync for i16 {} unsafe impl Sync for i32 {} unsafe impl Sync for isize {} unsafe impl Sync for char {} +unsafe impl Sync for f32 {} unsafe impl<'a, T: ?Sized> Sync for &'a T {} -unsafe impl Sync for [u8; 16] {} +unsafe impl Sync for [T; N] {} #[lang = "freeze"] unsafe auto trait Freeze {} @@ -467,7 +468,6 @@ pub fn panic(_msg: &'static str) -> ! { macro_rules! panic_const { ($($lang:ident = $message:expr,)+) => { - #[cfg(not(bootstrap))] pub mod panic_const { use super::*; diff --git a/rust-toolchain b/rust-toolchain index 612fc61ec27df..09e436b3eed0f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-03-28" +channel = "nightly-2024-04-05" components = ["rust-src", "rustc-dev", "llvm-tools"] diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index 03912b18ea5f2..0252d5b334036 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#![forbid(unsafe_code)]/* This line is ignored by bash +#![rustfmt::skip]/* This line is ignored by bash # This block is ignored by rustc pushd $(dirname "$0")/../ RUSTC="$(pwd)/dist/rustc-clif" @@ -26,11 +26,8 @@ fn main() -> Result<(), Box> { } let profile = std::fs::read_to_string(profile_name) .map_err(|err| format!("Failed to read profile {}", err))?; - let mut output = std::fs::OpenOptions::new() - .create(true) - .write(true) - .truncate(true) - .open(output_name)?; + let mut output = + std::fs::OpenOptions::new().create(true).write(true).truncate(true).open(output_name)?; for line in profile.lines() { let mut stack = &line[..line.rfind(" ").unwrap()]; diff --git a/src/num.rs b/src/num.rs index 796182418ad6c..714858084ec9d 100644 --- a/src/num.rs +++ b/src/num.rs @@ -130,7 +130,7 @@ pub(crate) fn codegen_int_binop<'tcx>( in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, ) -> CValue<'tcx> { - if bin_op != BinOp::Shl && bin_op != BinOp::Shr { + if !matches!(bin_op, BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked) { assert_eq!( in_lhs.layout().ty, in_rhs.layout().ty, From 242b261585ffb70108bfd236a260e95ec4b06556 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 6 Apr 2024 13:39:47 +0000 Subject: [PATCH 02/13] Don't run should-fail rustc tests These are expected to panic inside compiletest which fails when compiletest is compiled with panic=abort. --- scripts/test_rustc_tests.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index f42a008dc0c10..47e3ade2ede8e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -21,6 +21,11 @@ for test in $(rg --files-with-matches "lto" tests/{codegen-units,ui,incremental} rm $test done +# should-fail tests don't work when compiletest is compiled with panic=abort +for test in $(rg --files-with-matches "//@ should-fail" tests/{codegen-units,ui,incremental}); do + rm $test +done + for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|//@ error-pattern:|//@(\[.*\])? build-fail|//@(\[.*\])? run-fail|-Cllvm-args" tests/ui); do rm $test done @@ -116,8 +121,6 @@ rm -r tests/run-make/compiler-builtins # Expects lib/rustlib/src/rust to contain # genuine bugs # ============ -rm tests/incremental/spike-neg1.rs # errors out for some reason -rm tests/incremental/spike-neg2.rs # same rm -r tests/run-make/extern-fn-explicit-align # argument alignment not yet supported rm -r tests/run-make/panic-abort-eh_frame # .eh_frame emitted with panic=abort From 0f1ee59ea579527f82a69f3564bba5c3ee2a69dd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:05:30 +0000 Subject: [PATCH 03/13] Disable failing rand tests on FreeBSD --- .cirrus.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index 97c2f45d31e22..a98bf2b8b8988 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -16,4 +16,5 @@ task: # Disabling incr comp reduces cache size and incr comp doesn't save as much # on CI anyway. - export CARGO_BUILD_INCREMENTAL=false - - ./y.sh test + # Skip rand as it fails on FreeBSD due to rust-random/rand#1355 + - ./y.sh test --skip-test test.rust-random/rand From 6669758fb32c376a411c777bebdfd11855d2e447 Mon Sep 17 00:00:00 2001 From: Michael Baikov Date: Sat, 6 Apr 2024 09:07:54 -0400 Subject: [PATCH 04/13] Save/restore more items in cache with incremental compilation --- src/driver/aot.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 75268341a4fe0..e8c96486041b1 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -341,6 +341,8 @@ fn emit_cgu( object: Some(global_asm_object_file), dwarf_object: None, bytecode: None, + assembly: None, + llvm_ir: None, }), existing_work_product: None, }) @@ -378,7 +380,15 @@ fn emit_module( prof.artifact_size("object_file", &*name, file.metadata().unwrap().len()); - Ok(CompiledModule { name, kind, object: Some(tmp_file), dwarf_object: None, bytecode: None }) + Ok(CompiledModule { + name, + kind, + object: Some(tmp_file), + dwarf_object: None, + bytecode: None, + assembly: None, + llvm_ir: None, + }) } fn reuse_workproduct_for_cgu( @@ -426,6 +436,8 @@ fn reuse_workproduct_for_cgu( object: Some(obj_out_regular), dwarf_object: None, bytecode: None, + assembly: None, + llvm_ir: None, }, module_global_asm: has_global_asm.then(|| CompiledModule { name: cgu.name().to_string(), @@ -433,6 +445,8 @@ fn reuse_workproduct_for_cgu( object: Some(obj_out_global_asm), dwarf_object: None, bytecode: None, + assembly: None, + llvm_ir: None, }), existing_work_product: Some((cgu.work_product_id(), work_product)), }) @@ -678,6 +692,8 @@ pub(crate) fn run_aot( object: Some(tmp_file), dwarf_object: None, bytecode: None, + assembly: None, + llvm_ir: None, }) } else { None From 3549d9806d90853fc857e3bff964b7364c45659d Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Wed, 3 Apr 2024 08:54:03 -0400 Subject: [PATCH 05/13] Put checks that detect UB under their own flag below debug_assertions --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 0aa2bae8f78b1..1307a62a60d09 100644 --- a/src/base.rs +++ b/src/base.rs @@ -789,7 +789,7 @@ fn codegen_stmt<'tcx>( layout.offset_of_subfield(fx, fields.iter()).bytes() } NullOp::UbChecks => { - let val = fx.tcx.sess.opts.debug_assertions; + let val = fx.tcx.sess.ub_checks(); let val = CValue::by_val( fx.bcx.ins().iconst(types::I8, i64::try_from(val).unwrap()), fx.layout_of(fx.tcx.types.bool), From 39b25b3d714d463a6803a64f437f1b9ba8ced7b8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:39:05 +0000 Subject: [PATCH 06/13] Don't emit unwind tables on macOS They don't work anyway as object misses support for emitting the particular format macOS expects. And on arm64 macOS it causes compilation to abort due to an unsupported relocation type. Fixes rust-lang/rustc_codegen_cranelift#1371 --- src/debuginfo/unwind.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 96ab7a29205bf..eebd181341d08 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -38,6 +38,14 @@ impl UnwindContext { } pub(crate) fn add_function(&mut self, func_id: FuncId, context: &Context, isa: &dyn TargetIsa) { + if let target_lexicon::OperatingSystem::MacOSX { .. } = isa.triple().operating_system { + // The object crate doesn't currently support DW_GNU_EH_PE_absptr, which macOS + // requires for unwinding tables. In addition on arm64 it currently doesn't + // support 32bit relocations as we currently use for the unwinding table. + // See gimli-rs/object#415 and rust-lang/rustc_codegen_cranelift#1371 + return; + } + let unwind_info = if let Some(unwind_info) = context.compiled_code().unwrap().create_unwind_info(isa).unwrap() { From 0328ee571bbe3a1d21b5c01e816cf4224193a2fc Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:36:41 +0000 Subject: [PATCH 07/13] Fix caching on Cirrus CI --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index a98bf2b8b8988..5a464bfac3644 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -7,7 +7,7 @@ task: - curl https://sh.rustup.rs -sSf --output rustup.sh - sh rustup.sh --default-toolchain none -y --profile=minimal target_cache: - folder: target + folder: build/cg_clif prepare_script: - . $HOME/.cargo/env - ./y.sh prepare From 6bab2e750b01e01ec787c7673bcfdc8eb319e81e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:05:25 +0000 Subject: [PATCH 08/13] Fix showing error details in the dev release action --- .github/actions/github-release/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/github-release/main.js b/.github/actions/github-release/main.js index 6fcfca34ea776..1eb2b7f23b26c 100644 --- a/.github/actions/github-release/main.js +++ b/.github/actions/github-release/main.js @@ -56,7 +56,7 @@ async function runOnce() { force: true, }); } catch (e) { - console.log("ERROR: ", JSON.stringify(e.data, null, 2)); + console.log("ERROR: ", JSON.stringify(e.response, null, 2)); core.info(`creating dev tag`); try { await octokit.rest.git.createRef({ @@ -68,7 +68,7 @@ async function runOnce() { } catch (e) { // we might race with others, so assume someone else has created the // tag by this point. - console.log("failed to create tag: ", JSON.stringify(e.data, null, 2)); + console.log("failed to create tag: ", JSON.stringify(e.response, null, 2)); } } From f7cc528deb35a8cd92ab438f62414866c200a848 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:15:26 +0000 Subject: [PATCH 09/13] Restore required permission for the release job --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 913a5c5a8500c..14aa850ff5cb7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -268,6 +268,9 @@ jobs: if: ${{ github.ref == 'refs/heads/master' }} needs: [rustfmt, test, bench, dist] + permissions: + contents: write # for creating the dev tag and release + concurrency: group: release-dev cancel-in-progress: true From da09eadbabb4a76304fa6af01a6bdea9b4ede446 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 7 Apr 2024 16:46:21 -0400 Subject: [PATCH 10/13] Only traverse mono-reachable blocks in cg_clif --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 1307a62a60d09..771e5b219589a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -267,7 +267,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { .generic_activity("codegen prelude") .run(|| crate::abi::codegen_fn_prelude(fx, start_block)); - for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() { + for (bb, bb_data) in traversal::mono_reachable(fx.mir, fx.tcx, fx.instance) { let block = fx.get_block(bb); fx.bcx.switch_to_block(block); From 8a5eecc89736a5b54daa3c8dd7d88fc228b710fd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Apr 2024 09:59:43 +0000 Subject: [PATCH 11/13] Rustup to rustc 1.79.0-nightly (aa067fb98 2024-04-10) --- rust-toolchain | 2 +- src/base.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 09e436b3eed0f..3e7da4e161f09 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-04-05" +channel = "nightly-2024-04-11" components = ["rust-src", "rustc-dev", "llvm-tools"] diff --git a/src/base.rs b/src/base.rs index 771e5b219589a..f07421431daed 100644 --- a/src/base.rs +++ b/src/base.rs @@ -267,10 +267,19 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { .generic_activity("codegen prelude") .run(|| crate::abi::codegen_fn_prelude(fx, start_block)); - for (bb, bb_data) in traversal::mono_reachable(fx.mir, fx.tcx, fx.instance) { + let reachable_blocks = traversal::mono_reachable_as_bitset(fx.mir, fx.tcx, fx.instance); + + for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() { let block = fx.get_block(bb); fx.bcx.switch_to_block(block); + if !reachable_blocks.contains(bb) { + // We want to skip this block, because it's not reachable. But we still create + // the block so terminators in other blocks can reference it. + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + continue; + } + if bb_data.is_cleanup { // Unwinding after panicking is not supported continue; From d37f6d821d6de7e5f1a683cdda37b117b62afe87 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:13:17 +0000 Subject: [PATCH 12/13] Fix rustc tests --- patches/0027-stdlib-128bit-atomic-operations.patch | 13 +++++++++++++ scripts/test_rustc_tests.sh | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/patches/0027-stdlib-128bit-atomic-operations.patch b/patches/0027-stdlib-128bit-atomic-operations.patch index 646928893e96a..a3f370af91699 100644 --- a/patches/0027-stdlib-128bit-atomic-operations.patch +++ b/patches/0027-stdlib-128bit-atomic-operations.patch @@ -82,6 +82,19 @@ index d9de37e..8293fce 100644 #[cfg(target_has_atomic_load_store = "ptr")] macro_rules! atomic_int_ptr_sized { ( $($target_pointer_width:literal $align:literal)* ) => { $( +diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs +index 58b9ba4..91bbd0a 100644 +--- a/library/core/src/cell.rs ++++ b/library/core/src/cell.rs +@@ -2246,8 +2246,6 @@ unsafe_cell_primitive_into_inner! { + u32 "32" + i64 "64" + u64 "64" +- i128 "128" +- u128 "128" + isize "ptr" + usize "ptr" + } -- 2.26.2.7.g19db9cfb68 diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 47e3ade2ede8e..9c078c46c2e9f 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -84,7 +84,6 @@ rm -r tests/run-make/fmt-write-bloat/ # tests an optimization # ====================== rm tests/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM rm -r tests/run-make/cross-lang-lto # same -rm -r tests/run-make/issue-7349 # same rm -r tests/run-make/sepcomp-inlining # same rm -r tests/run-make/sepcomp-separate # same rm -r tests/run-make/sepcomp-cci-copies # same From 89f54caacf90e99fc8ba0d60a28bdadea3cfdf1e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:16:50 +0000 Subject: [PATCH 13/13] Reenable fixed rustc tests --- scripts/test_rustc_tests.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 9c078c46c2e9f..8580f4557e883 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,12 +10,6 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -# FIXME remove this workaround once ICE tests no longer emit an outdated nightly message -for test in $(rg -i --files-with-matches "//@(\[.*\])? failure-status: 101" tests/ui); do - echo "rm $test" - rm $test -done - rm -r tests/ui/{unsized-locals/,lto/,linkage*} || true for test in $(rg --files-with-matches "lto" tests/{codegen-units,ui,incremental}); do rm $test