From 9950bd1dc5bd249af274a14c7da30a2992c33295 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 23 Oct 2022 16:22:55 +0200 Subject: [PATCH 01/77] Merge commit '266e96785ab71834b917bf474f130a6d8fdecd4b' into sync_cg_clif-2022-10-23 --- .github/workflows/main.yml | 99 ++++++--- .gitignore | 6 +- .vscode/settings.json | 6 +- Cargo.lock | 62 +++--- Cargo.toml | 14 +- build_sysroot/Cargo.lock | 38 ++-- build_system/abi_cafe.rs | 52 +++++ build_system/abi_checker.rs | 60 ------ build_system/build_backend.rs | 16 +- build_system/build_sysroot.rs | 13 +- build_system/config.rs | 3 +- build_system/mod.rs | 21 +- build_system/prepare.rs | 190 ++++++++++++------ build_system/tests.rs | 179 ++++++++--------- build_system/utils.rs | 46 +++++ clean_all.sh | 6 +- config.txt | 2 +- example/issue-91827-extern-types.rs | 1 - example/mini_core.rs | 6 + example/mini_core_hello_world.rs | 1 + ...e-some-test-on-x86_64-pc-windows-gnu.patch | 29 +++ ...01-abi-checker-Disable-failing-tests.patch | 36 ---- ...table-simd-Disable-unsupported-tests.patch | 96 ++------- ...003-rand-Disable-rand-tests-on-mingw.patch | 47 +++++ rust-toolchain | 2 +- scripts/setup_rust_fork.sh | 6 + scripts/test_rustc_tests.sh | 8 +- src/abi/mod.rs | 53 ++++- src/allocator.rs | 4 +- src/archive.rs | 2 + src/base.rs | 12 +- src/concurrency_limiter.rs | 17 +- src/constant.rs | 87 ++++---- src/driver/aot.rs | 2 +- src/driver/jit.rs | 51 ++--- src/inline_asm.rs | 22 +- src/intrinsics/llvm.rs | 7 +- src/intrinsics/mod.rs | 62 +++--- src/intrinsics/simd.rs | 128 +++++++++++- src/lib.rs | 14 +- src/main_shim.rs | 2 +- src/num.rs | 61 ++++-- src/unsize.rs | 40 +++- src/value_and_place.rs | 48 +++++ src/vtable.rs | 26 ++- 45 files changed, 1045 insertions(+), 638 deletions(-) create mode 100644 build_system/abi_cafe.rs delete mode 100644 build_system/abi_checker.rs create mode 100644 patches/0001-abi-cafe-Disable-some-test-on-x86_64-pc-windows-gnu.patch delete mode 100644 patches/0001-abi-checker-Disable-failing-tests.patch create mode 100644 patches/0003-rand-Disable-rand-tests-on-mingw.patch diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8897e9ae8145..5061010c86cd3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,11 @@ jobs: matrix: include: - os: ubuntu-latest + env: + TARGET_TRIPLE: x86_64-unknown-linux-gnu - os: macos-latest + env: + TARGET_TRIPLE: x86_64-apple-darwin # cross-compile from Linux to Windows using mingw - os: ubuntu-latest env: @@ -112,7 +116,7 @@ jobs: if: matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' uses: actions/upload-artifact@v2 with: - name: cg_clif-${{ runner.os }} + name: cg_clif-${{ matrix.env.TARGET_TRIPLE }} path: cg_clif.tar.xz - name: Upload prebuilt cg_clif (cross compile) @@ -122,56 +126,89 @@ jobs: name: cg_clif-${{ runner.os }}-cross-x86_64-mingw path: cg_clif.tar.xz - build_windows: - runs-on: windows-latest + windows: + runs-on: ${{ matrix.os }} timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + include: + # Native Windows build with MSVC + - os: windows-latest + env: + TARGET_TRIPLE: x86_64-pc-windows-msvc + # cross-compile from Windows to Windows MinGW + - os: windows-latest + env: + TARGET_TRIPLE: x86_64-pc-windows-gnu + steps: - uses: actions/checkout@v3 - #- name: Cache cargo installed crates - # uses: actions/cache@v2 - # with: - # path: ~/.cargo/bin - # key: ${{ runner.os }}-cargo-installed-crates - - #- name: Cache cargo registry and index - # uses: actions/cache@v2 - # with: - # path: | - # ~/.cargo/registry - # ~/.cargo/git - # key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} - - #- name: Cache cargo target dir - # uses: actions/cache@v2 - # with: - # path: target - # key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} + - name: Cache cargo installed crates + uses: actions/cache@v2 + with: + path: ~/.cargo/bin + key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-installed-crates + + - name: Cache cargo registry and index + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo target dir + uses: actions/cache@v2 + with: + path: target + key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} + + - name: Set MinGW as the default toolchain + if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' + run: rustup set default-host x86_64-pc-windows-gnu - name: Prepare dependencies run: | git config --global user.email "user@example.com" git config --global user.name "User" git config --global core.autocrlf false - rustup set default-host x86_64-pc-windows-gnu rustc y.rs -o y.exe -g ./y.exe prepare + - name: Build without unstable features + env: + TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} + # This is the config rust-lang/rust uses for builds + run: ./y.rs build --no-unstable-features + - name: Build - #name: Test + run: ./y.rs build --sysroot none + + - name: Test run: | # Enable backtraces for easier debugging - #$Env:RUST_BACKTRACE=1 + $Env:RUST_BACKTRACE=1 # Reduce amount of benchmark runs as they are slow - #$Env:COMPILE_RUNS=2 - #$Env:RUN_RUNS=2 + $Env:COMPILE_RUNS=2 + $Env:RUN_RUNS=2 # Enable extra checks - #$Env:CG_CLIF_ENABLE_VERIFIER=1 - - ./y.exe build + $Env:CG_CLIF_ENABLE_VERIFIER=1 + + # WIP Disable some tests + + # This fails due to some weird argument handling by hyperfine, not an actual regression + # more of a build system issue + (Get-Content config.txt) -replace '(bench.simple-raytracer)', '# $1' | Out-File config.txt + + # This fails with a different output than expected + (Get-Content config.txt) -replace '(test.regex-shootout-regex-dna)', '# $1' | Out-File config.txt + + ./y.exe test - name: Package prebuilt cg_clif # don't use compression as xzip isn't supported by tar on windows and bzip2 hangs @@ -180,5 +217,5 @@ jobs: - name: Upload prebuilt cg_clif uses: actions/upload-artifact@v2 with: - name: cg_clif-${{ runner.os }} + name: cg_clif-${{ matrix.env.TARGET_TRIPLE }} path: cg_clif.tar diff --git a/.gitignore b/.gitignore index 6fd3e4443de5c..fae09592c6ac0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,4 @@ perf.data.old /build_sysroot/compiler-builtins /build_sysroot/rustc_version /rust -/rand -/regex -/simple-raytracer -/portable-simd -/abi-checker +/download diff --git a/.vscode/settings.json b/.vscode/settings.json index d88309e412ed0..13301bf20a5ed 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "rust-analyzer.cargo.features": ["unstable-features"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", - //"./build_sysroot/sysroot_src/src/libstd/Cargo.toml", + //"./build_sysroot/sysroot_src/library/std/Cargo.toml", { "roots": [ "./example/mini_core.rs", @@ -36,10 +36,10 @@ ] }, { - "roots": ["./scripts/filter_profile.rs"], + "roots": ["./example/std_example.rs"], "crates": [ { - "root_module": "./scripts/filter_profile.rs", + "root_module": "./example/std_example.rs", "edition": "2018", "deps": [{ "crate": 1, "name": "std" }], "cfg": [], diff --git a/Cargo.lock b/Cargo.lock index edae7e471578a..3fa9d56cd01a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,12 @@ name = "ar" version = "0.8.0" source = "git+https://github.com/bjorn3/rust-ar.git?branch=do_not_remove_cg_clif_ranlib#de9ab0e56bf3a208381d342aa5b60f9ff2891648" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "autocfg" version = "1.1.0" @@ -36,6 +42,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" + [[package]] name = "byteorder" version = "1.4.3" @@ -50,19 +62,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93945adbccc8d731503d3038814a51e8317497c9e205411820348132fa01a358" +checksum = "44409ccf2d0f663920cab563d2b79fcd6b2e9a2bcc6e929fef76c8f82ad6c17a" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b482acc9d0d0d1ad3288a90a8150ee648be3dce8dc8c8669ff026f72debdc31" +checksum = "98de2018ad96eb97f621f7d6b900a0cc661aec8d02ea4a50e56ecb48e5a2fcaf" dependencies = [ + "arrayvec", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", @@ -77,30 +91,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ec188d71e663192ef9048f204e410a7283b609942efc9fcc77da6d496edbb8" +checksum = "5287ce36e6c4758fbaf298bd1a8697ad97a4f2375a3d1b61142ea538db4877e5" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ad794b1b1c2c7bd9f7b76cfe0f084eaf7753e55d56191c3f7d89e8fa4978b99" +checksum = "2855c24219e2f08827f3f4ffb2da92e134ae8d8ecc185b11ec8f9878cf5f588e" [[package]] name = "cranelift-entity" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342da0d5056f4119d3c311c4aab2460ceb6ee6e127bb395b76dd2279a09ea7a5" +checksum = "0b65673279d75d34bf11af9660ae2dbd1c22e6d28f163f5c72f4e1dc56d56103" [[package]] name = "cranelift-frontend" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfff792f775b07d4d9cfe9f1c767ce755c6cbadda1bbd6db18a1c75ff9f7376a" +checksum = "3ed2b3d7a4751163f6c4a349205ab1b7d9c00eecf19dcea48592ef1f7688eefc" dependencies = [ "cranelift-codegen", "log", @@ -110,15 +124,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d51089478849f2ac8ef60a8a2d5346c8d4abfec0e45ac5b24530ef9f9499e1e" +checksum = "3be64cecea9d90105fc6a2ba2d003e98c867c1d6c4c86cc878f97ad9fb916293" [[package]] name = "cranelift-jit" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "095936e41720f86004b4c57ce88e6a13af28646bb3a6fb4afbebd5ae90c50029" +checksum = "f98ed42a70a0c9c388e34ec9477f57fc7300f541b1e5136a0e2ea02b1fac6015" dependencies = [ "anyhow", "cranelift-codegen", @@ -134,9 +148,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704a1aea4723d97eafe0fb7af110f6f6868b1ac95f5380bbc9adb2a3b8cf97e8" +checksum = "d658ac7f156708bfccb647216cc8b9387469f50d352ba4ad80150541e4ae2d49" dependencies = [ "anyhow", "cranelift-codegen", @@ -144,9 +158,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "885debe62f2078638d6585f54c9f05f5c2008f22ce5a2a9100ada785fc065dbd" +checksum = "c4a03a6ac1b063e416ca4b93f6247978c991475e8271465340caa6f92f3c16a4" dependencies = [ "cranelift-codegen", "libc", @@ -155,9 +169,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.87.0" +version = "0.88.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aac1310cf1081ae8eca916c92cd163b977c77cab6e831fa812273c26ff921816" +checksum = "eef0b4119b645b870a43a036d76c0ada3a076b1f82e8b8487659304c8b09049b" dependencies = [ "anyhow", "cranelift-codegen", @@ -232,9 +246,9 @@ checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" [[package]] name = "libloading" -version = "0.6.7" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" dependencies = [ "cfg-if", "winapi", diff --git a/Cargo.toml b/Cargo.toml index e7c3427485480..09cf5b4a1edd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,19 +8,19 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.87.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.87.0" -cranelift-module = "0.87.0" -cranelift-native = "0.87.0" -cranelift-jit = { version = "0.87.0", optional = true } -cranelift-object = "0.87.0" +cranelift-codegen = { version = "0.88.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.88.1" +cranelift-module = "0.88.1" +cranelift-native = "0.88.1" +cranelift-jit = { version = "0.88.1", optional = true } +cranelift-object = "0.88.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.9.1" -libloading = { version = "0.6.0", optional = true } +libloading = { version = "0.7.3", optional = true } once_cell = "1.10.0" smallvec = "1.8.1" diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 6c5043bb6f8e1..f6a9cb67290c7 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -54,11 +54,21 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-core", +] + [[package]] name = "compiler_builtins" -version = "0.1.79" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f873ce2bd3550b0b565f878b3d04ea8253f4259dc3d20223af2e1ba86f5ecca" +checksum = "18cd7635fea7bb481ea543b392789844c1ad581299da70184c7175ce3af76603" dependencies = [ "rustc-std-workspace-core", ] @@ -123,9 +133,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897cd85af6387be149f55acf168e41be176a02de7872403aaab184afc2f327e6" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "compiler_builtins", "libc", @@ -135,9 +145,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.132" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" dependencies = [ "rustc-std-workspace-core", ] @@ -182,7 +192,7 @@ name = "panic_abort" version = "0.0.0" dependencies = [ "alloc", - "cfg-if", + "cfg-if 0.1.10", "compiler_builtins", "core", "libc", @@ -193,7 +203,7 @@ name = "panic_unwind" version = "0.0.0" dependencies = [ "alloc", - "cfg-if", + "cfg-if 0.1.10", "compiler_builtins", "core", "libc", @@ -245,7 +255,7 @@ version = "0.0.0" dependencies = [ "addr2line", "alloc", - "cfg-if", + "cfg-if 1.0.0", "compiler_builtins", "core", "dlmalloc", @@ -267,7 +277,7 @@ dependencies = [ name = "std_detect" version = "0.1.5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "compiler_builtins", "libc", "rustc-std-workspace-alloc", @@ -289,7 +299,7 @@ dependencies = [ name = "test" version = "0.0.0" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "core", "getopts", "libc", @@ -301,9 +311,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", @@ -315,7 +325,7 @@ name = "unwind" version = "0.0.0" dependencies = [ "cc", - "cfg-if", + "cfg-if 0.1.10", "compiler_builtins", "core", "libc", diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs new file mode 100644 index 0000000000000..fae5b27163680 --- /dev/null +++ b/build_system/abi_cafe.rs @@ -0,0 +1,52 @@ +use std::env; +use std::path::Path; + +use super::build_sysroot; +use super::config; +use super::prepare; +use super::utils::{cargo_command, spawn_and_wait}; +use super::SysrootKind; + +pub(crate) fn run( + channel: &str, + sysroot_kind: SysrootKind, + target_dir: &Path, + cg_clif_dylib: &Path, + host_triple: &str, + target_triple: &str, +) { + if !config::get_bool("testsuite.abi-cafe") { + eprintln!("[SKIP] abi-cafe"); + return; + } + + if host_triple != target_triple { + eprintln!("[SKIP] abi-cafe (cross-compilation not supported)"); + return; + } + + eprintln!("Building sysroot for abi-cafe"); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + target_dir, + cg_clif_dylib, + host_triple, + target_triple, + ); + + eprintln!("Running abi-cafe"); + let abi_cafe_path = prepare::ABI_CAFE.source_dir(); + env::set_current_dir(abi_cafe_path.clone()).unwrap(); + + let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; + + let mut cmd = cargo_command("cargo", "run", Some(target_triple), &abi_cafe_path); + cmd.arg("--"); + cmd.arg("--pairs"); + cmd.args(pairs); + cmd.arg("--add-rustc-codegen-backend"); + cmd.arg(format!("cgclif:{}", cg_clif_dylib.display())); + + spawn_and_wait(cmd); +} diff --git a/build_system/abi_checker.rs b/build_system/abi_checker.rs deleted file mode 100644 index 67dbd0a38a4fb..0000000000000 --- a/build_system/abi_checker.rs +++ /dev/null @@ -1,60 +0,0 @@ -use super::build_sysroot; -use super::config; -use super::utils::spawn_and_wait; -use build_system::SysrootKind; -use std::env; -use std::path::Path; -use std::process::Command; - -pub(crate) fn run( - channel: &str, - sysroot_kind: SysrootKind, - target_dir: &Path, - cg_clif_build_dir: &Path, - host_triple: &str, - target_triple: &str, -) { - if !config::get_bool("testsuite.abi-checker") { - eprintln!("[SKIP] abi-checker"); - return; - } - - if host_triple != target_triple { - eprintln!("[SKIP] abi-checker (cross-compilation not supported)"); - return; - } - - eprintln!("Building sysroot for abi-checker"); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - target_dir, - cg_clif_build_dir, - host_triple, - target_triple, - ); - - eprintln!("Running abi-checker"); - let mut abi_checker_path = env::current_dir().unwrap(); - abi_checker_path.push("abi-checker"); - env::set_current_dir(abi_checker_path.clone()).unwrap(); - - let build_dir = abi_checker_path.parent().unwrap().join("build"); - let cg_clif_dylib_path = build_dir.join(if cfg!(windows) { "bin" } else { "lib" }).join( - env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, - ); - - let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; - - let mut cmd = Command::new("cargo"); - cmd.arg("run"); - cmd.arg("--target"); - cmd.arg(target_triple); - cmd.arg("--"); - cmd.arg("--pairs"); - cmd.args(pairs); - cmd.arg("--add-rustc-codegen-backend"); - cmd.arg(format!("cgclif:{}", cg_clif_dylib_path.display())); - - spawn_and_wait(cmd); -} diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 9e59b8199b412..cda468bcfa2df 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,16 +1,16 @@ use std::env; -use std::path::{Path, PathBuf}; -use std::process::Command; +use std::path::PathBuf; -use super::utils::is_ci; +use super::rustc_info::get_file_name; +use super::utils::{cargo_command, is_ci}; pub(crate) fn build_backend( channel: &str, host_triple: &str, use_unstable_features: bool, ) -> PathBuf { - let mut cmd = Command::new("cargo"); - cmd.arg("build").arg("--target").arg(host_triple); + let source_dir = std::env::current_dir().unwrap(); + let mut cmd = cargo_command("cargo", "build", Some(host_triple), &source_dir); cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode @@ -41,5 +41,9 @@ pub(crate) fn build_backend( eprintln!("[BUILD] rustc_codegen_cranelift"); super::utils::spawn_and_wait(cmd); - Path::new("target").join(host_triple).join(channel) + source_dir + .join("target") + .join(host_triple) + .join(channel) + .join(get_file_name("rustc_codegen_cranelift", "dylib")) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 7e205b0fd0b3b..856aecc49fd1c 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,14 +3,14 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command}; use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; -use super::utils::{spawn_and_wait, try_hard_link}; +use super::utils::{cargo_command, spawn_and_wait, try_hard_link}; use super::SysrootKind; pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, target_dir: &Path, - cg_clif_build_dir: &Path, + cg_clif_dylib_src: &Path, host_triple: &str, target_triple: &str, ) { @@ -23,7 +23,6 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); let cg_clif_dylib_path = target_dir .join(if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the @@ -32,8 +31,8 @@ pub(crate) fn build_sysroot( } else { "lib" }) - .join(&cg_clif_dylib); - try_hard_link(cg_clif_build_dir.join(cg_clif_dylib), &cg_clif_dylib_path); + .join(get_file_name("rustc_codegen_cranelift", "dylib")); + try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { @@ -186,10 +185,10 @@ fn build_clif_sysroot_for_triple( } // Build sysroot - let mut build_cmd = Command::new("cargo"); - build_cmd.arg("build").arg("--target").arg(triple).current_dir("build_sysroot"); + let mut build_cmd = cargo_command("cargo", "build", Some(triple), Path::new("build_sysroot")); let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); + rustflags.push_str(&format!(" --sysroot={}", target_dir.to_str().unwrap())); if channel == "release" { build_cmd.arg("--release"); rustflags.push_str(" -Zmir-opt-level=3"); diff --git a/build_system/config.rs b/build_system/config.rs index ef540cf1f822b..c31784e1097dc 100644 --- a/build_system/config.rs +++ b/build_system/config.rs @@ -1,4 +1,5 @@ -use std::{fs, process}; +use std::fs; +use std::process; fn load_config_file() -> Vec<(String, Option)> { fs::read_to_string("config.txt") diff --git a/build_system/mod.rs b/build_system/mod.rs index c3706dc6f8203..b25270d832ceb 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -4,7 +4,7 @@ use std::process; use self::utils::is_ci; -mod abi_checker; +mod abi_cafe; mod build_backend; mod build_sysroot; mod config; @@ -122,32 +122,23 @@ pub fn main() { host_triple.clone() }; - if target_triple.ends_with("-msvc") { - eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); - eprintln!("Switch to the MinGW toolchain for Windows support."); - eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); - eprintln!("set the global default target to MinGW"); - process::exit(1); - } - - let cg_clif_build_dir = - build_backend::build_backend(channel, &host_triple, use_unstable_features); + let cg_clif_dylib = build_backend::build_backend(channel, &host_triple, use_unstable_features); match command { Command::Test => { tests::run_tests( channel, sysroot_kind, &target_dir, - &cg_clif_build_dir, + &cg_clif_dylib, &host_triple, &target_triple, ); - abi_checker::run( + abi_cafe::run( channel, sysroot_kind, &target_dir, - &cg_clif_build_dir, + &cg_clif_dylib, &host_triple, &target_triple, ); @@ -157,7 +148,7 @@ pub fn main() { channel, sysroot_kind, &target_dir, - &cg_clif_build_dir, + &cg_clif_dylib, &host_triple, &target_triple, ); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index d23b7f00dcf16..f9ab8ae70412b 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,64 +1,67 @@ use std::env; use std::ffi::OsStr; -use std::ffi::OsString; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; -use super::utils::{copy_dir_recursively, spawn_and_wait}; +use super::utils::{cargo_command, copy_dir_recursively, spawn_and_wait}; + +pub(crate) const ABI_CAFE: GitRepo = GitRepo::github( + "Gankra", + "abi-cafe", + "4c6dc8c9c687e2b3a760ff2176ce236872b37212", + "abi-cafe", +); + +pub(crate) const RAND: GitRepo = + GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); + +pub(crate) const REGEX: GitRepo = + GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex"); + +pub(crate) const PORTABLE_SIMD: GitRepo = GitRepo::github( + "rust-lang", + "portable-simd", + "d5cd4a8112d958bd3a252327e0d069a6363249bd", + "portable-simd", +); + +pub(crate) const SIMPLE_RAYTRACER: GitRepo = GitRepo::github( + "ebobby", + "simple-raytracer", + "804a7a21b9e673a482797aa289a18ed480e4d813", + "", +); pub(crate) fn prepare() { + if Path::new("download").exists() { + std::fs::remove_dir_all(Path::new("download")).unwrap(); + } + std::fs::create_dir_all(Path::new("download")).unwrap(); + prepare_sysroot(); + // FIXME maybe install this only locally? eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); - clone_repo_shallow_github( - "abi-checker", - "Gankra", - "abi-checker", - "a2232d45f202846f5c02203c9f27355360f9a2ff", - ); - apply_patches("abi-checker", Path::new("abi-checker")); - - clone_repo_shallow_github( - "rand", - "rust-random", - "rand", - "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", - ); - apply_patches("rand", Path::new("rand")); - - clone_repo_shallow_github( - "regex", - "rust-lang", - "regex", - "341f207c1071f7290e3f228c710817c280c8dca1", - ); - - clone_repo_shallow_github( - "portable-simd", - "rust-lang", - "portable-simd", - "b8d6b6844602f80af79cd96401339ec594d472d8", - ); - apply_patches("portable-simd", Path::new("portable-simd")); - - clone_repo_shallow_github( - "simple-raytracer", - "ebobby", - "simple-raytracer", - "804a7a21b9e673a482797aa289a18ed480e4d813", - ); + ABI_CAFE.fetch(); + RAND.fetch(); + REGEX.fetch(); + PORTABLE_SIMD.fetch(); + SIMPLE_RAYTRACER.fetch(); eprintln!("[LLVM BUILD] simple-raytracer"); - let mut build_cmd = Command::new("cargo"); - build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); + let build_cmd = cargo_command("cargo", "build", None, &SIMPLE_RAYTRACER.source_dir()); spawn_and_wait(build_cmd); fs::copy( - Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), - Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")), + SIMPLE_RAYTRACER + .source_dir() + .join("target") + .join("debug") + .join(get_file_name("main", "bin")), + SIMPLE_RAYTRACER.source_dir().join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } @@ -90,38 +93,78 @@ fn prepare_sysroot() { apply_patches("sysroot", &sysroot_src); } +pub(crate) struct GitRepo { + url: GitRepoUrl, + rev: &'static str, + patch_name: &'static str, +} + +enum GitRepoUrl { + Github { user: &'static str, repo: &'static str }, +} + +impl GitRepo { + const fn github( + user: &'static str, + repo: &'static str, + rev: &'static str, + patch_name: &'static str, + ) -> GitRepo { + GitRepo { url: GitRepoUrl::Github { user, repo }, rev, patch_name } + } + + pub(crate) fn source_dir(&self) -> PathBuf { + match self.url { + GitRepoUrl::Github { user: _, repo } => { + std::env::current_dir().unwrap().join("download").join(repo) + } + } + } + + fn fetch(&self) { + match self.url { + GitRepoUrl::Github { user, repo } => { + clone_repo_shallow_github(&self.source_dir(), user, repo, self.rev); + } + } + apply_patches(self.patch_name, &self.source_dir()); + } +} + #[allow(dead_code)] -fn clone_repo(target_dir: &str, repo: &str, rev: &str) { +fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); // Ignore exit code as the repo may already have been checked out - Command::new("git").arg("clone").arg(repo).arg(target_dir).spawn().unwrap().wait().unwrap(); + Command::new("git").arg("clone").arg(repo).arg(&download_dir).spawn().unwrap().wait().unwrap(); let mut clean_cmd = Command::new("git"); - clean_cmd.arg("checkout").arg("--").arg(".").current_dir(target_dir); + clean_cmd.arg("checkout").arg("--").arg(".").current_dir(&download_dir); spawn_and_wait(clean_cmd); let mut checkout_cmd = Command::new("git"); - checkout_cmd.arg("checkout").arg("-q").arg(rev).current_dir(target_dir); + checkout_cmd.arg("checkout").arg("-q").arg(rev).current_dir(download_dir); spawn_and_wait(checkout_cmd); } -fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev: &str) { +fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: &str) { if cfg!(windows) { // Older windows doesn't have tar or curl by default. Fall back to using git. - clone_repo(target_dir, &format!("https://github.com/{}/{}.git", username, repo), rev); + clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev); return; } - let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", username, repo, rev); - let archive_file = format!("{}.tar.gz", rev); - let archive_dir = format!("{}-{}", repo, rev); + let downloads_dir = std::env::current_dir().unwrap().join("download"); - eprintln!("[DOWNLOAD] {}/{} from {}", username, repo, archive_url); + let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev); + let archive_file = downloads_dir.join(format!("{}.tar.gz", rev)); + let archive_dir = downloads_dir.join(format!("{}-{}", repo, rev)); + + eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url); // Remove previous results if they exists let _ = std::fs::remove_file(&archive_file); let _ = std::fs::remove_dir_all(&archive_dir); - let _ = std::fs::remove_dir_all(target_dir); + let _ = std::fs::remove_dir_all(&download_dir); // Download zip archive let mut download_cmd = Command::new("curl"); @@ -130,13 +173,13 @@ fn clone_repo_shallow_github(target_dir: &str, username: &str, repo: &str, rev: // Unpack tar archive let mut unpack_cmd = Command::new("tar"); - unpack_cmd.arg("xf").arg(&archive_file); + unpack_cmd.arg("xf").arg(&archive_file).current_dir(downloads_dir); spawn_and_wait(unpack_cmd); // Rename unpacked dir to the expected name - std::fs::rename(archive_dir, target_dir).unwrap(); + std::fs::rename(archive_dir, &download_dir).unwrap(); - init_git_repo(Path::new(target_dir)); + init_git_repo(&download_dir); // Cleanup std::fs::remove_file(archive_file).unwrap(); @@ -156,14 +199,20 @@ fn init_git_repo(repo_dir: &Path) { spawn_and_wait(git_commit_cmd); } -fn get_patches(crate_name: &str) -> Vec { - let mut patches: Vec<_> = fs::read_dir("patches") +fn get_patches(source_dir: &Path, crate_name: &str) -> Vec { + let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches")) .unwrap() .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) - .map(|path| path.file_name().unwrap().to_owned()) - .filter(|file_name| { - file_name.to_str().unwrap().split_once("-").unwrap().1.starts_with(crate_name) + .filter(|path| { + path.file_name() + .unwrap() + .to_str() + .unwrap() + .split_once("-") + .unwrap() + .1 + .starts_with(crate_name) }) .collect(); patches.sort(); @@ -171,11 +220,18 @@ fn get_patches(crate_name: &str) -> Vec { } fn apply_patches(crate_name: &str, target_dir: &Path) { - for patch in get_patches(crate_name) { - eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch); - let patch_arg = env::current_dir().unwrap().join("patches").join(patch); + if crate_name == "" { + return; + } + + for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) { + eprintln!( + "[PATCH] {:?} <- {:?}", + target_dir.file_name().unwrap(), + patch.file_name().unwrap() + ); let mut apply_patch_cmd = Command::new("git"); - apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); + apply_patch_cmd.arg("am").arg(patch).arg("-q").current_dir(target_dir); spawn_and_wait(apply_patch_cmd); } } diff --git a/build_system/tests.rs b/build_system/tests.rs index e21397cece8b3..a414b60f4e06b 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,7 +1,8 @@ use super::build_sysroot; use super::config; +use super::prepare; use super::rustc_info::get_wrapper_file_name; -use super::utils::{spawn_and_wait, spawn_and_wait_with_input}; +use super::utils::{cargo_command, hyperfine_command, spawn_and_wait, spawn_and_wait_with_input}; use build_system::SysrootKind; use std::env; use std::ffi::OsStr; @@ -217,103 +218,95 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("test.rust-random/rand", &|runner| { - runner.in_dir(["rand"], |runner| { - runner.run_cargo(["clean"]); + runner.in_dir(prepare::RAND.source_dir(), |runner| { + runner.run_cargo("clean", []); if runner.host_triple == runner.target_triple { eprintln!("[TEST] rust-random/rand"); - runner.run_cargo(["test", "--workspace"]); + runner.run_cargo("test", ["--workspace"]); } else { eprintln!("[AOT] rust-random/rand"); - runner.run_cargo([ - "build", - "--workspace", - "--target", - &runner.target_triple, - "--tests", - ]); + runner.run_cargo("build", ["--workspace", "--tests"]); } }); }), TestCase::new("bench.simple-raytracer", &|runner| { - runner.in_dir(["simple-raytracer"], |runner| { - let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()); + runner.in_dir(prepare::SIMPLE_RAYTRACER.source_dir(), |runner| { + let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap(); if runner.host_triple == runner.target_triple { eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); - let mut bench_compile = Command::new("hyperfine"); - bench_compile.arg("--runs"); - bench_compile.arg(&run_runs); - bench_compile.arg("--warmup"); - bench_compile.arg("1"); - bench_compile.arg("--prepare"); - bench_compile.arg(format!("{:?}", runner.cargo_command(["clean"]))); - - if cfg!(windows) { - bench_compile.arg("cmd /C \"set RUSTFLAGS= && cargo build\""); - } else { - bench_compile.arg("RUSTFLAGS='' cargo build"); - } + let prepare = runner.cargo_command("clean", []); + + let llvm_build_cmd = cargo_command("cargo", "build", None, Path::new(".")); + + let cargo_clif = runner + .root_dir + .clone() + .join("build") + .join(get_wrapper_file_name("cargo-clif", "bin")); + let clif_build_cmd = cargo_command(cargo_clif, "build", None, Path::new(".")); + + let bench_compile = + hyperfine_command(1, run_runs, Some(prepare), llvm_build_cmd, clif_build_cmd); - bench_compile.arg(format!("{:?}", runner.cargo_command(["build"]))); spawn_and_wait(bench_compile); eprintln!("[BENCH RUN] ebobby/simple-raytracer"); fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif")) .unwrap(); - let mut bench_run = Command::new("hyperfine"); - bench_run.arg("--runs"); - bench_run.arg(&run_runs); - bench_run.arg(PathBuf::from("./raytracer_cg_llvm")); - bench_run.arg(PathBuf::from("./raytracer_cg_clif")); + let bench_run = hyperfine_command( + 0, + run_runs, + None, + Command::new("./raytracer_cg_llvm"), + Command::new("./raytracer_cg_clif"), + ); spawn_and_wait(bench_run); } else { - runner.run_cargo(["clean"]); + runner.run_cargo("clean", []); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)"); eprintln!("[COMPILE] ebobby/simple-raytracer"); - runner.run_cargo(["build", "--target", &runner.target_triple]); + runner.run_cargo("build", []); eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)"); } }); }), TestCase::new("test.libcore", &|runner| { - runner.in_dir(["build_sysroot", "sysroot_src", "library", "core", "tests"], |runner| { - runner.run_cargo(["clean"]); - - if runner.host_triple == runner.target_triple { - runner.run_cargo(["test"]); - } else { - eprintln!("Cross-Compiling: Not running tests"); - runner.run_cargo(["build", "--target", &runner.target_triple, "--tests"]); - } - }); + runner.in_dir( + std::env::current_dir() + .unwrap() + .join("build_sysroot") + .join("sysroot_src") + .join("library") + .join("core") + .join("tests"), + |runner| { + runner.run_cargo("clean", []); + + if runner.host_triple == runner.target_triple { + runner.run_cargo("test", []); + } else { + eprintln!("Cross-Compiling: Not running tests"); + runner.run_cargo("build", ["--tests"]); + } + }, + ); }), TestCase::new("test.regex-shootout-regex-dna", &|runner| { - runner.in_dir(["regex"], |runner| { - runner.run_cargo(["clean"]); + runner.in_dir(prepare::REGEX.source_dir(), |runner| { + runner.run_cargo("clean", []); // newer aho_corasick versions throw a deprecation warning let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); - let mut build_cmd = runner.cargo_command([ - "build", - "--example", - "shootout-regex-dna", - "--target", - &runner.target_triple, - ]); + let mut build_cmd = runner.cargo_command("build", ["--example", "shootout-regex-dna"]); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command([ - "run", - "--example", - "shootout-regex-dna", - "--target", - &runner.target_triple, - ]); + let mut run_cmd = runner.cargo_command("run", ["--example", "shootout-regex-dna"]); run_cmd.env("RUSTFLAGS", lint_rust_flags); let input = @@ -353,41 +346,43 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ }); }), TestCase::new("test.regex", &|runner| { - runner.in_dir(["regex"], |runner| { - runner.run_cargo(["clean"]); + runner.in_dir(prepare::REGEX.source_dir(), |runner| { + runner.run_cargo("clean", []); // newer aho_corasick versions throw a deprecation warning let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command([ + let mut run_cmd = runner.cargo_command( "test", - "--tests", - "--", - "--exclude-should-panic", - "--test-threads", - "1", - "-Zunstable-options", - "-q", - ]); + [ + "--tests", + "--", + "--exclude-should-panic", + "--test-threads", + "1", + "-Zunstable-options", + "-q", + ], + ); run_cmd.env("RUSTFLAGS", lint_rust_flags); spawn_and_wait(run_cmd); } else { eprintln!("Cross-Compiling: Not running tests"); let mut build_cmd = - runner.cargo_command(["build", "--tests", "--target", &runner.target_triple]); + runner.cargo_command("build", ["--tests", "--target", &runner.target_triple]); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); } }); }), TestCase::new("test.portable-simd", &|runner| { - runner.in_dir(["portable-simd"], |runner| { - runner.run_cargo(["clean"]); - runner.run_cargo(["build", "--all-targets", "--target", &runner.target_triple]); + runner.in_dir(prepare::PORTABLE_SIMD.source_dir(), |runner| { + runner.run_cargo("clean", []); + runner.run_cargo("build", ["--all-targets", "--target", &runner.target_triple]); if runner.host_triple == runner.target_triple { - runner.run_cargo(["test", "-q"]); + runner.run_cargo("test", ["-q"]); } }); }), @@ -397,7 +392,7 @@ pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, target_dir: &Path, - cg_clif_build_dir: &Path, + cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, ) { @@ -408,7 +403,7 @@ pub(crate) fn run_tests( channel, SysrootKind::None, &target_dir, - cg_clif_build_dir, + cg_clif_dylib, &host_triple, &target_triple, ); @@ -427,7 +422,7 @@ pub(crate) fn run_tests( channel, sysroot_kind, &target_dir, - cg_clif_build_dir, + cg_clif_dylib, &host_triple, &target_triple, ); @@ -521,16 +516,8 @@ impl TestRunner { } } - fn in_dir<'a, I, F>(&self, dir: I, callback: F) - where - I: IntoIterator, - F: FnOnce(&TestRunner), - { + fn in_dir(&self, new: impl AsRef, callback: impl FnOnce(&TestRunner)) { let current = env::current_dir().unwrap(); - let mut new = current.clone(); - for d in dir { - new.push(d); - } env::set_current_dir(new).unwrap(); callback(self); @@ -595,25 +582,29 @@ impl TestRunner { spawn_and_wait(cmd); } - fn cargo_command(&self, args: I) -> Command + fn cargo_command<'a, I>(&self, subcommand: &str, args: I) -> Command where - I: IntoIterator, - S: AsRef, + I: IntoIterator, { let mut cargo_clif = self.root_dir.clone(); cargo_clif.push("build"); cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin")); - let mut cmd = Command::new(cargo_clif); + let mut cmd = cargo_command( + cargo_clif, + subcommand, + if subcommand == "clean" { None } else { Some(&self.target_triple) }, + Path::new("."), + ); cmd.args(args); cmd.env("RUSTFLAGS", &self.rust_flags); cmd } - fn run_cargo<'a, I>(&self, args: I) + fn run_cargo<'a, I>(&self, subcommand: &str, args: I) where I: IntoIterator, { - spawn_and_wait(self.cargo_command(args)); + spawn_and_wait(self.cargo_command(subcommand, args)); } } diff --git a/build_system/utils.rs b/build_system/utils.rs index bdf8f8ecd9970..48da64906e2a4 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -4,6 +4,52 @@ use std::io::Write; use std::path::Path; use std::process::{self, Command, Stdio}; +pub(crate) fn cargo_command( + cargo: impl AsRef, + subcommand: &str, + triple: Option<&str>, + source_dir: &Path, +) -> Command { + let mut cmd = Command::new(cargo.as_ref()); + cmd.arg(subcommand) + .arg("--manifest-path") + .arg(source_dir.join("Cargo.toml")) + .arg("--target-dir") + .arg(source_dir.join("target")); + + if let Some(triple) = triple { + cmd.arg("--target").arg(triple); + } + + cmd +} + +pub(crate) fn hyperfine_command( + warmup: u64, + runs: u64, + prepare: Option, + a: Command, + b: Command, +) -> Command { + let mut bench = Command::new("hyperfine"); + + if warmup != 0 { + bench.arg("--warmup").arg(warmup.to_string()); + } + + if runs != 0 { + bench.arg("--runs").arg(runs.to_string()); + } + + if let Some(prepare) = prepare { + bench.arg("--prepare").arg(format!("{:?}", prepare)); + } + + bench.arg(format!("{:?}", a)).arg(format!("{:?}", b)); + + bench +} + #[track_caller] pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { let src = src.as_ref(); diff --git a/clean_all.sh b/clean_all.sh index 62e52bd195800..fedab2433aa05 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -3,4 +3,8 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} rm -rf target/ build/ perf.data{,.old} y.bin -rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ +rm -rf download/ + +# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh +# FIXME remove at some point in the future +rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ diff --git a/config.txt b/config.txt index 2264d301d5920..0d539191b12f9 100644 --- a/config.txt +++ b/config.txt @@ -49,4 +49,4 @@ test.regex-shootout-regex-dna test.regex test.portable-simd -testsuite.abi-checker +testsuite.abi-cafe diff --git a/example/issue-91827-extern-types.rs b/example/issue-91827-extern-types.rs index 2ecc8b8238b18..039100696331b 100644 --- a/example/issue-91827-extern-types.rs +++ b/example/issue-91827-extern-types.rs @@ -5,7 +5,6 @@ // Test that we can handle unsized types with an extern type tail part. // Regression test for issue #91827. -#![feature(const_ptr_offset_from)] #![feature(extern_types)] use std::ptr::addr_of; diff --git a/example/mini_core.rs b/example/mini_core.rs index 42f8aa50ba1a9..7f85b52f083a7 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -559,16 +559,22 @@ pub union MaybeUninit { pub mod intrinsics { extern "rust-intrinsic" { + #[rustc_safe_intrinsic] pub fn abort() -> !; + #[rustc_safe_intrinsic] pub fn size_of() -> usize; pub fn size_of_val(val: *const T) -> usize; + #[rustc_safe_intrinsic] pub fn min_align_of() -> usize; pub fn min_align_of_val(val: *const T) -> usize; pub fn copy(src: *const T, dst: *mut T, count: usize); pub fn transmute(e: T) -> U; pub fn ctlz_nonzero(x: T) -> T; + #[rustc_safe_intrinsic] pub fn needs_drop() -> bool; + #[rustc_safe_intrinsic] pub fn bitreverse(x: T) -> T; + #[rustc_safe_intrinsic] pub fn bswap(x: T) -> T; pub fn write_bytes(dst: *mut T, val: u8, count: usize); } diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index e83be3a3df5c4..215d3556a17ca 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -93,6 +93,7 @@ fn start( main: fn() -> T, argc: isize, argv: *const *const u8, + _sigpipe: u8, ) -> isize { if argc == 3 { unsafe { puts(*argv as *const i8); } diff --git a/patches/0001-abi-cafe-Disable-some-test-on-x86_64-pc-windows-gnu.patch b/patches/0001-abi-cafe-Disable-some-test-on-x86_64-pc-windows-gnu.patch new file mode 100644 index 0000000000000..0e5e7cdfcdf1a --- /dev/null +++ b/patches/0001-abi-cafe-Disable-some-test-on-x86_64-pc-windows-gnu.patch @@ -0,0 +1,29 @@ +From 2b15fee2bb5fd14e34c7e17e44d99cb34f4c555d Mon Sep 17 00:00:00 2001 +From: Afonso Bordado +Date: Tue, 27 Sep 2022 07:55:17 +0100 +Subject: [PATCH] Disable some test on x86_64-pc-windows-gnu + +--- + src/report.rs | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/src/report.rs b/src/report.rs +index eeec614..f582867 100644 +--- a/src/report.rs ++++ b/src/report.rs +@@ -48,6 +48,12 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl + // + // THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES + ++ // x86_64-pc-windows-gnu has some broken i128 tests that aren't disabled by default ++ if cfg!(all(target_os = "windows", target_env = "gnu")) && test.test_name == "ui128" { ++ result.run = Link; ++ result.check = Pass(Link); ++ } ++ + // END OF VENDOR RESERVED AREA + // + // +-- +2.30.1.windows.1 + diff --git a/patches/0001-abi-checker-Disable-failing-tests.patch b/patches/0001-abi-checker-Disable-failing-tests.patch deleted file mode 100644 index 526366a759876..0000000000000 --- a/patches/0001-abi-checker-Disable-failing-tests.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 1a315ba225577dbbd1f449d9609f16f984f68708 Mon Sep 17 00:00:00 2001 -From: Afonso Bordado -Date: Fri, 12 Aug 2022 22:51:58 +0000 -Subject: [PATCH] Disable abi-checker tests - ---- - src/report.rs | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/src/report.rs b/src/report.rs -index 7346f5e..8347762 100644 ---- a/src/report.rs -+++ b/src/report.rs -@@ -45,6 +45,20 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl - // - // THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES - -+ // Currently MSVC has some broken ABI issues. Furthermore, they cause -+ // a STATUS_ACCESS_VIOLATION, so we can't even run them. Ensure that they compile and link. -+ if cfg!(windows) && (test.test_name == "bool" || test.test_name == "ui128") { -+ result.run = Link; -+ result.check = Pass(Link); -+ } -+ -+ // structs is broken in the current release of cranelift for aarch64. -+ // It has been fixed for cranelift 0.88: https://github.com/bytecodealliance/wasmtime/pull/4634 -+ if cfg!(target_arch = "aarch64") && test.test_name == "structs" { -+ result.run = Link; -+ result.check = Pass(Link); -+ } -+ - // END OF VENDOR RESERVED AREA - // - // --- -2.34.1 diff --git a/patches/0001-portable-simd-Disable-unsupported-tests.patch b/patches/0001-portable-simd-Disable-unsupported-tests.patch index 54e13b090abda..89e2b61c1fc85 100644 --- a/patches/0001-portable-simd-Disable-unsupported-tests.patch +++ b/patches/0001-portable-simd-Disable-unsupported-tests.patch @@ -1,80 +1,29 @@ -From 97c473937382a5b5858d9cce3c947855d23b2dc5 Mon Sep 17 00:00:00 2001 +From b742f03694b920cc14400727d54424e8e1b60928 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 18 Nov 2021 19:28:40 +0100 Subject: [PATCH] Disable unsupported tests --- - crates/core_simd/src/math.rs | 6 ++++++ - crates/core_simd/src/vector.rs | 2 ++ - crates/core_simd/tests/masks.rs | 2 ++ - crates/core_simd/tests/ops_macros.rs | 4 ++++ - 4 files changed, 14 insertions(+) + crates/core_simd/src/elements/int.rs | 8 ++++++++ + crates/core_simd/src/elements/uint.rs | 4 ++++ + crates/core_simd/src/masks/full_masks.rs | 6 ++++++ + crates/core_simd/src/vector.rs | 2 ++ + crates/core_simd/tests/masks.rs | 3 --- + 5 files changed, 20 insertions(+), 3 deletions(-) -diff --git a/crates/core_simd/src/math.rs b/crates/core_simd/src/math.rs -index 2bae414..2f87499 100644 ---- a/crates/core_simd/src/math.rs -+++ b/crates/core_simd/src/math.rs -@@ -5,6 +5,7 @@ macro_rules! impl_uint_arith { - ($($ty:ty),+) => { - $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { - -+ /* - /// Lanewise saturating add. - /// - /// # Examples -@@ -43,6 +44,7 @@ macro_rules! impl_uint_arith { - pub fn saturating_sub(self, second: Self) -> Self { - unsafe { simd_saturating_sub(self, second) } - } -+ */ - })+ - } - } -@@ -51,6 +53,7 @@ macro_rules! impl_int_arith { - ($($ty:ty),+) => { - $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { - -+ /* - /// Lanewise saturating add. - /// - /// # Examples -@@ -89,6 +92,7 @@ macro_rules! impl_int_arith { - pub fn saturating_sub(self, second: Self) -> Self { - unsafe { simd_saturating_sub(self, second) } - } -+ */ - - /// Lanewise absolute value, implemented in Rust. - /// Every lane becomes its absolute value. -@@ -109,6 +113,7 @@ macro_rules! impl_int_arith { - (self^m) - m - } - -+ /* - /// Lanewise saturating absolute value, implemented in Rust. - /// As abs(), except the MIN value becomes MAX instead of itself. - /// -@@ -151,6 +156,7 @@ macro_rules! impl_int_arith { - pub fn saturating_neg(self) -> Self { - Self::splat(0).saturating_sub(self) - } -+ */ - })+ - } - } diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs -index 7c5ec2b..c8631e8 100644 +index e8e8f68..7173c24 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs -@@ -75,6 +75,7 @@ where - Self(array) +@@ -250,6 +250,7 @@ where + unsafe { intrinsics::simd_cast(self) } } + /* /// Reads from potentially discontiguous indices in `slice` to construct a SIMD vector. /// If an index is out-of-bounds, the lane is instead selected from the `or` vector. /// -@@ -297,6 +298,7 @@ where +@@ -473,6 +474,7 @@ where // Cleared ☢️ *mut T Zone } } @@ -82,26 +31,5 @@ index 7c5ec2b..c8631e8 100644 } impl Copy for Simd -diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs -index 6a8ecd3..68fcb49 100644 ---- a/crates/core_simd/tests/masks.rs -+++ b/crates/core_simd/tests/masks.rs -@@ -68,6 +68,7 @@ macro_rules! test_mask_api { - assert_eq!(core_simd::Mask::<$type, 8>::from_int(int), mask); - } - -+ /* - #[cfg(feature = "generic_const_exprs")] - #[test] - fn roundtrip_bitmask_conversion() { -@@ -80,6 +81,7 @@ macro_rules! test_mask_api { - assert_eq!(bitmask, [0b01001001, 0b10000011]); - assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask); - } -+ */ - } - } - } -- -2.26.2.7.g19db9cfb68 - +2.25.1 diff --git a/patches/0003-rand-Disable-rand-tests-on-mingw.patch b/patches/0003-rand-Disable-rand-tests-on-mingw.patch new file mode 100644 index 0000000000000..d8775e2d022a0 --- /dev/null +++ b/patches/0003-rand-Disable-rand-tests-on-mingw.patch @@ -0,0 +1,47 @@ +From eec874c889b8d24e5ad50faded24288150f057b1 Mon Sep 17 00:00:00 2001 +From: Afonso Bordado +Date: Tue, 27 Sep 2022 08:13:58 +0100 +Subject: [PATCH] Disable rand tests on mingw + +--- + rand_distr/src/pareto.rs | 2 ++ + rand_distr/tests/value_stability.rs | 4 ++++ + 2 files changed, 6 insertions(+) + +diff --git a/rand_distr/src/pareto.rs b/rand_distr/src/pareto.rs +index 217899e..9cedeb7 100644 +--- a/rand_distr/src/pareto.rs ++++ b/rand_distr/src/pareto.rs +@@ -107,6 +107,8 @@ mod tests { + } + + #[test] ++ // This is broken on x86_64-pc-windows-gnu presumably due to a broken powf implementation ++ #[cfg_attr(all(target_os = "windows", target_env = "gnu"), ignore)] + fn value_stability() { + fn test_samples>( + distr: D, zero: F, expected: &[F], +diff --git a/rand_distr/tests/value_stability.rs b/rand_distr/tests/value_stability.rs +index 192ba74..0101ace 100644 +--- a/rand_distr/tests/value_stability.rs ++++ b/rand_distr/tests/value_stability.rs +@@ -72,6 +72,8 @@ fn unit_disc_stability() { + } + + #[test] ++// This is broken on x86_64-pc-windows-gnu ++#[cfg_attr(all(target_os = "windows", target_env = "gnu"), ignore)] + fn pareto_stability() { + test_samples(213, Pareto::new(1.0, 1.0).unwrap(), &[ + 1.0423688f32, 2.1235929, 4.132709, 1.4679428, +@@ -143,6 +145,8 @@ fn inverse_gaussian_stability() { + } + + #[test] ++// This is broken on x86_64-pc-windows-gnu ++#[cfg_attr(all(target_os = "windows", target_env = "gnu"), ignore)] + fn gamma_stability() { + // Gamma has 3 cases: shape == 1, shape < 1, shape > 1 + test_samples(223, Gamma::new(1.0, 5.0).unwrap(), &[ +-- +2.25.1 diff --git a/rust-toolchain b/rust-toolchain index 14f2746ecb19f..c0a2e7a7883fc 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-08-24" +channel = "nightly-2022-10-23" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 091bfa1e9926f..d6a37789599fe 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -10,6 +10,8 @@ git fetch git checkout -- . git checkout "$(rustc -V | cut -d' ' -f3 | tr -d '(')" +git am ../patches/*-sysroot-*.patch + git apply - <( let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); - (CallTarget::Indirect(sig, method), Some(ptr)) + (CallTarget::Indirect(sig, method), Some(ptr.get_addr(fx))) } // Normal call @@ -560,7 +560,19 @@ pub(crate) fn codegen_drop<'tcx>( // we don't actually need to drop anything } else { match ty.kind() { - ty::Dynamic(..) => { + ty::Dynamic(_, _, ty::Dyn) => { + // IN THIS ARM, WE HAVE: + // ty = *mut (dyn Trait) + // which is: exists ( *mut T, Vtable ) + // args[0] args[1] + // + // args = ( Data, Vtable ) + // | + // v + // /-------\ + // | ... | + // \-------/ + // let (ptr, vtable) = drop_place.to_ptr_maybe_unsized(); let ptr = ptr.get_addr(fx); let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap()); @@ -578,6 +590,43 @@ pub(crate) fn codegen_drop<'tcx>( let sig = fx.bcx.import_signature(sig); fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); } + ty::Dynamic(_, _, ty::DynStar) => { + // IN THIS ARM, WE HAVE: + // ty = *mut (dyn* Trait) + // which is: *mut exists (T, Vtable) + // + // args = [ * ] + // | + // v + // ( Data, Vtable ) + // | + // v + // /-------\ + // | ... | + // \-------/ + // + // + // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING + // + // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer) + // vtable = (*args[0]).1 // loads the vtable out + // (data, vtable) // an equivalent Rust `*mut dyn Trait` + // + // SO THEN WE CAN USE THE ABOVE CODE. + let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx); + let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable); + + let virtual_drop = Instance { + def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0), + substs: drop_instance.substs, + }; + let fn_abi = + RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty()); + + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); + let sig = fx.bcx.import_signature(sig); + fx.bcx.ins().call_indirect(sig, drop_fn, &[data]); + } _ => { assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _))); diff --git a/src/allocator.rs b/src/allocator.rs index 6d321c7b298a7..bad8a87b9bee4 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -78,7 +78,7 @@ fn codegen_inner( let callee_func_id = module.declare_function(&callee_name, Linkage::Import, &sig).unwrap(); let mut ctx = Context::new(); - ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig.clone()); + ctx.func.signature = sig.clone(); { let mut func_ctx = FunctionBuilderContext::new(); let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); @@ -116,7 +116,7 @@ fn codegen_inner( let callee_func_id = module.declare_function(callee_name, Linkage::Import, &sig).unwrap(); let mut ctx = Context::new(); - ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig); + ctx.func.signature = sig; { let mut func_ctx = FunctionBuilderContext::new(); let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); diff --git a/src/archive.rs b/src/archive.rs index b4c7909617079..31d3d0e06156b 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -159,6 +159,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { let err = err.to_string(); if err == "Unknown file magic" { // Not an object file; skip it. + } else if object::read::archive::ArchiveFile::parse(&*data).is_ok() { + // Nested archive file; skip it. } else { sess.fatal(&format!( "error parsing `{}` during archive creation: {}", diff --git a/src/base.rs b/src/base.rs index 4303d63fe2131..a41b561598f68 100644 --- a/src/base.rs +++ b/src/base.rs @@ -6,6 +6,8 @@ use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; +use cranelift_codegen::ir::UserFuncName; + use crate::constant::ConstantCx; use crate::debuginfo::FunctionDebugContext; use crate::prelude::*; @@ -64,7 +66,7 @@ pub(crate) fn codegen_fn<'tcx>( let mut func_ctx = FunctionBuilderContext::new(); let mut func = cached_func; func.clear(); - func.name = ExternalName::user(0, func_id.as_u32()); + func.name = UserFuncName::user(0, func_id.as_u32()); func.signature = sig; func.collect_debug_info(); @@ -706,9 +708,9 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); operand.unsize_value(fx, lval); } - Rvalue::Cast(CastKind::DynStar, _, _) => { - // FIXME(dyn-star) - unimplemented!() + Rvalue::Cast(CastKind::DynStar, ref operand, _) => { + let operand = codegen_operand(fx, operand); + operand.coerce_dyn_star(fx, lval); } Rvalue::Discriminant(place) => { let place = codegen_place(fx, place); @@ -922,7 +924,7 @@ pub(crate) fn codegen_operand<'tcx>( let cplace = codegen_place(fx, *place); cplace.to_cvalue(fx) } - Operand::Constant(const_) => crate::constant::codegen_constant(fx, const_), + Operand::Constant(const_) => crate::constant::codegen_constant_operand(fx, const_), } } diff --git a/src/concurrency_limiter.rs b/src/concurrency_limiter.rs index dfde97920461e..f855e20e0a1a3 100644 --- a/src/concurrency_limiter.rs +++ b/src/concurrency_limiter.rs @@ -10,6 +10,7 @@ pub(super) struct ConcurrencyLimiter { helper_thread: Option, state: Arc>, available_token_condvar: Arc, + finished: bool, } impl ConcurrencyLimiter { @@ -32,6 +33,7 @@ impl ConcurrencyLimiter { helper_thread: Some(helper_thread), state, available_token_condvar: Arc::new(Condvar::new()), + finished: false, } } @@ -56,16 +58,23 @@ impl ConcurrencyLimiter { let mut state = self.state.lock().unwrap(); state.job_already_done(); } -} -impl Drop for ConcurrencyLimiter { - fn drop(&mut self) { - // + pub(crate) fn finished(mut self) { self.helper_thread.take(); // Assert that all jobs have finished let state = Mutex::get_mut(Arc::get_mut(&mut self.state).unwrap()).unwrap(); state.assert_done(); + + self.finished = true; + } +} + +impl Drop for ConcurrencyLimiter { + fn drop(&mut self) { + if !self.finished && !std::thread::panicking() { + panic!("Forgot to call finished() on ConcurrencyLimiter"); + } } } diff --git a/src/constant.rs b/src/constant.rs index c5f44bb847964..d4bc3543b2d13 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -7,7 +7,6 @@ use rustc_middle::mir::interpret::{ }; use rustc_span::DUMMY_SP; -use cranelift_codegen::ir::GlobalValueData; use cranelift_module::*; use crate::prelude::*; @@ -81,53 +80,46 @@ pub(crate) fn codegen_tls_ref<'tcx>( CValue::by_val(tls_ptr, layout) } -fn codegen_static_ref<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - def_id: DefId, - layout: TyAndLayout<'tcx>, -) -> CPlace<'tcx> { - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - if fx.clif_comments.enabled() { - fx.add_comment(local_data_id, format!("{:?}", def_id)); - } - let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id); - assert!(!layout.is_unsized(), "unsized statics aren't supported"); - assert!( - matches!( - fx.bcx.func.global_values[local_data_id], - GlobalValueData::Symbol { tls: false, .. } - ), - "tls static referenced without Rvalue::ThreadLocalRef" - ); - CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout) -} - -pub(crate) fn codegen_constant<'tcx>( +pub(crate) fn eval_mir_constant<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, -) -> CValue<'tcx> { - let (const_val, ty) = match fx.monomorphize(constant.literal) { - ConstantKind::Ty(const_) => unreachable!("{:?}", const_), - ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs, promoted }, ty) +) -> (ConstValue<'tcx>, Ty<'tcx>) { + let constant_kind = fx.monomorphize(constant.literal); + let uv = match constant_kind { + ConstantKind::Ty(const_) => match const_.kind() { + ty::ConstKind::Unevaluated(uv) => uv.expand(), + ty::ConstKind::Value(val) => { + return (fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()); + } + err => span_bug!( + constant.span, + "encountered bad ConstKind after monomorphizing: {:?}", + err + ), + }, + ConstantKind::Unevaluated(mir::UnevaluatedConst { def, .. }, _) if fx.tcx.is_static(def.did) => { - assert!(substs.is_empty()); - assert!(promoted.is_none()); - - return codegen_static_ref(fx, def.did, fx.layout_of(ty)).to_cvalue(fx); - } - ConstantKind::Unevaluated(unevaluated, ty) => { - match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) { - Ok(const_val) => (const_val, ty), - Err(_) => { - span_bug!(constant.span, "erroneous constant not captured by required_consts"); - } - } + span_bug!(constant.span, "MIR constant refers to static"); } - ConstantKind::Val(val, ty) => (val, ty), + ConstantKind::Unevaluated(uv, _) => uv, + ConstantKind::Val(val, _) => return (val, constant_kind.ty()), }; + ( + fx.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap_or_else(|_err| { + span_bug!(constant.span, "erroneous constant not captured by required_consts"); + }), + constant_kind.ty(), + ) +} + +pub(crate) fn codegen_constant_operand<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + constant: &Constant<'tcx>, +) -> CValue<'tcx> { + let (const_val, ty) = eval_mir_constant(fx, constant); + codegen_const_value(fx, const_val, ty) } @@ -244,7 +236,7 @@ pub(crate) fn codegen_const_value<'tcx>( } } -pub(crate) fn pointer_for_allocation<'tcx>( +fn pointer_for_allocation<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, alloc: ConstAllocation<'tcx>, ) -> crate::pointer::Pointer { @@ -467,14 +459,13 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( operand: &Operand<'tcx>, ) -> Option> { match operand { - Operand::Constant(const_) => match const_.literal { - ConstantKind::Ty(const_) => fx - .monomorphize(const_) - .eval_for_mir(fx.tcx, ParamEnv::reveal_all()) - .try_to_value(fx.tcx), + Operand::Constant(const_) => match fx.monomorphize(const_.literal) { + ConstantKind::Ty(const_) => Some( + const_.eval_for_mir(fx.tcx, ParamEnv::reveal_all()).try_to_value(fx.tcx).unwrap(), + ), ConstantKind::Val(val, _) => Some(val), ConstantKind::Unevaluated(uv, _) => { - fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).ok() + Some(fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).unwrap()) } }, // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 8eabe1cbcb150..f873561c1713f 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -106,7 +106,7 @@ impl OngoingCodegen { } } - drop(self.concurrency_limiter); + self.concurrency_limiter.finished(); ( CodegenResults { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 0e77e4004c0bb..6a430b5215e36 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -67,13 +67,12 @@ fn create_jit_module( hotswap: bool, ) -> (JITModule, CodegenCx) { let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string()); - let imported_symbols = load_imported_symbols_for_jit(tcx.sess, crate_info); let isa = crate::build_isa(tcx.sess, backend_config); let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names()); jit_builder.hotswap(hotswap); crate::compiler_builtins::register_functions_for_jit(&mut jit_builder); - jit_builder.symbols(imported_symbols); + jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info)); jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8); let mut jit_module = JITModule::new(jit_builder); @@ -286,10 +285,10 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> }) } -fn load_imported_symbols_for_jit( +fn dep_symbol_lookup_fn( sess: &Session, crate_info: CrateInfo, -) -> Vec<(String, *const u8)> { +) -> Box Option<*const u8>> { use rustc_middle::middle::dependency_format::Linkage; let mut dylib_paths = Vec::new(); @@ -316,39 +315,23 @@ fn load_imported_symbols_for_jit( } } - let mut imported_symbols = Vec::new(); - for path in dylib_paths { - use object::{Object, ObjectSymbol}; - let lib = libloading::Library::new(&path).unwrap(); - let obj = std::fs::read(path).unwrap(); - let obj = object::File::parse(&*obj).unwrap(); - imported_symbols.extend(obj.dynamic_symbols().filter_map(|symbol| { - let name = symbol.name().unwrap().to_string(); - if name.is_empty() || !symbol.is_global() || symbol.is_undefined() { - return None; - } - if name.starts_with("rust_metadata_") { - // The metadata is part of a section that is not loaded by the dynamic linker in - // case of cg_llvm. - return None; - } - let dlsym_name = if cfg!(target_os = "macos") { - // On macOS `dlsym` expects the name without leading `_`. - assert!(name.starts_with('_'), "{:?}", name); - &name[1..] - } else { - &name - }; - let symbol: libloading::Symbol<'_, *const u8> = - unsafe { lib.get(dlsym_name.as_bytes()) }.unwrap(); - Some((name, *symbol)) - })); - std::mem::forget(lib) - } + let imported_dylibs = Box::leak( + dylib_paths + .into_iter() + .map(|path| unsafe { libloading::Library::new(&path).unwrap() }) + .collect::>(), + ); sess.abort_if_errors(); - imported_symbols + Box::new(move |sym_name| { + for dylib in &*imported_dylibs { + if let Ok(sym) = unsafe { dylib.get::<*const u8>(sym_name.as_bytes()) } { + return Some(*sym); + } + } + None + }) } fn codegen_shim<'tcx>( diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 8b3d475cb1802..3fcc84d39295f 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -27,7 +27,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( } // Used by stdarch - if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string()) + if template[0] == InlineAsmTemplatePiece::String("mov ".to_string()) && matches!( template[1], InlineAsmTemplatePiece::Placeholder { @@ -36,24 +36,26 @@ pub(crate) fn codegen_inline_asm<'tcx>( span: _ } ) - && template[2] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[3] == InlineAsmTemplatePiece::String("cpuid".to_string()) - && template[4] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string()) + && template[2] == InlineAsmTemplatePiece::String(", rbx".to_string()) + && template[3] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[4] == InlineAsmTemplatePiece::String("cpuid".to_string()) + && template[5] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[6] == InlineAsmTemplatePiece::String("xchg ".to_string()) && matches!( - template[6], + template[7], InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ } ) + && template[8] == InlineAsmTemplatePiece::String(", rbx".to_string()) { assert_eq!(operands.len(), 4); let (leaf, eax_place) = match operands[1] { InlineAsmOperand::InOut { reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)), - late: true, + late: _, ref in_value, out_place: Some(out_place), } => ( @@ -68,7 +70,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86( X86InlineAsmRegClass::reg, )), - late: true, + late: _, place: Some(place), } => crate::base::codegen_place(fx, place), _ => unreachable!(), @@ -76,7 +78,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( let (sub_leaf, ecx_place) = match operands[2] { InlineAsmOperand::InOut { reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)), - late: true, + late: _, ref in_value, out_place: Some(out_place), } => ( @@ -88,7 +90,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( let edx_place = match operands[3] { InlineAsmOperand::Out { reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)), - late: true, + late: _, place: Some(place), } => crate::base::codegen_place(fx, place), _ => unreachable!(), diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index a799dca938e21..783d426c30bcc 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -14,6 +14,10 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( target: Option, ) { match intrinsic { + "llvm.x86.sse2.pause" | "llvm.aarch64.isb" => { + // Spin loop hint + } + // Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8` "llvm.x86.sse2.pmovmskb.128" | "llvm.x86.avx2.pmovmskb" | "llvm.x86.sse2.movmsk.pd" => { intrinsic_args!(fx, args => (a); intrinsic); @@ -25,8 +29,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( let mut res = fx.bcx.ins().iconst(types::I32, 0); for lane in (0..lane_count).rev() { - let a_lane = - a.value_field(fx, mir::Field::new(lane.try_into().unwrap())).load_scalar(fx); + let a_lane = a.value_lane(fx, lane).load_scalar(fx); // cast float to int let a_lane = match lane_ty { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 2e4ca594f91bb..0302b843aa226 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -84,6 +84,30 @@ fn simd_for_each_lane<'tcx>( } } +fn simd_pair_for_each_lane_typed<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + x: CValue<'tcx>, + y: CValue<'tcx>, + ret: CPlace<'tcx>, + f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, CValue<'tcx>, CValue<'tcx>) -> CValue<'tcx>, +) { + assert_eq!(x.layout(), y.layout()); + let layout = x.layout(); + + let (lane_count, _lane_ty) = layout.ty.simd_size_and_type(fx.tcx); + let (ret_lane_count, _ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx); + assert_eq!(lane_count, ret_lane_count); + + for lane_idx in 0..lane_count { + let x_lane = x.value_lane(fx, lane_idx); + let y_lane = y.value_lane(fx, lane_idx); + + let res_lane = f(fx, x_lane, y_lane); + + ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane); + } +} + fn simd_pair_for_each_lane<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, x: CValue<'tcx>, @@ -504,37 +528,7 @@ fn codegen_regular_intrinsic_call<'tcx>( _ => unreachable!(), }; - let signed = type_sign(lhs.layout().ty); - - let checked_res = crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs); - - let (val, has_overflow) = checked_res.load_scalar_pair(fx); - let clif_ty = fx.clif_type(lhs.layout().ty).unwrap(); - - let (min, max) = type_min_max_value(&mut fx.bcx, clif_ty, signed); - - let val = match (intrinsic, signed) { - (sym::saturating_add, false) => fx.bcx.ins().select(has_overflow, max, val), - (sym::saturating_sub, false) => fx.bcx.ins().select(has_overflow, min, val), - (sym::saturating_add, true) => { - let rhs = rhs.load_scalar(fx); - let rhs_ge_zero = - fx.bcx.ins().icmp_imm(IntCC::SignedGreaterThanOrEqual, rhs, 0); - let sat_val = fx.bcx.ins().select(rhs_ge_zero, max, min); - fx.bcx.ins().select(has_overflow, sat_val, val) - } - (sym::saturating_sub, true) => { - let rhs = rhs.load_scalar(fx); - let rhs_ge_zero = - fx.bcx.ins().icmp_imm(IntCC::SignedGreaterThanOrEqual, rhs, 0); - let sat_val = fx.bcx.ins().select(rhs_ge_zero, min, max); - fx.bcx.ins().select(has_overflow, sat_val, val) - } - _ => unreachable!(), - }; - - let res = CValue::by_val(val, lhs.layout()); - + let res = crate::num::codegen_saturating_int_binop(fx, bin_op, lhs, rhs); ret.write_cvalue(fx, res); } sym::rotate_left => { @@ -819,8 +813,8 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::ptr_guaranteed_cmp => { intrinsic_args!(fx, args => (a, b); intrinsic); - let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b); - ret.write_cvalue(fx, val); + let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx); + ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8))); } sym::caller_location => { @@ -1206,7 +1200,7 @@ fn codegen_regular_intrinsic_call<'tcx>( // FIXME once unwinding is supported, change this to actually catch panics let f_sig = fx.bcx.func.import_signature(Signature { call_conv: fx.target_config.default_call_conv, - params: vec![AbiParam::new(fx.bcx.func.dfg.value_type(data))], + params: vec![AbiParam::new(pointer_ty(fx.tcx))], returns: vec![], }); diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 1f358b1bbb96e..51fce8c854bdb 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -2,6 +2,7 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_span::Symbol; +use rustc_target::abi::Endian; use super::*; use crate::prelude::*; @@ -26,7 +27,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( span: Span, ) { match intrinsic { - sym::simd_cast => { + sym::simd_as | sym::simd_cast => { intrinsic_args!(fx, args => (a); intrinsic); if !a.layout().ty.is_simd() { @@ -162,6 +163,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } } } else { + // FIXME remove this case intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap() }; @@ -650,8 +652,128 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } } - // simd_saturating_* - // simd_bitmask + sym::simd_select_bitmask => { + intrinsic_args!(fx, args => (m, a, b); intrinsic); + + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + assert_eq!(a.layout(), b.layout()); + + let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx); + let lane_layout = fx.layout_of(lane_ty); + + let m = m.load_scalar(fx); + + for lane in 0..lane_count { + let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64); + let m_lane = fx.bcx.ins().band_imm(m_lane, 1); + let a_lane = a.value_lane(fx, lane).load_scalar(fx); + let b_lane = b.value_lane(fx, lane).load_scalar(fx); + + let m_lane = fx.bcx.ins().icmp_imm(IntCC::Equal, m_lane, 0); + let res_lane = + CValue::by_val(fx.bcx.ins().select(m_lane, b_lane, a_lane), lane_layout); + + ret.place_lane(fx, lane).write_cvalue(fx, res_lane); + } + } + + sym::simd_bitmask => { + intrinsic_args!(fx, args => (a); intrinsic); + + let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx); + let lane_clif_ty = fx.clif_type(lane_ty).unwrap(); + + // The `fn simd_bitmask(vector) -> unsigned integer` intrinsic takes a + // vector mask and returns the most significant bit (MSB) of each lane in the form + // of either: + // * an unsigned integer + // * an array of `u8` + // If the vector has less than 8 lanes, a u8 is returned with zeroed trailing bits. + // + // The bit order of the result depends on the byte endianness, LSB-first for little + // endian and MSB-first for big endian. + let expected_int_bits = lane_count.max(8); + let expected_bytes = expected_int_bits / 8 + ((expected_int_bits % 8 > 0) as u64); + + match lane_ty.kind() { + ty::Int(_) | ty::Uint(_) => {} + _ => { + fx.tcx.sess.span_fatal( + span, + &format!( + "invalid monomorphization of `simd_bitmask` intrinsic: \ + vector argument `{}`'s element type `{}`, expected integer element \ + type", + a.layout().ty, + lane_ty + ), + ); + } + } + + let res_type = + Type::int_with_byte_size(u16::try_from(expected_bytes).unwrap()).unwrap(); + let mut res = fx.bcx.ins().iconst(res_type, 0); + + let lanes = match fx.tcx.sess.target.endian { + Endian::Big => Box::new(0..lane_count) as Box>, + Endian::Little => Box::new((0..lane_count).rev()) as Box>, + }; + for lane in lanes { + let a_lane = a.value_lane(fx, lane).load_scalar(fx); + + // extract sign bit of an int + let a_lane_sign = fx.bcx.ins().ushr_imm(a_lane, i64::from(lane_clif_ty.bits() - 1)); + + // shift sign bit into result + let a_lane_sign = clif_intcast(fx, a_lane_sign, res_type, false); + res = fx.bcx.ins().ishl_imm(res, 1); + res = fx.bcx.ins().bor(res, a_lane_sign); + } + + match ret.layout().ty.kind() { + ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => {} + ty::Array(elem, len) + if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) + && len.try_eval_usize(fx.tcx, ty::ParamEnv::reveal_all()) + == Some(expected_bytes) => {} + _ => { + fx.tcx.sess.span_fatal( + span, + &format!( + "invalid monomorphization of `simd_bitmask` intrinsic: \ + cannot return `{}`, expected `u{}` or `[u8; {}]`", + ret.layout().ty, + expected_int_bits, + expected_bytes + ), + ); + } + } + + let res = CValue::by_val(res, ret.layout()); + ret.write_cvalue(fx, res); + } + + sym::simd_saturating_add | sym::simd_saturating_sub => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + let bin_op = match intrinsic { + sym::simd_saturating_add => BinOp::Add, + sym::simd_saturating_sub => BinOp::Sub, + _ => unreachable!(), + }; + + // FIXME use vector instructions when possible + simd_pair_for_each_lane_typed(fx, x, y, ret, &|fx, x_lane, y_lane| { + crate::num::codegen_saturating_int_binop(fx, bin_op, x_lane, y_lane) + }); + } + + // simd_arith_offset // simd_scatter // simd_gather _ => { diff --git a/src/lib.rs b/src/lib.rs index 913414e761821..629d79d501240 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,8 +96,8 @@ mod prelude { pub(crate) use cranelift_codegen::ir::function::Function; pub(crate) use cranelift_codegen::ir::types; pub(crate) use cranelift_codegen::ir::{ - AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, - StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value, + AbiParam, Block, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, + StackSlotData, StackSlotKind, TrapCode, Type, Value, }; pub(crate) use cranelift_codegen::isa::{self, CallConv}; pub(crate) use cranelift_codegen::Context; @@ -251,7 +251,6 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box Box( BinOp::BitXor => b.bxor(lhs, rhs), BinOp::BitAnd => b.band(lhs, rhs), BinOp::BitOr => b.bor(lhs, rhs), - BinOp::Shl => { - let lhs_ty = fx.bcx.func.dfg.value_type(lhs); - let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1)); - fx.bcx.ins().ishl(lhs, actual_shift) - } + BinOp::Shl => b.ishl(lhs, rhs), BinOp::Shr => { - let lhs_ty = fx.bcx.func.dfg.value_type(lhs); - let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1)); if signed { - fx.bcx.ins().sshr(lhs, actual_shift) + b.sshr(lhs, rhs) } else { - fx.bcx.ins().ushr(lhs, actual_shift) + b.ushr(lhs, rhs) } } // Compare binops handles by `codegen_binop`. @@ -279,22 +273,15 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( } } BinOp::Shl => { - let lhs_ty = fx.bcx.func.dfg.value_type(lhs); - let masked_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1)); - let val = fx.bcx.ins().ishl(lhs, masked_shift); + let val = fx.bcx.ins().ishl(lhs, rhs); let ty = fx.bcx.func.dfg.value_type(val); let max_shift = i64::from(ty.bits()) - 1; let has_overflow = fx.bcx.ins().icmp_imm(IntCC::UnsignedGreaterThan, rhs, max_shift); (val, has_overflow) } BinOp::Shr => { - let lhs_ty = fx.bcx.func.dfg.value_type(lhs); - let masked_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1)); - let val = if !signed { - fx.bcx.ins().ushr(lhs, masked_shift) - } else { - fx.bcx.ins().sshr(lhs, masked_shift) - }; + let val = + if !signed { fx.bcx.ins().ushr(lhs, rhs) } else { fx.bcx.ins().sshr(lhs, rhs) }; let ty = fx.bcx.func.dfg.value_type(val); let max_shift = i64::from(ty.bits()) - 1; let has_overflow = fx.bcx.ins().icmp_imm(IntCC::UnsignedGreaterThan, rhs, max_shift); @@ -309,6 +296,42 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( CValue::by_val_pair(res, has_overflow, out_layout) } +pub(crate) fn codegen_saturating_int_binop<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + bin_op: BinOp, + lhs: CValue<'tcx>, + rhs: CValue<'tcx>, +) -> CValue<'tcx> { + assert_eq!(lhs.layout().ty, rhs.layout().ty); + + let signed = type_sign(lhs.layout().ty); + let clif_ty = fx.clif_type(lhs.layout().ty).unwrap(); + let (min, max) = type_min_max_value(&mut fx.bcx, clif_ty, signed); + + let checked_res = crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs); + let (val, has_overflow) = checked_res.load_scalar_pair(fx); + + let val = match (bin_op, signed) { + (BinOp::Add, false) => fx.bcx.ins().select(has_overflow, max, val), + (BinOp::Sub, false) => fx.bcx.ins().select(has_overflow, min, val), + (BinOp::Add, true) => { + let rhs = rhs.load_scalar(fx); + let rhs_ge_zero = fx.bcx.ins().icmp_imm(IntCC::SignedGreaterThanOrEqual, rhs, 0); + let sat_val = fx.bcx.ins().select(rhs_ge_zero, max, min); + fx.bcx.ins().select(has_overflow, sat_val, val) + } + (BinOp::Sub, true) => { + let rhs = rhs.load_scalar(fx); + let rhs_ge_zero = fx.bcx.ins().icmp_imm(IntCC::SignedGreaterThanOrEqual, rhs, 0); + let sat_val = fx.bcx.ins().select(rhs_ge_zero, min, max); + fx.bcx.ins().select(has_overflow, sat_val, val) + } + _ => unreachable!(), + }; + + CValue::by_val(val, lhs.layout()) +} + pub(crate) fn codegen_float_binop<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, diff --git a/src/unsize.rs b/src/unsize.rs index dd9d891ddbdee..9c88f7dbcda33 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -25,7 +25,12 @@ pub(crate) fn unsized_info<'tcx>( .bcx .ins() .iconst(fx.pointer_type, len.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64), - (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => { + ( + &ty::Dynamic(ref data_a, _, src_dyn_kind), + &ty::Dynamic(ref data_b, _, target_dyn_kind), + ) => { + assert_eq!(src_dyn_kind, target_dyn_kind); + let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); if data_a.principal_def_id() == data_b.principal_def_id() { @@ -101,6 +106,21 @@ fn unsize_ptr<'tcx>( } } +/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type. +pub(crate) fn cast_to_dyn_star<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + src: Value, + src_ty_and_layout: TyAndLayout<'tcx>, + dst_ty: Ty<'tcx>, + old_info: Option, +) -> (Value, Value) { + assert!( + matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), + "destination type must be a dyn*" + ); + (src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info)) +} + /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` pub(crate) fn coerce_unsized_into<'tcx>( @@ -147,6 +167,24 @@ pub(crate) fn coerce_unsized_into<'tcx>( } } +pub(crate) fn coerce_dyn_star<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + src: CValue<'tcx>, + dst: CPlace<'tcx>, +) { + let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() { + let (data, vtable) = src.load_scalar_pair(fx); + (data, Some(vtable)) + } else { + let data = src.load_scalar(fx); + (data, None) + }; + + let (data, vtable) = cast_to_dyn_star(fx, data, src.layout(), dst.layout().ty, extra); + + dst.write_cvalue(fx, CValue::by_val_pair(data, vtable, dst.layout())); +} + // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs pub(crate) fn size_and_align_of_dst<'tcx>( diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 3fa3e3657cb63..c3dfbd37279f9 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -107,6 +107,50 @@ impl<'tcx> CValue<'tcx> { } } + // FIXME remove + // Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the + // vtable pointer. + pub(crate) fn dyn_star_force_data_on_stack( + self, + fx: &mut FunctionCx<'_, '_, 'tcx>, + ) -> (Value, Value) { + assert!(self.1.ty.is_dyn_star()); + + match self.0 { + CValueInner::ByRef(ptr, None) => { + let (a_scalar, b_scalar) = match self.1.abi { + Abi::ScalarPair(a, b) => (a, b), + _ => unreachable!("dyn_star_force_data_on_stack({:?})", self), + }; + let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); + let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar); + let mut flags = MemFlags::new(); + flags.set_notrap(); + let vtable = ptr.offset(fx, b_offset).load(fx, clif_ty2, flags); + (ptr.get_addr(fx), vtable) + } + CValueInner::ByValPair(data, vtable) => { + let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData { + kind: StackSlotKind::ExplicitSlot, + // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to + // specify stack slot alignment. + size: (u32::try_from(fx.target_config.pointer_type().bytes()).unwrap() + 15) + / 16 + * 16, + }); + let data_ptr = Pointer::stack_slot(stack_slot); + let mut flags = MemFlags::new(); + flags.set_notrap(); + data_ptr.store(fx, data, flags); + + (data_ptr.get_addr(fx), vtable) + } + CValueInner::ByRef(_, Some(_)) | CValueInner::ByVal(_) => { + unreachable!("dyn_star_force_data_on_stack({:?})", self) + } + } + } + pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option)> { match self.0 { CValueInner::ByRef(ptr, meta) => Some((ptr, meta)), @@ -236,6 +280,10 @@ impl<'tcx> CValue<'tcx> { crate::unsize::coerce_unsized_into(fx, self, dest); } + pub(crate) fn coerce_dyn_star(self, fx: &mut FunctionCx<'_, '_, 'tcx>, dest: CPlace<'tcx>) { + crate::unsize::coerce_dyn_star(fx, self, dest); + } + /// If `ty` is signed, `const_val` must already be sign extended. pub(crate) fn const_val( fx: &mut FunctionCx<'_, '_, 'tcx>, diff --git a/src/vtable.rs b/src/vtable.rs index 36b3725ef42bc..f04fb82de8c81 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -45,12 +45,26 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, arg: CValue<'tcx>, idx: usize, -) -> (Value, Value) { - let (ptr, vtable) = if let Abi::ScalarPair(_, _) = arg.layout().abi { - arg.load_scalar_pair(fx) - } else { - let (ptr, vtable) = arg.try_to_ptr().unwrap(); - (ptr.get_addr(fx), vtable.unwrap()) +) -> (Pointer, Value) { + let (ptr, vtable) = 'block: { + if let ty::Ref(_, ty, _) = arg.layout().ty.kind() { + if ty.is_dyn_star() { + let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty); + let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout); + let ptr = dyn_star.place_field(fx, mir::Field::new(0)).to_ptr(); + let vtable = + dyn_star.place_field(fx, mir::Field::new(1)).to_cvalue(fx).load_scalar(fx); + break 'block (ptr, vtable); + } + } + + if let Abi::ScalarPair(_, _) = arg.layout().abi { + let (ptr, vtable) = arg.load_scalar_pair(fx); + (Pointer::new(ptr), vtable) + } else { + let (ptr, vtable) = arg.try_to_ptr().unwrap(); + (ptr, vtable.unwrap()) + } }; let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes(); From 63d1bf992067ad33ac8a7818b6c8aaf11ec46b5c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 23 Oct 2022 16:43:48 +0200 Subject: [PATCH 02/77] Rustfmt cg_clif's build system --- build_system/prepare.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index f9ab8ae70412b..3111f62f6c215 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -7,12 +7,8 @@ use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{cargo_command, copy_dir_recursively, spawn_and_wait}; -pub(crate) const ABI_CAFE: GitRepo = GitRepo::github( - "Gankra", - "abi-cafe", - "4c6dc8c9c687e2b3a760ff2176ce236872b37212", - "abi-cafe", -); +pub(crate) const ABI_CAFE: GitRepo = + GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); pub(crate) const RAND: GitRepo = GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); From e3311e47171758f5567b2cae33a650b342a36453 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Wed, 12 Oct 2022 14:44:01 -0700 Subject: [PATCH 03/77] Support raw-dylib functions being used inside inlined functions --- src/archive.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/archive.rs b/src/archive.rs index 31d3d0e06156b..f2e3bf16e6184 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -38,6 +38,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder { _lib_name: &str, _dll_imports: &[rustc_session::cstore::DllImport], _tmpdir: &Path, + _is_direct_dependency: bool, ) -> PathBuf { bug!("creating dll imports is not supported"); } From 43d3e9261fba6392cee2d038f026a807881e9680 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 26 Oct 2022 13:35:18 +0000 Subject: [PATCH 04/77] Check build system formatting on CI --- .github/workflows/main.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5061010c86cd3..ad70fac97fde8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,7 @@ jobs: - name: Rustfmt run: | cargo fmt --check + rustfmt --check build_system/mod.rs build: runs-on: ${{ matrix.os }} @@ -198,14 +199,14 @@ jobs: # Enable extra checks $Env:CG_CLIF_ENABLE_VERIFIER=1 - + # WIP Disable some tests - + # This fails due to some weird argument handling by hyperfine, not an actual regression # more of a build system issue (Get-Content config.txt) -replace '(bench.simple-raytracer)', '# $1' | Out-File config.txt - - # This fails with a different output than expected + + # This fails with a different output than expected (Get-Content config.txt) -replace '(test.regex-shootout-regex-dna)', '# $1' | Out-File config.txt ./y.exe test From 33a92bc8b0d4b1d7a424e53d12244370959a2293 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 27 Oct 2022 18:32:17 +0400 Subject: [PATCH 05/77] Update tooling --- src/base.rs | 6 +----- src/constant.rs | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/base.rs b/src/base.rs index a41b561598f68..1db44502742e9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -770,11 +770,7 @@ fn codegen_stmt<'tcx>( lval.write_cvalue(fx, CValue::by_val(operand, box_layout)); } Rvalue::NullaryOp(null_op, ty) => { - assert!( - lval.layout() - .ty - .is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()) - ); + assert!(lval.layout().ty.is_sized(fx.tcx, ParamEnv::reveal_all())); let layout = fx.layout_of(fx.monomorphize(ty)); let val = match null_op { NullOp::SizeOf => layout.size.bytes(), diff --git a/src/constant.rs b/src/constant.rs index d4bc3543b2d13..148b66d959e8a 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -5,7 +5,6 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, }; -use rustc_span::DUMMY_SP; use cranelift_module::*; @@ -291,7 +290,7 @@ fn data_id_for_static( let is_mutable = if tcx.is_mutable_static(def_id) { true } else { - !ty.is_freeze(tcx.at(DUMMY_SP), ParamEnv::reveal_all()) + !ty.is_freeze(tcx, ParamEnv::reveal_all()) }; let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes(); From d3fe9a8baa154d434983356cf1ee8d240a7bb75c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 27 Oct 2022 14:48:07 +0000 Subject: [PATCH 06/77] Update to Cranelift 0.89.1 This removes the rayon dependency that requires the previous update to Cranelift 0.89.0 to be reverted. --- Cargo.lock | 62 +++++++++++++++++++++++++++++++++--------------------- Cargo.toml | 12 +++++------ 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fa9d56cd01a3..45ec8c86414ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,18 +62,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44409ccf2d0f663920cab563d2b79fcd6b2e9a2bcc6e929fef76c8f82ad6c17a" +checksum = "e4d6bb61f78cc312fbdebbb8a11b5aea6c16355ee682c57b89914691f3d57d0d" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de2018ad96eb97f621f7d6b900a0cc661aec8d02ea4a50e56ecb48e5a2fcaf" +checksum = "b4f8572ccd8b99df7a8244d64feaa37f37877e47eccc245aa5e27f15dd336d7e" dependencies = [ "arrayvec", "bumpalo", @@ -91,30 +91,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5287ce36e6c4758fbaf298bd1a8697ad97a4f2375a3d1b61142ea538db4877e5" +checksum = "15f2f284f49249a9fda931332f3feed56492651f47c330ffe1aa5a51f2b9d6b6" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2855c24219e2f08827f3f4ffb2da92e134ae8d8ecc185b11ec8f9878cf5f588e" +checksum = "8f6190411c55dfd88e68f506dfdbd028da0551dca40793d40811ea03cb6e0f4a" [[package]] name = "cranelift-entity" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b65673279d75d34bf11af9660ae2dbd1c22e6d28f163f5c72f4e1dc56d56103" +checksum = "ed8aa1104f54509dfb386520711cd8a6a0992ae42ce2df06fdebdfff4de2c2dd" [[package]] name = "cranelift-frontend" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed2b3d7a4751163f6c4a349205ab1b7d9c00eecf19dcea48592ef1f7688eefc" +checksum = "d48087600d6c055f625754b1d9cc9cab36a0d26a365cbcb388825e331e0041ff" dependencies = [ "cranelift-codegen", "log", @@ -124,15 +124,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be64cecea9d90105fc6a2ba2d003e98c867c1d6c4c86cc878f97ad9fb916293" +checksum = "eead4df80ce3c68b913d071683790692a0316a67e3518b32e273169238876f0a" [[package]] name = "cranelift-jit" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98ed42a70a0c9c388e34ec9477f57fc7300f541b1e5136a0e2ea02b1fac6015" +checksum = "f6d92ab547bf300966d5ef714e5575ae0437a2f8da6f92a30a3d35f9e7971ae9" dependencies = [ "anyhow", "cranelift-codegen", @@ -148,9 +148,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d658ac7f156708bfccb647216cc8b9387469f50d352ba4ad80150541e4ae2d49" +checksum = "9ecae6c04ac78161c9380e4953ff5d56e44fe78e1e32a3d7e816bf2e9246283f" dependencies = [ "anyhow", "cranelift-codegen", @@ -158,9 +158,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a03a6ac1b063e416ca4b93f6247978c991475e8271465340caa6f92f3c16a4" +checksum = "3adde571ff9c6a77320b69ac03920c5ce70fed94f5f9ac53f5c0600a69fc142e" dependencies = [ "cranelift-codegen", "libc", @@ -169,9 +169,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.88.1" +version = "0.89.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef0b4119b645b870a43a036d76c0ada3a076b1f82e8b8487659304c8b09049b" +checksum = "afb602999187ba96b81822fe48dbd544ecc36179741c0bc2dd6602e3ee0c5ead" dependencies = [ "anyhow", "cranelift-codegen", @@ -190,6 +190,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fxhash" version = "0.2.1" @@ -216,7 +222,9 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ + "fallible-iterator", "indexmap", + "stable_deref_trait", ] [[package]] @@ -298,9 +306,9 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "regalloc2" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +checksum = "69025b4a161879ba90719837c06621c3d73cffa147a000aeacf458f6a9572485" dependencies = [ "fxhash", "log", @@ -352,6 +360,12 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "target-lexicon" version = "0.12.4" diff --git a/Cargo.toml b/Cargo.toml index 09cf5b4a1edd8..08b3ef0ee31be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.88.1", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.88.1" -cranelift-module = "0.88.1" -cranelift-native = "0.88.1" -cranelift-jit = { version = "0.88.1", optional = true } -cranelift-object = "0.88.1" +cranelift-codegen = { version = "0.89.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.89.1" +cranelift-module = "0.89.1" +cranelift-native = "0.89.1" +cranelift-jit = { version = "0.89.1", optional = true } +cranelift-object = "0.89.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From 5513583f3fecdd8474c153af70919bf640e55d2c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:58:33 +0000 Subject: [PATCH 07/77] Stop using a deprecated function --- src/value_and_place.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index c3dfbd37279f9..75f968f3f4b8d 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -392,7 +392,7 @@ impl<'tcx> CPlace<'tcx> { local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - let var = Variable::with_u32(fx.next_ssa_var); + let var = Variable::from_u32(fx.next_ssa_var); fx.next_ssa_var += 1; fx.bcx.declare_var(var, fx.clif_type(layout.ty).unwrap()); CPlace { inner: CPlaceInner::Var(local, var), layout } @@ -403,9 +403,9 @@ impl<'tcx> CPlace<'tcx> { local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - let var1 = Variable::with_u32(fx.next_ssa_var); + let var1 = Variable::from_u32(fx.next_ssa_var); fx.next_ssa_var += 1; - let var2 = Variable::with_u32(fx.next_ssa_var); + let var2 = Variable::from_u32(fx.next_ssa_var); fx.next_ssa_var += 1; let (ty1, ty2) = fx.clif_pair_type(layout.ty).unwrap(); From a24213d81b0b3cd8b131786c2af3fe03844ce09f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 09:54:05 +0000 Subject: [PATCH 08/77] Use 2021 edition for y.rs --- build_system/tests.rs | 2 +- y.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_system/tests.rs b/build_system/tests.rs index a414b60f4e06b..248546b077e0e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -3,7 +3,7 @@ use super::config; use super::prepare; use super::rustc_info::get_wrapper_file_name; use super::utils::{cargo_command, hyperfine_command, spawn_and_wait, spawn_and_wait_with_input}; -use build_system::SysrootKind; +use super::SysrootKind; use std::env; use std::ffi::OsStr; use std::fs; diff --git a/y.rs b/y.rs index f177b91c2c487..02e1e21ade1de 100755 --- a/y.rs +++ b/y.rs @@ -3,7 +3,7 @@ # This block is ignored by rustc set -e echo "[BUILD] y.rs" 1>&2 -rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 +rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021 exec ${0/.rs/.bin} $@ */ From bd8be325ab7381b7372047fd4316de24dd8cc2a3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:17:12 +0000 Subject: [PATCH 09/77] Better rust-analyzer.linkedProjects value --- .vscode/settings.json | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 13301bf20a5ed..95603bca595b4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,13 +7,7 @@ "rust-analyzer.cargo.features": ["unstable-features"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", - //"./build_sysroot/sysroot_src/library/std/Cargo.toml", { - "roots": [ - "./example/mini_core.rs", - "./example/mini_core_hello_world.rs", - "./example/mod_bench.rs" - ], "crates": [ { "root_module": "./example/mini_core.rs", @@ -36,34 +30,17 @@ ] }, { - "roots": ["./example/std_example.rs"], - "crates": [ - { - "root_module": "./example/std_example.rs", - "edition": "2018", - "deps": [{ "crate": 1, "name": "std" }], - "cfg": [], - }, - { - "root_module": "./build_sysroot/sysroot_src/library/std/src/lib.rs", - "edition": "2018", - "deps": [], - "cfg": [], - }, - ] - }, - { - "roots": ["./y.rs"], + "sysroot_src": "./build_sysroot/sysroot_src/library", "crates": [ { "root_module": "./y.rs", - "edition": "2018", - "deps": [{ "crate": 1, "name": "std" }], + "edition": "2021", + "deps": [], "cfg": [], }, { - "root_module": "./build_sysroot/sysroot_src/library/std/src/lib.rs", - "edition": "2018", + "root_module": "./example/std_example.rs", + "edition": "2015", "deps": [], "cfg": [], }, From ddc66ffecc85fa7ba089367fe7ad6c307cbea216 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:48:51 +0000 Subject: [PATCH 10/77] Make rust-analyzer run flycheck on the build system --- .vscode/settings.json | 8 +------- Cargo.toml | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 95603bca595b4..bc914e37d2b51 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,7 @@ "rust-analyzer.imports.granularity.enforce": true, "rust-analyzer.imports.granularity.group": "module", "rust-analyzer.imports.prefix": "crate", - "rust-analyzer.cargo.features": ["unstable-features"], + "rust-analyzer.cargo.features": ["unstable-features", "__check_build_system_using_ra"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", { @@ -32,12 +32,6 @@ { "sysroot_src": "./build_sysroot/sysroot_src/library", "crates": [ - { - "root_module": "./y.rs", - "edition": "2021", - "deps": [], - "cfg": [], - }, { "root_module": "./example/std_example.rs", "edition": "2015", diff --git a/Cargo.toml b/Cargo.toml index 08b3ef0ee31be..1a97feb70b752 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,13 @@ name = "rustc_codegen_cranelift" version = "0.1.0" edition = "2021" +[[bin]] +# This is used just to teach rust-analyzer how to check the build system. required-features is used +# to disable it for regular builds. +name = "y" +path = "./y.rs" +required-features = ["__check_build_system_using_ra"] + [lib] crate-type = ["dylib"] @@ -40,6 +47,7 @@ smallvec = "1.8.1" unstable-features = ["jit", "inline_asm"] jit = ["cranelift-jit", "libloading"] inline_asm = [] +__check_build_system_using_ra = [] [package.metadata.rust-analyzer] rustc_private = true From f17dbfc933eaef12d3ae29ca500675328eaeb08e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:51:15 +0000 Subject: [PATCH 11/77] Add rustdoc-clif wrapper --- build_system/build_sysroot.rs | 2 +- scripts/rustdoc-clif.rs | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 scripts/rustdoc-clif.rs diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 856aecc49fd1c..ba606278df56d 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -35,7 +35,7 @@ pub(crate) fn build_sysroot( try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); // Build and copy rustc and cargo wrappers - for wrapper in ["rustc-clif", "cargo-clif"] { + for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { let wrapper_name = get_wrapper_file_name(wrapper, "bin"); let mut build_cargo_wrapper_cmd = Command::new("rustc"); diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs new file mode 100644 index 0000000000000..a19d72acfa83e --- /dev/null +++ b/scripts/rustdoc-clif.rs @@ -0,0 +1,36 @@ +use std::env; +use std::ffi::OsString; +#[cfg(unix)] +use std::os::unix::process::CommandExt; +use std::path::PathBuf; +use std::process::Command; + +fn main() { + let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap()); + + let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join( + env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, + ); + + let mut args = std::env::args_os().skip(1).collect::>(); + args.push(OsString::from("-Cpanic=abort")); + args.push(OsString::from("-Zpanic-abort-tests")); + let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); + codegen_backend_arg.push(cg_clif_dylib_path); + args.push(codegen_backend_arg); + if !args.contains(&OsString::from("--sysroot")) { + args.push(OsString::from("--sysroot")); + args.push(OsString::from(sysroot.to_str().unwrap())); + } + + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + + #[cfg(unix)] + Command::new("rustdoc").args(args).exec(); + + #[cfg(not(unix))] + std::process::exit( + Command::new("rustdoc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + ); +} From e0ba71e39ad68e58a32e88367271e8d5eda38550 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:21:27 +0000 Subject: [PATCH 12/77] Ignore rustfmt for y.rs --- rustfmt.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rustfmt.toml b/rustfmt.toml index 2bd8f7d1bc15d..ebeca8662a519 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,5 @@ +ignore = ["y.rs"] + # Matches rustfmt.toml of rustc version = "Two" use_small_heuristics = "Max" From c57aacf3dd218f6d7b043a0605f4917265555c0d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 14:20:27 +0000 Subject: [PATCH 13/77] Update GHA actions for Node.js 12 deprecation --- .github/workflows/main.yml | 16 ++++++++-------- .github/workflows/nightly-cranelift.yml | 2 +- .github/workflows/rustc.yml | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad70fac97fde8..e6d75177b2796 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,13 +47,13 @@ jobs: - uses: actions/checkout@v3 - name: Cache cargo installed crates - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cargo/bin key: ${{ runner.os }}-cargo-installed-crates - name: Cache cargo registry and index - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -61,7 +61,7 @@ jobs: key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo target dir - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} @@ -122,7 +122,7 @@ jobs: - name: Upload prebuilt cg_clif (cross compile) if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: cg_clif-${{ runner.os }}-cross-x86_64-mingw path: cg_clif.tar.xz @@ -148,13 +148,13 @@ jobs: - uses: actions/checkout@v3 - name: Cache cargo installed crates - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cargo/bin key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-installed-crates - name: Cache cargo registry and index - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -162,7 +162,7 @@ jobs: key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo target dir - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: target key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} @@ -216,7 +216,7 @@ jobs: run: tar cvf cg_clif.tar build - name: Upload prebuilt cg_clif - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: cg_clif-${{ matrix.env.TARGET_TRIPLE }} path: cg_clif.tar diff --git a/.github/workflows/nightly-cranelift.yml b/.github/workflows/nightly-cranelift.yml index 0a3e7ca073b45..d0d58d2a7eacb 100644 --- a/.github/workflows/nightly-cranelift.yml +++ b/.github/workflows/nightly-cranelift.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - name: Cache cargo installed crates - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cargo/bin key: ubuntu-latest-cargo-installed-crates diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index b8a98b83ebe5e..a78d6b231d3f5 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -11,13 +11,13 @@ jobs: - uses: actions/checkout@v3 - name: Cache cargo installed crates - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cargo/bin key: ${{ runner.os }}-cargo-installed-crates - name: Cache cargo registry and index - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -25,7 +25,7 @@ jobs: key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo target dir - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} @@ -49,13 +49,13 @@ jobs: - uses: actions/checkout@v3 - name: Cache cargo installed crates - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cargo/bin key: ${{ runner.os }}-cargo-installed-crates - name: Cache cargo registry and index - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -63,7 +63,7 @@ jobs: key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo target dir - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} From 777d4732dc2389752ebaa4fc7256245c4873bc25 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:47:10 +0000 Subject: [PATCH 14/77] Fix transmuting from vector type to ScalarPair type Fixes #1292 --- example/std_example.rs | 2 ++ src/value_and_place.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/example/std_example.rs b/example/std_example.rs index ad108c34992e3..8481d9c39a3cf 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -164,6 +164,8 @@ unsafe fn test_simd() { let cmp_eq = _mm_cmpeq_epi8(y, y); let cmp_lt = _mm_cmplt_epi8(y, y); + let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); + assert_eq!((zero0, zero1), (0, 0)); assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]); assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 75f968f3f4b8d..6399b97012b12 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -590,7 +590,10 @@ impl<'tcx> CPlace<'tcx> { return; } CPlaceInner::VarPair(_local, var1, var2) => { - let (data1, data2) = CValue(from.0, dst_layout).load_scalar_pair(fx); + let (ptr, meta) = from.force_stack(fx); + assert!(meta.is_none()); + let (data1, data2) = + CValue(CValueInner::ByRef(ptr, None), dst_layout).load_scalar_pair(fx); let (dst_ty1, dst_ty2) = fx.clif_pair_type(self.layout().ty).unwrap(); transmute_value(fx, var1, data1, dst_ty1); transmute_value(fx, var2, data2, dst_ty2); From b166ad0b1ebd65db9241da72e08308f87ce6e50f Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 14 Oct 2022 02:24:58 +0100 Subject: [PATCH 15/77] Rewrite implementation of `#[alloc_error_handler]` The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318). --- src/allocator.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index bad8a87b9bee4..12bb00d346db4 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -5,6 +5,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; use rustc_session::config::OomStrategy; +use rustc_span::symbol::sym; /// Returns whether an allocator shim was created pub(crate) fn codegen( @@ -23,7 +24,7 @@ pub(crate) fn codegen( module, unwind_context, kind, - tcx.lang_items().oom().is_some(), + tcx.alloc_error_handler_kind(()).unwrap(), tcx.sess.opts.unstable_opts.oom, ); true @@ -36,7 +37,7 @@ fn codegen_inner( module: &mut impl Module, unwind_context: &mut UnwindContext, kind: AllocatorKind, - has_alloc_error_handler: bool, + alloc_error_handler_kind: AllocatorKind, oom_strategy: OomStrategy, ) { let usize_ty = module.target_config().pointer_type(); @@ -108,12 +109,12 @@ fn codegen_inner( returns: vec![], }; - let callee_name = if has_alloc_error_handler { "__rg_oom" } else { "__rdl_oom" }; + let callee_name = alloc_error_handler_kind.fn_name(sym::oom); let func_id = module.declare_function("__rust_alloc_error_handler", Linkage::Export, &sig).unwrap(); - let callee_func_id = module.declare_function(callee_name, Linkage::Import, &sig).unwrap(); + let callee_func_id = module.declare_function(&callee_name, Linkage::Import, &sig).unwrap(); let mut ctx = Context::new(); ctx.func.signature = sig; From 051b6dd25fdd2d9cb86745d8f0c1b8416ae42ac3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Nov 2022 12:28:48 +0100 Subject: [PATCH 16/77] Rustup to rustc 1.67.0-nightly (edf018221 2022-11-02) --- build_sysroot/Cargo.lock | 8 ++++---- rust-toolchain | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index f6a9cb67290c7..a8e828ba5ff25 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -40,9 +40,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "cfg-if" @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.135" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index c0a2e7a7883fc..3f3cf19583218 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-10-23" +channel = "nightly-2022-11-03" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 449f95b7a50fd35b6fbe50ff7e06d1b16b130aa8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Nov 2022 11:55:06 +0000 Subject: [PATCH 17/77] Update rustc test suite failure list --- scripts/test_rustc_tests.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 9b5db3cf81f0e..d21dd6c0f7460 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -20,6 +20,7 @@ for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pat done git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed +git checkout -- src/test/ui/proc-macro/pretty-print-hack/ # missing features # ================ @@ -30,6 +31,7 @@ rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abo # requires compiling with -Cpanic=unwind rm -r src/test/ui/macros/rfc-2011-nicer-assert-messages/ +rm -r src/test/run-make/test-benches # vendor intrinsics rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected @@ -94,8 +96,6 @@ rm -r src/test/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump # genuine bugs # ============ -rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition - rm src/test/incremental/spike-neg1.rs # errors out for some reason rm src/test/incremental/spike-neg2.rs # same rm src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs # gives a stackoverflow before the backend runs @@ -111,6 +111,7 @@ rm src/test/ui/simple_global_asm.rs # TODO add needs-asm-support rm src/test/ui/test-attrs/test-type.rs # TODO panic message on stderr. correct stdout # not sure if this is actually a bug in the test suite, but the symbol list shows the function without leading _ for some reason rm -r src/test/run-make/native-link-modifier-bundle +rm src/test/ui/process/nofile-limit.rs # TODO some AArch64 linking issue rm src/test/ui/stdio-is-blocking.rs # really slow with unoptimized libstd From 7941cba900a7bc958b45d5ceda1a0265901ba656 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Nov 2022 13:48:16 +0000 Subject: [PATCH 18/77] Remove some commented out code --- example/mini_core_hello_world.rs | 2 -- src/constant.rs | 5 ----- 2 files changed, 7 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 215d3556a17ca..c00f8a2e0cdad 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -171,8 +171,6 @@ fn main() { assert_eq!(slice_ptr as usize % 4, 0); - //return; - unsafe { printf("Hello %s\n\0" as *const str as *const i8, "printf\0" as *const str as *const i8); diff --git a/src/constant.rs b/src/constant.rs index 148b66d959e8a..cd30bcf98f799 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -28,9 +28,7 @@ impl ConstantCx { } pub(crate) fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut dyn Module) { - //println!("todo {:?}", self.todo); define_all_allocs(tcx, module, &mut self); - //println!("done {:?}", self.done); self.done.clear(); } } @@ -358,8 +356,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant (data_id, alloc, None) } TodoItem::Static(def_id) => { - //println!("static {:?}", def_id); - let section_name = tcx.codegen_fn_attrs(def_id).link_section; let alloc = tcx.eval_static_initializer(def_id).unwrap(); @@ -369,7 +365,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } }; - //("data_id {}", data_id); if cx.done.contains(&data_id) { continue; } From 0b37af8c6168f11221ba74115eb3c5725fd13c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sat, 5 Nov 2022 13:24:46 +0100 Subject: [PATCH 19/77] Update `target-lexicon` to fix new targets parsing (#1293) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45ec8c86414ca..6bf913e7f1d21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,9 +368,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "target-lexicon" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" +checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" [[package]] name = "version_check" From b5523e3e7a197bcb204cacf27097bffc2123e9fd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 6 Nov 2022 14:15:20 +0100 Subject: [PATCH 20/77] fix cranelift and gcc --- src/constant.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 148b66d959e8a..0b8393e3d17c0 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -398,7 +398,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); data_ctx.define(bytes.into_boxed_slice()); - for &(offset, alloc_id) in alloc.provenance().iter() { + for &(offset, alloc_id) in alloc.provenance().ptrs().iter() { let addend = { let endianness = tcx.data_layout.endian; let offset = offset.bytes() as usize; @@ -431,7 +431,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant { tcx.sess.fatal(&format!( "Allocation {:?} contains reference to TLS value {:?}", - alloc, def_id + alloc_id, def_id )); } From ade426fa83a4840a3940aee184e8b65ecfeeb6aa Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 9 Nov 2022 02:52:59 -0600 Subject: [PATCH 21/77] Fix `rustdoc --version` when used with download-rustc Previously, rustdoc would unconditionally report the version that *rustc* was compiled with. That showed things like `nightly-2022-10-30`, which wasn't right, since this was a `dev` build compiled from source. Fix it by changing `rustc_driver::version` to a macro expanded at invocation time. --- src/debuginfo/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index c55db2017ee68..2ba012a77b0a9 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -59,7 +59,7 @@ impl DebugContext { let producer = format!( "cg_clif (rustc {}, cranelift {})", - rustc_interface::util::version_str().unwrap_or("unknown version"), + rustc_interface::util::rustc_version_str().unwrap_or("unknown version"), cranelift_codegen::VERSION, ); let comp_dir = tcx From d1e499aa2d5e16eab6b70c04b28bd04b67de3c60 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Nov 2022 12:30:30 +0100 Subject: [PATCH 22/77] Rustup to rustc 1.67.0-nightly (e75aab045 2022-11-09) --- build_sysroot/Cargo.lock | 37 +++++++++++++++---------------------- example/mini_core.rs | 7 +++++-- rust-toolchain | 2 +- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index a8e828ba5ff25..dcb791bd3f161 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ "compiler_builtins", "gimli", @@ -32,17 +32,11 @@ dependencies = [ "core", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "cc" -version = "1.0.74" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" [[package]] name = "cfg-if" @@ -66,9 +60,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18cd7635fea7bb481ea543b392789844c1ad581299da70184c7175ce3af76603" +checksum = "70ee07c7fcd313705c3556f0e3070c4f235568d740c0e3fa7532af64c5d98917" dependencies = [ "rustc-std-workspace-core", ] @@ -111,9 +105,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -164,12 +158,11 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", - "autocfg", "compiler_builtins", "rustc-std-workspace-alloc", "rustc-std-workspace-core", @@ -177,9 +170,9 @@ dependencies = [ [[package]] name = "object" -version = "0.26.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "compiler_builtins", "memchr", @@ -192,7 +185,7 @@ name = "panic_abort" version = "0.0.0" dependencies = [ "alloc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "compiler_builtins", "core", "libc", @@ -203,7 +196,7 @@ name = "panic_unwind" version = "0.0.0" dependencies = [ "alloc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "compiler_builtins", "core", "libc", @@ -325,7 +318,7 @@ name = "unwind" version = "0.0.0" dependencies = [ "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "compiler_builtins", "core", "libc", diff --git a/example/mini_core.rs b/example/mini_core.rs index 7f85b52f083a7..1f9db1eb2a97a 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -19,6 +19,9 @@ pub trait Sized {} #[lang = "destruct"] pub trait Destruct {} +#[lang = "tuple_trait"] +pub trait Tuple {} + #[lang = "unsize"] pub trait Unsize {} @@ -443,7 +446,7 @@ pub struct PhantomData; #[lang = "fn_once"] #[rustc_paren_sugar] -pub trait FnOnce { +pub trait FnOnce { #[lang = "fn_once_output"] type Output; @@ -452,7 +455,7 @@ pub trait FnOnce { #[lang = "fn_mut"] #[rustc_paren_sugar] -pub trait FnMut: FnOnce { +pub trait FnMut: FnOnce { extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; } diff --git a/rust-toolchain b/rust-toolchain index 3f3cf19583218..f6e816ce5d791 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-11-03" +channel = "nightly-2022-11-10" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From f5caaea98a394f5186b6dbf99fcf1b2ad9ad78a0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 13 Nov 2022 12:14:59 +0100 Subject: [PATCH 23/77] add is_sized method on Abi and Layout, and use it --- src/constant.rs | 2 +- src/value_and_place.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 148b66d959e8a..df1150ec0b8ce 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -128,7 +128,7 @@ pub(crate) fn codegen_const_value<'tcx>( ty: Ty<'tcx>, ) -> CValue<'tcx> { let layout = fx.layout_of(ty); - assert!(!layout.is_unsized(), "sized const value"); + assert!(layout.is_sized(), "unsized const value"); if layout.is_zst() { return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index c3dfbd37279f9..c5bd574623df6 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -19,7 +19,7 @@ fn codegen_field<'tcx>( }; if let Some(extra) = extra { - if !field_layout.is_unsized() { + if field_layout.is_sized() { return simple(fx); } match field_layout.ty.kind() { @@ -364,7 +364,7 @@ impl<'tcx> CPlace<'tcx> { fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - assert!(!layout.is_unsized()); + assert!(layout.is_sized()); if layout.size.bytes() == 0 { return CPlace { inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None), @@ -825,7 +825,7 @@ impl<'tcx> CPlace<'tcx> { fx: &FunctionCx<'_, '_, 'tcx>, variant: VariantIdx, ) -> Self { - assert!(!self.layout().is_unsized()); + assert!(self.layout().is_sized()); let layout = self.layout().for_variant(fx, variant); CPlace { inner: self.inner, layout } } From 2d0c41a9a3915e7d1c4a4a363b83b1954dab055e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 15 Nov 2022 12:06:20 +0100 Subject: [PATCH 24/77] cleanup and dedupe CTFE and Miri error reporting --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index c0c6c76473ba8..5478caee57d45 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -47,7 +47,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) { all_constants_ok = false; match err { - ErrorHandled::Reported(_) | ErrorHandled::Linted => { + ErrorHandled::Reported(_) => { fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); } ErrorHandled::TooGeneric => { From 268219da020114913e101642e47699149778bbd8 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 16 Nov 2022 21:58:58 +0000 Subject: [PATCH 25/77] Use `as_deref` in compiler (but only where it makes sense) --- build_system/utils.rs | 2 +- src/config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_system/utils.rs b/build_system/utils.rs index 48da64906e2a4..c627af4e62fe1 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -104,5 +104,5 @@ pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) { } pub(crate) fn is_ci() -> bool { - env::var("CI").as_ref().map(|val| &**val) == Ok("true") + env::var("CI").as_deref() == Ok("true") } diff --git a/src/config.rs b/src/config.rs index e59a0cb0a2323..45522fb1a4cab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,7 @@ use std::env; use std::str::FromStr; fn bool_env_var(key: &str) -> bool { - env::var(key).as_ref().map(|val| &**val) == Ok("1") + env::var(key).as_deref() == Ok("1") } /// The mode to use for compilation. From 6ee9712cd44a9b19132413abfe39d42720724dc6 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Thu, 17 Nov 2022 14:59:32 +0530 Subject: [PATCH 26/77] Use custom entry name in cranelift This is a continuation of 9f0a8620bd7d325e6d42417b08daff3e55cb88f6 for cranelift. Signed-off-by: Ayush Singh --- src/abi/mod.rs | 25 +++++++++++++++---------- src/main_shim.rs | 8 ++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 99059e788a074..1e22537c2ba42 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -22,7 +22,19 @@ fn clif_sig_from_fn_abi<'tcx>( default_call_conv: CallConv, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> Signature { - let call_conv = match fn_abi.conv { + let call_conv = conv_to_call_conv(fn_abi.conv, default_call_conv); + + let inputs = fn_abi.args.iter().map(|arg_abi| arg_abi.get_abi_param(tcx).into_iter()).flatten(); + + let (return_ptr, returns) = fn_abi.ret.get_abi_return(tcx); + // Sometimes the first param is an pointer to the place where the return value needs to be stored. + let params: Vec<_> = return_ptr.into_iter().chain(inputs).collect(); + + Signature { params, returns, call_conv } +} + +pub(crate) fn conv_to_call_conv(c: Conv, default_call_conv: CallConv) -> CallConv { + match c { Conv::Rust | Conv::C => default_call_conv, Conv::RustCold => CallConv::Cold, Conv::X86_64SysV => CallConv::SystemV, @@ -38,15 +50,8 @@ fn clif_sig_from_fn_abi<'tcx>( | Conv::X86VectorCall | Conv::AmdGpuKernel | Conv::AvrInterrupt - | Conv::AvrNonBlockingInterrupt => todo!("{:?}", fn_abi.conv), - }; - let inputs = fn_abi.args.iter().map(|arg_abi| arg_abi.get_abi_param(tcx).into_iter()).flatten(); - - let (return_ptr, returns) = fn_abi.ret.get_abi_return(tcx); - // Sometimes the first param is an pointer to the place where the return value needs to be stored. - let params: Vec<_> = return_ptr.into_iter().chain(inputs).collect(); - - Signature { params, returns, call_conv } + | Conv::AvrNonBlockingInterrupt => todo!("{:?}", c), + } } pub(crate) fn get_function_sig<'tcx>( diff --git a/src/main_shim.rs b/src/main_shim.rs index cae6312a60735..f7434633ea442 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -63,10 +63,14 @@ pub(crate) fn maybe_create_entry_wrapper( AbiParam::new(m.target_config().pointer_type()), ], returns: vec![AbiParam::new(m.target_config().pointer_type() /*isize*/)], - call_conv: CallConv::triple_default(m.isa().triple()), + call_conv: crate::conv_to_call_conv( + tcx.sess.target.options.entry_abi, + CallConv::triple_default(m.isa().triple()), + ), }; - let cmain_func_id = m.declare_function("main", Linkage::Export, &cmain_sig).unwrap(); + let entry_name = tcx.sess.target.options.entry_name.as_ref(); + let cmain_func_id = m.declare_function(entry_name, Linkage::Export, &cmain_sig).unwrap(); let instance = Instance::mono(tcx, rust_main_def_id).polymorphize(tcx); From a3c89a7ade837cb3d64c17e0b58a67d2c57f2887 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Nov 2022 13:41:21 +0100 Subject: [PATCH 27/77] deduplicate constant evaluation in cranelift backend also sync LLVM and cranelift structure a bit --- src/constant.rs | 58 ++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 5478caee57d45..077f33bb99cf7 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -38,22 +38,8 @@ impl ConstantCx { pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { let mut all_constants_ok = true; for constant in &fx.mir.required_consts { - let unevaluated = match fx.monomorphize(constant.literal) { - ConstantKind::Ty(_) => unreachable!(), - ConstantKind::Unevaluated(uv, _) => uv, - ConstantKind::Val(..) => continue, - }; - - if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) { + if eval_mir_constant(fx, constant).is_none() { all_constants_ok = false; - match err { - ErrorHandled::Reported(_) => { - fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); - } - ErrorHandled::TooGeneric => { - span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err); - } - } } } all_constants_ok @@ -80,15 +66,15 @@ pub(crate) fn codegen_tls_ref<'tcx>( } pub(crate) fn eval_mir_constant<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, + fx: &FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, -) -> (ConstValue<'tcx>, Ty<'tcx>) { +) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> { let constant_kind = fx.monomorphize(constant.literal); let uv = match constant_kind { ConstantKind::Ty(const_) => match const_.kind() { ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Value(val) => { - return (fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()); + return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty())); } err => span_bug!( constant.span, @@ -102,22 +88,31 @@ pub(crate) fn eval_mir_constant<'tcx>( span_bug!(constant.span, "MIR constant refers to static"); } ConstantKind::Unevaluated(uv, _) => uv, - ConstantKind::Val(val, _) => return (val, constant_kind.ty()), + ConstantKind::Val(val, _) => return Some((val, constant_kind.ty())), }; - ( - fx.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap_or_else(|_err| { - span_bug!(constant.span, "erroneous constant not captured by required_consts"); - }), - constant_kind.ty(), - ) + let val = fx + .tcx + .const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None) + .map_err(|err| match err { + ErrorHandled::Reported(_) => { + fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); + } + ErrorHandled::TooGeneric => { + span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err); + } + }) + .ok(); + val.map(|val| (val, constant_kind.ty())) } pub(crate) fn codegen_constant_operand<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, ) -> CValue<'tcx> { - let (const_val, ty) = eval_mir_constant(fx, constant); + let (const_val, ty) = eval_mir_constant(fx, constant).unwrap_or_else(|| { + span_bug!(constant.span, "erroneous constant not captured by required_consts") + }); codegen_const_value(fx, const_val, ty) } @@ -453,20 +448,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant assert!(cx.todo.is_empty(), "{:?}", cx.todo); } +/// Used only for intrinsic implementations that need a compile-time constant pub(crate) fn mir_operand_get_const_val<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, operand: &Operand<'tcx>, ) -> Option> { match operand { - Operand::Constant(const_) => match fx.monomorphize(const_.literal) { - ConstantKind::Ty(const_) => Some( - const_.eval_for_mir(fx.tcx, ParamEnv::reveal_all()).try_to_value(fx.tcx).unwrap(), - ), - ConstantKind::Val(val, _) => Some(val), - ConstantKind::Unevaluated(uv, _) => { - Some(fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).unwrap()) - } - }, + Operand::Constant(const_) => Some(eval_mir_constant(fx, const_).unwrap().0), // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored // inside a temporary before being passed to the intrinsic requiring the const argument. // This code tries to find a single constant defining definition of the referenced local. From be1006be507dc1f5f25e8260267ead842d53df40 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:26:37 +0100 Subject: [PATCH 28/77] Rustup to rustc 1.67.0-nightly (c5d82ed7a 2022-11-19) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index dcb791bd3f161..bb6a2cadf4909 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -60,9 +60,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.83" +version = "0.1.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ee07c7fcd313705c3556f0e3070c4f235568d740c0e3fa7532af64c5d98917" +checksum = "989b2c1ca6e90ad06fdc69d1d1862fa28d27a977be6d92ae2fa762cf61fe0b10" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index f6e816ce5d791..887d8ea9e4362 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-11-10" +channel = "nightly-2022-11-20" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 9723c79af7baa9f778566058aa1d50a8e2711b96 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 20 Nov 2022 19:32:44 +0000 Subject: [PATCH 29/77] Fix running rustc tests --- scripts/setup_rust_fork.sh | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index d6a37789599fe..5a73cb0e2c22d 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -27,24 +27,6 @@ index d95b5b7f17f..00b6f0e3635 100644 [dev-dependencies] rand = "0.7" rand_xorshift = "0.2" -diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs -index 8431aa7b818..a3ff7e68ce5 100644 ---- a/src/tools/compiletest/src/runtest.rs -+++ b/src/tools/compiletest/src/runtest.rs -@@ -3489,12 +3489,7 @@ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> S - let compiler_src_dir = base_dir.join("compiler"); - normalize_path(&compiler_src_dir, "$(echo '$COMPILER_DIR')"); - -- if let Some(virtual_rust_source_base_dir) = -- option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) -- { -- normalize_path(&virtual_rust_source_base_dir.join("library"), "$(echo '$SRC_DIR')"); -- normalize_path(&virtual_rust_source_base_dir.join("compiler"), "$(echo '$COMPILER_DIR')"); -- } -+ normalize_path(&Path::new("$(cd ../build_sysroot/sysroot_src/library; pwd)"), "$(echo '$SRC_DIR')"); - - // Paths into the build directory - let test_build_dir = &self.config.build_base; EOF cat > config.toml < Date: Mon, 21 Nov 2022 16:29:09 +0000 Subject: [PATCH 30/77] Fix discriminant handling --- src/common.rs | 2 +- src/discriminant.rs | 196 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 153 insertions(+), 45 deletions(-) diff --git a/src/common.rs b/src/common.rs index 589594465783e..6a3ab8881bb66 100644 --- a/src/common.rs +++ b/src/common.rs @@ -162,7 +162,7 @@ pub(crate) fn codegen_icmp_imm( } } } else { - let rhs = i64::try_from(rhs).expect("codegen_icmp_imm rhs out of range for <128bit int"); + let rhs = rhs as i64; // Truncates on purpose in case rhs is actually an unsigned value fx.bcx.ins().icmp_imm(intcc, lhs, rhs) } } diff --git a/src/discriminant.rs b/src/discriminant.rs index 97b395bcd0518..11aa52a332c18 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -1,6 +1,7 @@ //! Handling of enum discriminants //! -//! Adapted from +//! Adapted from +//! () use rustc_target::abi::{Int, TagEncoding, Variants}; @@ -47,13 +48,18 @@ pub(crate) fn codegen_set_discriminant<'tcx>( } => { if variant_index != untagged_variant { let niche = place.place_field(fx, mir::Field::new(tag_field)); + let niche_type = fx.clif_type(niche.layout().ty).unwrap(); let niche_value = variant_index.as_u32() - niche_variants.start().as_u32(); - let niche_value = ty::ScalarInt::try_from_uint( - u128::from(niche_value).wrapping_add(niche_start), - niche.layout().size, - ) - .unwrap(); - let niche_llval = CValue::const_val(fx, niche.layout(), niche_value); + let niche_value = (niche_value as u128).wrapping_add(niche_start); + let niche_value = match niche_type { + types::I128 => { + let lsb = fx.bcx.ins().iconst(types::I64, niche_value as u64 as i64); + let msb = fx.bcx.ins().iconst(types::I64, (niche_value >> 64) as u64 as i64); + fx.bcx.ins().iconcat(lsb, msb) + } + ty => fx.bcx.ins().iconst(ty, niche_value as i64), + }; + let niche_llval = CValue::by_val(niche_value, niche.layout()); niche.write_cvalue(fx, niche_llval); } } @@ -96,6 +102,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>( } }; + let cast_to_size = dest_layout.layout.size(); let cast_to = fx.clif_type(dest_layout.ty).unwrap(); // Read the tag/niche-encoded discriminant from memory. @@ -114,21 +121,128 @@ pub(crate) fn codegen_get_discriminant<'tcx>( dest.write_cvalue(fx, res); } TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start } => { - // Rebase from niche values to discriminants, and check - // whether the result is in range for the niche variants. - - // We first compute the "relative discriminant" (wrt `niche_variants`), - // that is, if `n = niche_variants.end() - niche_variants.start()`, - // we remap `niche_start..=niche_start + n` (which may wrap around) - // to (non-wrap-around) `0..=n`, to be able to check whether the - // discriminant corresponds to a niche variant with one comparison. - // We also can't go directly to the (variant index) discriminant - // and check that it is in the range `niche_variants`, because - // that might not fit in the same type, on top of needing an extra - // comparison (see also the comment on `let niche_discr`). - let relative_discr = if niche_start == 0 { - tag + let tag_size = tag_scalar.size(fx); + let max_unsigned = tag_size.unsigned_int_max(); + let max_signed = tag_size.signed_int_max() as u128; + let min_signed = max_signed + 1; + let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32(); + let niche_end = niche_start.wrapping_add(relative_max as u128) & max_unsigned; + let range = tag_scalar.valid_range(fx); + + let sle = |lhs: u128, rhs: u128| -> bool { + // Signed and unsigned comparisons give the same results, + // except that in signed comparisons an integer with the + // sign bit set is less than one with the sign bit clear. + // Toggle the sign bit to do a signed comparison. + (lhs ^ min_signed) <= (rhs ^ min_signed) + }; + + // We have a subrange `niche_start..=niche_end` inside `range`. + // If the value of the tag is inside this subrange, it's a + // "niche value", an increment of the discriminant. Otherwise it + // indicates the untagged variant. + // A general algorithm to extract the discriminant from the tag + // is: + // relative_tag = tag - niche_start + // is_niche = relative_tag <= (ule) relative_max + // discr = if is_niche { + // cast(relative_tag) + niche_variants.start() + // } else { + // untagged_variant + // } + // However, we will likely be able to emit simpler code. + + // Find the least and greatest values in `range`, considered + // both as signed and unsigned. + let (low_unsigned, high_unsigned) = + if range.start <= range.end { (range.start, range.end) } else { (0, max_unsigned) }; + let (low_signed, high_signed) = if sle(range.start, range.end) { + (range.start, range.end) + } else { + (min_signed, max_signed) + }; + + let niches_ule = niche_start <= niche_end; + let niches_sle = sle(niche_start, niche_end); + let cast_smaller = cast_to_size <= tag_size; + + // In the algorithm above, we can change + // cast(relative_tag) + niche_variants.start() + // into + // cast(tag + (niche_variants.start() - niche_start)) + // if either the casted type is no larger than the original + // type, or if the niche values are contiguous (in either the + // signed or unsigned sense). + let can_incr = cast_smaller || niches_ule || niches_sle; + + let data_for_boundary_niche = || -> Option<(IntCC, u128)> { + if !can_incr { + None + } else if niche_start == low_unsigned { + Some((IntCC::UnsignedLessThanOrEqual, niche_end)) + } else if niche_end == high_unsigned { + Some((IntCC::UnsignedGreaterThanOrEqual, niche_start)) + } else if niche_start == low_signed { + Some((IntCC::SignedLessThanOrEqual, niche_end)) + } else if niche_end == high_signed { + Some((IntCC::SignedGreaterThanOrEqual, niche_start)) + } else { + None + } + }; + + let (is_niche, tagged_discr, delta) = if relative_max == 0 { + // Best case scenario: only one tagged variant. This will + // likely become just a comparison and a jump. + // The algorithm is: + // is_niche = tag == niche_start + // discr = if is_niche { + // niche_start + // } else { + // untagged_variant + // } + let is_niche = codegen_icmp_imm(fx, IntCC::Equal, tag, niche_start as i128); + let tagged_discr = + fx.bcx.ins().iconst(cast_to, niche_variants.start().as_u32() as i64); + (is_niche, tagged_discr, 0) + } else if let Some((predicate, constant)) = data_for_boundary_niche() { + // The niche values are either the lowest or the highest in + // `range`. We can avoid the first subtraction in the + // algorithm. + // The algorithm is now this: + // is_niche = tag <= niche_end + // discr = if is_niche { + // cast(tag + (niche_variants.start() - niche_start)) + // } else { + // untagged_variant + // } + // (the first line may instead be tag >= niche_start, + // and may be a signed or unsigned comparison) + // The arithmetic must be done before the cast, so we can + // have the correct wrapping behavior. See issue #104519 for + // the consequences of getting this wrong. + let is_niche = codegen_icmp_imm(fx, predicate, tag, constant as i128); + let delta = (niche_variants.start().as_u32() as u128).wrapping_sub(niche_start); + let incr_tag = if delta == 0 { + tag + } else { + let delta = match fx.bcx.func.dfg.value_type(tag) { + types::I128 => { + let lsb = fx.bcx.ins().iconst(types::I64, delta as u64 as i64); + let msb = fx.bcx.ins().iconst(types::I64, (delta >> 64) as u64 as i64); + fx.bcx.ins().iconcat(lsb, msb) + } + ty => fx.bcx.ins().iconst(ty, delta as i64), + }; + fx.bcx.ins().iadd(tag, delta) + }; + + let cast_tag = clif_intcast(fx, incr_tag, cast_to, !niches_ule); + + (is_niche, cast_tag, 0) } else { + // The special cases don't apply, so we'll have to go with + // the general algorithm. let niche_start = match fx.bcx.func.dfg.value_type(tag) { types::I128 => { let lsb = fx.bcx.ins().iconst(types::I64, niche_start as u64 as i64); @@ -138,40 +252,34 @@ pub(crate) fn codegen_get_discriminant<'tcx>( } ty => fx.bcx.ins().iconst(ty, niche_start as i64), }; - fx.bcx.ins().isub(tag, niche_start) - }; - let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32(); - let is_niche = { - codegen_icmp_imm( + let relative_discr = fx.bcx.ins().isub(tag, niche_start); + let cast_tag = clif_intcast(fx, relative_discr, cast_to, false); + let is_niche = crate::common::codegen_icmp_imm( fx, IntCC::UnsignedLessThanOrEqual, relative_discr, i128::from(relative_max), - ) + ); + (is_niche, cast_tag, niche_variants.start().as_u32() as u128) }; - // NOTE(eddyb) this addition needs to be performed on the final - // type, in case the niche itself can't represent all variant - // indices (e.g. `u8` niche with more than `256` variants, - // but enough uninhabited variants so that the remaining variants - // fit in the niche). - // In other words, `niche_variants.end - niche_variants.start` - // is representable in the niche, but `niche_variants.end` - // might not be, in extreme cases. - let niche_discr = { - let relative_discr = if relative_max == 0 { - // HACK(eddyb) since we have only one niche, we know which - // one it is, and we can avoid having a dynamic value here. - fx.bcx.ins().iconst(cast_to, 0) - } else { - clif_intcast(fx, relative_discr, cast_to, false) + let tagged_discr = if delta == 0 { + tagged_discr + } else { + let delta = match cast_to { + types::I128 => { + let lsb = fx.bcx.ins().iconst(types::I64, delta as u64 as i64); + let msb = fx.bcx.ins().iconst(types::I64, (delta >> 64) as u64 as i64); + fx.bcx.ins().iconcat(lsb, msb) + } + ty => fx.bcx.ins().iconst(ty, delta as i64), }; - fx.bcx.ins().iadd_imm(relative_discr, i64::from(niche_variants.start().as_u32())) + fx.bcx.ins().iadd(tagged_discr, delta) }; let untagged_variant = fx.bcx.ins().iconst(cast_to, i64::from(untagged_variant.as_u32())); - let discr = fx.bcx.ins().select(is_niche, niche_discr, untagged_variant); + let discr = fx.bcx.ins().select(is_niche, tagged_discr, untagged_variant); let res = CValue::by_val(discr, dest_layout); dest.write_cvalue(fx, res); } From a449d0d1431b789adf7c4c27e0db028ad2218a4a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:00:28 +0000 Subject: [PATCH 31/77] Rustfmt --- src/discriminant.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/discriminant.rs b/src/discriminant.rs index 11aa52a332c18..b452047c76096 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -54,7 +54,8 @@ pub(crate) fn codegen_set_discriminant<'tcx>( let niche_value = match niche_type { types::I128 => { let lsb = fx.bcx.ins().iconst(types::I64, niche_value as u64 as i64); - let msb = fx.bcx.ins().iconst(types::I64, (niche_value >> 64) as u64 as i64); + let msb = + fx.bcx.ins().iconst(types::I64, (niche_value >> 64) as u64 as i64); fx.bcx.ins().iconcat(lsb, msb) } ty => fx.bcx.ins().iconst(ty, niche_value as i64), From d30c1ddce734ea7a7614c8b5dd8473707f5da926 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 22 Nov 2022 19:29:36 +0100 Subject: [PATCH 32/77] Rustup to rustc 1.67.0-nightly (b7bc90fea 2022-11-21) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index bb6a2cadf4909..bcfabc246dfcb 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" diff --git a/rust-toolchain b/rust-toolchain index 887d8ea9e4362..86c8ee1cc1d50 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-11-20" +channel = "nightly-2022-11-22" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 24ebf425ae3b9c3f95d5b8f239d18a2d7e66b540 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 22 Nov 2022 19:29:06 +0000 Subject: [PATCH 33/77] Update rustc test suite failure list --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d21dd6c0f7460..74a99802b1027 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -66,6 +66,7 @@ rm src/test/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/ui/abi/stack-probes.rs # stack probes not yet implemented rm src/test/ui/simd/intrinsic/ptr-cast.rs # simd_expose_addr intrinsic unimplemented +rm -r src/test/run-make/repr128-dwarf # debuginfo test # optimization tests # ================== From bcee07e78d58513dbf96ebc45445d8f2781baf5a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 23 Nov 2022 18:22:51 +0000 Subject: [PATCH 34/77] Add `Mutability::{is_mut,is_not}` --- src/constant.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 077f33bb99cf7..a6bde88408497 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -257,9 +257,9 @@ pub(crate) fn data_id_for_alloc_id( mutability: rustc_hir::Mutability, ) -> DataId { cx.todo.push(TodoItem::Alloc(alloc_id)); - *cx.anon_allocs.entry(alloc_id).or_insert_with(|| { - module.declare_anonymous_data(mutability == rustc_hir::Mutability::Mut, false).unwrap() - }) + *cx.anon_allocs + .entry(alloc_id) + .or_insert_with(|| module.declare_anonymous_data(mutability.is_mut(), false).unwrap()) } fn data_id_for_static( @@ -343,12 +343,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } }; let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| { - module - .declare_anonymous_data( - alloc.inner().mutability == rustc_hir::Mutability::Mut, - false, - ) - .unwrap() + module.declare_anonymous_data(alloc.inner().mutability.is_mut(), false).unwrap() }); (data_id, alloc, None) } From 5399526aee6addd6c13b05cac0549224937a8430 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 28 May 2022 10:43:51 +0000 Subject: [PATCH 35/77] Rewrite LLVM's archive writer in Rust This allows it to be used by other codegen backends --- Cargo.lock | 6 -- Cargo.toml | 1 - src/archive.rs | 224 ++----------------------------------------------- 3 files changed, 5 insertions(+), 226 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fa9d56cd01a3..3b406036c356e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,11 +19,6 @@ version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" -[[package]] -name = "ar" -version = "0.8.0" -source = "git+https://github.com/bjorn3/rust-ar.git?branch=do_not_remove_cg_clif_ranlib#de9ab0e56bf3a208381d342aa5b60f9ff2891648" - [[package]] name = "arrayvec" version = "0.7.2" @@ -324,7 +319,6 @@ dependencies = [ name = "rustc_codegen_cranelift" version = "0.1.0" dependencies = [ - "ar", "cranelift-codegen", "cranelift-frontend", "cranelift-jit", diff --git a/Cargo.toml b/Cargo.toml index 09cf5b4a1edd8..0fdd5de118ccb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } -ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.9.1" libloading = { version = "0.7.3", optional = true } once_cell = "1.10.0" diff --git a/src/archive.rs b/src/archive.rs index f2e3bf16e6184..5a29bc18def54 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,35 +1,15 @@ -//! Creation of ar archives like for the lib and staticlib crate type - -use std::collections::BTreeMap; -use std::fs::File; -use std::io::{self, Read, Seek}; use std::path::{Path, PathBuf}; -use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder}; +use rustc_codegen_ssa::back::archive::{ + get_native_object_symbols, ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, +}; use rustc_session::Session; -use object::read::archive::ArchiveFile; -use object::{Object, ObjectSymbol, ReadCache}; - -#[derive(Debug)] -enum ArchiveEntry { - FromArchive { archive_index: usize, file_range: (u64, u64) }, - File(PathBuf), -} - pub(crate) struct ArArchiveBuilderBuilder; impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder { fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box + 'a> { - Box::new(ArArchiveBuilder { - sess, - use_gnu_style_archive: sess.target.archive_format == "gnu", - // FIXME fix builtin ranlib on macOS - no_builtin_ranlib: sess.target.is_like_osx, - - src_archives: vec![], - entries: vec![], - }) + Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols)) } fn create_dll_import_lib( @@ -40,200 +20,6 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder { _tmpdir: &Path, _is_direct_dependency: bool, ) -> PathBuf { - bug!("creating dll imports is not supported"); - } -} - -pub(crate) struct ArArchiveBuilder<'a> { - sess: &'a Session, - use_gnu_style_archive: bool, - no_builtin_ranlib: bool, - - src_archives: Vec, - // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at - // the end of an archive for linkers to not get confused. - entries: Vec<(Vec, ArchiveEntry)>, -} - -impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { - fn add_file(&mut self, file: &Path) { - self.entries.push(( - file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(), - ArchiveEntry::File(file.to_owned()), - )); - } - - fn add_archive( - &mut self, - archive_path: &Path, - mut skip: Box bool + 'static>, - ) -> std::io::Result<()> { - let read_cache = ReadCache::new(std::fs::File::open(&archive_path)?); - let archive = ArchiveFile::parse(&read_cache).unwrap(); - let archive_index = self.src_archives.len(); - - for entry in archive.members() { - let entry = entry.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; - let file_name = String::from_utf8(entry.name().to_vec()) - .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; - if !skip(&file_name) { - self.entries.push(( - file_name.into_bytes(), - ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() }, - )); - } - } - - self.src_archives.push(read_cache.into_inner()); - Ok(()) - } - - fn build(mut self: Box, output: &Path) -> bool { - enum BuilderKind { - Bsd(ar::Builder), - Gnu(ar::GnuBuilder), - } - - let sess = self.sess; - - let mut symbol_table = BTreeMap::new(); - - let mut entries = Vec::new(); - - for (mut entry_name, entry) in self.entries { - // FIXME only read the symbol table of the object files to avoid having to keep all - // object files in memory at once, or read them twice. - let data = match entry { - ArchiveEntry::FromArchive { archive_index, file_range } => { - // FIXME read symbols from symtab - let src_read_cache = &mut self.src_archives[archive_index]; - - src_read_cache.seek(io::SeekFrom::Start(file_range.0)).unwrap(); - let mut data = std::vec::from_elem(0, usize::try_from(file_range.1).unwrap()); - src_read_cache.read_exact(&mut data).unwrap(); - - data - } - ArchiveEntry::File(file) => std::fs::read(file).unwrap_or_else(|err| { - sess.fatal(&format!( - "error while reading object file during archive building: {}", - err - )); - }), - }; - - if !self.no_builtin_ranlib { - if symbol_table.contains_key(&entry_name) { - // The ar crate can't handle creating a symbol table in case of multiple archive - // members with the same name. Work around this by prepending a number until we - // get a unique name. - for i in 1.. { - let new_name = format!("{}_", i) - .into_bytes() - .into_iter() - .chain(entry_name.iter().copied()) - .collect::>(); - if !symbol_table.contains_key(&new_name) { - entry_name = new_name; - break; - } - } - } - - match object::File::parse(&*data) { - Ok(object) => { - symbol_table.insert( - entry_name.to_vec(), - object - .symbols() - .filter_map(|symbol| { - if symbol.is_undefined() || symbol.is_local() { - None - } else { - symbol.name().map(|name| name.as_bytes().to_vec()).ok() - } - }) - .collect::>(), - ); - } - Err(err) => { - let err = err.to_string(); - if err == "Unknown file magic" { - // Not an object file; skip it. - } else if object::read::archive::ArchiveFile::parse(&*data).is_ok() { - // Nested archive file; skip it. - } else { - sess.fatal(&format!( - "error parsing `{}` during archive creation: {}", - String::from_utf8_lossy(&entry_name), - err - )); - } - } - } - } - - entries.push((entry_name, data)); - } - - let mut builder = if self.use_gnu_style_archive { - BuilderKind::Gnu( - ar::GnuBuilder::new( - File::create(output).unwrap_or_else(|err| { - sess.fatal(&format!( - "error opening destination during archive building: {}", - err - )); - }), - entries.iter().map(|(name, _)| name.clone()).collect(), - ar::GnuSymbolTableFormat::Size32, - symbol_table, - ) - .unwrap(), - ) - } else { - BuilderKind::Bsd( - ar::Builder::new( - File::create(output).unwrap_or_else(|err| { - sess.fatal(&format!( - "error opening destination during archive building: {}", - err - )); - }), - symbol_table, - ) - .unwrap(), - ) - }; - - let any_members = !entries.is_empty(); - - // Add all files - for (entry_name, data) in entries.into_iter() { - let header = ar::Header::new(entry_name, data.len() as u64); - match builder { - BuilderKind::Bsd(ref mut builder) => builder.append(&header, &mut &*data).unwrap(), - BuilderKind::Gnu(ref mut builder) => builder.append(&header, &mut &*data).unwrap(), - } - } - - // Finalize archive - std::mem::drop(builder); - - if self.no_builtin_ranlib { - let ranlib = crate::toolchain::get_toolchain_binary(self.sess, "ranlib"); - - // Run ranlib to be able to link the archive - let status = std::process::Command::new(ranlib) - .arg(output) - .status() - .expect("Couldn't run ranlib"); - - if !status.success() { - self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code())); - } - } - - any_members + unimplemented!("creating dll imports is not yet supported"); } } From a085a2ad2db4a03939c4ad07458398837676cbd5 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 27 Nov 2022 11:15:06 +0000 Subject: [PATCH 36/77] Prefer doc comments over `//`-comments in compiler --- src/value_and_place.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index c5bd574623df6..34746ff6b6645 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -108,8 +108,8 @@ impl<'tcx> CValue<'tcx> { } // FIXME remove - // Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the - // vtable pointer. + /// Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the + /// vtable pointer. pub(crate) fn dyn_star_force_data_on_stack( self, fx: &mut FunctionCx<'_, '_, 'tcx>, From ef6400d6bed54cb2a83732a9e0c6c78e9e4bc246 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 27 Nov 2022 17:17:47 +0000 Subject: [PATCH 37/77] Split x86 specific intrinsics into intrinsics/llvm_x86.rs --- src/intrinsics/llvm.rs | 172 +------------------------------- src/intrinsics/llvm_x86.rs | 197 +++++++++++++++++++++++++++++++++++++ src/intrinsics/mod.rs | 1 + 3 files changed, 203 insertions(+), 167 deletions(-) create mode 100644 src/intrinsics/llvm_x86.rs diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index 783d426c30bcc..a32f0a19f6410 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -8,135 +8,16 @@ use rustc_middle::ty::subst::SubstsRef; pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, intrinsic: &str, - _substs: SubstsRef<'tcx>, + substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], ret: CPlace<'tcx>, target: Option, ) { - match intrinsic { - "llvm.x86.sse2.pause" | "llvm.aarch64.isb" => { - // Spin loop hint - } - - // Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8` - "llvm.x86.sse2.pmovmskb.128" | "llvm.x86.avx2.pmovmskb" | "llvm.x86.sse2.movmsk.pd" => { - intrinsic_args!(fx, args => (a); intrinsic); - - let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx); - let lane_ty = fx.clif_type(lane_ty).unwrap(); - assert!(lane_count <= 32); - - let mut res = fx.bcx.ins().iconst(types::I32, 0); - - for lane in (0..lane_count).rev() { - let a_lane = a.value_lane(fx, lane).load_scalar(fx); - - // cast float to int - let a_lane = match lane_ty { - types::F32 => fx.bcx.ins().bitcast(types::I32, a_lane), - types::F64 => fx.bcx.ins().bitcast(types::I64, a_lane), - _ => a_lane, - }; - - // extract sign bit of an int - let a_lane_sign = fx.bcx.ins().ushr_imm(a_lane, i64::from(lane_ty.bits() - 1)); - - // shift sign bit into result - let a_lane_sign = clif_intcast(fx, a_lane_sign, types::I32, false); - res = fx.bcx.ins().ishl_imm(res, 1); - res = fx.bcx.ins().bor(res, a_lane_sign); - } - - let res = CValue::by_val(res, fx.layout_of(fx.tcx.types.i32)); - ret.write_cvalue(fx, res); - } - "llvm.x86.sse2.cmp.ps" | "llvm.x86.sse2.cmp.pd" => { - let (x, y, kind) = match args { - [x, y, kind] => (x, y, kind), - _ => bug!("wrong number of args for intrinsic {intrinsic}"), - }; - let x = codegen_operand(fx, x); - let y = codegen_operand(fx, y); - let kind = crate::constant::mir_operand_get_const_val(fx, kind) - .expect("llvm.x86.sse2.cmp.* kind not const"); - - let flt_cc = match kind - .try_to_bits(Size::from_bytes(1)) - .unwrap_or_else(|| panic!("kind not scalar: {:?}", kind)) - { - 0 => FloatCC::Equal, - 1 => FloatCC::LessThan, - 2 => FloatCC::LessThanOrEqual, - 7 => FloatCC::Ordered, - 3 => FloatCC::Unordered, - 4 => FloatCC::NotEqual, - 5 => FloatCC::UnorderedOrGreaterThanOrEqual, - 6 => FloatCC::UnorderedOrGreaterThan, - kind => unreachable!("kind {:?}", kind), - }; - - simd_pair_for_each_lane(fx, x, y, ret, &|fx, lane_ty, res_lane_ty, x_lane, y_lane| { - let res_lane = match lane_ty.kind() { - ty::Float(_) => fx.bcx.ins().fcmp(flt_cc, x_lane, y_lane), - _ => unreachable!("{:?}", lane_ty), - }; - bool_to_zero_or_max_uint(fx, res_lane_ty, res_lane) - }); - } - "llvm.x86.sse2.psrli.d" => { - let (a, imm8) = match args { - [a, imm8] => (a, imm8), - _ => bug!("wrong number of args for intrinsic {intrinsic}"), - }; - let a = codegen_operand(fx, a); - let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) - .expect("llvm.x86.sse2.psrli.d imm8 not const"); - - simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 - .try_to_bits(Size::from_bytes(4)) - .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) - { - imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)), - _ => fx.bcx.ins().iconst(types::I32, 0), - }); - } - "llvm.x86.sse2.pslli.d" => { - let (a, imm8) = match args { - [a, imm8] => (a, imm8), - _ => bug!("wrong number of args for intrinsic {intrinsic}"), - }; - let a = codegen_operand(fx, a); - let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) - .expect("llvm.x86.sse2.psrli.d imm8 not const"); - - simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 - .try_to_bits(Size::from_bytes(4)) - .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) - { - imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)), - _ => fx.bcx.ins().iconst(types::I32, 0), - }); - } - "llvm.x86.sse2.storeu.dq" => { - intrinsic_args!(fx, args => (mem_addr, a); intrinsic); - let mem_addr = mem_addr.load_scalar(fx); - - // FIXME correctly handle the unalignment - let dest = CPlace::for_ptr(Pointer::new(mem_addr), a.layout()); - dest.write_cvalue(fx, a); - } - "llvm.x86.addcarry.64" => { - intrinsic_args!(fx, args => (c_in, a, b); intrinsic); - let c_in = c_in.load_scalar(fx); - - llvm_add_sub(fx, BinOp::Add, ret, c_in, a, b); - } - "llvm.x86.subborrow.64" => { - intrinsic_args!(fx, args => (b_in, a, b); intrinsic); - let b_in = b_in.load_scalar(fx); + if intrinsic.starts_with("llvm.x86") { + return llvm_x86::codegen_x86_llvm_intrinsic_call(fx, intrinsic, substs, args, ret, target); + } - llvm_add_sub(fx, BinOp::Sub, ret, b_in, a, b); - } + match intrinsic { _ => { fx.tcx .sess @@ -151,46 +32,3 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( fx.bcx.ins().jump(ret_block, &[]); } -// llvm.x86.avx2.vperm2i128 -// llvm.x86.ssse3.pshuf.b.128 -// llvm.x86.avx2.pshuf.b -// llvm.x86.avx2.psrli.w -// llvm.x86.sse2.psrli.w - -fn llvm_add_sub<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - bin_op: BinOp, - ret: CPlace<'tcx>, - cb_in: Value, - a: CValue<'tcx>, - b: CValue<'tcx>, -) { - assert_eq!( - a.layout().ty, - fx.tcx.types.u64, - "llvm.x86.addcarry.64/llvm.x86.subborrow.64 second operand must be u64" - ); - assert_eq!( - b.layout().ty, - fx.tcx.types.u64, - "llvm.x86.addcarry.64/llvm.x86.subborrow.64 third operand must be u64" - ); - - // c + carry -> c + first intermediate carry or borrow respectively - let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b); - let c = int0.value_field(fx, mir::Field::new(0)); - let cb0 = int0.value_field(fx, mir::Field::new(1)).load_scalar(fx); - - // c + carry -> c + second intermediate carry or borrow respectively - let cb_in_as_u64 = fx.bcx.ins().uextend(types::I64, cb_in); - let cb_in_as_u64 = CValue::by_val(cb_in_as_u64, fx.layout_of(fx.tcx.types.u64)); - let int1 = crate::num::codegen_checked_int_binop(fx, bin_op, c, cb_in_as_u64); - let (c, cb1) = int1.load_scalar_pair(fx); - - // carry0 | carry1 -> carry or borrow respectively - let cb_out = fx.bcx.ins().bor(cb0, cb1); - - let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter())); - let val = CValue::by_val_pair(cb_out, c, layout); - ret.write_cvalue(fx, val); -} diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs new file mode 100644 index 0000000000000..7bc161fbe5523 --- /dev/null +++ b/src/intrinsics/llvm_x86.rs @@ -0,0 +1,197 @@ +//! Emulate x86 LLVM intrinsics + +use crate::intrinsics::*; +use crate::prelude::*; + +use rustc_middle::ty::subst::SubstsRef; + +pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + intrinsic: &str, + _substs: SubstsRef<'tcx>, + args: &[mir::Operand<'tcx>], + ret: CPlace<'tcx>, + target: Option, +) { + match intrinsic { + "llvm.x86.sse2.pause" | "llvm.aarch64.isb" => { + // Spin loop hint + } + + // Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8` + "llvm.x86.sse2.pmovmskb.128" | "llvm.x86.avx2.pmovmskb" | "llvm.x86.sse2.movmsk.pd" => { + intrinsic_args!(fx, args => (a); intrinsic); + + let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx); + let lane_ty = fx.clif_type(lane_ty).unwrap(); + assert!(lane_count <= 32); + + let mut res = fx.bcx.ins().iconst(types::I32, 0); + + for lane in (0..lane_count).rev() { + let a_lane = a.value_lane(fx, lane).load_scalar(fx); + + // cast float to int + let a_lane = match lane_ty { + types::F32 => fx.bcx.ins().bitcast(types::I32, a_lane), + types::F64 => fx.bcx.ins().bitcast(types::I64, a_lane), + _ => a_lane, + }; + + // extract sign bit of an int + let a_lane_sign = fx.bcx.ins().ushr_imm(a_lane, i64::from(lane_ty.bits() - 1)); + + // shift sign bit into result + let a_lane_sign = clif_intcast(fx, a_lane_sign, types::I32, false); + res = fx.bcx.ins().ishl_imm(res, 1); + res = fx.bcx.ins().bor(res, a_lane_sign); + } + + let res = CValue::by_val(res, fx.layout_of(fx.tcx.types.i32)); + ret.write_cvalue(fx, res); + } + "llvm.x86.sse2.cmp.ps" | "llvm.x86.sse2.cmp.pd" => { + let (x, y, kind) = match args { + [x, y, kind] => (x, y, kind), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let x = codegen_operand(fx, x); + let y = codegen_operand(fx, y); + let kind = crate::constant::mir_operand_get_const_val(fx, kind) + .expect("llvm.x86.sse2.cmp.* kind not const"); + + let flt_cc = match kind + .try_to_bits(Size::from_bytes(1)) + .unwrap_or_else(|| panic!("kind not scalar: {:?}", kind)) + { + 0 => FloatCC::Equal, + 1 => FloatCC::LessThan, + 2 => FloatCC::LessThanOrEqual, + 7 => FloatCC::Ordered, + 3 => FloatCC::Unordered, + 4 => FloatCC::NotEqual, + 5 => FloatCC::UnorderedOrGreaterThanOrEqual, + 6 => FloatCC::UnorderedOrGreaterThan, + kind => unreachable!("kind {:?}", kind), + }; + + simd_pair_for_each_lane(fx, x, y, ret, &|fx, lane_ty, res_lane_ty, x_lane, y_lane| { + let res_lane = match lane_ty.kind() { + ty::Float(_) => fx.bcx.ins().fcmp(flt_cc, x_lane, y_lane), + _ => unreachable!("{:?}", lane_ty), + }; + bool_to_zero_or_max_uint(fx, res_lane_ty, res_lane) + }); + } + "llvm.x86.sse2.psrli.d" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.sse2.psrli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.sse2.pslli.d" => { + let (a, imm8) = match args { + [a, imm8] => (a, imm8), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8) + .expect("llvm.x86.sse2.psrli.d imm8 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) + { + imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + "llvm.x86.sse2.storeu.dq" => { + intrinsic_args!(fx, args => (mem_addr, a); intrinsic); + let mem_addr = mem_addr.load_scalar(fx); + + // FIXME correctly handle the unalignment + let dest = CPlace::for_ptr(Pointer::new(mem_addr), a.layout()); + dest.write_cvalue(fx, a); + } + "llvm.x86.addcarry.64" => { + intrinsic_args!(fx, args => (c_in, a, b); intrinsic); + let c_in = c_in.load_scalar(fx); + + llvm_add_sub(fx, BinOp::Add, ret, c_in, a, b); + } + "llvm.x86.subborrow.64" => { + intrinsic_args!(fx, args => (b_in, a, b); intrinsic); + let b_in = b_in.load_scalar(fx); + + llvm_add_sub(fx, BinOp::Sub, ret, b_in, a, b); + } + _ => { + fx.tcx.sess.warn(&format!( + "unsupported x86 llvm intrinsic {}; replacing with trap", + intrinsic + )); + crate::trap::trap_unimplemented(fx, intrinsic); + return; + } + } + + let dest = target.expect("all llvm intrinsics used by stdlib should return"); + let ret_block = fx.get_block(dest); + fx.bcx.ins().jump(ret_block, &[]); +} + +// llvm.x86.avx2.vperm2i128 +// llvm.x86.ssse3.pshuf.b.128 +// llvm.x86.avx2.pshuf.b +// llvm.x86.avx2.psrli.w +// llvm.x86.sse2.psrli.w + +fn llvm_add_sub<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + bin_op: BinOp, + ret: CPlace<'tcx>, + cb_in: Value, + a: CValue<'tcx>, + b: CValue<'tcx>, +) { + assert_eq!( + a.layout().ty, + fx.tcx.types.u64, + "llvm.x86.addcarry.64/llvm.x86.subborrow.64 second operand must be u64" + ); + assert_eq!( + b.layout().ty, + fx.tcx.types.u64, + "llvm.x86.addcarry.64/llvm.x86.subborrow.64 third operand must be u64" + ); + + // c + carry -> c + first intermediate carry or borrow respectively + let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b); + let c = int0.value_field(fx, mir::Field::new(0)); + let cb0 = int0.value_field(fx, mir::Field::new(1)).load_scalar(fx); + + // c + carry -> c + second intermediate carry or borrow respectively + let cb_in_as_u64 = fx.bcx.ins().uextend(types::I64, cb_in); + let cb_in_as_u64 = CValue::by_val(cb_in_as_u64, fx.layout_of(fx.tcx.types.u64)); + let int1 = crate::num::codegen_checked_int_binop(fx, bin_op, c, cb_in_as_u64); + let (c, cb1) = int1.load_scalar_pair(fx); + + // carry0 | carry1 -> carry or borrow respectively + let cb_out = fx.bcx.ins().bor(cb0, cb1); + + let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter())); + let val = CValue::by_val_pair(cb_out, c, layout); + ret.write_cvalue(fx, val); +} diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 0302b843aa226..eaf4e19cb034c 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -14,6 +14,7 @@ macro_rules! intrinsic_args { mod cpuid; mod llvm; +mod llvm_x86; mod simd; pub(crate) use cpuid::codegen_cpuid_call; From 136798319874ee368f7a111332b5f14545c233f3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 27 Nov 2022 18:09:57 +0000 Subject: [PATCH 38/77] Begin implementing llvm simd intrinsics for aarch64 --- src/intrinsics/llvm.rs | 22 ++++++- src/intrinsics/llvm_aarch64.rs | 115 +++++++++++++++++++++++++++++++++ src/intrinsics/mod.rs | 1 + 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/intrinsics/llvm_aarch64.rs diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index a32f0a19f6410..f722e52284fe8 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -13,11 +13,32 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( ret: CPlace<'tcx>, target: Option, ) { + if intrinsic.starts_with("llvm.aarch64") { + return llvm_aarch64::codegen_aarch64_llvm_intrinsic_call( + fx, intrinsic, substs, args, ret, target, + ); + } if intrinsic.starts_with("llvm.x86") { return llvm_x86::codegen_x86_llvm_intrinsic_call(fx, intrinsic, substs, args, ret, target); } match intrinsic { + _ if intrinsic.starts_with("llvm.ctlz.v") => { + intrinsic_args!(fx, args => (a); intrinsic); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().clz(lane) + }); + } + + _ if intrinsic.starts_with("llvm.ctpop.v") => { + intrinsic_args!(fx, args => (a); intrinsic); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().popcnt(lane) + }); + } + _ => { fx.tcx .sess @@ -31,4 +52,3 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } - diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs new file mode 100644 index 0000000000000..f9f34e16aec1b --- /dev/null +++ b/src/intrinsics/llvm_aarch64.rs @@ -0,0 +1,115 @@ +//! Emulate AArch64 LLVM intrinsics + +use crate::intrinsics::*; +use crate::prelude::*; + +use rustc_middle::ty::subst::SubstsRef; + +pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + intrinsic: &str, + _substs: SubstsRef<'tcx>, + args: &[mir::Operand<'tcx>], + ret: CPlace<'tcx>, + target: Option, +) { + // llvm.aarch64.neon.sqshl.v*i* + + match intrinsic { + _ if intrinsic.starts_with("llvm.aarch64.neon.abs.v") => { + intrinsic_args!(fx, args => (a); intrinsic); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().iabs(lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.cls.v") => { + intrinsic_args!(fx, args => (a); intrinsic); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().cls(lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.sqadd.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane_typed(fx, x, y, ret, &|fx, x_lane, y_lane| { + crate::num::codegen_saturating_int_binop(fx, BinOp::Add, x_lane, y_lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.sqsub.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane_typed(fx, x, y, ret, &|fx, x_lane, y_lane| { + crate::num::codegen_saturating_int_binop(fx, BinOp::Sub, x_lane, y_lane) + }); + } + + /* + _ if intrinsic.starts_with("llvm.aarch64.neon.sshl.v") + || intrinsic.starts_with("llvm.aarch64.neon.sqshl.v") + // FIXME split this one out once saturating is implemented + || intrinsic.starts_with("llvm.aarch64.neon.sqshlu.v") => + { + intrinsic_args!(fx, args => (a, b); intrinsic); + + simd_pair_for_each_lane(fx, a, b, ret, &|fx, _lane_ty, _res_lane_ty, a, b| { + // FIXME saturate? + fx.bcx.ins().ishl(a, b) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.sqshrn.v") => { + let (a, imm32) = match args { + [a, imm32] => (a, imm32), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm32 = crate::constant::mir_operand_get_const_val(fx, imm32) + .expect("llvm.aarch64.neon.sqshrn.v* imm32 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm32 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm32 not scalar: {:?}", imm32)) + { + imm32 if imm32 < 32 => fx.bcx.ins().sshr_imm(lane, i64::from(imm32 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.sqshrun.v") => { + let (a, imm32) = match args { + [a, imm32] => (a, imm32), + _ => bug!("wrong number of args for intrinsic {intrinsic}"), + }; + let a = codegen_operand(fx, a); + let imm32 = crate::constant::mir_operand_get_const_val(fx, imm32) + .expect("llvm.aarch64.neon.sqshrn.v* imm32 not const"); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm32 + .try_to_bits(Size::from_bytes(4)) + .unwrap_or_else(|| panic!("imm32 not scalar: {:?}", imm32)) + { + imm32 if imm32 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm32 as u8)), + _ => fx.bcx.ins().iconst(types::I32, 0), + }); + } + */ + + _ => { + fx.tcx.sess.warn(&format!( + "unsupported AArch64 llvm intrinsic {}; replacing with trap", + intrinsic + )); + crate::trap::trap_unimplemented(fx, intrinsic); + return; + } + } + + let dest = target.expect("all llvm intrinsics used by stdlib should return"); + let ret_block = fx.get_block(dest); + fx.bcx.ins().jump(ret_block, &[]); +} diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index eaf4e19cb034c..8f13af8154e9e 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -14,6 +14,7 @@ macro_rules! intrinsic_args { mod cpuid; mod llvm; +mod llvm_aarch64; mod llvm_x86; mod simd; From 75838d9e8be67b0f707bdb372abe71063a79100a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 27 Nov 2022 18:32:29 +0000 Subject: [PATCH 39/77] Implement more llvm simd intrinsics for AArch64 --- src/intrinsics/llvm_aarch64.rs | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs index f9f34e16aec1b..1daf14288243a 100644 --- a/src/intrinsics/llvm_aarch64.rs +++ b/src/intrinsics/llvm_aarch64.rs @@ -32,6 +32,14 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( }); } + _ if intrinsic.starts_with("llvm.aarch64.neon.rbit.v") => { + intrinsic_args!(fx, args => (a); intrinsic); + + simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().bitrev(lane) + }); + } + _ if intrinsic.starts_with("llvm.aarch64.neon.sqadd.v") => { intrinsic_args!(fx, args => (x, y); intrinsic); @@ -48,6 +56,78 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( }); } + _ if intrinsic.starts_with("llvm.aarch64.neon.smax.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::SignedGreaterThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.umax.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.smaxv.i") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| { + let gt = fx.bcx.ins().icmp(IntCC::SignedGreaterThan, a, b); + fx.bcx.ins().select(gt, a, b) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.umaxv.i") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, a, b); + fx.bcx.ins().select(gt, a, b) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.smin.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::SignedLessThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.umin.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedLessThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.sminv.i") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| { + let gt = fx.bcx.ins().icmp(IntCC::SignedLessThan, a, b); + fx.bcx.ins().select(gt, a, b) + }); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.uminv.i") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedLessThan, a, b); + fx.bcx.ins().select(gt, a, b) + }); + } + /* _ if intrinsic.starts_with("llvm.aarch64.neon.sshl.v") || intrinsic.starts_with("llvm.aarch64.neon.sqshl.v") From f851dfacfe92284124e0c5419ebd054d39ff5dc3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 27 Nov 2022 18:34:07 +0000 Subject: [PATCH 40/77] Rustfmt --- src/intrinsics/llvm_aarch64.rs | 57 ++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs index 1daf14288243a..7959176ac85df 100644 --- a/src/intrinsics/llvm_aarch64.rs +++ b/src/intrinsics/llvm_aarch64.rs @@ -59,19 +59,31 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( _ if intrinsic.starts_with("llvm.aarch64.neon.smax.v") => { intrinsic_args!(fx, args => (x, y); intrinsic); - simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { - let gt = fx.bcx.ins().icmp(IntCC::SignedGreaterThan, x_lane, y_lane); - fx.bcx.ins().select(gt, x_lane, y_lane) - }); + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::SignedGreaterThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }, + ); } _ if intrinsic.starts_with("llvm.aarch64.neon.umax.v") => { intrinsic_args!(fx, args => (x, y); intrinsic); - simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { - let gt = fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, x_lane, y_lane); - fx.bcx.ins().select(gt, x_lane, y_lane) - }); + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }, + ); } _ if intrinsic.starts_with("llvm.aarch64.neon.smaxv.i") => { @@ -95,19 +107,31 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( _ if intrinsic.starts_with("llvm.aarch64.neon.smin.v") => { intrinsic_args!(fx, args => (x, y); intrinsic); - simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { - let gt = fx.bcx.ins().icmp(IntCC::SignedLessThan, x_lane, y_lane); - fx.bcx.ins().select(gt, x_lane, y_lane) - }); + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::SignedLessThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }, + ); } _ if intrinsic.starts_with("llvm.aarch64.neon.umin.v") => { intrinsic_args!(fx, args => (x, y); intrinsic); - simd_pair_for_each_lane(fx, x, y, ret, &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { - let gt = fx.bcx.ins().icmp(IntCC::UnsignedLessThan, x_lane, y_lane); - fx.bcx.ins().select(gt, x_lane, y_lane) - }); + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| { + let gt = fx.bcx.ins().icmp(IntCC::UnsignedLessThan, x_lane, y_lane); + fx.bcx.ins().select(gt, x_lane, y_lane) + }, + ); } _ if intrinsic.starts_with("llvm.aarch64.neon.sminv.i") => { @@ -178,7 +202,6 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( }); } */ - _ => { fx.tcx.sess.warn(&format!( "unsupported AArch64 llvm intrinsic {}; replacing with trap", From cdae9bab588880339b260c46f468294a76e554b1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:51:03 +0000 Subject: [PATCH 41/77] Introduce CargoProject type and use it where possible --- build_system/abi_cafe.rs | 15 +- build_system/build_backend.rs | 10 +- build_system/build_sysroot.rs | 13 +- build_system/prepare.rs | 50 ++-- build_system/rustc_info.rs | 20 ++ build_system/tests.rs | 484 ++++++++++++++++++---------------- build_system/utils.rs | 163 ++++++++++-- 7 files changed, 456 insertions(+), 299 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index fae5b27163680..8949f9f7e7d9a 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -1,12 +1,16 @@ -use std::env; use std::path::Path; use super::build_sysroot; use super::config; -use super::prepare; -use super::utils::{cargo_command, spawn_and_wait}; +use super::prepare::GitRepo; +use super::utils::{spawn_and_wait, CargoProject, Compiler}; use super::SysrootKind; +pub(crate) static ABI_CAFE_REPO: GitRepo = + GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); + +static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, "."); + pub(crate) fn run( channel: &str, sysroot_kind: SysrootKind, @@ -36,17 +40,16 @@ pub(crate) fn run( ); eprintln!("Running abi-cafe"); - let abi_cafe_path = prepare::ABI_CAFE.source_dir(); - env::set_current_dir(abi_cafe_path.clone()).unwrap(); let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; - let mut cmd = cargo_command("cargo", "run", Some(target_triple), &abi_cafe_path); + let mut cmd = ABI_CAFE.run(&Compiler::host()); cmd.arg("--"); cmd.arg("--pairs"); cmd.args(pairs); cmd.arg("--add-rustc-codegen-backend"); cmd.arg(format!("cgclif:{}", cg_clif_dylib.display())); + cmd.current_dir(ABI_CAFE.source_dir()); spawn_and_wait(cmd); } diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index cda468bcfa2df..48648830a9f58 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -2,15 +2,16 @@ use std::env; use std::path::PathBuf; use super::rustc_info::get_file_name; -use super::utils::{cargo_command, is_ci}; +use super::utils::{is_ci, CargoProject, Compiler}; + +static CG_CLIF: CargoProject = CargoProject::local("."); pub(crate) fn build_backend( channel: &str, host_triple: &str, use_unstable_features: bool, ) -> PathBuf { - let source_dir = std::env::current_dir().unwrap(); - let mut cmd = cargo_command("cargo", "build", Some(host_triple), &source_dir); + let mut cmd = CG_CLIF.build(&Compiler::host()); cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode @@ -41,7 +42,8 @@ pub(crate) fn build_backend( eprintln!("[BUILD] rustc_codegen_cranelift"); super::utils::spawn_and_wait(cmd); - source_dir + CG_CLIF + .source_dir() .join("target") .join(host_triple) .join(channel) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index ba606278df56d..731b94472ab5f 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command}; use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; -use super::utils::{cargo_command, spawn_and_wait, try_hard_link}; +use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::SysrootKind; pub(crate) fn build_sysroot( @@ -149,6 +149,8 @@ pub(crate) fn build_sysroot( } } +static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot"); + fn build_clif_sysroot_for_triple( channel: &str, target_dir: &Path, @@ -185,19 +187,22 @@ fn build_clif_sysroot_for_triple( } // Build sysroot - let mut build_cmd = cargo_command("cargo", "build", Some(triple), Path::new("build_sysroot")); let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); rustflags.push_str(&format!(" --sysroot={}", target_dir.to_str().unwrap())); if channel == "release" { - build_cmd.arg("--release"); rustflags.push_str(" -Zmir-opt-level=3"); } if let Some(linker) = linker { use std::fmt::Write; write!(rustflags, " -Clinker={}", linker).unwrap(); } - build_cmd.env("RUSTFLAGS", rustflags); + let mut compiler = Compiler::with_triple(triple.to_owned()); + compiler.rustflags = rustflags; + let mut build_cmd = STANDARD_LIBRARY.build(&compiler); + if channel == "release" { + build_cmd.arg("--release"); + } build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); spawn_and_wait(build_cmd); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 3111f62f6c215..b06d42af14722 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -5,30 +5,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; -use super::utils::{cargo_command, copy_dir_recursively, spawn_and_wait}; - -pub(crate) const ABI_CAFE: GitRepo = - GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); - -pub(crate) const RAND: GitRepo = - GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); - -pub(crate) const REGEX: GitRepo = - GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex"); - -pub(crate) const PORTABLE_SIMD: GitRepo = GitRepo::github( - "rust-lang", - "portable-simd", - "d5cd4a8112d958bd3a252327e0d069a6363249bd", - "portable-simd", -); - -pub(crate) const SIMPLE_RAYTRACER: GitRepo = GitRepo::github( - "ebobby", - "simple-raytracer", - "804a7a21b9e673a482797aa289a18ed480e4d813", - "", -); +use super::utils::{copy_dir_recursively, spawn_and_wait, Compiler}; pub(crate) fn prepare() { if Path::new("download").exists() { @@ -42,22 +19,25 @@ pub(crate) fn prepare() { eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); - ABI_CAFE.fetch(); - RAND.fetch(); - REGEX.fetch(); - PORTABLE_SIMD.fetch(); - SIMPLE_RAYTRACER.fetch(); + super::abi_cafe::ABI_CAFE_REPO.fetch(); + super::tests::RAND_REPO.fetch(); + super::tests::REGEX_REPO.fetch(); + super::tests::PORTABLE_SIMD_REPO.fetch(); + super::tests::SIMPLE_RAYTRACER_REPO.fetch(); eprintln!("[LLVM BUILD] simple-raytracer"); - let build_cmd = cargo_command("cargo", "build", None, &SIMPLE_RAYTRACER.source_dir()); + let host_compiler = Compiler::host(); + let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler); spawn_and_wait(build_cmd); fs::copy( - SIMPLE_RAYTRACER - .source_dir() - .join("target") + super::tests::SIMPLE_RAYTRACER + .target_dir() + .join(&host_compiler.triple) .join("debug") .join(get_file_name("main", "bin")), - SIMPLE_RAYTRACER.source_dir().join(get_file_name("raytracer_cg_llvm", "bin")), + super::tests::SIMPLE_RAYTRACER_REPO + .source_dir() + .join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } @@ -100,7 +80,7 @@ enum GitRepoUrl { } impl GitRepo { - const fn github( + pub(crate) const fn github( user: &'static str, repo: &'static str, rev: &'static str, diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 3c08b6fa3894d..8e5ab688e131b 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -23,6 +23,16 @@ pub(crate) fn get_host_triple() -> String { .to_owned() } +pub(crate) fn get_cargo_path() -> PathBuf { + let cargo_path = Command::new("rustup") + .stderr(Stdio::inherit()) + .args(&["which", "cargo"]) + .output() + .unwrap() + .stdout; + Path::new(String::from_utf8(cargo_path).unwrap().trim()).to_owned() +} + pub(crate) fn get_rustc_path() -> PathBuf { let rustc_path = Command::new("rustup") .stderr(Stdio::inherit()) @@ -33,6 +43,16 @@ pub(crate) fn get_rustc_path() -> PathBuf { Path::new(String::from_utf8(rustc_path).unwrap().trim()).to_owned() } +pub(crate) fn get_rustdoc_path() -> PathBuf { + let rustc_path = Command::new("rustup") + .stderr(Stdio::inherit()) + .args(&["which", "rustdoc"]) + .output() + .unwrap() + .stdout; + Path::new(String::from_utf8(rustc_path).unwrap().trim()).to_owned() +} + pub(crate) fn get_default_sysroot() -> PathBuf { let default_sysroot = Command::new("rustc") .stderr(Stdio::inherit()) diff --git a/build_system/tests.rs b/build_system/tests.rs index 248546b077e0e..b1c5c64883990 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,8 +1,12 @@ +use crate::build_system::rustc_info::get_cargo_path; + use super::build_sysroot; use super::config; -use super::prepare; +use super::prepare::GitRepo; use super::rustc_info::get_wrapper_file_name; -use super::utils::{cargo_command, hyperfine_command, spawn_and_wait, spawn_and_wait_with_input}; +use super::utils::{ + hyperfine_command, spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, +}; use super::SysrootKind; use std::env; use std::ffi::OsStr; @@ -30,7 +34,7 @@ const NO_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "lib,dylib", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); }), TestCase::new("build.example", &|runner| { @@ -39,7 +43,7 @@ const NO_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "lib", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); }), TestCase::new("jit.mini_core_hello_world", &|runner| { @@ -51,7 +55,7 @@ const NO_SYSROOT_SUITE: &[TestCase] = &[ "--cfg", "jit", "--target", - &runner.host_triple, + &runner.target_compiler.triple, ]); jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); spawn_and_wait(jit_cmd); @@ -65,7 +69,7 @@ const NO_SYSROOT_SUITE: &[TestCase] = &[ "--cfg", "jit", "--target", - &runner.host_triple, + &runner.target_compiler.triple, ]); jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd"); spawn_and_wait(jit_cmd); @@ -79,7 +83,7 @@ const NO_SYSROOT_SUITE: &[TestCase] = &[ "bin", "-g", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("mini_core_hello_world", ["abc", "bcd"]); }), @@ -94,7 +98,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("arbitrary_self_types_pointers_and_wrappers", []); }), @@ -106,7 +110,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("issue_91827_extern_types", []); }), @@ -116,7 +120,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "lib", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); }), TestCase::new("aot.alloc_example", &|runner| { @@ -125,7 +129,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("alloc_example", []); }), @@ -136,7 +140,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "-Cprefer-dynamic", "example/std_example.rs", "--target", - &runner.host_triple, + &runner.target_compiler.triple, ]); eprintln!("[JIT-lazy] std_example"); @@ -146,7 +150,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "-Cprefer-dynamic", "example/std_example.rs", "--target", - &runner.host_triple, + &runner.target_compiler.triple, ]); }), TestCase::new("aot.std_example", &|runner| { @@ -155,7 +159,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("std_example", ["arg"]); }), @@ -167,7 +171,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("dst_field_align", []); }), @@ -178,7 +182,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "bin", "-Cpanic=abort", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("subslice-patterns-const-eval", []); }), @@ -189,7 +193,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "bin", "-Cpanic=abort", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("track-caller-attribute", []); }), @@ -200,7 +204,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "bin", "-Cpanic=abort", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("float-minmax-pass", []); }), @@ -210,181 +214,218 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ "--crate-type", "bin", "--target", - &runner.target_triple, + &runner.target_compiler.triple, ]); runner.run_out_command("mod_bench", []); }), ]; -const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ - TestCase::new("test.rust-random/rand", &|runner| { - runner.in_dir(prepare::RAND.source_dir(), |runner| { - runner.run_cargo("clean", []); +pub(crate) static RAND_REPO: GitRepo = + GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); - if runner.host_triple == runner.target_triple { - eprintln!("[TEST] rust-random/rand"); - runner.run_cargo("test", ["--workspace"]); - } else { - eprintln!("[AOT] rust-random/rand"); - runner.run_cargo("build", ["--workspace", "--tests"]); - } - }); - }), - TestCase::new("bench.simple-raytracer", &|runner| { - runner.in_dir(prepare::SIMPLE_RAYTRACER.source_dir(), |runner| { - let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap(); +static RAND: CargoProject = CargoProject::git(&RAND_REPO, "."); - if runner.host_triple == runner.target_triple { - eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); - let prepare = runner.cargo_command("clean", []); +pub(crate) static REGEX_REPO: GitRepo = + GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex"); - let llvm_build_cmd = cargo_command("cargo", "build", None, Path::new(".")); +static REGEX: CargoProject = CargoProject::git(®EX_REPO, "."); - let cargo_clif = runner - .root_dir - .clone() - .join("build") - .join(get_wrapper_file_name("cargo-clif", "bin")); - let clif_build_cmd = cargo_command(cargo_clif, "build", None, Path::new(".")); +pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( + "rust-lang", + "portable-simd", + "d5cd4a8112d958bd3a252327e0d069a6363249bd", + "portable-simd", +); - let bench_compile = - hyperfine_command(1, run_runs, Some(prepare), llvm_build_cmd, clif_build_cmd); +static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, "."); - spawn_and_wait(bench_compile); +pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( + "ebobby", + "simple-raytracer", + "804a7a21b9e673a482797aa289a18ed480e4d813", + "", +); - eprintln!("[BENCH RUN] ebobby/simple-raytracer"); - fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif")) - .unwrap(); +pub(crate) static SIMPLE_RAYTRACER: CargoProject = CargoProject::git(&SIMPLE_RAYTRACER_REPO, "."); - let bench_run = hyperfine_command( - 0, - run_runs, - None, - Command::new("./raytracer_cg_llvm"), - Command::new("./raytracer_cg_clif"), - ); - spawn_and_wait(bench_run); - } else { - runner.run_cargo("clean", []); - eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)"); - eprintln!("[COMPILE] ebobby/simple-raytracer"); - runner.run_cargo("build", []); - eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)"); - } - }); +static LIBCORE_TESTS: CargoProject = + CargoProject::local("build_sysroot/sysroot_src/library/core/tests"); + +const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ + TestCase::new("test.rust-random/rand", &|runner| { + spawn_and_wait(RAND.clean(&runner.target_compiler.cargo)); + + if runner.is_native { + eprintln!("[TEST] rust-random/rand"); + let mut test_cmd = RAND.test(&runner.target_compiler); + test_cmd.arg("--workspace"); + spawn_and_wait(test_cmd); + } else { + eprintln!("[AOT] rust-random/rand"); + let mut build_cmd = RAND.build(&runner.target_compiler); + build_cmd.arg("--workspace").arg("--tests"); + spawn_and_wait(build_cmd); + } }), - TestCase::new("test.libcore", &|runner| { - runner.in_dir( - std::env::current_dir() + TestCase::new("bench.simple-raytracer", &|runner| { + let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap(); + + if runner.is_native { + eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); + let cargo_clif = env::current_dir() .unwrap() - .join("build_sysroot") - .join("sysroot_src") - .join("library") - .join("core") - .join("tests"), - |runner| { - runner.run_cargo("clean", []); - - if runner.host_triple == runner.target_triple { - runner.run_cargo("test", []); - } else { - eprintln!("Cross-Compiling: Not running tests"); - runner.run_cargo("build", ["--tests"]); - } - }, - ); + .join("build") + .join(get_wrapper_file_name("cargo-clif", "bin")); + let source_dir = SIMPLE_RAYTRACER.source_dir(); + let manifest_path = SIMPLE_RAYTRACER.manifest_path(); + let target_dir = SIMPLE_RAYTRACER.target_dir(); + + let clean_cmd = format!( + "cargo clean --manifest-path {manifest_path} --target-dir {target_dir}", + manifest_path = manifest_path.display(), + target_dir = target_dir.display(), + ); + let llvm_build_cmd = format!( + "cargo build --manifest-path {manifest_path} --target-dir {target_dir}", + manifest_path = manifest_path.display(), + target_dir = target_dir.display(), + ); + let clif_build_cmd = format!( + "{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}", + cargo_clif = cargo_clif.display(), + manifest_path = manifest_path.display(), + target_dir = target_dir.display(), + ); + + let bench_compile = + hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd); + + spawn_and_wait(bench_compile); + + eprintln!("[BENCH RUN] ebobby/simple-raytracer"); + fs::copy(target_dir.join("debug").join("main"), source_dir.join("raytracer_cg_clif")) + .unwrap(); + + let mut bench_run = hyperfine_command( + 0, + run_runs, + None, + &source_dir.join("raytracer_cg_llvm").display().to_string(), + &source_dir.join("raytracer_cg_clif").display().to_string(), + ); + bench_run.current_dir(SIMPLE_RAYTRACER.source_dir()); + spawn_and_wait(bench_run); + } else { + spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo)); + eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)"); + eprintln!("[COMPILE] ebobby/simple-raytracer"); + spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler)); + eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)"); + } + }), + TestCase::new("test.libcore", &|runner| { + spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo)); + + if runner.is_native { + spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler)); + } else { + eprintln!("Cross-Compiling: Not running tests"); + let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler); + build_cmd.arg("--tests"); + spawn_and_wait(build_cmd); + } }), TestCase::new("test.regex-shootout-regex-dna", &|runner| { - runner.in_dir(prepare::REGEX.source_dir(), |runner| { - runner.run_cargo("clean", []); + spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo)); - // newer aho_corasick versions throw a deprecation warning - let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); + // newer aho_corasick versions throw a deprecation warning + let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags); - let mut build_cmd = runner.cargo_command("build", ["--example", "shootout-regex-dna"]); - build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); - spawn_and_wait(build_cmd); + let mut build_cmd = REGEX.build(&runner.target_compiler); + build_cmd.arg("--example").arg("shootout-regex-dna"); + build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); + spawn_and_wait(build_cmd); + + if runner.is_native { + let mut run_cmd = REGEX.run(&runner.target_compiler); + run_cmd.arg("--example").arg("shootout-regex-dna"); + run_cmd.env("RUSTFLAGS", lint_rust_flags); - if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command("run", ["--example", "shootout-regex-dna"]); - run_cmd.env("RUSTFLAGS", lint_rust_flags); - - let input = - fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap(); - let expected_path = PathBuf::from("examples/regexdna-output.txt"); - let expected = fs::read_to_string(&expected_path).unwrap(); - - let output = spawn_and_wait_with_input(run_cmd, input); - // Make sure `[codegen mono items] start` doesn't poison the diff - let output = output - .lines() - .filter(|line| !line.contains("codegen mono items")) - .chain(Some("")) // This just adds the trailing newline - .collect::>() - .join("\r\n"); - - let output_matches = expected.lines().eq(output.lines()); - if !output_matches { - let res_path = PathBuf::from("res.txt"); - fs::write(&res_path, &output).unwrap(); - - if cfg!(windows) { - println!("Output files don't match!"); - println!("Expected Output:\n{}", expected); - println!("Actual Output:\n{}", output); - } else { - let mut diff = Command::new("diff"); - diff.arg("-u"); - diff.arg(res_path); - diff.arg(expected_path); - spawn_and_wait(diff); - } - - std::process::exit(1); + let input = + fs::read_to_string(REGEX.source_dir().join("examples").join("regexdna-input.txt")) + .unwrap(); + let expected_path = REGEX.source_dir().join("examples").join("regexdna-output.txt"); + let expected = fs::read_to_string(&expected_path).unwrap(); + + let output = spawn_and_wait_with_input(run_cmd, input); + // Make sure `[codegen mono items] start` doesn't poison the diff + let output = output + .lines() + .filter(|line| !line.contains("codegen mono items")) + .chain(Some("")) // This just adds the trailing newline + .collect::>() + .join("\r\n"); + + let output_matches = expected.lines().eq(output.lines()); + if !output_matches { + let res_path = REGEX.source_dir().join("res.txt"); + fs::write(&res_path, &output).unwrap(); + + if cfg!(windows) { + println!("Output files don't match!"); + println!("Expected Output:\n{}", expected); + println!("Actual Output:\n{}", output); + } else { + let mut diff = Command::new("diff"); + diff.arg("-u"); + diff.arg(res_path); + diff.arg(expected_path); + spawn_and_wait(diff); } + + std::process::exit(1); } - }); + } }), TestCase::new("test.regex", &|runner| { - runner.in_dir(prepare::REGEX.source_dir(), |runner| { - runner.run_cargo("clean", []); - - // newer aho_corasick versions throw a deprecation warning - let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags); - - if runner.host_triple == runner.target_triple { - let mut run_cmd = runner.cargo_command( - "test", - [ - "--tests", - "--", - "--exclude-should-panic", - "--test-threads", - "1", - "-Zunstable-options", - "-q", - ], - ); - run_cmd.env("RUSTFLAGS", lint_rust_flags); - spawn_and_wait(run_cmd); - } else { - eprintln!("Cross-Compiling: Not running tests"); - let mut build_cmd = - runner.cargo_command("build", ["--tests", "--target", &runner.target_triple]); - build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); - spawn_and_wait(build_cmd); - } - }); + spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo)); + + // newer aho_corasick versions throw a deprecation warning + let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags); + + if runner.is_native { + let mut run_cmd = REGEX.test(&runner.target_compiler); + run_cmd.args([ + "--tests", + "--", + "--exclude-should-panic", + "--test-threads", + "1", + "-Zunstable-options", + "-q", + ]); + run_cmd.env("RUSTFLAGS", lint_rust_flags); + spawn_and_wait(run_cmd); + } else { + eprintln!("Cross-Compiling: Not running tests"); + let mut build_cmd = REGEX.build(&runner.target_compiler); + build_cmd.arg("--tests"); + build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); + spawn_and_wait(build_cmd); + } }), TestCase::new("test.portable-simd", &|runner| { - runner.in_dir(prepare::PORTABLE_SIMD.source_dir(), |runner| { - runner.run_cargo("clean", []); - runner.run_cargo("build", ["--all-targets", "--target", &runner.target_triple]); + spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo)); - if runner.host_triple == runner.target_triple { - runner.run_cargo("test", ["-q"]); - } - }); + let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler); + build_cmd.arg("--all-targets"); + spawn_and_wait(build_cmd); + + if runner.is_native { + let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler); + test_cmd.arg("-q"); + spawn_and_wait(test_cmd); + } }), ]; @@ -442,13 +483,11 @@ pub(crate) fn run_tests( } struct TestRunner { - root_dir: PathBuf, out_dir: PathBuf, + is_native: bool, jit_supported: bool, - rust_flags: String, - run_wrapper: Vec, - host_triple: String, - target_triple: String, + host_compiler: Compiler, + target_compiler: Compiler, } impl TestRunner { @@ -463,19 +502,31 @@ impl TestRunner { let jit_supported = target_triple.contains("x86_64") && is_native && !host_triple.contains("windows"); - let mut rust_flags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); - let mut run_wrapper = Vec::new(); + let mut rustc_clif = root_dir.clone(); + rustc_clif.push("build"); + rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); + + let mut rustdoc_clif = root_dir.clone(); + rustdoc_clif.push("build"); + rustdoc_clif.push(get_wrapper_file_name("rustdoc-clif", "bin")); + + let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); + let mut runner = vec![]; if !is_native { match target_triple.as_str() { "aarch64-unknown-linux-gnu" => { // We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rust_flags); - run_wrapper = vec!["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]; + rustflags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rustflags); + runner = vec![ + "qemu-aarch64".to_owned(), + "-L".to_owned(), + "/usr/aarch64-linux-gnu".to_owned(), + ]; } "x86_64-pc-windows-gnu" => { // We are cross-compiling for Windows. Run tests in wine. - run_wrapper = vec!["wine"]; + runner = vec!["wine".to_owned()]; } _ => { println!("Unknown non-native platform"); @@ -484,19 +535,31 @@ impl TestRunner { } // FIXME fix `#[linkage = "extern_weak"]` without this - if host_triple.contains("darwin") { - rust_flags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rust_flags); + if target_triple.contains("darwin") { + rustflags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rustflags); } - Self { - root_dir, - out_dir, - jit_supported, - rust_flags, - run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(), - host_triple, - target_triple, - } + let host_compiler = Compiler { + cargo: get_cargo_path(), + rustc: rustc_clif.clone(), + rustdoc: rustdoc_clif.clone(), + rustflags: String::new(), + rustdocflags: String::new(), + triple: host_triple, + runner: vec![], + }; + + let target_compiler = Compiler { + cargo: get_cargo_path(), + rustc: rustc_clif.clone(), + rustdoc: rustdoc_clif.clone(), + rustflags: rustflags.clone(), + rustdocflags: rustflags, + triple: target_triple, + runner, + }; + + Self { out_dir, is_native, jit_supported, host_compiler, target_compiler } } pub fn run_testsuite(&self, tests: &[TestCase]) { @@ -516,25 +579,14 @@ impl TestRunner { } } - fn in_dir(&self, new: impl AsRef, callback: impl FnOnce(&TestRunner)) { - let current = env::current_dir().unwrap(); - - env::set_current_dir(new).unwrap(); - callback(self); - env::set_current_dir(current).unwrap(); - } - + #[must_use] fn rustc_command(&self, args: I) -> Command where I: IntoIterator, S: AsRef, { - let mut rustc_clif = self.root_dir.clone(); - rustc_clif.push("build"); - rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); - - let mut cmd = Command::new(rustc_clif); - cmd.args(self.rust_flags.split_whitespace()); + let mut cmd = Command::new(&self.target_compiler.rustc); + cmd.args(self.target_compiler.rustflags.split_whitespace()); cmd.arg("-L"); cmd.arg(format!("crate={}", self.out_dir.display())); cmd.arg("--out-dir"); @@ -559,8 +611,8 @@ impl TestRunner { let mut full_cmd = vec![]; // Prepend the RUN_WRAPPER's - if !self.run_wrapper.is_empty() { - full_cmd.extend(self.run_wrapper.iter().cloned()); + if !self.target_compiler.runner.is_empty() { + full_cmd.extend(self.target_compiler.runner.iter().cloned()); } full_cmd.push({ @@ -581,30 +633,4 @@ impl TestRunner { spawn_and_wait(cmd); } - - fn cargo_command<'a, I>(&self, subcommand: &str, args: I) -> Command - where - I: IntoIterator, - { - let mut cargo_clif = self.root_dir.clone(); - cargo_clif.push("build"); - cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin")); - - let mut cmd = cargo_command( - cargo_clif, - subcommand, - if subcommand == "clean" { None } else { Some(&self.target_triple) }, - Path::new("."), - ); - cmd.args(args); - cmd.env("RUSTFLAGS", &self.rust_flags); - cmd - } - - fn run_cargo<'a, I>(&self, subcommand: &str, args: I) - where - I: IntoIterator, - { - spawn_and_wait(self.cargo_command(subcommand, args)); - } } diff --git a/build_system/utils.rs b/build_system/utils.rs index 48da64906e2a4..75869f38118ca 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -1,35 +1,156 @@ use std::env; use std::fs; use std::io::Write; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; -pub(crate) fn cargo_command( - cargo: impl AsRef, - subcommand: &str, - triple: Option<&str>, - source_dir: &Path, -) -> Command { - let mut cmd = Command::new(cargo.as_ref()); - cmd.arg(subcommand) - .arg("--manifest-path") - .arg(source_dir.join("Cargo.toml")) - .arg("--target-dir") - .arg(source_dir.join("target")); +use super::prepare::GitRepo; +use super::rustc_info::{get_cargo_path, get_host_triple, get_rustc_path, get_rustdoc_path}; + +pub(crate) struct Compiler { + pub(crate) cargo: PathBuf, + pub(crate) rustc: PathBuf, + pub(crate) rustdoc: PathBuf, + pub(crate) rustflags: String, + pub(crate) rustdocflags: String, + pub(crate) triple: String, + pub(crate) runner: Vec, +} + +impl Compiler { + pub(crate) fn host() -> Compiler { + Compiler { + cargo: get_cargo_path(), + rustc: get_rustc_path(), + rustdoc: get_rustdoc_path(), + rustflags: String::new(), + rustdocflags: String::new(), + triple: get_host_triple(), + runner: vec![], + } + } + + pub(crate) fn with_triple(triple: String) -> Compiler { + Compiler { + cargo: get_cargo_path(), + rustc: get_rustc_path(), + rustdoc: get_rustdoc_path(), + rustflags: String::new(), + rustdocflags: String::new(), + triple, + runner: vec![], + } + } +} + +enum CargoProjectSource { + Local, + GitRepo(&'static GitRepo), +} + +pub(crate) struct CargoProject { + source: CargoProjectSource, + path: &'static str, +} + +impl CargoProject { + pub(crate) const fn local(path: &'static str) -> CargoProject { + CargoProject { source: CargoProjectSource::Local, path } + } + + pub(crate) const fn git(git_repo: &'static GitRepo, path: &'static str) -> CargoProject { + CargoProject { source: CargoProjectSource::GitRepo(git_repo), path } + } + + pub(crate) fn source_dir(&self) -> PathBuf { + match self.source { + CargoProjectSource::Local => std::env::current_dir().unwrap(), + CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(), + } + .join(self.path) + } + + pub(crate) fn manifest_path(&self) -> PathBuf { + self.source_dir().join("Cargo.toml") + } - if let Some(triple) = triple { - cmd.arg("--target").arg(triple); + pub(crate) fn target_dir(&self) -> PathBuf { + match self.source { + CargoProjectSource::Local => std::env::current_dir().unwrap(), + CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(), + } + .join(self.path) + .join("target") + } + + fn base_cmd(&self, command: &str, cargo: &Path) -> Command { + let mut cmd = Command::new(cargo); + + cmd.arg(command) + .arg("--manifest-path") + .arg(self.manifest_path()) + .arg("--target-dir") + .arg(self.target_dir()); + + cmd + } + + fn build_cmd(&self, command: &str, compiler: &Compiler) -> Command { + let mut cmd = self.base_cmd(command, &compiler.cargo); + + cmd.arg("--target").arg(&compiler.triple); + + cmd.env("RUSTC", &compiler.rustc); + cmd.env("RUSTDOC", &compiler.rustdoc); + cmd.env("RUSTFLAGS", &compiler.rustflags); + cmd.env("RUSTDOCFLAGS", &compiler.rustdocflags); + if !compiler.runner.is_empty() { + cmd.env( + format!("CARGO_TARGET_{}_RUNNER", compiler.triple.to_uppercase().replace('-', "_")), + compiler.runner.join(" "), + ); + } + + cmd } - cmd + #[must_use] + pub(crate) fn fetch(&self, cargo: impl AsRef) -> Command { + let mut cmd = Command::new(cargo.as_ref()); + + cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path()); + + cmd + } + + #[must_use] + pub(crate) fn clean(&self, cargo: &Path) -> Command { + self.base_cmd("clean", cargo) + } + + #[must_use] + pub(crate) fn build(&self, compiler: &Compiler) -> Command { + self.build_cmd("build", compiler) + } + + #[must_use] + pub(crate) fn test(&self, compiler: &Compiler) -> Command { + self.build_cmd("test", compiler) + } + + #[must_use] + pub(crate) fn run(&self, compiler: &Compiler) -> Command { + self.build_cmd("run", compiler) + } } +#[must_use] pub(crate) fn hyperfine_command( warmup: u64, runs: u64, - prepare: Option, - a: Command, - b: Command, + prepare: Option<&str>, + a: &str, + b: &str, ) -> Command { let mut bench = Command::new("hyperfine"); @@ -42,10 +163,10 @@ pub(crate) fn hyperfine_command( } if let Some(prepare) = prepare { - bench.arg("--prepare").arg(format!("{:?}", prepare)); + bench.arg("--prepare").arg(prepare); } - bench.arg(format!("{:?}", a)).arg(format!("{:?}", b)); + bench.arg(a).arg(b); bench } From 26d48c9a378f20f817e779328affc6c2643a3505 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 13:01:49 +0000 Subject: [PATCH 42/77] Rename the build/ directory to dist/ This will allow putting all temporary build artifacts in build/ in the future, keeping all the build output artifacts in dist/ --- .github/workflows/main.yml | 4 ++-- .gitignore | 1 + Readme.md | 2 +- build_system/mod.rs | 2 +- build_system/tests.rs | 6 +++--- clean_all.sh | 4 ++-- docs/usage.md | 12 ++++++------ scripts/filter_profile.rs | 2 +- scripts/setup_rust_fork.sh | 2 +- scripts/test_rustc_tests.sh | 2 +- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6d75177b2796..de3c89f3383da 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -111,7 +111,7 @@ jobs: ./y.rs test - name: Package prebuilt cg_clif - run: tar cvfJ cg_clif.tar.xz build + run: tar cvfJ cg_clif.tar.xz dist - name: Upload prebuilt cg_clif if: matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' @@ -213,7 +213,7 @@ jobs: - name: Package prebuilt cg_clif # don't use compression as xzip isn't supported by tar on windows and bzip2 hangs - run: tar cvf cg_clif.tar build + run: tar cvf cg_clif.tar dist - name: Upload prebuilt cg_clif uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index fae09592c6ac0..b443fd58a1b98 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ perf.data.old /build_sysroot/sysroot_src /build_sysroot/compiler-builtins /build_sysroot/rustc_version +/dist /rust /download diff --git a/Readme.md b/Readme.md index 1e84c7fa3657b..0e9c77244d4cc 100644 --- a/Readme.md +++ b/Readme.md @@ -37,7 +37,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo In the directory with your project (where you can do the usual `cargo build`), run: ```bash -$ $cg_clif_dir/build/cargo-clif build +$ $cg_clif_dir/dist/cargo-clif build ``` This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend. diff --git a/build_system/mod.rs b/build_system/mod.rs index b25270d832ceb..b246a70e89f18 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -75,7 +75,7 @@ pub fn main() { } }; - let mut target_dir = PathBuf::from("build"); + let mut target_dir = PathBuf::from("dist"); let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; diff --git a/build_system/tests.rs b/build_system/tests.rs index b1c5c64883990..174b77206fba6 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -274,7 +274,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); let cargo_clif = env::current_dir() .unwrap() - .join("build") + .join("dist") .join(get_wrapper_file_name("cargo-clif", "bin")); let source_dir = SIMPLE_RAYTRACER.source_dir(); let manifest_path = SIMPLE_RAYTRACER.manifest_path(); @@ -503,11 +503,11 @@ impl TestRunner { target_triple.contains("x86_64") && is_native && !host_triple.contains("windows"); let mut rustc_clif = root_dir.clone(); - rustc_clif.push("build"); + rustc_clif.push("dist"); rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); let mut rustdoc_clif = root_dir.clone(); - rustdoc_clif.push("build"); + rustdoc_clif.push("dist"); rustdoc_clif.push(get_wrapper_file_name("rustdoc-clif", "bin")); let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); diff --git a/clean_all.sh b/clean_all.sh index fedab2433aa05..cd20f3ea3f1e7 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -2,9 +2,9 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} -rm -rf target/ build/ perf.data{,.old} y.bin +rm -rf target/ dist/ perf.data{,.old} y.bin rm -rf download/ # Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh # FIXME remove at some point in the future -rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ +rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ build/ diff --git a/docs/usage.md b/docs/usage.md index 33f146e7ba27a..4c2b0fa170498 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -9,7 +9,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo In the directory with your project (where you can do the usual `cargo build`), run: ```bash -$ $cg_clif_dir/build/cargo-clif build +$ $cg_clif_dir/dist/cargo-clif build ``` This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend. @@ -19,7 +19,7 @@ This will build your project with rustc_codegen_cranelift instead of the usual L > You should prefer using the Cargo method. ```bash -$ $cg_clif_dir/build/rustc-clif my_crate.rs +$ $cg_clif_dir/dist/rustc-clif my_crate.rs ``` ## Jit mode @@ -32,20 +32,20 @@ In jit mode cg_clif will immediately execute your code without creating an execu > The jit mode will probably need cargo integration to make this possible. ```bash -$ $cg_clif_dir/build/cargo-clif jit +$ $cg_clif_dir/dist/cargo-clif jit ``` or ```bash -$ $cg_clif_dir/build/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs +$ $cg_clif_dir/dist/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs ``` There is also an experimental lazy jit mode. In this mode functions are only compiled once they are first called. ```bash -$ $cg_clif_dir/build/cargo-clif lazy-jit +$ $cg_clif_dir/dist/cargo-clif lazy-jit ``` ## Shell @@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell ```bash function jit_naked() { - echo "$@" | $cg_clif_dir/build/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic + echo "$@" | $cg_clif_dir/dist/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic } function jit() { diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index e6f60d1c0cb23..f782671fe36f9 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -2,7 +2,7 @@ #![forbid(unsafe_code)]/* This line is ignored by bash # This block is ignored by rustc pushd $(dirname "$0")/../ -RUSTC="$(pwd)/build/rustc-clif" +RUSTC="$(pwd)/dist/rustc-clif" popd PROFILE=$1 OUTPUT=$2 exec $RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic $0 #*/ diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 5a73cb0e2c22d..6c64b7de7daa1 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -36,7 +36,7 @@ changelog-seen = 2 ninja = false [build] -rustc = "$(pwd)/../build/rustc-clif" +rustc = "$(pwd)/../dist/rustc-clif" cargo = "$(rustup which cargo)" full-bootstrap = true local-rebuild = true diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 74a99802b1027..d2656f783ad86 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -89,7 +89,7 @@ rm src/test/ui/consts/issue-33537.rs # same # doesn't work due to the way the rustc test suite is invoked. # should work when using ./x.py test the way it is intended # ============================================================ -rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ +rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in dist/bin/ rm -r src/test/run-make/unstable-flag-required # same rm -r src/test/run-make/rustdoc-* # same rm -r src/test/run-make/issue-88756-default-output # same From 052d5ccf5dc83db14917f4a52329a3bf2465af74 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 13:03:47 +0000 Subject: [PATCH 43/77] Implement __isb for AArch64 This is necessary for the mutex implementation of libstd when there is contention. Seems like I hadn't hit this before by sheer luck. --- src/intrinsics/llvm_aarch64.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs index 7959176ac85df..b431158d2690f 100644 --- a/src/intrinsics/llvm_aarch64.rs +++ b/src/intrinsics/llvm_aarch64.rs @@ -16,6 +16,10 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( // llvm.aarch64.neon.sqshl.v*i* match intrinsic { + "llvm.aarch64.isb" => { + fx.bcx.ins().fence(); + } + _ if intrinsic.starts_with("llvm.aarch64.neon.abs.v") => { intrinsic_args!(fx, args => (a); intrinsic); From 9c21990283e55c9de4ad90d6923f64a45bff2b27 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:02:08 +0000 Subject: [PATCH 44/77] Rename target_dir to dist_dir in a couple of places --- build_system/abi_cafe.rs | 4 ++-- build_system/build_sysroot.rs | 28 ++++++++++++++-------------- build_system/mod.rs | 20 ++++++++++---------- build_system/tests.rs | 6 +++--- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 8949f9f7e7d9a..bff5b8f41020a 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -14,7 +14,7 @@ static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, "."); pub(crate) fn run( channel: &str, sysroot_kind: SysrootKind, - target_dir: &Path, + dist_dir: &Path, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, @@ -33,7 +33,7 @@ pub(crate) fn run( build_sysroot::build_sysroot( channel, sysroot_kind, - target_dir, + dist_dir, cg_clif_dylib, host_triple, target_triple, diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 731b94472ab5f..4b21df85f5fbf 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -9,21 +9,21 @@ use super::SysrootKind; pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, - target_dir: &Path, + dist_dir: &Path, cg_clif_dylib_src: &Path, host_triple: &str, target_triple: &str, ) { eprintln!("[BUILD] sysroot {:?}", sysroot_kind); - if target_dir.exists() { - fs::remove_dir_all(target_dir).unwrap(); + if dist_dir.exists() { + fs::remove_dir_all(dist_dir).unwrap(); } - fs::create_dir_all(target_dir.join("bin")).unwrap(); - fs::create_dir_all(target_dir.join("lib")).unwrap(); + fs::create_dir_all(dist_dir.join("bin")).unwrap(); + fs::create_dir_all(dist_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib_path = target_dir + let cg_clif_dylib_path = dist_dir .join(if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the // binaries. @@ -42,14 +42,14 @@ pub(crate) fn build_sysroot( build_cargo_wrapper_cmd .arg(PathBuf::from("scripts").join(format!("{wrapper}.rs"))) .arg("-o") - .arg(target_dir.join(wrapper_name)) + .arg(dist_dir.join(wrapper_name)) .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); } let default_sysroot = super::rustc_info::get_default_sysroot(); - let rustlib = target_dir.join("lib").join("rustlib"); + let rustlib = dist_dir.join("lib").join("rustlib"); let host_rustlib_lib = rustlib.join(host_triple).join("lib"); let target_rustlib_lib = rustlib.join(target_triple).join("lib"); fs::create_dir_all(&host_rustlib_lib).unwrap(); @@ -114,7 +114,7 @@ pub(crate) fn build_sysroot( SysrootKind::Clif => { build_clif_sysroot_for_triple( channel, - target_dir, + dist_dir, host_triple, &cg_clif_dylib_path, None, @@ -129,7 +129,7 @@ pub(crate) fn build_sysroot( }; build_clif_sysroot_for_triple( channel, - target_dir, + dist_dir, target_triple, &cg_clif_dylib_path, linker, @@ -142,7 +142,7 @@ pub(crate) fn build_sysroot( let file = file.unwrap().path(); let filename = file.file_name().unwrap().to_str().unwrap(); if filename.contains("std-") && !filename.contains(".rlib") { - try_hard_link(&file, target_dir.join("lib").join(file.file_name().unwrap())); + try_hard_link(&file, dist_dir.join("lib").join(file.file_name().unwrap())); } } } @@ -153,7 +153,7 @@ static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot"); fn build_clif_sysroot_for_triple( channel: &str, - target_dir: &Path, + dist_dir: &Path, triple: &str, cg_clif_dylib_path: &Path, linker: Option<&str>, @@ -189,7 +189,7 @@ fn build_clif_sysroot_for_triple( // Build sysroot let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); - rustflags.push_str(&format!(" --sysroot={}", target_dir.to_str().unwrap())); + rustflags.push_str(&format!(" --sysroot={}", dist_dir.to_str().unwrap())); if channel == "release" { rustflags.push_str(" -Zmir-opt-level=3"); } @@ -221,7 +221,7 @@ fn build_clif_sysroot_for_triple( }; try_hard_link( entry.path(), - target_dir.join("lib").join("rustlib").join(triple).join("lib").join(entry.file_name()), + dist_dir.join("lib").join("rustlib").join(triple).join("lib").join(entry.file_name()), ); } } diff --git a/build_system/mod.rs b/build_system/mod.rs index b246a70e89f18..531f42cf87300 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -17,10 +17,10 @@ fn usage() { eprintln!("Usage:"); eprintln!(" ./y.rs prepare"); eprintln!( - " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]" ); eprintln!( - " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]" ); } @@ -75,15 +75,15 @@ pub fn main() { } }; - let mut target_dir = PathBuf::from("dist"); + let mut dist_dir = PathBuf::from("dist"); let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; while let Some(arg) = args.next().as_deref() { match arg { - "--target-dir" => { - target_dir = PathBuf::from(args.next().unwrap_or_else(|| { - arg_error!("--target-dir requires argument"); + "--dist-dir" => { + dist_dir = PathBuf::from(args.next().unwrap_or_else(|| { + arg_error!("--dist-dir requires argument"); })) } "--debug" => channel = "debug", @@ -101,7 +101,7 @@ pub fn main() { arg => arg_error!("Unexpected argument {}", arg), } } - target_dir = std::env::current_dir().unwrap().join(target_dir); + dist_dir = std::env::current_dir().unwrap().join(dist_dir); let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { host_triple @@ -128,7 +128,7 @@ pub fn main() { tests::run_tests( channel, sysroot_kind, - &target_dir, + &dist_dir, &cg_clif_dylib, &host_triple, &target_triple, @@ -137,7 +137,7 @@ pub fn main() { abi_cafe::run( channel, sysroot_kind, - &target_dir, + &dist_dir, &cg_clif_dylib, &host_triple, &target_triple, @@ -147,7 +147,7 @@ pub fn main() { build_sysroot::build_sysroot( channel, sysroot_kind, - &target_dir, + &dist_dir, &cg_clif_dylib, &host_triple, &target_triple, diff --git a/build_system/tests.rs b/build_system/tests.rs index 174b77206fba6..aa46cd0a250e7 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -432,7 +432,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, - target_dir: &Path, + dist_dir: &Path, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, @@ -443,7 +443,7 @@ pub(crate) fn run_tests( build_sysroot::build_sysroot( channel, SysrootKind::None, - &target_dir, + &dist_dir, cg_clif_dylib, &host_triple, &target_triple, @@ -462,7 +462,7 @@ pub(crate) fn run_tests( build_sysroot::build_sysroot( channel, sysroot_kind, - &target_dir, + &dist_dir, cg_clif_dylib, &host_triple, &target_triple, From 3cf89947808758840dfe640eb927edd99e64b27b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:40:48 +0100 Subject: [PATCH 45/77] Ignore out-of-stack test cc #1301 --- scripts/test_rustc_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d2656f783ad86..192c4d1f0c7eb 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -105,6 +105,8 @@ rm src/test/ui/type-alias-impl-trait/assoc-projection-ice.rs # produces ICE rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors +rm src/test/ui/runtime/out-of-stack.rs # SIGSEGV instead of SIGABRT for some reason (#1301) + # bugs in the test suite # ====================== rm src/test/ui/backtrace.rs # TODO warning From 6768d0dd72ddde27f7b297f1eec8e58b9eeaaedc Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:13:33 +0000 Subject: [PATCH 46/77] Booleans have been removed from Cranelift --- src/base.rs | 4 +--- src/intrinsics/mod.rs | 13 ++++++------- src/intrinsics/simd.rs | 5 +---- src/num.rs | 6 +----- src/optimize/peephole.rs | 20 -------------------- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/base.rs b/src/base.rs index 1db44502742e9..41e58d34b0070 100644 --- a/src/base.rs +++ b/src/base.rs @@ -388,11 +388,9 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { _ => unreachable!("{:?}", targets), }; - let discr = crate::optimize::peephole::maybe_unwrap_bint(&mut fx.bcx, discr); let (discr, is_inverted) = crate::optimize::peephole::maybe_unwrap_bool_not(&mut fx.bcx, discr); let test_zero = if is_inverted { !test_zero } else { test_zero }; - let discr = crate::optimize::peephole::maybe_unwrap_bint(&mut fx.bcx, discr); if let Some(taken) = crate::optimize::peephole::maybe_known_branch_taken( &fx.bcx, discr, test_zero, ) { @@ -569,7 +567,7 @@ fn codegen_stmt<'tcx>( UnOp::Not => match layout.ty.kind() { ty::Bool => { let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0); - CValue::by_val(fx.bcx.ins().bint(types::I8, res), layout) + CValue::by_val(res, layout) } ty::Uint(_) | ty::Int(_) => { CValue::by_val(fx.bcx.ins().bnot(val), layout) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 8f13af8154e9e..5c90ef8588bd4 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -197,7 +197,9 @@ fn bool_to_zero_or_max_uint<'tcx>( ty => ty, }; - let val = fx.bcx.ins().bint(int_ty, val); + let val = if int_ty == types::I8 { val } else { fx.bcx.ins().uextend(int_ty, val) }; + + // FIXME use bmask instead let mut res = fx.bcx.ins().ineg(val); if ty.is_float() { @@ -938,8 +940,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let old = fx.bcx.ins().atomic_cas(MemFlags::trusted(), ptr, test_old, new); let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old); - let ret_val = - CValue::by_val_pair(old, fx.bcx.ins().bint(types::I8, is_eq), ret.layout()); + let ret_val = CValue::by_val_pair(old, is_eq, ret.layout()); ret.write_cvalue(fx, ret_val) } @@ -1261,8 +1262,7 @@ fn codegen_regular_intrinsic_call<'tcx>( flags.set_notrap(); let lhs_val = fx.bcx.ins().load(clty, flags, lhs_ref, 0); let rhs_val = fx.bcx.ins().load(clty, flags, rhs_ref, 0); - let eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val); - fx.bcx.ins().bint(types::I8, eq) + fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val) } else { // Just call `memcmp` (like slices do in core) when the // size is too large or it's not a power-of-two. @@ -1272,8 +1272,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let returns = vec![AbiParam::new(types::I32)]; let args = &[lhs_ref, rhs_ref, bytes_val]; let cmp = fx.lib_call("memcmp", params, returns, args)[0]; - let eq = fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0); - fx.bcx.ins().bint(types::I8, eq) + fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0) }; ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout())); } diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 51fce8c854bdb..567c12fe316d7 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -112,10 +112,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => unreachable!(), }; - let ty = fx.clif_type(res_lane_ty).unwrap(); - - let res_lane = fx.bcx.ins().bint(ty, res_lane); - fx.bcx.ins().ineg(res_lane) + bool_to_zero_or_max_uint(fx, res_lane_ty, res_lane) }); } diff --git a/src/num.rs b/src/num.rs index ecbab408ded97..afacbec644582 100644 --- a/src/num.rs +++ b/src/num.rs @@ -49,7 +49,6 @@ fn codegen_compare_bin_op<'tcx>( ) -> CValue<'tcx> { let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap(); let val = fx.bcx.ins().icmp(intcc, lhs, rhs); - let val = fx.bcx.ins().bint(types::I8, val); CValue::by_val(val, fx.layout_of(fx.tcx.types.bool)) } @@ -290,8 +289,6 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( _ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs), }; - let has_overflow = fx.bcx.ins().bint(types::I8, has_overflow); - let out_layout = fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter())); CValue::by_val_pair(res, has_overflow, out_layout) } @@ -368,7 +365,6 @@ pub(crate) fn codegen_float_binop<'tcx>( _ => unreachable!(), }; let val = fx.bcx.ins().fcmp(fltcc, lhs, rhs); - let val = fx.bcx.ins().bint(types::I8, val); return CValue::by_val(val, fx.layout_of(fx.tcx.types.bool)); } _ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs), @@ -440,7 +436,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>( _ => panic!("bin_op {:?} on ptr", bin_op), }; - CValue::by_val(fx.bcx.ins().bint(types::I8, res), fx.layout_of(fx.tcx.types.bool)) + CValue::by_val(res, fx.layout_of(fx.tcx.types.bool)) } } diff --git a/src/optimize/peephole.rs b/src/optimize/peephole.rs index d637b4d89293c..7f45bbd8f2813 100644 --- a/src/optimize/peephole.rs +++ b/src/optimize/peephole.rs @@ -3,19 +3,6 @@ use cranelift_codegen::ir::{condcodes::IntCC, InstructionData, Opcode, Value, ValueDef}; use cranelift_frontend::FunctionBuilder; -/// If the given value was produced by a `bint` instruction, return it's input, otherwise return the -/// given value. -pub(crate) fn maybe_unwrap_bint(bcx: &mut FunctionBuilder<'_>, arg: Value) -> Value { - if let ValueDef::Result(arg_inst, 0) = bcx.func.dfg.value_def(arg) { - match bcx.func.dfg[arg_inst] { - InstructionData::Unary { opcode: Opcode::Bint, arg } => arg, - _ => arg, - } - } else { - arg - } -} - /// If the given value was produced by the lowering of `Rvalue::Not` return the input and true, /// otherwise return the given value and false. pub(crate) fn maybe_unwrap_bool_not(bcx: &mut FunctionBuilder<'_>, arg: Value) -> (Value, bool) { @@ -48,13 +35,6 @@ pub(crate) fn maybe_known_branch_taken( }; match bcx.func.dfg[arg_inst] { - InstructionData::UnaryBool { opcode: Opcode::Bconst, imm } => { - if test_zero { - Some(!imm) - } else { - Some(imm) - } - } InstructionData::UnaryImm { opcode: Opcode::Iconst, imm } => { if test_zero { Some(imm.bits() == 0) From 16a2641444e16747ad87c09057d78054ce9ea63a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:18:19 +0000 Subject: [PATCH 47/77] Remove all usages of iconst.i128 Support was removed from Cranelift --- src/cast.rs | 2 +- src/common.rs | 9 +++++++++ src/discriminant.rs | 10 ++++++++-- src/intrinsics/simd.rs | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index bad5d1f08a9cf..5091c5a9fedac 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -149,7 +149,7 @@ pub(crate) fn clif_int_or_float_cast( } let is_not_nan = fx.bcx.ins().fcmp(FloatCC::Equal, from, from); - let zero = fx.bcx.ins().iconst(to_ty, 0); + let zero = type_zero_value(&mut fx.bcx, to_ty); fx.bcx.ins().select(is_not_nan, val, zero) } else if from_ty.is_float() && to_ty.is_float() { // float -> float diff --git a/src/common.rs b/src/common.rs index 6a3ab8881bb66..2dcd42fbd8f43 100644 --- a/src/common.rs +++ b/src/common.rs @@ -167,6 +167,15 @@ pub(crate) fn codegen_icmp_imm( } } +pub(crate) fn type_zero_value(bcx: &mut FunctionBuilder<'_>, ty: Type) -> Value { + if ty == types::I128 { + let zero = bcx.ins().iconst(types::I64, 0); + bcx.ins().iconcat(zero, zero) + } else { + bcx.ins().iconst(ty, 0) + } +} + pub(crate) fn type_min_max_value( bcx: &mut FunctionBuilder<'_>, ty: Type, diff --git a/src/discriminant.rs b/src/discriminant.rs index b452047c76096..3cbf313adf0df 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -278,8 +278,14 @@ pub(crate) fn codegen_get_discriminant<'tcx>( fx.bcx.ins().iadd(tagged_discr, delta) }; - let untagged_variant = - fx.bcx.ins().iconst(cast_to, i64::from(untagged_variant.as_u32())); + let untagged_variant = if cast_to == types::I128 { + let zero = fx.bcx.ins().iconst(types::I64, 0); + let untagged_variant = + fx.bcx.ins().iconst(types::I64, i64::from(untagged_variant.as_u32())); + fx.bcx.ins().iconcat(untagged_variant, zero) + } else { + fx.bcx.ins().iconst(cast_to, i64::from(untagged_variant.as_u32())) + }; let discr = fx.bcx.ins().select(is_niche, tagged_discr, untagged_variant); let res = CValue::by_val(discr, dest_layout); dest.write_cvalue(fx, res); diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 567c12fe316d7..14f5e9187399f 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -713,7 +713,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let res_type = Type::int_with_byte_size(u16::try_from(expected_bytes).unwrap()).unwrap(); - let mut res = fx.bcx.ins().iconst(res_type, 0); + let mut res = type_zero_value(&mut fx.bcx, res_type); let lanes = match fx.tcx.sess.target.endian { Endian::Big => Box::new(0..lane_count) as Box>, From 777106a581dff9d42347cf84fc400bbde65649a9 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:18:25 +0000 Subject: [PATCH 48/77] Fix warning --- src/debuginfo/unwind.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index d26392c4913b5..493359c743f11 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -39,7 +39,9 @@ impl UnwindContext { } pub(crate) fn add_function(&mut self, func_id: FuncId, context: &Context, isa: &dyn TargetIsa) { - let unwind_info = if let Some(unwind_info) = context.create_unwind_info(isa).unwrap() { + let unwind_info = if let Some(unwind_info) = + context.compiled_code().unwrap().create_unwind_info(isa).unwrap() + { unwind_info } else { return; From e9115eb6471661b8d29826fab4369dca9f79db52 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:20:30 +0000 Subject: [PATCH 49/77] Use git version of Cranelift --- Cargo.lock | 80 ++++++++++++++++++++++++++++++++---------------------- Cargo.toml | 12 ++++---- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6bf913e7f1d21..e3298873e2797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,24 +62,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4d6bb61f78cc312fbdebbb8a11b5aea6c16355ee682c57b89914691f3d57d0d" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f8572ccd8b99df7a8244d64feaa37f37877e47eccc245aa5e27f15dd336d7e" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "arrayvec", "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", "cranelift-isle", "gimli", @@ -91,30 +90,39 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2f284f49249a9fda931332f3feed56492651f47c330ffe1aa5a51f2b9d6b6" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6190411c55dfd88e68f506dfdbd028da0551dca40793d40811ea03cb6e0f4a" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" + +[[package]] +name = "cranelift-egraph" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed8aa1104f54509dfb386520711cd8a6a0992ae42ce2df06fdebdfff4de2c2dd" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" [[package]] name = "cranelift-frontend" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48087600d6c055f625754b1d9cc9cab36a0d26a365cbcb388825e331e0041ff" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "cranelift-codegen", "log", @@ -124,15 +132,13 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eead4df80ce3c68b913d071683790692a0316a67e3518b32e273169238876f0a" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" [[package]] name = "cranelift-jit" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d92ab547bf300966d5ef714e5575ae0437a2f8da6f92a30a3d35f9e7971ae9" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "anyhow", "cranelift-codegen", @@ -143,14 +149,14 @@ dependencies = [ "log", "region", "target-lexicon", + "wasmtime-jit-icache-coherence", "windows-sys", ] [[package]] name = "cranelift-module" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ecae6c04ac78161c9380e4953ff5d56e44fe78e1e32a3d7e816bf2e9246283f" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "anyhow", "cranelift-codegen", @@ -158,9 +164,8 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adde571ff9c6a77320b69ac03920c5ce70fed94f5f9ac53f5c0600a69fc142e" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "cranelift-codegen", "libc", @@ -169,9 +174,8 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.89.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb602999187ba96b81822fe48dbd544ecc36179741c0bc2dd6602e3ee0c5ead" +version = "0.90.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" dependencies = [ "anyhow", "cranelift-codegen", @@ -384,6 +388,16 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "2.0.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +dependencies = [ + "cfg-if", + "libc", + "windows-sys", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 1a97feb70b752..9f4a7e4f0483d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.89.1", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.89.1" -cranelift-module = "0.89.1" -cranelift-native = "0.89.1" -cranelift-jit = { version = "0.89.1", optional = true } -cranelift-object = "0.89.1" +cranelift-codegen = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", features = ["unwind", "all-arch"] } +cranelift-frontend = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } +cranelift-module = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } +cranelift-native = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } +cranelift-jit = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", optional = true } +cranelift-object = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From ae98a2f570721601c0804f9996dbdf267ca9f193 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 2 Nov 2022 15:03:43 +0000 Subject: [PATCH 50/77] Simplify some code based on newly implemented instructions --- Cargo.lock | 30 +++++++------- src/base.rs | 6 --- src/intrinsics/mod.rs | 93 ++++++------------------------------------- 3 files changed, 28 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3298873e2797..540ba1ca79a18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cranelift-entity", ] @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "arrayvec", "bumpalo", @@ -91,7 +91,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cranelift-codegen-shared", ] @@ -99,12 +99,12 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" [[package]] name = "cranelift-egraph" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cranelift-entity", "fxhash", @@ -117,12 +117,12 @@ dependencies = [ [[package]] name = "cranelift-entity" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" [[package]] name = "cranelift-frontend" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cranelift-codegen", "log", @@ -133,12 +133,12 @@ dependencies = [ [[package]] name = "cranelift-isle" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" [[package]] name = "cranelift-jit" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "anyhow", "cranelift-codegen", @@ -156,7 +156,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "anyhow", "cranelift-codegen", @@ -165,7 +165,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cranelift-codegen", "libc", @@ -175,7 +175,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "anyhow", "cranelift-codegen", @@ -310,9 +310,9 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "regalloc2" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69025b4a161879ba90719837c06621c3d73cffa147a000aeacf458f6a9572485" +checksum = "91b2eab54204ea0117fe9a060537e0b07a4e72f7c7d182361ecc346cab2240e5" dependencies = [ "fxhash", "log", @@ -391,7 +391,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasmtime-jit-icache-coherence" version = "2.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080" +source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" dependencies = [ "cfg-if", "libc", diff --git a/src/base.rs b/src/base.rs index 41e58d34b0070..12a15fbaee6b3 100644 --- a/src/base.rs +++ b/src/base.rs @@ -575,12 +575,6 @@ fn codegen_stmt<'tcx>( _ => unreachable!("un op Not for {:?}", layout.ty), }, UnOp::Neg => match layout.ty.kind() { - ty::Int(IntTy::I128) => { - // FIXME remove this case once ineg.i128 works - let zero = - CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size)); - crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand) - } ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout), ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout), _ => unreachable!("un op Neg for {:?}", layout.ty), diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 5c90ef8588bd4..76fc399097ad2 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -197,10 +197,7 @@ fn bool_to_zero_or_max_uint<'tcx>( ty => ty, }; - let val = if int_ty == types::I8 { val } else { fx.bcx.ins().uextend(int_ty, val) }; - - // FIXME use bmask instead - let mut res = fx.bcx.ins().ineg(val); + let mut res = fx.bcx.ins().bmask(int_ty, val); if ty.is_float() { res = fx.bcx.ins().bitcast(ty, res); @@ -636,85 +633,21 @@ fn codegen_regular_intrinsic_call<'tcx>( ret.write_cvalue(fx, res); } sym::bswap => { - // FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift - fn swap(bcx: &mut FunctionBuilder<'_>, v: Value) -> Value { - match bcx.func.dfg.value_type(v) { - types::I8 => v, - - // https://code.woboq.org/gcc/include/bits/byteswap.h.html - types::I16 => { - let tmp1 = bcx.ins().ishl_imm(v, 8); - let n1 = bcx.ins().band_imm(tmp1, 0xFF00); - - let tmp2 = bcx.ins().ushr_imm(v, 8); - let n2 = bcx.ins().band_imm(tmp2, 0x00FF); - - bcx.ins().bor(n1, n2) - } - types::I32 => { - let tmp1 = bcx.ins().ishl_imm(v, 24); - let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000); - - let tmp2 = bcx.ins().ishl_imm(v, 8); - let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000); - - let tmp3 = bcx.ins().ushr_imm(v, 8); - let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00); - - let tmp4 = bcx.ins().ushr_imm(v, 24); - let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF); - - let or_tmp1 = bcx.ins().bor(n1, n2); - let or_tmp2 = bcx.ins().bor(n3, n4); - bcx.ins().bor(or_tmp1, or_tmp2) - } - types::I64 => { - let tmp1 = bcx.ins().ishl_imm(v, 56); - let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000_0000_0000u64 as i64); - - let tmp2 = bcx.ins().ishl_imm(v, 40); - let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000_0000_0000u64 as i64); - - let tmp3 = bcx.ins().ishl_imm(v, 24); - let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00_0000_0000u64 as i64); - - let tmp4 = bcx.ins().ishl_imm(v, 8); - let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF_0000_0000u64 as i64); - - let tmp5 = bcx.ins().ushr_imm(v, 8); - let n5 = bcx.ins().band_imm(tmp5, 0x0000_0000_FF00_0000u64 as i64); - - let tmp6 = bcx.ins().ushr_imm(v, 24); - let n6 = bcx.ins().band_imm(tmp6, 0x0000_0000_00FF_0000u64 as i64); - - let tmp7 = bcx.ins().ushr_imm(v, 40); - let n7 = bcx.ins().band_imm(tmp7, 0x0000_0000_0000_FF00u64 as i64); - - let tmp8 = bcx.ins().ushr_imm(v, 56); - let n8 = bcx.ins().band_imm(tmp8, 0x0000_0000_0000_00FFu64 as i64); - - let or_tmp1 = bcx.ins().bor(n1, n2); - let or_tmp2 = bcx.ins().bor(n3, n4); - let or_tmp3 = bcx.ins().bor(n5, n6); - let or_tmp4 = bcx.ins().bor(n7, n8); - - let or_tmp5 = bcx.ins().bor(or_tmp1, or_tmp2); - let or_tmp6 = bcx.ins().bor(or_tmp3, or_tmp4); - bcx.ins().bor(or_tmp5, or_tmp6) - } - types::I128 => { - let (lo, hi) = bcx.ins().isplit(v); - let lo = swap(bcx, lo); - let hi = swap(bcx, hi); - bcx.ins().iconcat(hi, lo) - } - ty => unreachable!("bswap {}", ty), - } - } intrinsic_args!(fx, args => (arg); intrinsic); let val = arg.load_scalar(fx); - let res = CValue::by_val(swap(&mut fx.bcx, val), arg.layout()); + let res = match fx.bcx.func.dfg.value_type(val) { + types::I8 => val, + types::I128 => { + // FIXME(bytecodealliance/wasmtime#1092) bswap.i128 is not yet implemented + let (lsb, msb) = fx.bcx.ins().isplit(val); + let lsb_swap = fx.bcx.ins().bswap(lsb); + let msb_swap = fx.bcx.ins().bswap(msb); + fx.bcx.ins().iconcat(msb_swap, lsb_swap) + } + _ => fx.bcx.ins().bswap(val), + }; + let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); } sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => { From 83dc7d1a123d2b2e0b0b84aa3d0ae6dc4a59fd4e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:10:12 +0000 Subject: [PATCH 51/77] Fix for removal of raw_bitcast --- Cargo.lock | 26 +++++++++++++------------- src/value_and_place.rs | 4 +--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 540ba1ca79a18..61e091bfe847d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cranelift-entity", ] @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "arrayvec", "bumpalo", @@ -91,7 +91,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cranelift-codegen-shared", ] @@ -99,12 +99,12 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" [[package]] name = "cranelift-egraph" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cranelift-entity", "fxhash", @@ -117,12 +117,12 @@ dependencies = [ [[package]] name = "cranelift-entity" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" [[package]] name = "cranelift-frontend" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cranelift-codegen", "log", @@ -133,12 +133,12 @@ dependencies = [ [[package]] name = "cranelift-isle" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" [[package]] name = "cranelift-jit" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "anyhow", "cranelift-codegen", @@ -156,7 +156,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "anyhow", "cranelift-codegen", @@ -165,7 +165,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cranelift-codegen", "libc", @@ -175,7 +175,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "anyhow", "cranelift-codegen", @@ -391,7 +391,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasmtime-jit-icache-coherence" version = "2.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc" +source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" dependencies = [ "cfg-if", "libc", diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 58a6508de7a3c..da712808c9423 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -515,9 +515,7 @@ impl<'tcx> CPlace<'tcx> { | (types::F32, types::I32) | (types::I64, types::F64) | (types::F64, types::I64) => fx.bcx.ins().bitcast(dst_ty, data), - _ if src_ty.is_vector() && dst_ty.is_vector() => { - fx.bcx.ins().raw_bitcast(dst_ty, data) - } + _ if src_ty.is_vector() && dst_ty.is_vector() => fx.bcx.ins().bitcast(dst_ty, data), _ if src_ty.is_vector() || dst_ty.is_vector() => { // FIXME do something more efficient for transmutes between vectors and integers. let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData { From 3df425e11e4cef5f9c4c08cd545db2bffdbb97bd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:10:28 +0000 Subject: [PATCH 52/77] bswap.i128 is now supported --- src/intrinsics/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 76fc399097ad2..7a380acf79857 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -636,16 +636,10 @@ fn codegen_regular_intrinsic_call<'tcx>( intrinsic_args!(fx, args => (arg); intrinsic); let val = arg.load_scalar(fx); - let res = match fx.bcx.func.dfg.value_type(val) { - types::I8 => val, - types::I128 => { - // FIXME(bytecodealliance/wasmtime#1092) bswap.i128 is not yet implemented - let (lsb, msb) = fx.bcx.ins().isplit(val); - let lsb_swap = fx.bcx.ins().bswap(lsb); - let msb_swap = fx.bcx.ins().bswap(msb); - fx.bcx.ins().iconcat(msb_swap, lsb_swap) - } - _ => fx.bcx.ins().bswap(val), + let res = if fx.bcx.func.dfg.value_type(val) == types::I8 { + val + } else { + fx.bcx.ins().bswap(val) }; let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); From 155f5697949d21d5658115808d982aec01fbb649 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Nov 2022 10:47:43 +0000 Subject: [PATCH 53/77] Update cranelift to the upcoming release-3.0.0 branch --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 12 ++++++------ src/driver/jit.rs | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61e091bfe847d..73d07648c3aac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cranelift-entity", ] @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "arrayvec", "bumpalo", @@ -91,7 +91,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cranelift-codegen-shared", ] @@ -99,12 +99,12 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" [[package]] name = "cranelift-egraph" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cranelift-entity", "fxhash", @@ -117,12 +117,12 @@ dependencies = [ [[package]] name = "cranelift-entity" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" [[package]] name = "cranelift-frontend" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cranelift-codegen", "log", @@ -133,12 +133,12 @@ dependencies = [ [[package]] name = "cranelift-isle" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" [[package]] name = "cranelift-jit" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "anyhow", "cranelift-codegen", @@ -156,7 +156,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "anyhow", "cranelift-codegen", @@ -165,7 +165,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cranelift-codegen", "libc", @@ -175,7 +175,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "anyhow", "cranelift-codegen", @@ -391,7 +391,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasmtime-jit-icache-coherence" version = "2.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#2c69b94744c93247075ed1c6754b4cb5549cd90d" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 9f4a7e4f0483d..16c1636f9c59a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", features = ["unwind", "all-arch"] } -cranelift-frontend = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-module = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-native = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-jit = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", optional = true } -cranelift-object = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git" } +cranelift-codegen = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0", features = ["unwind", "all-arch"] } +cranelift-frontend = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } +cranelift-module = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } +cranelift-native = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } +cranelift-jit = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0", optional = true } +cranelift-object = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 6a430b5215e36..1dcb8025183c9 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -159,7 +159,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { tcx.sess.abort_if_errors(); - jit_module.finalize_definitions(); + jit_module.finalize_definitions().unwrap(); unsafe { cx.unwind_context.register_jit(&jit_module) }; println!( @@ -278,7 +278,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> }); assert!(cx.global_asm.is_empty()); - jit_module.finalize_definitions(); + jit_module.finalize_definitions().unwrap(); unsafe { cx.unwind_context.register_jit(&jit_module) }; jit_module.get_finalized_function(func_id) }) From 202bdc1ceb7190b13e333737f696b519f2ba0550 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 21 Nov 2022 19:11:18 +0000 Subject: [PATCH 54/77] Update Cranelift to 0.90.0 --- Cargo.lock | 39 ++++++++++++++++++++++++++------------- Cargo.toml | 12 ++++++------ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73d07648c3aac..11c1fda981272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,8 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c200df7d943cd2b8cb3a67f6a56781c63849f122d74deff24d1767c3918b0bdc" dependencies = [ "cranelift-entity", ] @@ -71,7 +72,8 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f365623f4c3d576f47f11868568d0c90e18ac169497a9ed73c433fe2d3f9f2fb" dependencies = [ "arrayvec", "bumpalo", @@ -91,7 +93,8 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbaf79f8ae63bd86dc40a04417a7cc1691a217f6db204438026c164679b4694" dependencies = [ "cranelift-codegen-shared", ] @@ -99,12 +102,14 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "587db55845c943d8211e9c7198a977fa6686b44f18df15f31cec9a12fcf5dda8" [[package]] name = "cranelift-egraph" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6dccc0b16b7b8c1278162e436beebb35f3d321743b639d2b578138d630f43e" dependencies = [ "cranelift-entity", "fxhash", @@ -117,12 +122,14 @@ dependencies = [ [[package]] name = "cranelift-entity" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b062935d2c6dba87387d2ac163eb9c54967ed6143c3136fffaba8acb5eaa9e" [[package]] name = "cranelift-frontend" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476ea81fe736b858d2d2c53b9d9fd28082589f57ebe4e1654a68af7359800a0c" dependencies = [ "cranelift-codegen", "log", @@ -133,12 +140,14 @@ dependencies = [ [[package]] name = "cranelift-isle" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c50a465703c15d3d913f6b0db8320c4e92c940f0f0cad874c7fcf5aecc066c0" [[package]] name = "cranelift-jit" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7178efab39f6c39e152ad8c6250d6010a296fd6232a77e4d8e3288b75732af7d" dependencies = [ "anyhow", "cranelift-codegen", @@ -156,7 +165,8 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb622cbbe26af304c8598599f3e3dbb6a8e88a0af0f8e9506e068daa7a8b01a6" dependencies = [ "anyhow", "cranelift-codegen", @@ -165,7 +175,8 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d9e0d1382584b8d454ec12c86fd562b64ccd454c1199846c1b7d158db9ed38" dependencies = [ "cranelift-codegen", "libc", @@ -175,7 +186,8 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.90.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10d885261f93086c39882238862dcee007993738a01fb51a3532cf5db0f55d54" dependencies = [ "anyhow", "cranelift-codegen", @@ -391,7 +403,8 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasmtime-jit-icache-coherence" version = "2.0.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=release-3.0.0#0102cd7bc0c9a178a8a492340961f5822f9b95c8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb7b3e58024d8d395dfc4efbe2a58360a1998565b118b0342b3cf62a4084bde" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 16c1636f9c59a..6e5bfca67159a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0", features = ["unwind", "all-arch"] } -cranelift-frontend = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } -cranelift-module = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } -cranelift-native = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } -cranelift-jit = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0", optional = true } -cranelift-object = { version = "0.90", git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-3.0.0" } +cranelift-codegen = { version = "0.90", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.90" +cranelift-module = "0.90" +cranelift-native = "0.90" +cranelift-jit = { version = "0.90", optional = true } +cranelift-object = "0.90" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From a54a3775c90f3f5f7a13e64809a01fb3364e8d4a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 17:46:48 +0000 Subject: [PATCH 55/77] Update Cranelift to 0.90.1 This fixes building on FreeBSD --- Cargo.lock | 52 ++++++++++++++++++++++++++-------------------------- Cargo.toml | 12 ++++++------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11c1fda981272..de5d166b8ef68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,18 +62,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c200df7d943cd2b8cb3a67f6a56781c63849f122d74deff24d1767c3918b0bdc" +checksum = "b62c772976416112fa4484cbd688cb6fb35fd430005c1c586224fc014018abad" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f365623f4c3d576f47f11868568d0c90e18ac169497a9ed73c433fe2d3f9f2fb" +checksum = "9b40ed2dd13c2ac7e24f88a3090c68ad3414eb1d066a95f8f1f7b3b819cb4e46" dependencies = [ "arrayvec", "bumpalo", @@ -92,24 +92,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbaf79f8ae63bd86dc40a04417a7cc1691a217f6db204438026c164679b4694" +checksum = "bb927a8f1c27c34ee3759b6b0ffa528d2330405d5cc4511f0cab33fe2279f4b5" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "587db55845c943d8211e9c7198a977fa6686b44f18df15f31cec9a12fcf5dda8" +checksum = "43dfa417b884a9ab488d95fd6b93b25e959321fe7bfd7a0a960ba5d7fb7ab927" [[package]] name = "cranelift-egraph" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6dccc0b16b7b8c1278162e436beebb35f3d321743b639d2b578138d630f43e" +checksum = "e0a66b39785efd8513d2cca967ede56d6cc57c8d7986a595c7c47d0c78de8dce" dependencies = [ "cranelift-entity", "fxhash", @@ -121,15 +121,15 @@ dependencies = [ [[package]] name = "cranelift-entity" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b062935d2c6dba87387d2ac163eb9c54967ed6143c3136fffaba8acb5eaa9e" +checksum = "0637ffde963cb5d759bc4d454cfa364b6509e6c74cdaa21298add0ed9276f346" [[package]] name = "cranelift-frontend" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "476ea81fe736b858d2d2c53b9d9fd28082589f57ebe4e1654a68af7359800a0c" +checksum = "fb72b8342685e850cb037350418f62cc4fc55d6c2eb9c7ca01b82f9f1a6f3d56" dependencies = [ "cranelift-codegen", "log", @@ -139,15 +139,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c50a465703c15d3d913f6b0db8320c4e92c940f0f0cad874c7fcf5aecc066c0" +checksum = "850579cb9e4b448f7c301f1e6e6cbad99abe3f1f1d878a4994cb66e33c6db8cd" [[package]] name = "cranelift-jit" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7178efab39f6c39e152ad8c6250d6010a296fd6232a77e4d8e3288b75732af7d" +checksum = "9add822ad66dcbe152b5ab57de10240a2df4505099f2f6c27159acb711890bd4" dependencies = [ "anyhow", "cranelift-codegen", @@ -164,9 +164,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb622cbbe26af304c8598599f3e3dbb6a8e88a0af0f8e9506e068daa7a8b01a6" +checksum = "406b772626fc2664864cf947f3895a23b619895c7fff635f3622e2d857f4492f" dependencies = [ "anyhow", "cranelift-codegen", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7d9e0d1382584b8d454ec12c86fd562b64ccd454c1199846c1b7d158db9ed38" +checksum = "2d0a279e5bcba3e0466c734d8d8eb6bfc1ad29e95c37f3e4955b492b5616335e" dependencies = [ "cranelift-codegen", "libc", @@ -185,9 +185,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.90.0" +version = "0.90.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10d885261f93086c39882238862dcee007993738a01fb51a3532cf5db0f55d54" +checksum = "39793c550f0c1d7db96c2fc1324583670c8143befe6edbfbaf1c68aba53be983" dependencies = [ "anyhow", "cranelift-codegen", @@ -402,9 +402,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasmtime-jit-icache-coherence" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb7b3e58024d8d395dfc4efbe2a58360a1998565b118b0342b3cf62a4084bde" +checksum = "e6bbabb309c06cc238ee91b1455b748c45f0bdcab0dda2c2db85b0a1e69fcb66" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 6e5bfca67159a..a9ad5a5d38387 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.90", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.90" -cranelift-module = "0.90" -cranelift-native = "0.90" -cranelift-jit = { version = "0.90", optional = true } -cranelift-object = "0.90" +cranelift-codegen = { version = "0.90.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.90.1" +cranelift-module = "0.90.1" +cranelift-native = "0.90.1" +cranelift-jit = { version = "0.90.1", optional = true } +cranelift-object = "0.90.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From 5e97a3951d8a6c6fe0f0c5b6b0f42a42563a2bc8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:15:40 +0000 Subject: [PATCH 56/77] Make sure the target dir is always explicitly set when using cargo --- build_system/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 531f42cf87300..ef1109afe0a7c 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -48,8 +48,15 @@ pub(crate) enum SysrootKind { pub fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); - // The target dir is expected in the default location. Guard against the user changing it. - env::set_var("CARGO_TARGET_DIR", "target"); + + { + // Make sure we always explicitly specify the target dir + let target = "build/target_dir_should_be_set_explicitly"; + env::set_var("CARGO_TARGET_DIR", target); + std::fs::create_dir_all("build").unwrap(); + let _ = std::fs::remove_file(target); + let file = std::fs::File::create(target).unwrap(); + } if is_ci() { // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway From e75dfef4d4002dcb8e2daaf99b9d0ce922053f73 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 17:37:30 +0000 Subject: [PATCH 57/77] Put all temporary build artifacts in build/ --- build_system/abi_cafe.rs | 2 +- build_system/build_backend.rs | 5 ++--- build_system/build_sysroot.rs | 13 +++++------- build_system/mod.rs | 5 +++-- build_system/prepare.rs | 4 +--- build_system/tests.rs | 38 +++++++++++++++++------------------ build_system/utils.rs | 20 +++++++++--------- clean_all.sh | 4 ++-- 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index bff5b8f41020a..469df9483a7f7 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -9,7 +9,7 @@ use super::SysrootKind; pub(crate) static ABI_CAFE_REPO: GitRepo = GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); -static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, "."); +static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, ".", "abi_cafe"); pub(crate) fn run( channel: &str, diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 48648830a9f58..b1c902abd17d1 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use super::rustc_info::get_file_name; use super::utils::{is_ci, CargoProject, Compiler}; -static CG_CLIF: CargoProject = CargoProject::local("."); +static CG_CLIF: CargoProject = CargoProject::local(".", "cg_clif"); pub(crate) fn build_backend( channel: &str, @@ -43,8 +43,7 @@ pub(crate) fn build_backend( super::utils::spawn_and_wait(cmd); CG_CLIF - .source_dir() - .join("target") + .target_dir() .join(host_triple) .join(channel) .join(get_file_name("rustc_codegen_cranelift", "dylib")) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 4b21df85f5fbf..f78803268d36d 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,5 +1,5 @@ use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process::{self, Command}; use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; @@ -40,7 +40,7 @@ pub(crate) fn build_sysroot( let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd - .arg(PathBuf::from("scripts").join(format!("{wrapper}.rs"))) + .arg(Path::new("scripts").join(format!("{wrapper}.rs"))) .arg("-o") .arg(dist_dir.join(wrapper_name)) .arg("-g"); @@ -149,7 +149,7 @@ pub(crate) fn build_sysroot( } } -static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot"); +static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot", "build_sysroot"); fn build_clif_sysroot_for_triple( channel: &str, @@ -176,7 +176,7 @@ fn build_clif_sysroot_for_triple( } } - let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); + let build_dir = STANDARD_LIBRARY.target_dir().join(triple).join(channel); if !super::config::get_bool("keep_sysroot") { // Cleanup the deps dir, but keep build scripts and the incremental cache for faster @@ -207,10 +207,7 @@ fn build_clif_sysroot_for_triple( spawn_and_wait(build_cmd); // Copy all relevant files to the sysroot - for entry in - fs::read_dir(Path::new("build_sysroot/target").join(triple).join(channel).join("deps")) - .unwrap() - { + for entry in fs::read_dir(build_dir.join("deps")).unwrap() { let entry = entry.unwrap(); if let Some(ext) = entry.path().extension() { if ext == "rmeta" || ext == "d" || ext == "dSYM" || ext == "clif" { diff --git a/build_system/mod.rs b/build_system/mod.rs index ef1109afe0a7c..f3ccfcb151869 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -49,13 +49,14 @@ pub fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); + std::fs::create_dir_all("build").unwrap(); + { // Make sure we always explicitly specify the target dir let target = "build/target_dir_should_be_set_explicitly"; env::set_var("CARGO_TARGET_DIR", target); - std::fs::create_dir_all("build").unwrap(); let _ = std::fs::remove_file(target); - let file = std::fs::File::create(target).unwrap(); + std::fs::File::create(target).unwrap(); } if is_ci() { diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b06d42af14722..99ec3ef2092f6 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -35,9 +35,7 @@ pub(crate) fn prepare() { .join(&host_compiler.triple) .join("debug") .join(get_file_name("main", "bin")), - super::tests::SIMPLE_RAYTRACER_REPO - .source_dir() - .join(get_file_name("raytracer_cg_llvm", "bin")), + Path::new("build").join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } diff --git a/build_system/tests.rs b/build_system/tests.rs index aa46cd0a250e7..0645b69bf7c1a 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -223,12 +223,12 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) static RAND_REPO: GitRepo = GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); -static RAND: CargoProject = CargoProject::git(&RAND_REPO, "."); +static RAND: CargoProject = CargoProject::git(&RAND_REPO, ".", "rand"); pub(crate) static REGEX_REPO: GitRepo = GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex"); -static REGEX: CargoProject = CargoProject::git(®EX_REPO, "."); +static REGEX: CargoProject = CargoProject::git(®EX_REPO, ".", "regex"); pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "rust-lang", @@ -237,7 +237,7 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "portable-simd", ); -static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, "."); +static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, ".", "portable_simd"); pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", @@ -246,10 +246,11 @@ pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "", ); -pub(crate) static SIMPLE_RAYTRACER: CargoProject = CargoProject::git(&SIMPLE_RAYTRACER_REPO, "."); +pub(crate) static SIMPLE_RAYTRACER: CargoProject = + CargoProject::git(&SIMPLE_RAYTRACER_REPO, ".", "simple_raytracer"); static LIBCORE_TESTS: CargoProject = - CargoProject::local("build_sysroot/sysroot_src/library/core/tests"); + CargoProject::local("build_sysroot/sysroot_src/library/core/tests", "core_tests"); const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("test.rust-random/rand", &|runner| { @@ -276,7 +277,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ .unwrap() .join("dist") .join(get_wrapper_file_name("cargo-clif", "bin")); - let source_dir = SIMPLE_RAYTRACER.source_dir(); let manifest_path = SIMPLE_RAYTRACER.manifest_path(); let target_dir = SIMPLE_RAYTRACER.target_dir(); @@ -303,17 +303,15 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ spawn_and_wait(bench_compile); eprintln!("[BENCH RUN] ebobby/simple-raytracer"); - fs::copy(target_dir.join("debug").join("main"), source_dir.join("raytracer_cg_clif")) - .unwrap(); - - let mut bench_run = hyperfine_command( - 0, - run_runs, - None, - &source_dir.join("raytracer_cg_llvm").display().to_string(), - &source_dir.join("raytracer_cg_clif").display().to_string(), - ); - bench_run.current_dir(SIMPLE_RAYTRACER.source_dir()); + fs::copy( + target_dir.join("debug").join("main"), + Path::new("build").join("raytracer_cg_clif"), + ) + .unwrap(); + + let mut bench_run = + hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif"); + bench_run.current_dir(Path::new("build")); spawn_and_wait(bench_run); } else { spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo)); @@ -449,7 +447,7 @@ pub(crate) fn run_tests( &target_triple, ); - let _ = fs::remove_dir_all(Path::new("target").join("out")); + let _ = fs::remove_dir_all(Path::new("build").join("example")); runner.run_testsuite(NO_SYSROOT_SUITE); } else { eprintln!("[SKIP] no_sysroot tests"); @@ -495,8 +493,8 @@ impl TestRunner { let root_dir = env::current_dir().unwrap(); let mut out_dir = root_dir.clone(); - out_dir.push("target"); - out_dir.push("out"); + out_dir.push("build"); + out_dir.push("example"); let is_native = host_triple == target_triple; let jit_supported = diff --git a/build_system/utils.rs b/build_system/utils.rs index 75869f38118ca..5a03fcf085625 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -51,15 +51,20 @@ enum CargoProjectSource { pub(crate) struct CargoProject { source: CargoProjectSource, path: &'static str, + target: &'static str, } impl CargoProject { - pub(crate) const fn local(path: &'static str) -> CargoProject { - CargoProject { source: CargoProjectSource::Local, path } + pub(crate) const fn local(path: &'static str, target: &'static str) -> CargoProject { + CargoProject { source: CargoProjectSource::Local, path, target } } - pub(crate) const fn git(git_repo: &'static GitRepo, path: &'static str) -> CargoProject { - CargoProject { source: CargoProjectSource::GitRepo(git_repo), path } + pub(crate) const fn git( + git_repo: &'static GitRepo, + path: &'static str, + target: &'static str, + ) -> CargoProject { + CargoProject { source: CargoProjectSource::GitRepo(git_repo), path, target } } pub(crate) fn source_dir(&self) -> PathBuf { @@ -75,12 +80,7 @@ impl CargoProject { } pub(crate) fn target_dir(&self) -> PathBuf { - match self.source { - CargoProjectSource::Local => std::env::current_dir().unwrap(), - CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(), - } - .join(self.path) - .join("target") + std::env::current_dir().unwrap().join("build").join(self.target) } fn base_cmd(&self, command: &str, cargo: &Path) -> Command { diff --git a/clean_all.sh b/clean_all.sh index cd20f3ea3f1e7..1760e5836ecce 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -2,9 +2,9 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} -rm -rf target/ dist/ perf.data{,.old} y.bin +rm -rf target/ build/ dist/ perf.data{,.old} y.bin rm -rf download/ # Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh # FIXME remove at some point in the future -rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ build/ +rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ From 4529979330038c6accce45533f34aae681a6017c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 13:30:03 +0000 Subject: [PATCH 58/77] Introduce RelPath --- build_system/abi_cafe.rs | 12 +----- build_system/build_backend.rs | 3 +- build_system/build_sysroot.rs | 72 ++++++++++++++++------------------- build_system/mod.rs | 20 ++-------- build_system/path.rs | 71 ++++++++++++++++++++++++++++++++++ build_system/prepare.rs | 53 ++++++++++++-------------- build_system/tests.rs | 68 ++++++++++++--------------------- build_system/utils.rs | 30 +++------------ 8 files changed, 165 insertions(+), 164 deletions(-) create mode 100644 build_system/path.rs diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 469df9483a7f7..acb2bd5aeae7b 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -9,12 +9,11 @@ use super::SysrootKind; pub(crate) static ABI_CAFE_REPO: GitRepo = GitRepo::github("Gankra", "abi-cafe", "4c6dc8c9c687e2b3a760ff2176ce236872b37212", "abi-cafe"); -static ABI_CAFE: CargoProject = CargoProject::git(&ABI_CAFE_REPO, ".", "abi_cafe"); +static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe"); pub(crate) fn run( channel: &str, sysroot_kind: SysrootKind, - dist_dir: &Path, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, @@ -30,14 +29,7 @@ pub(crate) fn run( } eprintln!("Building sysroot for abi-cafe"); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - dist_dir, - cg_clif_dylib, - host_triple, - target_triple, - ); + build_sysroot::build_sysroot(channel, sysroot_kind, cg_clif_dylib, host_triple, target_triple); eprintln!("Running abi-cafe"); diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index b1c902abd17d1..5cbeb7d0f9f68 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,10 +1,11 @@ use std::env; use std::path::PathBuf; +use super::path::RelPath; use super::rustc_info::get_file_name; use super::utils::{is_ci, CargoProject, Compiler}; -static CG_CLIF: CargoProject = CargoProject::local(".", "cg_clif"); +static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); pub(crate) fn build_backend( channel: &str, diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index f78803268d36d..fcd668b8aa58c 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -2,36 +2,39 @@ use std::fs; use std::path::Path; use std::process::{self, Command}; +use super::path::RelPath; use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::SysrootKind; +static DIST_DIR: RelPath = RelPath::DIST; +static BIN_DIR: RelPath = RelPath::DIST.join("bin"); +static LIB_DIR: RelPath = RelPath::DIST.join("lib"); +static RUSTLIB_DIR: RelPath = LIB_DIR.join("rustlib"); + pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, - dist_dir: &Path, cg_clif_dylib_src: &Path, host_triple: &str, target_triple: &str, ) { eprintln!("[BUILD] sysroot {:?}", sysroot_kind); - if dist_dir.exists() { - fs::remove_dir_all(dist_dir).unwrap(); - } - fs::create_dir_all(dist_dir.join("bin")).unwrap(); - fs::create_dir_all(dist_dir.join("lib")).unwrap(); + DIST_DIR.ensure_fresh(); + BIN_DIR.ensure_exists(); + LIB_DIR.ensure_exists(); // Copy the backend - let cg_clif_dylib_path = dist_dir - .join(if cfg!(windows) { - // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the - // binaries. - "bin" - } else { - "lib" - }) - .join(get_file_name("rustc_codegen_cranelift", "dylib")); + let cg_clif_dylib_path = if cfg!(windows) { + // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the + // binaries. + BIN_DIR + } else { + LIB_DIR + } + .to_path() + .join(get_file_name("rustc_codegen_cranelift", "dylib")); try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); // Build and copy rustc and cargo wrappers @@ -40,18 +43,17 @@ pub(crate) fn build_sysroot( let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd - .arg(Path::new("scripts").join(format!("{wrapper}.rs"))) + .arg(RelPath::SCRIPTS.to_path().join(&format!("{wrapper}.rs"))) .arg("-o") - .arg(dist_dir.join(wrapper_name)) + .arg(DIST_DIR.to_path().join(wrapper_name)) .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); } let default_sysroot = super::rustc_info::get_default_sysroot(); - let rustlib = dist_dir.join("lib").join("rustlib"); - let host_rustlib_lib = rustlib.join(host_triple).join("lib"); - let target_rustlib_lib = rustlib.join(target_triple).join("lib"); + let host_rustlib_lib = RUSTLIB_DIR.to_path().join(host_triple).join("lib"); + let target_rustlib_lib = RUSTLIB_DIR.to_path().join(target_triple).join("lib"); fs::create_dir_all(&host_rustlib_lib).unwrap(); fs::create_dir_all(&target_rustlib_lib).unwrap(); @@ -112,13 +114,7 @@ pub(crate) fn build_sysroot( } } SysrootKind::Clif => { - build_clif_sysroot_for_triple( - channel, - dist_dir, - host_triple, - &cg_clif_dylib_path, - None, - ); + build_clif_sysroot_for_triple(channel, host_triple, &cg_clif_dylib_path, None); if host_triple != target_triple { // When cross-compiling it is often necessary to manually pick the right linker @@ -127,13 +123,7 @@ pub(crate) fn build_sysroot( } else { None }; - build_clif_sysroot_for_triple( - channel, - dist_dir, - target_triple, - &cg_clif_dylib_path, - linker, - ); + build_clif_sysroot_for_triple(channel, target_triple, &cg_clif_dylib_path, linker); } // Copy std for the host to the lib dir. This is necessary for the jit mode to find @@ -142,23 +132,25 @@ pub(crate) fn build_sysroot( let file = file.unwrap().path(); let filename = file.file_name().unwrap().to_str().unwrap(); if filename.contains("std-") && !filename.contains(".rlib") { - try_hard_link(&file, dist_dir.join("lib").join(file.file_name().unwrap())); + try_hard_link(&file, LIB_DIR.to_path().join(file.file_name().unwrap())); } } } } } -static STANDARD_LIBRARY: CargoProject = CargoProject::local("build_sysroot", "build_sysroot"); +// FIXME move to download/ or dist/ +pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = RelPath::BUILD_SYSROOT.join("rustc_version"); +pub(crate) static SYSROOT_SRC: RelPath = RelPath::BUILD_SYSROOT.join("sysroot_src"); +static STANDARD_LIBRARY: CargoProject = CargoProject::new(&RelPath::BUILD_SYSROOT, "build_sysroot"); fn build_clif_sysroot_for_triple( channel: &str, - dist_dir: &Path, triple: &str, cg_clif_dylib_path: &Path, linker: Option<&str>, ) { - match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) { + match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path()) { Err(e) => { eprintln!("Failed to get rustc version for patched sysroot source: {}", e); eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source"); @@ -189,7 +181,7 @@ fn build_clif_sysroot_for_triple( // Build sysroot let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); - rustflags.push_str(&format!(" --sysroot={}", dist_dir.to_str().unwrap())); + rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path().to_str().unwrap())); if channel == "release" { rustflags.push_str(" -Zmir-opt-level=3"); } @@ -218,7 +210,7 @@ fn build_clif_sysroot_for_triple( }; try_hard_link( entry.path(), - dist_dir.join("lib").join("rustlib").join(triple).join("lib").join(entry.file_name()), + RUSTLIB_DIR.to_path().join(triple).join("lib").join(entry.file_name()), ); } } diff --git a/build_system/mod.rs b/build_system/mod.rs index f3ccfcb151869..cc789c8f10b65 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -8,6 +8,7 @@ mod abi_cafe; mod build_backend; mod build_sysroot; mod config; +mod path; mod prepare; mod rustc_info; mod tests; @@ -133,29 +134,14 @@ pub fn main() { let cg_clif_dylib = build_backend::build_backend(channel, &host_triple, use_unstable_features); match command { Command::Test => { - tests::run_tests( - channel, - sysroot_kind, - &dist_dir, - &cg_clif_dylib, - &host_triple, - &target_triple, - ); + tests::run_tests(channel, sysroot_kind, &cg_clif_dylib, &host_triple, &target_triple); - abi_cafe::run( - channel, - sysroot_kind, - &dist_dir, - &cg_clif_dylib, - &host_triple, - &target_triple, - ); + abi_cafe::run(channel, sysroot_kind, &cg_clif_dylib, &host_triple, &target_triple); } Command::Build => { build_sysroot::build_sysroot( channel, sysroot_kind, - &dist_dir, &cg_clif_dylib, &host_triple, &target_triple, diff --git a/build_system/path.rs b/build_system/path.rs new file mode 100644 index 0000000000000..73a17a3980fb9 --- /dev/null +++ b/build_system/path.rs @@ -0,0 +1,71 @@ +use std::fs; +use std::path::PathBuf; + +/*pub(crate) struct Paths { + source_dir: PathBuf, + download_dir: PathBuf, + build_dir: PathBuf, + dist_dir: PathBuf, +}*/ + +#[doc(hidden)] +#[derive(Debug, Copy, Clone)] +pub(crate) enum PathBase { + Source, + Download, + Build, + Dist, +} + +impl PathBase { + fn to_path(self) -> PathBuf { + // FIXME pass in all paths instead + let current_dir = std::env::current_dir().unwrap(); + match self { + PathBase::Source => current_dir, + PathBase::Download => current_dir.join("download"), + PathBase::Build => current_dir.join("build"), + PathBase::Dist => current_dir.join("dist"), + } + } +} + +#[derive(Debug, Copy, Clone)] +pub(crate) enum RelPath { + Base(PathBase), + Join(&'static RelPath, &'static str), +} + +impl RelPath { + pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source); + pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download); + pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build); + pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist); + + pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts"); + pub(crate) const BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); + pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches"); + + pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath { + RelPath::Join(self, suffix) + } + + pub(crate) fn to_path(&self) -> PathBuf { + match self { + RelPath::Base(base) => base.to_path(), + RelPath::Join(base, suffix) => base.to_path().join(suffix), + } + } + + pub(crate) fn ensure_exists(&self) { + fs::create_dir_all(self.to_path()).unwrap(); + } + + pub(crate) fn ensure_fresh(&self) { + let path = self.to_path(); + if path.exists() { + fs::remove_dir_all(&path).unwrap(); + } + fs::create_dir_all(path).unwrap(); + } +} diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 99ec3ef2092f6..09568aae9f382 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,17 +1,18 @@ -use std::env; use std::ffi::OsStr; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; +use super::build_sysroot::{SYSROOT_RUSTC_VERSION, SYSROOT_SRC}; +use super::path::RelPath; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait, Compiler}; pub(crate) fn prepare() { - if Path::new("download").exists() { - std::fs::remove_dir_all(Path::new("download")).unwrap(); + if RelPath::DOWNLOAD.to_path().exists() { + std::fs::remove_dir_all(RelPath::DOWNLOAD.to_path()).unwrap(); } - std::fs::create_dir_all(Path::new("download")).unwrap(); + std::fs::create_dir_all(RelPath::DOWNLOAD.to_path()).unwrap(); prepare_sysroot(); @@ -35,7 +36,7 @@ pub(crate) fn prepare() { .join(&host_compiler.triple) .join("debug") .join(get_file_name("main", "bin")), - Path::new("build").join(get_file_name("raytracer_cg_llvm", "bin")), + RelPath::BUILD.to_path().join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } @@ -43,28 +44,26 @@ pub(crate) fn prepare() { fn prepare_sysroot() { let rustc_path = get_rustc_path(); let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust"); - let sysroot_src = env::current_dir().unwrap().join("build_sysroot").join("sysroot_src"); + let sysroot_src = SYSROOT_SRC; assert!(sysroot_src_orig.exists()); - if sysroot_src.exists() { - fs::remove_dir_all(&sysroot_src).unwrap(); - } - fs::create_dir_all(sysroot_src.join("library")).unwrap(); + sysroot_src.ensure_fresh(); + fs::create_dir_all(sysroot_src.to_path().join("library")).unwrap(); eprintln!("[COPY] sysroot src"); - copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library")); + copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.to_path().join("library")); let rustc_version = get_rustc_version(); - fs::write(Path::new("build_sysroot").join("rustc_version"), &rustc_version).unwrap(); + fs::write(SYSROOT_RUSTC_VERSION.to_path(), &rustc_version).unwrap(); eprintln!("[GIT] init"); let mut git_init_cmd = Command::new("git"); - git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); + git_init_cmd.arg("init").arg("-q").current_dir(sysroot_src.to_path()); spawn_and_wait(git_init_cmd); - init_git_repo(&sysroot_src); + init_git_repo(&sysroot_src.to_path()); - apply_patches("sysroot", &sysroot_src); + apply_patches("sysroot", &sysroot_src.to_path()); } pub(crate) struct GitRepo { @@ -87,21 +86,19 @@ impl GitRepo { GitRepo { url: GitRepoUrl::Github { user, repo }, rev, patch_name } } - pub(crate) fn source_dir(&self) -> PathBuf { + pub(crate) const fn source_dir(&self) -> RelPath { match self.url { - GitRepoUrl::Github { user: _, repo } => { - std::env::current_dir().unwrap().join("download").join(repo) - } + GitRepoUrl::Github { user: _, repo } => RelPath::DOWNLOAD.join(repo), } } fn fetch(&self) { match self.url { GitRepoUrl::Github { user, repo } => { - clone_repo_shallow_github(&self.source_dir(), user, repo, self.rev); + clone_repo_shallow_github(&self.source_dir().to_path(), user, repo, self.rev); } } - apply_patches(self.patch_name, &self.source_dir()); + apply_patches(self.patch_name, &self.source_dir().to_path()); } } @@ -127,11 +124,9 @@ fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: & return; } - let downloads_dir = std::env::current_dir().unwrap().join("download"); - let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev); - let archive_file = downloads_dir.join(format!("{}.tar.gz", rev)); - let archive_dir = downloads_dir.join(format!("{}-{}", repo, rev)); + let archive_file = RelPath::DOWNLOAD.to_path().join(format!("{}.tar.gz", rev)); + let archive_dir = RelPath::DOWNLOAD.to_path().join(format!("{}-{}", repo, rev)); eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url); @@ -147,7 +142,7 @@ fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: & // Unpack tar archive let mut unpack_cmd = Command::new("tar"); - unpack_cmd.arg("xf").arg(&archive_file).current_dir(downloads_dir); + unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path()); spawn_and_wait(unpack_cmd); // Rename unpacked dir to the expected name @@ -173,8 +168,8 @@ fn init_git_repo(repo_dir: &Path) { spawn_and_wait(git_commit_cmd); } -fn get_patches(source_dir: &Path, crate_name: &str) -> Vec { - let mut patches: Vec<_> = fs::read_dir(source_dir.join("patches")) +fn get_patches(crate_name: &str) -> Vec { + let mut patches: Vec<_> = fs::read_dir(RelPath::PATCHES.to_path()) .unwrap() .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) @@ -198,7 +193,7 @@ fn apply_patches(crate_name: &str, target_dir: &Path) { return; } - for patch in get_patches(&std::env::current_dir().unwrap(), crate_name) { + for patch in get_patches(crate_name) { eprintln!( "[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), diff --git a/build_system/tests.rs b/build_system/tests.rs index 0645b69bf7c1a..3e495617fb27d 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,9 +1,8 @@ -use crate::build_system::rustc_info::get_cargo_path; - use super::build_sysroot; use super::config; +use super::path::RelPath; use super::prepare::GitRepo; -use super::rustc_info::get_wrapper_file_name; +use super::rustc_info::{get_cargo_path, get_wrapper_file_name}; use super::utils::{ hyperfine_command, spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, }; @@ -11,9 +10,11 @@ use super::SysrootKind; use std::env; use std::ffi::OsStr; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process::Command; +static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example"); + struct TestCase { config: &'static str, func: &'static dyn Fn(&TestRunner), @@ -223,12 +224,12 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) static RAND_REPO: GitRepo = GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand"); -static RAND: CargoProject = CargoProject::git(&RAND_REPO, ".", "rand"); +static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand"); pub(crate) static REGEX_REPO: GitRepo = GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex"); -static REGEX: CargoProject = CargoProject::git(®EX_REPO, ".", "regex"); +static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex"); pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "rust-lang", @@ -237,7 +238,8 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github( "portable-simd", ); -static PORTABLE_SIMD: CargoProject = CargoProject::git(&PORTABLE_SIMD_REPO, ".", "portable_simd"); +static PORTABLE_SIMD: CargoProject = + CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd"); pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", @@ -247,10 +249,10 @@ pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( ); pub(crate) static SIMPLE_RAYTRACER: CargoProject = - CargoProject::git(&SIMPLE_RAYTRACER_REPO, ".", "simple_raytracer"); + CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer"); static LIBCORE_TESTS: CargoProject = - CargoProject::local("build_sysroot/sysroot_src/library/core/tests", "core_tests"); + CargoProject::new(&RelPath::BUILD_SYSROOT.join("sysroot_src/library/core/tests"), "core_tests"); const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("test.rust-random/rand", &|runner| { @@ -273,10 +275,8 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ if runner.is_native { eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); - let cargo_clif = env::current_dir() - .unwrap() - .join("dist") - .join(get_wrapper_file_name("cargo-clif", "bin")); + let cargo_clif = + RelPath::DIST.to_path().join(get_wrapper_file_name("cargo-clif", "bin")); let manifest_path = SIMPLE_RAYTRACER.manifest_path(); let target_dir = SIMPLE_RAYTRACER.target_dir(); @@ -305,13 +305,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ eprintln!("[BENCH RUN] ebobby/simple-raytracer"); fs::copy( target_dir.join("debug").join("main"), - Path::new("build").join("raytracer_cg_clif"), + RelPath::BUILD.to_path().join("raytracer_cg_clif"), ) .unwrap(); let mut bench_run = hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif"); - bench_run.current_dir(Path::new("build")); + bench_run.current_dir(RelPath::BUILD.to_path()); spawn_and_wait(bench_run); } else { spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo)); @@ -430,7 +430,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) fn run_tests( channel: &str, sysroot_kind: SysrootKind, - dist_dir: &Path, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, @@ -441,13 +440,12 @@ pub(crate) fn run_tests( build_sysroot::build_sysroot( channel, SysrootKind::None, - &dist_dir, cg_clif_dylib, &host_triple, &target_triple, ); - let _ = fs::remove_dir_all(Path::new("build").join("example")); + BUILD_EXAMPLE_OUT_DIR.ensure_fresh(); runner.run_testsuite(NO_SYSROOT_SUITE); } else { eprintln!("[SKIP] no_sysroot tests"); @@ -460,7 +458,6 @@ pub(crate) fn run_tests( build_sysroot::build_sysroot( channel, sysroot_kind, - &dist_dir, cg_clif_dylib, &host_triple, &target_triple, @@ -481,7 +478,6 @@ pub(crate) fn run_tests( } struct TestRunner { - out_dir: PathBuf, is_native: bool, jit_supported: bool, host_compiler: Compiler, @@ -490,23 +486,13 @@ struct TestRunner { impl TestRunner { pub fn new(host_triple: String, target_triple: String) -> Self { - let root_dir = env::current_dir().unwrap(); - - let mut out_dir = root_dir.clone(); - out_dir.push("build"); - out_dir.push("example"); - let is_native = host_triple == target_triple; let jit_supported = target_triple.contains("x86_64") && is_native && !host_triple.contains("windows"); - let mut rustc_clif = root_dir.clone(); - rustc_clif.push("dist"); - rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); - - let mut rustdoc_clif = root_dir.clone(); - rustdoc_clif.push("dist"); - rustdoc_clif.push(get_wrapper_file_name("rustdoc-clif", "bin")); + let rustc_clif = RelPath::DIST.to_path().join(get_wrapper_file_name("rustc-clif", "bin")); + let rustdoc_clif = + RelPath::DIST.to_path().join(get_wrapper_file_name("rustdoc-clif", "bin")); let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); let mut runner = vec![]; @@ -549,15 +535,15 @@ impl TestRunner { let target_compiler = Compiler { cargo: get_cargo_path(), - rustc: rustc_clif.clone(), - rustdoc: rustdoc_clif.clone(), + rustc: rustc_clif, + rustdoc: rustdoc_clif, rustflags: rustflags.clone(), rustdocflags: rustflags, triple: target_triple, runner, }; - Self { out_dir, is_native, jit_supported, host_compiler, target_compiler } + Self { is_native, jit_supported, host_compiler, target_compiler } } pub fn run_testsuite(&self, tests: &[TestCase]) { @@ -586,9 +572,9 @@ impl TestRunner { let mut cmd = Command::new(&self.target_compiler.rustc); cmd.args(self.target_compiler.rustflags.split_whitespace()); cmd.arg("-L"); - cmd.arg(format!("crate={}", self.out_dir.display())); + cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path().display())); cmd.arg("--out-dir"); - cmd.arg(format!("{}", self.out_dir.display())); + cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path().display())); cmd.arg("-Cdebuginfo=2"); cmd.args(args); cmd @@ -613,11 +599,7 @@ impl TestRunner { full_cmd.extend(self.target_compiler.runner.iter().cloned()); } - full_cmd.push({ - let mut out_path = self.out_dir.clone(); - out_path.push(name); - out_path.to_str().unwrap().to_string() - }); + full_cmd.push(BUILD_EXAMPLE_OUT_DIR.to_path().join(name).to_str().unwrap().to_string()); for arg in args.into_iter() { full_cmd.push(arg.to_string()); diff --git a/build_system/utils.rs b/build_system/utils.rs index 5a03fcf085625..422492df0071f 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -4,7 +4,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; -use super::prepare::GitRepo; +use super::path::RelPath; use super::rustc_info::{get_cargo_path, get_host_triple, get_rustc_path, get_rustdoc_path}; pub(crate) struct Compiler { @@ -43,36 +43,18 @@ impl Compiler { } } -enum CargoProjectSource { - Local, - GitRepo(&'static GitRepo), -} - pub(crate) struct CargoProject { - source: CargoProjectSource, - path: &'static str, + source: &'static RelPath, target: &'static str, } impl CargoProject { - pub(crate) const fn local(path: &'static str, target: &'static str) -> CargoProject { - CargoProject { source: CargoProjectSource::Local, path, target } - } - - pub(crate) const fn git( - git_repo: &'static GitRepo, - path: &'static str, - target: &'static str, - ) -> CargoProject { - CargoProject { source: CargoProjectSource::GitRepo(git_repo), path, target } + pub(crate) const fn new(path: &'static RelPath, target: &'static str) -> CargoProject { + CargoProject { source: path, target } } pub(crate) fn source_dir(&self) -> PathBuf { - match self.source { - CargoProjectSource::Local => std::env::current_dir().unwrap(), - CargoProjectSource::GitRepo(git_repo) => git_repo.source_dir(), - } - .join(self.path) + self.source.to_path() } pub(crate) fn manifest_path(&self) -> PathBuf { @@ -80,7 +62,7 @@ impl CargoProject { } pub(crate) fn target_dir(&self) -> PathBuf { - std::env::current_dir().unwrap().join("build").join(self.target) + RelPath::BUILD.join(self.target).to_path() } fn base_cmd(&self, command: &str, cargo: &Path) -> Command { From 82b2d8e41893629ff65505fc0d4767f1db73b180 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 14:54:37 +0000 Subject: [PATCH 59/77] Introduce Dirs type to avoid hard coding src and dest locations --- build_system/abi_cafe.rs | 15 ++++-- build_system/build_backend.rs | 7 +-- build_system/build_sysroot.rs | 42 ++++++++++------- build_system/mod.rs | 57 ++++++++++++++--------- build_system/path.rs | 39 ++++++++-------- build_system/prepare.rs | 75 ++++++++++++++++-------------- build_system/tests.rs | 86 +++++++++++++++++++---------------- build_system/utils.rs | 44 +++++++++--------- 8 files changed, 207 insertions(+), 158 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index acb2bd5aeae7b..a081fdaa1c7e6 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -2,6 +2,7 @@ use std::path::Path; use super::build_sysroot; use super::config; +use super::path::Dirs; use super::prepare::GitRepo; use super::utils::{spawn_and_wait, CargoProject, Compiler}; use super::SysrootKind; @@ -14,6 +15,7 @@ static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), " pub(crate) fn run( channel: &str, sysroot_kind: SysrootKind, + dirs: &Dirs, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, @@ -29,19 +31,26 @@ pub(crate) fn run( } eprintln!("Building sysroot for abi-cafe"); - build_sysroot::build_sysroot(channel, sysroot_kind, cg_clif_dylib, host_triple, target_triple); + build_sysroot::build_sysroot( + dirs, + channel, + sysroot_kind, + cg_clif_dylib, + host_triple, + target_triple, + ); eprintln!("Running abi-cafe"); let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; - let mut cmd = ABI_CAFE.run(&Compiler::host()); + let mut cmd = ABI_CAFE.run(&Compiler::host(), dirs); cmd.arg("--"); cmd.arg("--pairs"); cmd.args(pairs); cmd.arg("--add-rustc-codegen-backend"); cmd.arg(format!("cgclif:{}", cg_clif_dylib.display())); - cmd.current_dir(ABI_CAFE.source_dir()); + cmd.current_dir(ABI_CAFE.source_dir(dirs)); spawn_and_wait(cmd); } diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 5cbeb7d0f9f68..fde8ef424ccc5 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,18 +1,19 @@ use std::env; use std::path::PathBuf; -use super::path::RelPath; +use super::path::{Dirs, RelPath}; use super::rustc_info::get_file_name; use super::utils::{is_ci, CargoProject, Compiler}; static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); pub(crate) fn build_backend( + dirs: &Dirs, channel: &str, host_triple: &str, use_unstable_features: bool, ) -> PathBuf { - let mut cmd = CG_CLIF.build(&Compiler::host()); + let mut cmd = CG_CLIF.build(&Compiler::host(), dirs); cmd.env("CARGO_BUILD_INCREMENTAL", "true"); // Force incr comp even in release mode @@ -44,7 +45,7 @@ pub(crate) fn build_backend( super::utils::spawn_and_wait(cmd); CG_CLIF - .target_dir() + .target_dir(dirs) .join(host_triple) .join(channel) .join(get_file_name("rustc_codegen_cranelift", "dylib")) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index fcd668b8aa58c..35c972e6b383a 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::Path; use std::process::{self, Command}; -use super::path::RelPath; +use super::path::{Dirs, RelPath}; use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::SysrootKind; @@ -13,6 +13,7 @@ static LIB_DIR: RelPath = RelPath::DIST.join("lib"); static RUSTLIB_DIR: RelPath = LIB_DIR.join("rustlib"); pub(crate) fn build_sysroot( + dirs: &Dirs, channel: &str, sysroot_kind: SysrootKind, cg_clif_dylib_src: &Path, @@ -21,9 +22,9 @@ pub(crate) fn build_sysroot( ) { eprintln!("[BUILD] sysroot {:?}", sysroot_kind); - DIST_DIR.ensure_fresh(); - BIN_DIR.ensure_exists(); - LIB_DIR.ensure_exists(); + DIST_DIR.ensure_fresh(dirs); + BIN_DIR.ensure_exists(dirs); + LIB_DIR.ensure_exists(dirs); // Copy the backend let cg_clif_dylib_path = if cfg!(windows) { @@ -33,7 +34,7 @@ pub(crate) fn build_sysroot( } else { LIB_DIR } - .to_path() + .to_path(dirs) .join(get_file_name("rustc_codegen_cranelift", "dylib")); try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); @@ -43,17 +44,17 @@ pub(crate) fn build_sysroot( let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd - .arg(RelPath::SCRIPTS.to_path().join(&format!("{wrapper}.rs"))) + .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg("-o") - .arg(DIST_DIR.to_path().join(wrapper_name)) + .arg(DIST_DIR.to_path(dirs).join(wrapper_name)) .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); } let default_sysroot = super::rustc_info::get_default_sysroot(); - let host_rustlib_lib = RUSTLIB_DIR.to_path().join(host_triple).join("lib"); - let target_rustlib_lib = RUSTLIB_DIR.to_path().join(target_triple).join("lib"); + let host_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(host_triple).join("lib"); + let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib"); fs::create_dir_all(&host_rustlib_lib).unwrap(); fs::create_dir_all(&target_rustlib_lib).unwrap(); @@ -114,7 +115,7 @@ pub(crate) fn build_sysroot( } } SysrootKind::Clif => { - build_clif_sysroot_for_triple(channel, host_triple, &cg_clif_dylib_path, None); + build_clif_sysroot_for_triple(dirs, channel, host_triple, &cg_clif_dylib_path, None); if host_triple != target_triple { // When cross-compiling it is often necessary to manually pick the right linker @@ -123,7 +124,13 @@ pub(crate) fn build_sysroot( } else { None }; - build_clif_sysroot_for_triple(channel, target_triple, &cg_clif_dylib_path, linker); + build_clif_sysroot_for_triple( + dirs, + channel, + target_triple, + &cg_clif_dylib_path, + linker, + ); } // Copy std for the host to the lib dir. This is necessary for the jit mode to find @@ -132,7 +139,7 @@ pub(crate) fn build_sysroot( let file = file.unwrap().path(); let filename = file.file_name().unwrap().to_str().unwrap(); if filename.contains("std-") && !filename.contains(".rlib") { - try_hard_link(&file, LIB_DIR.to_path().join(file.file_name().unwrap())); + try_hard_link(&file, LIB_DIR.to_path(dirs).join(file.file_name().unwrap())); } } } @@ -145,12 +152,13 @@ pub(crate) static SYSROOT_SRC: RelPath = RelPath::BUILD_SYSROOT.join("sysroot_sr static STANDARD_LIBRARY: CargoProject = CargoProject::new(&RelPath::BUILD_SYSROOT, "build_sysroot"); fn build_clif_sysroot_for_triple( + dirs: &Dirs, channel: &str, triple: &str, cg_clif_dylib_path: &Path, linker: Option<&str>, ) { - match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path()) { + match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) { Err(e) => { eprintln!("Failed to get rustc version for patched sysroot source: {}", e); eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source"); @@ -168,7 +176,7 @@ fn build_clif_sysroot_for_triple( } } - let build_dir = STANDARD_LIBRARY.target_dir().join(triple).join(channel); + let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(triple).join(channel); if !super::config::get_bool("keep_sysroot") { // Cleanup the deps dir, but keep build scripts and the incremental cache for faster @@ -181,7 +189,7 @@ fn build_clif_sysroot_for_triple( // Build sysroot let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); - rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path().to_str().unwrap())); + rustflags.push_str(&format!(" --sysroot={}", DIST_DIR.to_path(dirs).to_str().unwrap())); if channel == "release" { rustflags.push_str(" -Zmir-opt-level=3"); } @@ -191,7 +199,7 @@ fn build_clif_sysroot_for_triple( } let mut compiler = Compiler::with_triple(triple.to_owned()); compiler.rustflags = rustflags; - let mut build_cmd = STANDARD_LIBRARY.build(&compiler); + let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); if channel == "release" { build_cmd.arg("--release"); } @@ -210,7 +218,7 @@ fn build_clif_sysroot_for_triple( }; try_hard_link( entry.path(), - RUSTLIB_DIR.to_path().join(triple).join("lib").join(entry.file_name()), + RUSTLIB_DIR.to_path(dirs).join(triple).join("lib").join(entry.file_name()), ); } } diff --git a/build_system/mod.rs b/build_system/mod.rs index cc789c8f10b65..b36df96c0b24a 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,5 +1,4 @@ use std::env; -use std::path::PathBuf; use std::process; use self::utils::is_ci; @@ -17,12 +16,8 @@ mod utils; fn usage() { eprintln!("Usage:"); eprintln!(" ./y.rs prepare"); - eprintln!( - " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]" - ); - eprintln!( - " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--dist-dir DIR] [--no-unstable-features]" - ); + eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]"); + eprintln!(" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]"); } macro_rules! arg_error { @@ -50,13 +45,22 @@ pub fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); - std::fs::create_dir_all("build").unwrap(); + let current_dir = std::env::current_dir().unwrap(); + let dirs = path::Dirs { + source_dir: current_dir.clone(), + download_dir: current_dir.join("download"), + build_dir: current_dir.join("build"), + dist_dir: current_dir.join("dist"), + }; + + path::RelPath::BUILD.ensure_exists(&dirs); { // Make sure we always explicitly specify the target dir - let target = "build/target_dir_should_be_set_explicitly"; - env::set_var("CARGO_TARGET_DIR", target); - let _ = std::fs::remove_file(target); + let target = + path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs); + env::set_var("CARGO_TARGET_DIR", &target); + let _ = std::fs::remove_file(&target); std::fs::File::create(target).unwrap(); } @@ -71,7 +75,7 @@ pub fn main() { if args.next().is_some() { arg_error!("./y.rs prepare doesn't expect arguments"); } - prepare::prepare(); + prepare::prepare(&dirs); process::exit(0); } Some("build") => Command::Build, @@ -84,17 +88,11 @@ pub fn main() { } }; - let mut dist_dir = PathBuf::from("dist"); let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; while let Some(arg) = args.next().as_deref() { match arg { - "--dist-dir" => { - dist_dir = PathBuf::from(args.next().unwrap_or_else(|| { - arg_error!("--dist-dir requires argument"); - })) - } "--debug" => channel = "debug", "--sysroot" => { sysroot_kind = match args.next().as_deref() { @@ -110,7 +108,6 @@ pub fn main() { arg => arg_error!("Unexpected argument {}", arg), } } - dist_dir = std::env::current_dir().unwrap().join(dist_dir); let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { host_triple @@ -131,15 +128,31 @@ pub fn main() { host_triple.clone() }; - let cg_clif_dylib = build_backend::build_backend(channel, &host_triple, use_unstable_features); + let cg_clif_dylib = + build_backend::build_backend(&dirs, channel, &host_triple, use_unstable_features); match command { Command::Test => { - tests::run_tests(channel, sysroot_kind, &cg_clif_dylib, &host_triple, &target_triple); + tests::run_tests( + &dirs, + channel, + sysroot_kind, + &cg_clif_dylib, + &host_triple, + &target_triple, + ); - abi_cafe::run(channel, sysroot_kind, &cg_clif_dylib, &host_triple, &target_triple); + abi_cafe::run( + channel, + sysroot_kind, + &dirs, + &cg_clif_dylib, + &host_triple, + &target_triple, + ); } Command::Build => { build_sysroot::build_sysroot( + &dirs, channel, sysroot_kind, &cg_clif_dylib, diff --git a/build_system/path.rs b/build_system/path.rs index 73a17a3980fb9..e93981f1d64d3 100644 --- a/build_system/path.rs +++ b/build_system/path.rs @@ -1,12 +1,13 @@ use std::fs; use std::path::PathBuf; -/*pub(crate) struct Paths { - source_dir: PathBuf, - download_dir: PathBuf, - build_dir: PathBuf, - dist_dir: PathBuf, -}*/ +#[derive(Debug, Clone)] +pub(crate) struct Dirs { + pub(crate) source_dir: PathBuf, + pub(crate) download_dir: PathBuf, + pub(crate) build_dir: PathBuf, + pub(crate) dist_dir: PathBuf, +} #[doc(hidden)] #[derive(Debug, Copy, Clone)] @@ -18,14 +19,12 @@ pub(crate) enum PathBase { } impl PathBase { - fn to_path(self) -> PathBuf { - // FIXME pass in all paths instead - let current_dir = std::env::current_dir().unwrap(); + fn to_path(self, dirs: &Dirs) -> PathBuf { match self { - PathBase::Source => current_dir, - PathBase::Download => current_dir.join("download"), - PathBase::Build => current_dir.join("build"), - PathBase::Dist => current_dir.join("dist"), + PathBase::Source => dirs.source_dir.clone(), + PathBase::Download => dirs.download_dir.clone(), + PathBase::Build => dirs.build_dir.clone(), + PathBase::Dist => dirs.dist_dir.clone(), } } } @@ -50,19 +49,19 @@ impl RelPath { RelPath::Join(self, suffix) } - pub(crate) fn to_path(&self) -> PathBuf { + pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf { match self { - RelPath::Base(base) => base.to_path(), - RelPath::Join(base, suffix) => base.to_path().join(suffix), + RelPath::Base(base) => base.to_path(dirs), + RelPath::Join(base, suffix) => base.to_path(dirs).join(suffix), } } - pub(crate) fn ensure_exists(&self) { - fs::create_dir_all(self.to_path()).unwrap(); + pub(crate) fn ensure_exists(&self, dirs: &Dirs) { + fs::create_dir_all(self.to_path(dirs)).unwrap(); } - pub(crate) fn ensure_fresh(&self) { - let path = self.to_path(); + pub(crate) fn ensure_fresh(&self, dirs: &Dirs) { + let path = self.to_path(dirs); if path.exists() { fs::remove_dir_all(&path).unwrap(); } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 09568aae9f382..0eaa8e820baea 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -4,66 +4,69 @@ use std::path::{Path, PathBuf}; use std::process::Command; use super::build_sysroot::{SYSROOT_RUSTC_VERSION, SYSROOT_SRC}; -use super::path::RelPath; +use super::path::{Dirs, RelPath}; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait, Compiler}; -pub(crate) fn prepare() { - if RelPath::DOWNLOAD.to_path().exists() { - std::fs::remove_dir_all(RelPath::DOWNLOAD.to_path()).unwrap(); +pub(crate) fn prepare(dirs: &Dirs) { + if RelPath::DOWNLOAD.to_path(dirs).exists() { + std::fs::remove_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap(); } - std::fs::create_dir_all(RelPath::DOWNLOAD.to_path()).unwrap(); + std::fs::create_dir_all(RelPath::DOWNLOAD.to_path(dirs)).unwrap(); - prepare_sysroot(); + prepare_sysroot(dirs); // FIXME maybe install this only locally? eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); - super::abi_cafe::ABI_CAFE_REPO.fetch(); - super::tests::RAND_REPO.fetch(); - super::tests::REGEX_REPO.fetch(); - super::tests::PORTABLE_SIMD_REPO.fetch(); - super::tests::SIMPLE_RAYTRACER_REPO.fetch(); + super::abi_cafe::ABI_CAFE_REPO.fetch(dirs); + super::tests::RAND_REPO.fetch(dirs); + super::tests::REGEX_REPO.fetch(dirs); + super::tests::PORTABLE_SIMD_REPO.fetch(dirs); + super::tests::SIMPLE_RAYTRACER_REPO.fetch(dirs); eprintln!("[LLVM BUILD] simple-raytracer"); let host_compiler = Compiler::host(); - let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler); + let build_cmd = super::tests::SIMPLE_RAYTRACER.build(&host_compiler, dirs); spawn_and_wait(build_cmd); fs::copy( super::tests::SIMPLE_RAYTRACER - .target_dir() + .target_dir(dirs) .join(&host_compiler.triple) .join("debug") .join(get_file_name("main", "bin")), - RelPath::BUILD.to_path().join(get_file_name("raytracer_cg_llvm", "bin")), + RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } -fn prepare_sysroot() { +fn prepare_sysroot(dirs: &Dirs) { let rustc_path = get_rustc_path(); let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust"); let sysroot_src = SYSROOT_SRC; assert!(sysroot_src_orig.exists()); - sysroot_src.ensure_fresh(); - fs::create_dir_all(sysroot_src.to_path().join("library")).unwrap(); + sysroot_src.ensure_fresh(dirs); + fs::create_dir_all(sysroot_src.to_path(dirs).join("library")).unwrap(); eprintln!("[COPY] sysroot src"); - copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.to_path().join("library")); + copy_dir_recursively( + &sysroot_src_orig.join("library"), + &sysroot_src.to_path(dirs).join("library"), + ); let rustc_version = get_rustc_version(); - fs::write(SYSROOT_RUSTC_VERSION.to_path(), &rustc_version).unwrap(); + fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); eprintln!("[GIT] init"); let mut git_init_cmd = Command::new("git"); - git_init_cmd.arg("init").arg("-q").current_dir(sysroot_src.to_path()); + git_init_cmd.arg("init").arg("-q").current_dir(sysroot_src.to_path(dirs)); spawn_and_wait(git_init_cmd); - init_git_repo(&sysroot_src.to_path()); + init_git_repo(&sysroot_src.to_path(dirs)); - apply_patches("sysroot", &sysroot_src.to_path()); + apply_patches(dirs, "sysroot", &sysroot_src.to_path(dirs)); } pub(crate) struct GitRepo { @@ -92,13 +95,19 @@ impl GitRepo { } } - fn fetch(&self) { + fn fetch(&self, dirs: &Dirs) { match self.url { GitRepoUrl::Github { user, repo } => { - clone_repo_shallow_github(&self.source_dir().to_path(), user, repo, self.rev); + clone_repo_shallow_github( + dirs, + &self.source_dir().to_path(dirs), + user, + repo, + self.rev, + ); } } - apply_patches(self.patch_name, &self.source_dir().to_path()); + apply_patches(dirs, self.patch_name, &self.source_dir().to_path(dirs)); } } @@ -117,7 +126,7 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { spawn_and_wait(checkout_cmd); } -fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: &str) { +fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: &str, rev: &str) { if cfg!(windows) { // Older windows doesn't have tar or curl by default. Fall back to using git. clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev); @@ -125,8 +134,8 @@ fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: & } let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev); - let archive_file = RelPath::DOWNLOAD.to_path().join(format!("{}.tar.gz", rev)); - let archive_dir = RelPath::DOWNLOAD.to_path().join(format!("{}-{}", repo, rev)); + let archive_file = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}.tar.gz", rev)); + let archive_dir = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}-{}", repo, rev)); eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url); @@ -142,7 +151,7 @@ fn clone_repo_shallow_github(download_dir: &Path, user: &str, repo: &str, rev: & // Unpack tar archive let mut unpack_cmd = Command::new("tar"); - unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path()); + unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path(dirs)); spawn_and_wait(unpack_cmd); // Rename unpacked dir to the expected name @@ -168,8 +177,8 @@ fn init_git_repo(repo_dir: &Path) { spawn_and_wait(git_commit_cmd); } -fn get_patches(crate_name: &str) -> Vec { - let mut patches: Vec<_> = fs::read_dir(RelPath::PATCHES.to_path()) +fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec { + let mut patches: Vec<_> = fs::read_dir(RelPath::PATCHES.to_path(dirs)) .unwrap() .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) @@ -188,12 +197,12 @@ fn get_patches(crate_name: &str) -> Vec { patches } -fn apply_patches(crate_name: &str, target_dir: &Path) { +fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) { if crate_name == "" { return; } - for patch in get_patches(crate_name) { + for patch in get_patches(dirs, crate_name) { eprintln!( "[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), diff --git a/build_system/tests.rs b/build_system/tests.rs index 3e495617fb27d..bd31d5e6bbf28 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -1,6 +1,6 @@ use super::build_sysroot; use super::config; -use super::path::RelPath; +use super::path::{Dirs, RelPath}; use super::prepare::GitRepo; use super::rustc_info::{get_cargo_path, get_wrapper_file_name}; use super::utils::{ @@ -256,16 +256,16 @@ static LIBCORE_TESTS: CargoProject = const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ TestCase::new("test.rust-random/rand", &|runner| { - spawn_and_wait(RAND.clean(&runner.target_compiler.cargo)); + spawn_and_wait(RAND.clean(&runner.target_compiler.cargo, &runner.dirs)); if runner.is_native { eprintln!("[TEST] rust-random/rand"); - let mut test_cmd = RAND.test(&runner.target_compiler); + let mut test_cmd = RAND.test(&runner.target_compiler, &runner.dirs); test_cmd.arg("--workspace"); spawn_and_wait(test_cmd); } else { eprintln!("[AOT] rust-random/rand"); - let mut build_cmd = RAND.build(&runner.target_compiler); + let mut build_cmd = RAND.build(&runner.target_compiler, &runner.dirs); build_cmd.arg("--workspace").arg("--tests"); spawn_and_wait(build_cmd); } @@ -275,10 +275,11 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ if runner.is_native { eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); - let cargo_clif = - RelPath::DIST.to_path().join(get_wrapper_file_name("cargo-clif", "bin")); - let manifest_path = SIMPLE_RAYTRACER.manifest_path(); - let target_dir = SIMPLE_RAYTRACER.target_dir(); + let cargo_clif = RelPath::DIST + .to_path(&runner.dirs) + .join(get_wrapper_file_name("cargo-clif", "bin")); + let manifest_path = SIMPLE_RAYTRACER.manifest_path(&runner.dirs); + let target_dir = SIMPLE_RAYTRACER.target_dir(&runner.dirs); let clean_cmd = format!( "cargo clean --manifest-path {manifest_path} --target-dir {target_dir}", @@ -305,54 +306,56 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ eprintln!("[BENCH RUN] ebobby/simple-raytracer"); fs::copy( target_dir.join("debug").join("main"), - RelPath::BUILD.to_path().join("raytracer_cg_clif"), + RelPath::BUILD.to_path(&runner.dirs).join("raytracer_cg_clif"), ) .unwrap(); let mut bench_run = hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif"); - bench_run.current_dir(RelPath::BUILD.to_path()); + bench_run.current_dir(RelPath::BUILD.to_path(&runner.dirs)); spawn_and_wait(bench_run); } else { - spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo)); + spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo, &runner.dirs)); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)"); eprintln!("[COMPILE] ebobby/simple-raytracer"); - spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler)); + spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler, &runner.dirs)); eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)"); } }), TestCase::new("test.libcore", &|runner| { - spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo)); + spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo, &runner.dirs)); if runner.is_native { - spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler)); + spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler, &runner.dirs)); } else { eprintln!("Cross-Compiling: Not running tests"); - let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler); + let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler, &runner.dirs); build_cmd.arg("--tests"); spawn_and_wait(build_cmd); } }), TestCase::new("test.regex-shootout-regex-dna", &|runner| { - spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo)); + spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo, &runner.dirs)); // newer aho_corasick versions throw a deprecation warning let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags); - let mut build_cmd = REGEX.build(&runner.target_compiler); + let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs); build_cmd.arg("--example").arg("shootout-regex-dna"); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); if runner.is_native { - let mut run_cmd = REGEX.run(&runner.target_compiler); + let mut run_cmd = REGEX.run(&runner.target_compiler, &runner.dirs); run_cmd.arg("--example").arg("shootout-regex-dna"); run_cmd.env("RUSTFLAGS", lint_rust_flags); - let input = - fs::read_to_string(REGEX.source_dir().join("examples").join("regexdna-input.txt")) - .unwrap(); - let expected_path = REGEX.source_dir().join("examples").join("regexdna-output.txt"); + let input = fs::read_to_string( + REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-input.txt"), + ) + .unwrap(); + let expected_path = + REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-output.txt"); let expected = fs::read_to_string(&expected_path).unwrap(); let output = spawn_and_wait_with_input(run_cmd, input); @@ -366,7 +369,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ let output_matches = expected.lines().eq(output.lines()); if !output_matches { - let res_path = REGEX.source_dir().join("res.txt"); + let res_path = REGEX.source_dir(&runner.dirs).join("res.txt"); fs::write(&res_path, &output).unwrap(); if cfg!(windows) { @@ -386,13 +389,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ } }), TestCase::new("test.regex", &|runner| { - spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo)); + spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo, &runner.dirs)); // newer aho_corasick versions throw a deprecation warning let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags); if runner.is_native { - let mut run_cmd = REGEX.test(&runner.target_compiler); + let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs); run_cmd.args([ "--tests", "--", @@ -406,21 +409,21 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ spawn_and_wait(run_cmd); } else { eprintln!("Cross-Compiling: Not running tests"); - let mut build_cmd = REGEX.build(&runner.target_compiler); + let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs); build_cmd.arg("--tests"); build_cmd.env("RUSTFLAGS", lint_rust_flags.clone()); spawn_and_wait(build_cmd); } }), TestCase::new("test.portable-simd", &|runner| { - spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo)); + spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo, &runner.dirs)); - let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler); + let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs); build_cmd.arg("--all-targets"); spawn_and_wait(build_cmd); if runner.is_native { - let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler); + let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs); test_cmd.arg("-q"); spawn_and_wait(test_cmd); } @@ -428,16 +431,18 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ ]; pub(crate) fn run_tests( + dirs: &Dirs, channel: &str, sysroot_kind: SysrootKind, cg_clif_dylib: &Path, host_triple: &str, target_triple: &str, ) { - let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string()); + let runner = TestRunner::new(dirs.clone(), host_triple.to_string(), target_triple.to_string()); if config::get_bool("testsuite.no_sysroot") { build_sysroot::build_sysroot( + dirs, channel, SysrootKind::None, cg_clif_dylib, @@ -445,7 +450,7 @@ pub(crate) fn run_tests( &target_triple, ); - BUILD_EXAMPLE_OUT_DIR.ensure_fresh(); + BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs); runner.run_testsuite(NO_SYSROOT_SUITE); } else { eprintln!("[SKIP] no_sysroot tests"); @@ -456,6 +461,7 @@ pub(crate) fn run_tests( if run_base_sysroot || run_extended_sysroot { build_sysroot::build_sysroot( + dirs, channel, sysroot_kind, cg_clif_dylib, @@ -480,19 +486,21 @@ pub(crate) fn run_tests( struct TestRunner { is_native: bool, jit_supported: bool, + dirs: Dirs, host_compiler: Compiler, target_compiler: Compiler, } impl TestRunner { - pub fn new(host_triple: String, target_triple: String) -> Self { + pub fn new(dirs: Dirs, host_triple: String, target_triple: String) -> Self { let is_native = host_triple == target_triple; let jit_supported = target_triple.contains("x86_64") && is_native && !host_triple.contains("windows"); - let rustc_clif = RelPath::DIST.to_path().join(get_wrapper_file_name("rustc-clif", "bin")); + let rustc_clif = + RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin")); let rustdoc_clif = - RelPath::DIST.to_path().join(get_wrapper_file_name("rustdoc-clif", "bin")); + RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin")); let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string()); let mut runner = vec![]; @@ -543,7 +551,7 @@ impl TestRunner { runner, }; - Self { is_native, jit_supported, host_compiler, target_compiler } + Self { is_native, jit_supported, dirs, host_compiler, target_compiler } } pub fn run_testsuite(&self, tests: &[TestCase]) { @@ -572,9 +580,9 @@ impl TestRunner { let mut cmd = Command::new(&self.target_compiler.rustc); cmd.args(self.target_compiler.rustflags.split_whitespace()); cmd.arg("-L"); - cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path().display())); + cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display())); cmd.arg("--out-dir"); - cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path().display())); + cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display())); cmd.arg("-Cdebuginfo=2"); cmd.args(args); cmd @@ -599,7 +607,9 @@ impl TestRunner { full_cmd.extend(self.target_compiler.runner.iter().cloned()); } - full_cmd.push(BUILD_EXAMPLE_OUT_DIR.to_path().join(name).to_str().unwrap().to_string()); + full_cmd.push( + BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(), + ); for arg in args.into_iter() { full_cmd.push(arg.to_string()); diff --git a/build_system/utils.rs b/build_system/utils.rs index 422492df0071f..dab6308bc1d54 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -4,7 +4,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; -use super::path::RelPath; +use super::path::{Dirs, RelPath}; use super::rustc_info::{get_cargo_path, get_host_triple, get_rustc_path, get_rustdoc_path}; pub(crate) struct Compiler { @@ -53,32 +53,32 @@ impl CargoProject { CargoProject { source: path, target } } - pub(crate) fn source_dir(&self) -> PathBuf { - self.source.to_path() + pub(crate) fn source_dir(&self, dirs: &Dirs) -> PathBuf { + self.source.to_path(dirs) } - pub(crate) fn manifest_path(&self) -> PathBuf { - self.source_dir().join("Cargo.toml") + pub(crate) fn manifest_path(&self, dirs: &Dirs) -> PathBuf { + self.source_dir(dirs).join("Cargo.toml") } - pub(crate) fn target_dir(&self) -> PathBuf { - RelPath::BUILD.join(self.target).to_path() + pub(crate) fn target_dir(&self, dirs: &Dirs) -> PathBuf { + RelPath::BUILD.join(self.target).to_path(dirs) } - fn base_cmd(&self, command: &str, cargo: &Path) -> Command { + fn base_cmd(&self, command: &str, cargo: &Path, dirs: &Dirs) -> Command { let mut cmd = Command::new(cargo); cmd.arg(command) .arg("--manifest-path") - .arg(self.manifest_path()) + .arg(self.manifest_path(dirs)) .arg("--target-dir") - .arg(self.target_dir()); + .arg(self.target_dir(dirs)); cmd } - fn build_cmd(&self, command: &str, compiler: &Compiler) -> Command { - let mut cmd = self.base_cmd(command, &compiler.cargo); + fn build_cmd(&self, command: &str, compiler: &Compiler, dirs: &Dirs) -> Command { + let mut cmd = self.base_cmd(command, &compiler.cargo, dirs); cmd.arg("--target").arg(&compiler.triple); @@ -97,32 +97,32 @@ impl CargoProject { } #[must_use] - pub(crate) fn fetch(&self, cargo: impl AsRef) -> Command { + pub(crate) fn fetch(&self, cargo: impl AsRef, dirs: &Dirs) -> Command { let mut cmd = Command::new(cargo.as_ref()); - cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path()); + cmd.arg("fetch").arg("--manifest-path").arg(self.manifest_path(dirs)); cmd } #[must_use] - pub(crate) fn clean(&self, cargo: &Path) -> Command { - self.base_cmd("clean", cargo) + pub(crate) fn clean(&self, cargo: &Path, dirs: &Dirs) -> Command { + self.base_cmd("clean", cargo, dirs) } #[must_use] - pub(crate) fn build(&self, compiler: &Compiler) -> Command { - self.build_cmd("build", compiler) + pub(crate) fn build(&self, compiler: &Compiler, dirs: &Dirs) -> Command { + self.build_cmd("build", compiler, dirs) } #[must_use] - pub(crate) fn test(&self, compiler: &Compiler) -> Command { - self.build_cmd("test", compiler) + pub(crate) fn test(&self, compiler: &Compiler, dirs: &Dirs) -> Command { + self.build_cmd("test", compiler, dirs) } #[must_use] - pub(crate) fn run(&self, compiler: &Compiler) -> Command { - self.build_cmd("run", compiler) + pub(crate) fn run(&self, compiler: &Compiler, dirs: &Dirs) -> Command { + self.build_cmd("run", compiler, dirs) } } From d7b02c307d0b40f076a172b1ebd6d2e5d6e4cb98 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:24:45 +0000 Subject: [PATCH 60/77] Fix installing hyperfine --- build_system/prepare.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 0eaa8e820baea..28322c1cb5128 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -18,7 +18,14 @@ pub(crate) fn prepare(dirs: &Dirs) { // FIXME maybe install this only locally? eprintln!("[INSTALL] hyperfine"); - Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); + Command::new("cargo") + .arg("install") + .arg("hyperfine") + .env_remove("CARGO_TARGET_DIR") + .spawn() + .unwrap() + .wait() + .unwrap(); super::abi_cafe::ABI_CAFE_REPO.fetch(dirs); super::tests::RAND_REPO.fetch(dirs); From 702a293776e0ddc76c12dea6ffb30c3900124deb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:49:34 +0000 Subject: [PATCH 61/77] Fix build dir caching --- .github/workflows/main.yml | 4 ++-- .github/workflows/rustc.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de3c89f3383da..424ede3614508 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: - name: Cache cargo target dir uses: actions/cache@v3 with: - path: target + path: build/cg_clif key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Install MinGW toolchain and wine @@ -164,7 +164,7 @@ jobs: - name: Cache cargo target dir uses: actions/cache@v3 with: - path: target + path: build/cg_clif key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Set MinGW as the default toolchain diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index a78d6b231d3f5..bef806318efa8 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -27,7 +27,7 @@ jobs: - name: Cache cargo target dir uses: actions/cache@v3 with: - path: target + path: build/cg_clif key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Prepare dependencies @@ -65,7 +65,7 @@ jobs: - name: Cache cargo target dir uses: actions/cache@v3 with: - path: target + path: build/cg_clif key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} - name: Prepare dependencies From b6ac5a3cebcb6b4cc23bf5e883899e075774781f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 1 Dec 2022 17:42:29 +0000 Subject: [PATCH 62/77] Allow specifying where build artifacts should be written to --- build_system/mod.rs | 92 ++++++++++++++++++++++++++++++--------------- test.sh | 2 +- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index b36df96c0b24a..1afc9a55c73b5 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -1,4 +1,5 @@ use std::env; +use std::path::PathBuf; use std::process; use self::utils::is_ci; @@ -13,11 +14,31 @@ mod rustc_info; mod tests; mod utils; +const USAGE: &str = r#"The build system of cg_clif. + +USAGE: + ./y.rs prepare [--out-dir DIR] + ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] + ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features] + +OPTIONS: + --sysroot none|clif|llvm + Which sysroot libraries to use: + `none` will not include any standard library in the sysroot. + `clif` will build the standard library using Cranelift. + `llvm` will use the pre-compiled standard library of rustc which is compiled with LLVM. + + --out-dir DIR + Specify the directory in which the download, build and dist directories are stored. + By default this is the working directory. + + --no-unstable-features + fSome features are not yet ready for production usage. This option will disable these + features. This includes the JIT mode and inline assembly support. +"#; + fn usage() { - eprintln!("Usage:"); - eprintln!(" ./y.rs prepare"); - eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]"); - eprintln!(" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]"); + eprintln!("{USAGE}"); } macro_rules! arg_error { @@ -30,6 +51,7 @@ macro_rules! arg_error { #[derive(PartialEq, Debug)] enum Command { + Prepare, Build, Test, } @@ -45,25 +67,6 @@ pub fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); - let current_dir = std::env::current_dir().unwrap(); - let dirs = path::Dirs { - source_dir: current_dir.clone(), - download_dir: current_dir.join("download"), - build_dir: current_dir.join("build"), - dist_dir: current_dir.join("dist"), - }; - - path::RelPath::BUILD.ensure_exists(&dirs); - - { - // Make sure we always explicitly specify the target dir - let target = - path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs); - env::set_var("CARGO_TARGET_DIR", &target); - let _ = std::fs::remove_file(&target); - std::fs::File::create(target).unwrap(); - } - 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"); @@ -71,13 +74,7 @@ pub fn main() { let mut args = env::args().skip(1); let command = match args.next().as_deref() { - Some("prepare") => { - if args.next().is_some() { - arg_error!("./y.rs prepare doesn't expect arguments"); - } - prepare::prepare(&dirs); - process::exit(0); - } + Some("prepare") => Command::Prepare, Some("build") => Command::Build, Some("test") => Command::Test, Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), @@ -88,11 +85,17 @@ pub fn main() { } }; + let mut out_dir = PathBuf::from("."); let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; while let Some(arg) = args.next().as_deref() { match arg { + "--out-dir" => { + out_dir = PathBuf::from(args.next().unwrap_or_else(|| { + arg_error!("--out-dir requires argument"); + })) + } "--debug" => channel = "debug", "--sysroot" => { sysroot_kind = match args.next().as_deref() { @@ -128,9 +131,38 @@ pub fn main() { host_triple.clone() }; + // FIXME allow changing the location of these dirs using cli arguments + let current_dir = std::env::current_dir().unwrap(); + out_dir = current_dir.join(out_dir); + let dirs = path::Dirs { + source_dir: current_dir.clone(), + download_dir: out_dir.join("download"), + build_dir: out_dir.join("build"), + dist_dir: out_dir.join("dist"), + }; + + path::RelPath::BUILD.ensure_exists(&dirs); + + { + // Make sure we always explicitly specify the target dir + let target = + path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs); + env::set_var("CARGO_TARGET_DIR", &target); + let _ = std::fs::remove_file(&target); + std::fs::File::create(target).unwrap(); + } + + if command == Command::Prepare { + prepare::prepare(&dirs); + process::exit(0); + } + let cg_clif_dylib = build_backend::build_backend(&dirs, channel, &host_triple, use_unstable_features); match command { + Command::Prepare => { + // Handled above + } Command::Test => { tests::run_tests( &dirs, diff --git a/test.sh b/test.sh index 3d929a1d50ce2..13e7784539d5a 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -exec ./y.rs test +exec ./y.rs test "$@" From 04eaaa043d15b3c99e46819464669eb52d37320c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 2 Dec 2022 12:44:14 +0000 Subject: [PATCH 63/77] Fix crash with TAIT in the call codegen code The new logic is closer to what cg_llvm does. Fixes #1240 --- build_system/tests.rs | 10 ++++++++++ config.txt | 1 + example/issue-72793.rs | 24 ++++++++++++++++++++++++ src/abi/mod.rs | 23 +++++++++++------------ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 example/issue-72793.rs diff --git a/build_system/tests.rs b/build_system/tests.rs index bd31d5e6bbf28..99a8e5b322070 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -219,6 +219,16 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ ]); runner.run_out_command("mod_bench", []); }), + TestCase::new("aot.issue-72793", &|runner| { + runner.run_rustc([ + "example/issue-72793.rs", + "--crate-type", + "bin", + "--target", + &runner.target_compiler.triple, + ]); + runner.run_out_command("issue-72793", []); + }), ]; pub(crate) static RAND_REPO: GitRepo = diff --git a/config.txt b/config.txt index 0d539191b12f9..258b67e931476 100644 --- a/config.txt +++ b/config.txt @@ -40,6 +40,7 @@ aot.subslice-patterns-const-eval aot.track-caller-attribute aot.float-minmax-pass aot.mod_bench +aot.issue-72793 testsuite.extended_sysroot test.rust-random/rand diff --git a/example/issue-72793.rs b/example/issue-72793.rs new file mode 100644 index 0000000000000..b1bb9b8e1e730 --- /dev/null +++ b/example/issue-72793.rs @@ -0,0 +1,24 @@ +// Adapted from rustc ui test suite (ui/type-alias-impl-trait/issue-72793.rs) + +#![feature(type_alias_impl_trait)] + +trait T { type Item; } + +type Alias<'a> = impl T; + +struct S; +impl<'a> T for &'a S { + type Item = &'a (); +} + +fn filter_positive<'a>() -> Alias<'a> { + &S +} + +fn with_positive(fun: impl Fn(Alias<'_>)) { + fun(filter_positive()); +} + +fn main() { + with_positive(|_| ()); +} diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 1e22537c2ba42..d62966b162fa2 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -341,14 +341,13 @@ pub(crate) fn codegen_terminator_call<'tcx>( destination: Place<'tcx>, target: Option, ) { - let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx)); - let fn_sig = - fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx)); + let func = codegen_operand(fx, func); + let fn_sig = func.layout().ty.fn_sig(fx.tcx); let ret_place = codegen_place(fx, destination); // Handle special calls like intrinsics and empty drop glue. - let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() { + let instance = if let ty::FnDef(def_id, substs) = *func.layout().ty.kind() { let instance = ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs) .unwrap() .unwrap() @@ -391,17 +390,17 @@ pub(crate) fn codegen_terminator_call<'tcx>( None }; - let extra_args = &args[fn_sig.inputs().len()..]; + let extra_args = &args[fn_sig.inputs().skip_binder().len()..]; let extra_args = fx .tcx .mk_type_list(extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx)))); let fn_abi = if let Some(instance) = instance { RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args) } else { - RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), extra_args) + RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_sig, extra_args) }; - let is_cold = if fn_sig.abi == Abi::RustCold { + let is_cold = if fn_sig.abi() == Abi::RustCold { true } else { instance @@ -418,7 +417,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } // Unpack arguments tuple for closures - let mut args = if fn_sig.abi == Abi::RustCall { + let mut args = if fn_sig.abi() == Abi::RustCall { assert_eq!(args.len(), 2, "rust-call abi requires two arguments"); let self_arg = codegen_call_argument_operand(fx, &args[0]); let pack_arg = codegen_call_argument_operand(fx, &args[1]); @@ -486,7 +485,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( fx.add_comment(nop_inst, "indirect call"); } - let func = codegen_operand(fx, func).load_scalar(fx); + let func = func.load_scalar(fx); let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); @@ -517,11 +516,11 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; // FIXME find a cleaner way to support varargs - if fn_sig.c_variadic { - if !matches!(fn_sig.abi, Abi::C { .. }) { + if fn_sig.c_variadic() { + if !matches!(fn_sig.abi(), Abi::C { .. }) { fx.tcx.sess.span_fatal( source_info.span, - &format!("Variadic call for non-C abi {:?}", fn_sig.abi), + &format!("Variadic call for non-C abi {:?}", fn_sig.abi()), ); } let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap(); From f845eafc2f507fe90c787ba3cdc522ca6d5effae Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 2 Dec 2022 21:57:04 +0100 Subject: [PATCH 64/77] Switch Linux runner to ubuntu-20.04 to unbreak CI Earlier today CI started to fail on Linux with a crash during the jit mode. Turns out ubuntu-latest switched from ubuntu-20.04 to ubuntu-22.04. Let's switch back to ubuntu-20.04 for now to unbreak CI until I figured out the root cause. cc #1303 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 424ede3614508..625084e3b0809 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest + - os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed env: TARGET_TRIPLE: x86_64-unknown-linux-gnu - os: macos-latest From e12a882a6762b58a544d45da043a1b311c7fab22 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 3 Dec 2022 23:23:01 +0000 Subject: [PATCH 65/77] S390X CI Support (#1304) --- .github/workflows/main.yml | 10 ++++++++++ build_system/build_sysroot.rs | 8 ++++---- build_system/tests.rs | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 625084e3b0809..babadc4d4677e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,6 +42,10 @@ jobs: - os: ubuntu-latest env: TARGET_TRIPLE: aarch64-unknown-linux-gnu + # s390x requires QEMU 6.1 or greater, we could build it from source, but ubuntu 22.04 comes with 6.2 by default + - os: ubuntu-latest + env: + TARGET_TRIPLE: s390x-unknown-linux-gnu steps: - uses: actions/checkout@v3 @@ -79,6 +83,12 @@ jobs: 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' + run: | + sudo apt-get update + sudo apt-get install -y gcc-s390x-linux-gnu qemu-user + - name: Prepare dependencies run: | git config --global user.email "user@example.com" diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 35c972e6b383a..cbbf09b9b97b8 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -119,10 +119,10 @@ pub(crate) fn build_sysroot( if host_triple != target_triple { // When cross-compiling it is often necessary to manually pick the right linker - let linker = if target_triple == "aarch64-unknown-linux-gnu" { - Some("aarch64-linux-gnu-gcc") - } else { - None + let linker = match target_triple { + "aarch64-unknown-linux-gnu" => Some("aarch64-linux-gnu-gcc"), + "s390x-unknown-linux-gnu" => Some("s390x-linux-gnu-gcc"), + _ => None, }; build_clif_sysroot_for_triple( dirs, diff --git a/build_system/tests.rs b/build_system/tests.rs index 99a8e5b322070..1c372736ed65d 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -526,6 +526,15 @@ impl TestRunner { "/usr/aarch64-linux-gnu".to_owned(), ]; } + "s390x-unknown-linux-gnu" => { + // We are cross-compiling for s390x. Use the correct linker and run tests in qemu. + rustflags = format!("-Clinker=s390x-linux-gnu-gcc{}", rustflags); + runner = vec![ + "qemu-s390x".to_owned(), + "-L".to_owned(), + "/usr/s390x-linux-gnu".to_owned(), + ]; + } "x86_64-pc-windows-gnu" => { // We are cross-compiling for Windows. Run tests in wine. runner = vec!["wine".to_owned()]; From 63fab514dbfc7fc499d8ad8fefcc76310b97d3c1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 4 Dec 2022 10:33:32 +0100 Subject: [PATCH 66/77] Rustup to rustc 1.67.0-nightly (234151769 2022-12-03) --- build_sysroot/Cargo.lock | 26 ++++++++------------------ rust-toolchain | 2 +- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index bcfabc246dfcb..360e16f0e8306 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -38,16 +38,6 @@ version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -dependencies = [ - "compiler_builtins", - "rustc-std-workspace-core", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -139,9 +129,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.137" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" dependencies = [ "rustc-std-workspace-core", ] @@ -185,7 +175,7 @@ name = "panic_abort" version = "0.0.0" dependencies = [ "alloc", - "cfg-if 1.0.0", + "cfg-if", "compiler_builtins", "core", "libc", @@ -196,7 +186,7 @@ name = "panic_unwind" version = "0.0.0" dependencies = [ "alloc", - "cfg-if 1.0.0", + "cfg-if", "compiler_builtins", "core", "libc", @@ -248,7 +238,7 @@ version = "0.0.0" dependencies = [ "addr2line", "alloc", - "cfg-if 1.0.0", + "cfg-if", "compiler_builtins", "core", "dlmalloc", @@ -270,7 +260,7 @@ dependencies = [ name = "std_detect" version = "0.1.5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "compiler_builtins", "libc", "rustc-std-workspace-alloc", @@ -292,7 +282,7 @@ dependencies = [ name = "test" version = "0.0.0" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "core", "getopts", "libc", @@ -318,7 +308,7 @@ name = "unwind" version = "0.0.0" dependencies = [ "cc", - "cfg-if 1.0.0", + "cfg-if", "compiler_builtins", "core", "libc", diff --git a/rust-toolchain b/rust-toolchain index 86c8ee1cc1d50..483436e38177f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-11-22" +channel = "nightly-2022-12-04" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 34336b8d94cee06628f0f4d9d932634135e32a38 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sat, 3 Dec 2022 16:03:27 -0800 Subject: [PATCH 67/77] Remove unneeded field from `SwitchTargets` --- src/base.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index 1db44502742e9..06813d7ec953f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -372,8 +372,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { } } - TerminatorKind::SwitchInt { discr, switch_ty, targets } => { - let discr = codegen_operand(fx, discr).load_scalar(fx); + TerminatorKind::SwitchInt { discr, targets } => { + let discr = codegen_operand(fx, discr); + let switch_ty = discr.layout().ty; + let discr = discr.load_scalar(fx); let use_bool_opt = switch_ty.kind() == fx.tcx.types.bool.kind() || (targets.iter().count() == 1 && targets.iter().next().unwrap().0 == 0); From ef1cb95687167308bafe994e7fef05f68287e554 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 11 Dec 2022 11:10:14 +0100 Subject: [PATCH 68/77] Rustup to rustc 1.68.0-nightly (c6fcdb690 2022-12-10) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 360e16f0e8306..bba3210536ef7 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.84" +version = "0.1.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989b2c1ca6e90ad06fdc69d1d1862fa28d27a977be6d92ae2fa762cf61fe0b10" +checksum = "13e81c6cd7ab79f51a0c927d22858d61ad12bd0b3865f0b13ece02a4486aeabb" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 483436e38177f..b0b877906c59c 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-12-04" +channel = "nightly-2022-12-11" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 21f43556ac1b5c32a2396db42eb852ccfac2112e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 10 Dec 2022 17:26:40 +0100 Subject: [PATCH 69/77] Fix for "Support Option and similar enums as type of static variable with linkage attribute" cc rust-lang/rust#104799 --- src/constant.rs | 77 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 9b29b17e3a111..dee6fb5b5130d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -266,16 +266,7 @@ fn data_id_for_static( def_id: DefId, definition: bool, ) -> DataId { - let rlinkage = tcx.codegen_fn_attrs(def_id).linkage; - let linkage = if definition { - crate::linkage::get_static_linkage(tcx, def_id) - } else if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak) - || rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny) - { - Linkage::Preemptible - } else { - Linkage::Import - }; + let attrs = tcx.codegen_fn_attrs(def_id); let instance = Instance::mono(tcx, def_id).polymorphize(tcx); let symbol_name = tcx.symbol_name(instance).name; @@ -287,22 +278,30 @@ fn data_id_for_static( }; let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes(); - let attrs = tcx.codegen_fn_attrs(def_id); + if let Some(import_linkage) = attrs.import_linkage { + assert!(!definition); - let data_id = match module.declare_data( - &*symbol_name, - linkage, - is_mutable, - attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), - ) { - Ok(data_id) => data_id, - Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( - "attempt to declare `{symbol_name}` as static, but it was already declared as function" - )), - Err(err) => Err::<_, _>(err).unwrap(), - }; + let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak + || import_linkage == rustc_middle::mir::mono::Linkage::WeakAny + { + Linkage::Preemptible + } else { + Linkage::Import + }; + + let data_id = match module.declare_data( + &*symbol_name, + linkage, + is_mutable, + attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), + ) { + Ok(data_id) => data_id, + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + "attempt to declare `{symbol_name}` as static, but it was already declared as function" + )), + Err(err) => Err::<_, _>(err).unwrap(), + }; - if rlinkage.is_some() { // Comment copied from https://github.com/rust-lang/rust/blob/45060c2a66dfd667f88bd8b94261b28a58d85bd5/src/librustc_codegen_llvm/consts.rs#L141 // Declare an internal global `extern_with_linkage_foo` which // is initialized with the address of `foo`. If `foo` is @@ -324,10 +323,34 @@ fn data_id_for_static( Err(ModuleError::DuplicateDefinition(_)) => {} res => res.unwrap(), } - ref_data_id - } else { - data_id + + return ref_data_id; } + + let linkage = if definition { + crate::linkage::get_static_linkage(tcx, def_id) + } else if attrs.linkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak) + || attrs.linkage == Some(rustc_middle::mir::mono::Linkage::WeakAny) + { + Linkage::Preemptible + } else { + Linkage::Import + }; + + let data_id = match module.declare_data( + &*symbol_name, + linkage, + is_mutable, + attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), + ) { + Ok(data_id) => data_id, + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + "attempt to declare `{symbol_name}` as static, but it was already declared as function" + )), + Err(err) => Err::<_, _>(err).unwrap(), + }; + + data_id } fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx) { From a89cef5a0a79e6ac60d0f8d7a05ecc6583ea0ba5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 11 Dec 2022 10:56:34 +0000 Subject: [PATCH 70/77] Update rustc test suite failure list --- scripts/test_rustc_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 192c4d1f0c7eb..04ad77ec97eac 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -67,6 +67,7 @@ rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/ui/abi/stack-probes.rs # stack probes not yet implemented rm src/test/ui/simd/intrinsic/ptr-cast.rs # simd_expose_addr intrinsic unimplemented rm -r src/test/run-make/repr128-dwarf # debuginfo test +rm src/test/codegen-units/item-collection/asm-sym.rs # requires support for sym in asm!() # optimization tests # ================== @@ -85,6 +86,7 @@ rm src/test/ui/abi/stack-protector.rs # requires stack protector support rm src/test/ui/mir/mir_misc_casts.rs # depends on deduplication of constants rm src/test/ui/mir/mir_raw_fat_ptr.rs # same rm src/test/ui/consts/issue-33537.rs # same +rm src/test/ui/layout/valid_range_oob.rs # different ICE message # doesn't work due to the way the rustc test suite is invoked. # should work when using ./x.py test the way it is intended @@ -94,6 +96,7 @@ rm -r src/test/run-make/unstable-flag-required # same rm -r src/test/run-make/rustdoc-* # same rm -r src/test/run-make/issue-88756-default-output # same rm -r src/test/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump +rm -r src/test/ui/consts/missing_span_in_backtrace.rs # expects sysroot source to be elsewhere # genuine bugs # ============ @@ -115,6 +118,7 @@ rm src/test/ui/test-attrs/test-type.rs # TODO panic message on stderr. correct s # not sure if this is actually a bug in the test suite, but the symbol list shows the function without leading _ for some reason rm -r src/test/run-make/native-link-modifier-bundle rm src/test/ui/process/nofile-limit.rs # TODO some AArch64 linking issue +rm src/test/ui/dyn-star/dispatch-on-pin-mut.rs # TODO failed assertion in vtable::get_ptr_and_method_ref rm src/test/ui/stdio-is-blocking.rs # really slow with unoptimized libstd From 7e10f1a0f4291846198cf9020b0c73d30c80c92c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 11 Dec 2022 12:44:41 +0000 Subject: [PATCH 71/77] Update dependencies --- Cargo.lock | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f1278de16820..e4d3e9ca5ae0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.60" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "arrayvec" @@ -39,9 +39,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byteorder" @@ -218,9 +218,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", @@ -249,9 +249,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", @@ -259,15 +259,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.127" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", "winapi", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "regalloc2" @@ -366,9 +366,9 @@ checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "stable_deref_trait" From f7c76ad6624118c96717298fb0a8e6f84b5a9265 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 11 Dec 2022 19:46:58 +0000 Subject: [PATCH 72/77] bug! with a better error message for failing Instance::resolve --- src/abi/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 1e22537c2ba42..98b5fb1cce285 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -349,10 +349,9 @@ pub(crate) fn codegen_terminator_call<'tcx>( // Handle special calls like intrinsics and empty drop glue. let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() { - let instance = ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs) - .unwrap() - .unwrap() - .polymorphize(fx.tcx); + let instance = + ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs) + .polymorphize(fx.tcx); if fx.tcx.symbol_name(instance).name.starts_with("llvm.") { crate::intrinsics::codegen_llvm_intrinsic_call( From 6e772b86a8b62132173f9610302361aadb2167bd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 13 Dec 2022 18:23:52 +0100 Subject: [PATCH 73/77] Rustup to rustc 1.68.0-nightly (37d7de337 2022-12-12) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index b0b877906c59c..d8f28dbcc15c8 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-12-11" +channel = "nightly-2022-12-13" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 08ba5d4e809ecf39d9f909c28b0a2f38f372155d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 14 Dec 2022 12:25:53 +0000 Subject: [PATCH 74/77] Remove a couple of module.isa() calls --- src/abi/mod.rs | 6 +++--- src/allocator.rs | 4 ++-- src/base.rs | 2 +- src/driver/jit.rs | 8 ++++++-- src/driver/mod.rs | 3 ++- src/main_shim.rs | 6 +++--- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 42371d2af5016..65cc6b4376713 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -56,13 +56,13 @@ pub(crate) fn conv_to_call_conv(c: Conv, default_call_conv: CallConv) -> CallCon pub(crate) fn get_function_sig<'tcx>( tcx: TyCtxt<'tcx>, - triple: &target_lexicon::Triple, + default_call_conv: CallConv, inst: Instance<'tcx>, ) -> Signature { assert!(!inst.substs.needs_infer()); clif_sig_from_fn_abi( tcx, - CallConv::triple_default(triple), + default_call_conv, &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()), ) } @@ -74,7 +74,7 @@ pub(crate) fn import_function<'tcx>( inst: Instance<'tcx>, ) -> FuncId { let name = tcx.symbol_name(inst).name; - let sig = get_function_sig(tcx, module.isa().triple(), inst); + let sig = get_function_sig(tcx, module.target_config().default_call_conv, inst); match module.declare_function(name, Linkage::Import, &sig) { Ok(func_id) => func_id, Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( diff --git a/src/allocator.rs b/src/allocator.rs index 12bb00d346db4..8508227179ac6 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -66,7 +66,7 @@ fn codegen_inner( }; let sig = Signature { - call_conv: CallConv::triple_default(module.isa().triple()), + call_conv: module.target_config().default_call_conv, params: arg_tys.iter().cloned().map(AbiParam::new).collect(), returns: output.into_iter().map(AbiParam::new).collect(), }; @@ -104,7 +104,7 @@ fn codegen_inner( } let sig = Signature { - call_conv: CallConv::triple_default(module.isa().triple()), + call_conv: module.target_config().default_call_conv, params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)], returns: vec![], }; diff --git a/src/base.rs b/src/base.rs index ac3c0be025c5e..89d955e8bf2e1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -59,7 +59,7 @@ pub(crate) fn codegen_fn<'tcx>( // Declare function let symbol_name = tcx.symbol_name(instance).name.to_string(); - let sig = get_function_sig(tcx, module.isa().triple(), instance); + let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance); let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap(); // Make the FunctionBuilder diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 1dcb8025183c9..be1b8c9ead3bf 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -245,7 +245,11 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> let backend_config = lazy_jit_state.backend_config.clone(); let name = tcx.symbol_name(instance).name; - let sig = crate::abi::get_function_sig(tcx, jit_module.isa().triple(), instance); + let sig = crate::abi::get_function_sig( + tcx, + jit_module.target_config().default_call_conv, + instance, + ); let func_id = jit_module.declare_function(name, Linkage::Export, &sig).unwrap(); let current_ptr = jit_module.read_got_entry(func_id); @@ -344,7 +348,7 @@ fn codegen_shim<'tcx>( let pointer_type = module.target_config().pointer_type(); let name = tcx.symbol_name(inst).name; - let sig = crate::abi::get_function_sig(tcx, module.isa().triple(), inst); + let sig = crate::abi::get_function_sig(tcx, module.target_config().default_call_conv, inst); let func_id = module.declare_function(name, Linkage::Export, &sig).unwrap(); let instance_ptr = Box::into_raw(Box::new(inst)); diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 8f5714ecb4177..6e925cea27707 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -24,7 +24,8 @@ fn predefine_mono_items<'tcx>( MonoItem::Fn(instance) => { let name = tcx.symbol_name(instance).name; let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name)); - let sig = get_function_sig(tcx, module.isa().triple(), instance); + let sig = + get_function_sig(tcx, module.target_config().default_call_conv, instance); let linkage = crate::linkage::get_clif_linkage( mono_item, linkage, diff --git a/src/main_shim.rs b/src/main_shim.rs index f7434633ea442..c10054e7f0d2c 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -65,7 +65,7 @@ pub(crate) fn maybe_create_entry_wrapper( returns: vec![AbiParam::new(m.target_config().pointer_type() /*isize*/)], call_conv: crate::conv_to_call_conv( tcx.sess.target.options.entry_abi, - CallConv::triple_default(m.isa().triple()), + m.target_config().default_call_conv, ), }; @@ -75,7 +75,7 @@ pub(crate) fn maybe_create_entry_wrapper( let instance = Instance::mono(tcx, rust_main_def_id).polymorphize(tcx); let main_name = tcx.symbol_name(instance).name; - let main_sig = get_function_sig(tcx, m.isa().triple(), instance); + let main_sig = get_function_sig(tcx, m.target_config().default_call_conv, instance); let main_func_id = m.declare_function(main_name, Linkage::Import, &main_sig).unwrap(); let mut ctx = Context::new(); @@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper( .polymorphize(tcx); let report_name = tcx.symbol_name(report).name; - let report_sig = get_function_sig(tcx, m.isa().triple(), report); + let report_sig = get_function_sig(tcx, m.target_config().default_call_conv, report); let report_func_id = m.declare_function(report_name, Linkage::Import, &report_sig).unwrap(); let report_func_ref = m.declare_func_in_func(report_func_id, &mut bcx.func); From a45924cc21d3138ee449d1cf756ca914ce10f52d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 14 Dec 2022 15:21:18 +0000 Subject: [PATCH 75/77] Explicitly provide dummy git author name and email This avoids the need to tell git beforehand about your name and email --- .cirrus.yml | 2 -- .github/workflows/main.yml | 7 +------ build_system/prepare.rs | 21 +++++++++++++++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 732edd66196d7..d627c2ee09c4e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -12,8 +12,6 @@ task: folder: target prepare_script: - . $HOME/.cargo/env - - git config --global user.email "user@example.com" - - git config --global user.name "User" - ./y.rs prepare test_script: - . $HOME/.cargo/env diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index babadc4d4677e..a6bb12a66a247 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,10 +90,7 @@ jobs: sudo apt-get install -y gcc-s390x-linux-gnu qemu-user - name: Prepare dependencies - run: | - git config --global user.email "user@example.com" - git config --global user.name "User" - ./y.rs prepare + run: ./y.rs prepare - name: Build without unstable features env: @@ -183,8 +180,6 @@ jobs: - name: Prepare dependencies run: | - git config --global user.email "user@example.com" - git config --global user.name "User" git config --global core.autocrlf false rustc y.rs -o y.exe -g ./y.exe prepare diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 28322c1cb5128..8826f1bd2595a 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -180,7 +180,16 @@ fn init_git_repo(repo_dir: &Path) { spawn_and_wait(git_add_cmd); let mut git_commit_cmd = Command::new("git"); - git_commit_cmd.arg("commit").arg("-m").arg("Initial commit").arg("-q").current_dir(repo_dir); + git_commit_cmd + .arg("-c") + .arg("user.name=Dummy") + .arg("-c") + .arg("user.email=dummy@example.com") + .arg("commit") + .arg("-m") + .arg("Initial commit") + .arg("-q") + .current_dir(repo_dir); spawn_and_wait(git_commit_cmd); } @@ -216,7 +225,15 @@ fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) { patch.file_name().unwrap() ); let mut apply_patch_cmd = Command::new("git"); - apply_patch_cmd.arg("am").arg(patch).arg("-q").current_dir(target_dir); + apply_patch_cmd + .arg("-c") + .arg("user.name=Dummy") + .arg("-c") + .arg("user.email=dummy@example.com") + .arg("am") + .arg(patch) + .arg("-q") + .current_dir(target_dir); spawn_and_wait(apply_patch_cmd); } } From 2bb3996244cf1b89878da9e39841e9f6bf061602 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 14 Dec 2022 15:23:24 +0000 Subject: [PATCH 76/77] Remove unnecessary git init --- build_system/prepare.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 8826f1bd2595a..8ac67e8f94228 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -67,10 +67,6 @@ fn prepare_sysroot(dirs: &Dirs) { fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); eprintln!("[GIT] init"); - let mut git_init_cmd = Command::new("git"); - git_init_cmd.arg("init").arg("-q").current_dir(sysroot_src.to_path(dirs)); - spawn_and_wait(git_init_cmd); - init_git_repo(&sysroot_src.to_path(dirs)); apply_patches(dirs, "sysroot", &sysroot_src.to_path(dirs)); From 13e33c03ffade7beda7a6e8c71fa3939882d85b1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 14 Dec 2022 19:47:46 +0100 Subject: [PATCH 77/77] Add tidy exceptions --- src/tools/tidy/src/deps.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 7ee8c5d3bad15..75454cbdc5fe6 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -57,6 +57,7 @@ const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[ ("cranelift-codegen", "Apache-2.0 WITH LLVM-exception"), ("cranelift-codegen-meta", "Apache-2.0 WITH LLVM-exception"), ("cranelift-codegen-shared", "Apache-2.0 WITH LLVM-exception"), + ("cranelift-egraph", "Apache-2.0 WITH LLVM-exception"), ("cranelift-entity", "Apache-2.0 WITH LLVM-exception"), ("cranelift-frontend", "Apache-2.0 WITH LLVM-exception"), ("cranelift-isle", "Apache-2.0 WITH LLVM-exception"), @@ -67,6 +68,7 @@ const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[ ("mach", "BSD-2-Clause"), ("regalloc2", "Apache-2.0 WITH LLVM-exception"), ("target-lexicon", "Apache-2.0 WITH LLVM-exception"), + ("wasmtime-jit-icache-coherence", "Apache-2.0 WITH LLVM-exception"), ]; const EXCEPTIONS_BOOTSTRAP: &[(&str, &str)] = &[ @@ -291,6 +293,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "cranelift-codegen", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", "cranelift-frontend", "cranelift-isle", @@ -299,6 +302,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "cranelift-native", "cranelift-object", "crc32fast", + "fallible-iterator", "fxhash", "getrandom", "gimli", @@ -315,9 +319,11 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "region", "slice-group-by", "smallvec", + "stable_deref_trait", "target-lexicon", "version_check", "wasi", + "wasmtime-jit-icache-coherence", "winapi", "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",