From b5cbb87e628d267ecc5c1353c6abba63db02a2dd Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 23 Feb 2022 11:49:34 +0100 Subject: [PATCH 01/44] Merge commit '35d9c6bf256968e1b40e0d554607928bdf9cebea' into sync_cg_clif-2022-02-23 --- Cargo.lock | 67 +- Cargo.toml | 14 +- build_sysroot/Cargo.lock | 26 +- build_system/build_backend.rs | 2 +- build_system/build_sysroot.rs | 10 +- build_system/mod.rs | 127 ++++ build_system/prepare.rs | 6 +- clean_all.sh | 2 +- ...ins-Disable-128bit-atomic-operations.patch | 16 +- ...-sysroot-Disable-not-compiling-tests.patch | 4 +- ...027-sysroot-128bit-atomic-operations.patch | 33 - rust-toolchain | 2 +- scripts/test_rustc_tests.sh | 5 +- src/allocator.rs | 9 +- src/base.rs | 56 +- src/driver/aot.rs | 3 + src/driver/jit.rs | 10 +- src/intrinsics/llvm.rs | 30 +- src/intrinsics/mod.rs | 632 +++++++++--------- src/intrinsics/simd.rs | 447 ++++++++----- src/main_shim.rs | 4 +- src/optimize/mod.rs | 2 +- src/pretty_clif.rs | 10 +- y.rs | 133 +--- 24 files changed, 842 insertions(+), 808 deletions(-) create mode 100644 build_system/mod.rs diff --git a/Cargo.lock b/Cargo.lock index faed52727c828..f15e319e3b807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.51" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" +checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" [[package]] name = "ar" @@ -33,18 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc0cb7df82c8cf8f2e6a8dd394a0932a71369c160cc9b027dca414fced242513" +checksum = "71447555acc6c875c52c407d572fc1327dc5c34cba72b4b2e7ad048aa4e4fd19" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4463c15fa42eee909e61e5eac4866b7c6d22d0d8c621e57a0c5380753bfa8c" +checksum = "ec9a10261891a7a919b0d4f6aa73582e88441d9a8f6173c88efbe4a5a362ea67" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -59,31 +59,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793f6a94a053a55404ea16e1700202a88101672b8cd6b4df63e13cde950852bf" +checksum = "815755d76fcbcf6e17ab888545b28ab775f917cb12ce0797e60cd41a2288692c" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44aa1846df275bce5eb30379d65964c7afc63c05a117076e62a119c25fe174be" +checksum = "23ea92f2a67335a2e4d3c9c65624c3b14ae287d595b0650822c41824febab66b" [[package]] name = "cranelift-entity" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a45d8d6318bf8fc518154d9298eab2a8154ec068a8885ff113f6db8d69bb3a" +checksum = "bd25847875e388c500ad3624b4d2e14067955c93185194a7222246a25b91c975" [[package]] name = "cranelift-frontend" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e07339bd461766deb7605169de039e01954768ff730fa1254e149001884a8525" +checksum = "308bcfb7eb47bdf5ff6e1ace262af4ed39ec19f204c751fffb037e0e82a0c8bf" dependencies = [ "cranelift-codegen", "log", @@ -93,9 +92,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e8f0d60fb5d67f7a1e5c49db38ba96d1c846921faef02085fc5590b74781747" +checksum = "f560b3a314b8d15facf411e5d29b917c3e787a2bbc3fcdc5183bc0c5b7d4fe01" dependencies = [ "anyhow", "cranelift-codegen", @@ -111,21 +110,19 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825ac7e0959cbe7ddc9cc21209f0319e611a57f9fcb2b723861fe7ef2017e651" +checksum = "3a57aba9e603d694d1430ff38bd914bae23ef9c2e44b25a65e318905807e654c" dependencies = [ "anyhow", "cranelift-codegen", - "cranelift-entity", - "log", ] [[package]] name = "cranelift-native" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e2fca76ff57e0532936a71e3fc267eae6a19a86656716479c66e7f912e3d7b" +checksum = "12cdc799aee673be2317e631d4569a1ba0a7e77a07a7ce45557086d2e02e9514" dependencies = [ "cranelift-codegen", "libc", @@ -134,9 +131,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.78.0" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55500d0fc9bb05c0944fc4506649249d28f55bd4fe95b87f0e55bf41058f0e6d" +checksum = "502a7333836052fcdf4425d7f7a21264d99f862d32b9c3a0e47cd920487a9b60" dependencies = [ "anyhow", "cranelift-codegen", @@ -148,18 +145,18 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" +checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3" dependencies = [ "cfg-if", ] [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" dependencies = [ "indexmap", ] @@ -182,9 +179,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.112" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" [[package]] name = "libloading" @@ -233,9 +230,9 @@ dependencies = [ [[package]] name = "regalloc" -version = "0.0.32" +version = "0.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6304468554ed921da3d32c355ea107b8d13d7b8996c3adfb7aab48d3bc321f4" +checksum = "62446b1d3ebf980bdc68837700af1d77b37bc430e524bf95319c6eada2a4cc02" dependencies = [ "log", "rustc-hash", @@ -281,9 +278,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "target-lexicon" diff --git a/Cargo.toml b/Cargo.toml index 2d19040b5091c..178404af42d67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,14 +8,14 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.78.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.78.0" -cranelift-module = "0.78.0" -cranelift-native = "0.78.0" -cranelift-jit = { version = "0.78.0", optional = true } -cranelift-object = "0.78.0" +cranelift-codegen = { version = "0.81.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.81.0" +cranelift-module = "0.81.0" +cranelift-native = "0.81.0" +cranelift-jit = { version = "0.81.0", optional = true } +cranelift-object = "0.81.0" target-lexicon = "0.12.0" -gimli = { version = "0.25.0", default-features = false, features = ["write"]} +gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.27.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" } diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index dd09656248022..b97863951429c 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -34,15 +34,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "cfg-if" @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.66" +version = "0.1.70" dependencies = [ "rustc-std-workspace-core", ] @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -121,9 +121,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "1ab7905ea95c6d9af62940f9d7dd9596d54c334ae2c15300c482051292d5637f" dependencies = [ "compiler_builtins", "libc", @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.112" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" dependencies = [ "rustc-std-workspace-core", ] @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 1382c7e53793e..0a56eb131ed30 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -49,7 +49,7 @@ pub(crate) fn build_backend( cmd.env("RUSTFLAGS", rustflags); eprintln!("[BUILD] rustc_codegen_cranelift"); - crate::utils::spawn_and_wait(cmd); + super::utils::spawn_and_wait(cmd); Path::new("target").join(host_triple).join(channel) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 2956fb698e175..c9c003d461095 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,9 +3,9 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; -use crate::rustc_info::{get_file_name, get_rustc_version}; -use crate::utils::{spawn_and_wait, try_hard_link}; -use crate::SysrootKind; +use super::rustc_info::{get_file_name, get_rustc_version}; +use super::utils::{spawn_and_wait, try_hard_link}; +use super::SysrootKind; pub(crate) fn build_sysroot( channel: &str, @@ -52,7 +52,7 @@ pub(crate) fn build_sysroot( .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); - let default_sysroot = crate::rustc_info::get_default_sysroot(); + let default_sysroot = super::rustc_info::get_default_sysroot(); let rustlib = target_dir.join("lib").join("rustlib"); let host_rustlib_lib = rustlib.join(host_triple).join("lib"); @@ -167,7 +167,7 @@ fn build_clif_sysroot_for_triple( let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); - if !crate::config::get_bool("keep_sysroot") { + if !super::config::get_bool("keep_sysroot") { // Cleanup the target dir with the exception of build scripts and the incremental cache for dir in ["build", "deps", "examples", "native"] { if build_dir.join(dir).exists() { diff --git a/build_system/mod.rs b/build_system/mod.rs new file mode 100644 index 0000000000000..b228da3981fdb --- /dev/null +++ b/build_system/mod.rs @@ -0,0 +1,127 @@ +use std::env; +use std::path::PathBuf; +use std::process; + +mod build_backend; +mod build_sysroot; +mod config; +mod prepare; +mod rustc_info; +mod utils; + +fn usage() { + eprintln!("Usage:"); + eprintln!(" ./y.rs prepare"); + eprintln!( + " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + ); +} + +macro_rules! arg_error { + ($($err:tt)*) => {{ + eprintln!($($err)*); + usage(); + std::process::exit(1); + }}; +} + +enum Command { + Build, +} + +#[derive(Copy, Clone)] +pub(crate) enum SysrootKind { + None, + Clif, + Llvm, +} + +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"); + + let mut args = env::args().skip(1); + let command = match args.next().as_deref() { + Some("prepare") => { + if args.next().is_some() { + arg_error!("./x.rs prepare doesn't expect arguments"); + } + prepare::prepare(); + process::exit(0); + } + Some("build") => Command::Build, + Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), + Some(command) => arg_error!("Unknown command {}", command), + None => { + usage(); + process::exit(0); + } + }; + + let mut target_dir = PathBuf::from("build"); + 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"); + })) + } + "--debug" => channel = "debug", + "--sysroot" => { + sysroot_kind = match args.next().as_deref() { + Some("none") => SysrootKind::None, + Some("clif") => SysrootKind::Clif, + Some("llvm") => SysrootKind::Llvm, + Some(arg) => arg_error!("Unknown sysroot kind {}", arg), + None => arg_error!("--sysroot requires argument"), + } + } + "--no-unstable-features" => use_unstable_features = false, + flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), + arg => arg_error!("Unexpected argument {}", arg), + } + } + + let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { + host_triple + } else if let Some(host_triple) = config::get_value("host") { + host_triple + } else { + rustc_info::get_host_triple() + }; + let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { + if target_triple != "" { + target_triple + } else { + host_triple.clone() // Empty target triple can happen on GHA + } + } else if let Some(target_triple) = config::get_value("target") { + target_triple + } else { + 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); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + cg_clif_build_dir, + &host_triple, + &target_triple, + ); +} diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 561e2ed7b0017..4a7df2cebbcb6 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -5,8 +5,8 @@ use std::fs; use std::path::Path; use std::process::Command; -use crate::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; -use crate::utils::{copy_dir_recursively, spawn_and_wait}; +use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; +use super::utils::{copy_dir_recursively, spawn_and_wait}; pub(crate) fn prepare() { prepare_sysroot(); @@ -92,7 +92,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.66", + "0.1.70", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/clean_all.sh b/clean_all.sh index 865de7d234f14..ea1f8c1e8920a 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -2,5 +2,5 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} -rm -rf target/ build/ perf.data{,.old} +rm -rf target/ build/ perf.data{,.old} y.bin rm -rf rand/ regex/ simple-raytracer/ portable-simd/ diff --git a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch index 7daea99f5794d..460e42d1d8cc3 100644 --- a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch +++ b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch @@ -13,33 +13,33 @@ index 107762c..2d1ae10 100644 --- a/src/mem/mod.rs +++ b/src/mem/mod.rs @@ -137,10 +137,6 @@ intrinsics! { - pub extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { memcpy_element_unordered_atomic(dest, src, bytes); } - #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { - memcpy_element_unordered_atomic(dest, src, bytes); - } #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { + pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { @@ -158,10 +154,6 @@ intrinsics! { - pub extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { memmove_element_unordered_atomic(dest, src, bytes); } - #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { - memmove_element_unordered_atomic(dest, src, bytes); - } #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { + pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { @@ -179,8 +171,4 @@ intrinsics! { - pub extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { + pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { memset_element_unordered_atomic(s, c, bytes); } - #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { +- pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { - memset_element_unordered_atomic(s, c, bytes); - } } diff --git a/patches/0022-sysroot-Disable-not-compiling-tests.patch b/patches/0022-sysroot-Disable-not-compiling-tests.patch index 25a315f666e27..1c45c7573c813 100644 --- a/patches/0022-sysroot-Disable-not-compiling-tests.patch +++ b/patches/0022-sysroot-Disable-not-compiling-tests.patch @@ -22,7 +22,7 @@ index 0000000..46fd999 +[package] +name = "core" +version = "0.0.0" -+edition = "2018" ++edition = "2021" + +[lib] +name = "coretests" @@ -44,7 +44,7 @@ index 1a6be3a..42dbd59 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -250,6 +250,7 @@ fn test_unsized_nonnull() { - assert!(ys == zs); + }; } +/* diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch index ffee641457ab2..8e6652af3747b 100644 --- a/patches/0027-sysroot-128bit-atomic-operations.patch +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -8,7 +8,6 @@ Cranelift doesn't support them yet library/core/src/panic/unwind_safe.rs | 6 ----- library/core/src/sync/atomic.rs | 38 --------------------------- library/core/tests/atomic.rs | 4 --- - library/std/src/time/monotonic.rs | 6 +++-- 4 files changed, 4 insertions(+), 50 deletions(-) diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs @@ -99,38 +98,6 @@ index b735957..ea728b6 100644 #[cfg(target_has_atomic = "ptr")] assert_eq!(align_of::(), size_of::()); #[cfg(target_has_atomic = "ptr")] -diff --git a/library/std/src/time/monotonic.rs b/library/std/src/time/monotonic.rs -index fa96b7a..2854f9c 100644 ---- a/library/std/src/time/monotonic.rs -+++ b/library/std/src/time/monotonic.rs -@@ -5,7 +5,7 @@ pub(super) fn monotonize(raw: time::Instant) -> time::Instant { - inner::monotonize(raw) - } - --#[cfg(any(all(target_has_atomic = "64", not(target_has_atomic = "128")), target_arch = "aarch64"))] -+#[cfg(target_has_atomic = "64")] - pub mod inner { - use crate::sync::atomic::AtomicU64; - use crate::sync::atomic::Ordering::*; -@@ -70,6 +70,7 @@ pub mod inner { - } - } - -+/* - #[cfg(all(target_has_atomic = "128", not(target_arch = "aarch64")))] - pub mod inner { - use crate::sync::atomic::AtomicU128; -@@ -94,8 +95,9 @@ pub mod inner { - ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap() - } - } -+*/ - --#[cfg(not(any(target_has_atomic = "64", target_has_atomic = "128")))] -+#[cfg(not(target_has_atomic = "64"))] - pub mod inner { - use crate::cmp; - use crate::sys::time; -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index cab94c0b8cfa7..1019b1f069e50 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-12-30" +channel = "nightly-2022-02-23" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 6bcc3049ecc4e..b146ea360376a 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -8,7 +8,7 @@ source ./scripts/setup_rust_fork.sh echo "[TEST] Test suite of rustc" pushd rust -cargo install ripgrep +command -v rg >/dev/null 2>&1 || cargo install ripgrep rm -r src/test/ui/{extern/,panics/,unsized-locals/,lto/,simd*,linkage*,unwind-*.rs} || true for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// needs-asm-support" src/test/ui); do @@ -78,6 +78,8 @@ rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # same rm src/test/ui/match/issue-82392.rs # differing error rm src/test/ui/consts/min_const_fn/address_of_const.rs # same rm src/test/ui/consts/issue-miri-1910.rs # same +rm src/test/ui/generic-associated-types/bugs/issue-80626.rs # same +rm src/test/ui/generic-associated-types/bugs/issue-89008.rs # same rm src/test/ui/type-alias-impl-trait/cross_crate_ice*.rs # requires removed aux dep rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition @@ -98,6 +100,7 @@ rm src/test/ui/abi/stack-protector.rs # requires stack protector support rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code 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 rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM diff --git a/src/allocator.rs b/src/allocator.rs index 637d30f9344f9..82247b47888e7 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -3,7 +3,6 @@ use crate::prelude::*; -use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; /// Returns whether an allocator shim was created @@ -91,9 +90,7 @@ fn codegen_inner( bcx.seal_all_blocks(); bcx.finalize(); } - module - .define_function(func_id, &mut ctx, &mut NullTrapSink {}, &mut NullStackMapSink {}) - .unwrap(); + module.define_function(func_id, &mut ctx).unwrap(); unwind_context.add_function(func_id, &ctx, module.isa()); } @@ -130,8 +127,6 @@ fn codegen_inner( bcx.seal_all_blocks(); bcx.finalize(); } - module - .define_function(func_id, &mut ctx, &mut NullTrapSink {}, &mut NullStackMapSink {}) - .unwrap(); + module.define_function(func_id, &mut ctx).unwrap(); unwind_context.add_function(func_id, &ctx, module.isa()); } diff --git a/src/base.rs b/src/base.rs index 917afa4eae06c..0a6ef6441fa03 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1,13 +1,15 @@ //! Codegen of a single function -use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_ast::InlineAsmOptions; use rustc_index::vec::IndexVec; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::FnAbiOf; +use indexmap::IndexSet; + use crate::constant::ConstantCx; use crate::prelude::*; +use crate::pretty_clif::CommentWriter; pub(crate) fn codegen_fn<'tcx>( cx: &mut crate::CodegenCx<'tcx>, @@ -99,27 +101,54 @@ pub(crate) fn codegen_fn<'tcx>( // Recover all necessary data from fx, before accessing func will prevent future access to it. let instance = fx.instance; - let mut clif_comments = fx.clif_comments; + let clif_comments = fx.clif_comments; let source_info_set = fx.source_info_set; let local_map = fx.local_map; fx.constants_cx.finalize(fx.tcx, &mut *fx.module); - // Store function in context - let context = &mut cx.cached_context; - context.func = func; - crate::pretty_clif::write_clif_file( tcx, "unopt", module.isa(), instance, - &context, + &func, &clif_comments, ); // Verify function - verify_func(tcx, &clif_comments, &context.func); + verify_func(tcx, &clif_comments, &func); + + compile_fn( + cx, + module, + instance, + symbol_name.name, + func_id, + func, + clif_comments, + source_info_set, + local_map, + ); +} + +fn compile_fn<'tcx>( + cx: &mut crate::CodegenCx<'tcx>, + module: &mut dyn Module, + instance: Instance<'tcx>, + symbol_name: &str, + func_id: FuncId, + func: Function, + mut clif_comments: CommentWriter, + source_info_set: IndexSet, + local_map: IndexVec>, +) { + let tcx = cx.tcx; + + // Store function in context + let context = &mut cx.cached_context; + context.clear(); + context.func = func; // If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128` // instruction, which doesn't have an encoding. @@ -145,9 +174,7 @@ pub(crate) fn codegen_fn<'tcx>( // Define function tcx.sess.time("define function", || { context.want_disasm = crate::pretty_clif::should_write_ir(tcx); - module - .define_function(func_id, context, &mut NullTrapSink {}, &mut NullStackMapSink {}) - .unwrap() + module.define_function(func_id, context).unwrap() }); // Write optimized function to file for debugging @@ -156,7 +183,7 @@ pub(crate) fn codegen_fn<'tcx>( "opt", module.isa(), instance, - &context, + &context.func, &clif_comments, ); @@ -177,7 +204,7 @@ pub(crate) fn codegen_fn<'tcx>( debug_context.define_function( instance, func_id, - symbol_name.name, + symbol_name, isa, context, &source_info_set, @@ -186,9 +213,6 @@ pub(crate) fn codegen_fn<'tcx>( } unwind_context.add_function(func_id, &context, isa); }); - - // Clear context to make it usable for the next function - context.clear(); } pub(crate) fn verify_func( diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 046e4393a68d6..2e047c7eea14e 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -56,6 +56,9 @@ fn emit_module( let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name)); let obj = product.object.write().unwrap(); + + tcx.sess.prof.artifact_size("object_file", name.clone(), obj.len().try_into().unwrap()); + if let Err(err) = std::fs::write(&tmp_file, obj) { tcx.sess.fatal(&format!("error writing object file: {}", err)); } diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 309d27090b5cb..9e07528313dd8 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -7,7 +7,6 @@ use std::lazy::SyncOnceCell; use std::os::raw::{c_char, c_int}; use std::sync::{mpsc, Mutex}; -use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_codegen_ssa::CrateInfo; use rustc_middle::mir::mono::MonoItem; use rustc_session::Session; @@ -381,12 +380,5 @@ fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx>, module: &mut JITModule, inst: In let ret_vals = trampoline_builder.func.dfg.inst_results(call_inst).to_vec(); trampoline_builder.ins().return_(&ret_vals); - module - .define_function( - func_id, - &mut cx.cached_context, - &mut NullTrapSink {}, - &mut NullStackMapSink {}, - ) - .unwrap(); + module.define_function(func_id, &mut cx.cached_context).unwrap(); } diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index be3704ca2768e..098862b0662f3 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -8,14 +8,14 @@ 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>], destination: Option<(CPlace<'tcx>, BasicBlock)>, ) { let ret = destination.unwrap().0; intrinsic_match! { - fx, intrinsic, substs, args, + fx, intrinsic, args, _ => { fx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic)); crate::trap::trap_unimplemented(fx, intrinsic); @@ -52,8 +52,8 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( ret.write_cvalue(fx, res); }; "llvm.x86.sse2.cmp.ps" | "llvm.x86.sse2.cmp.pd", (c x, c y, o kind) { - let kind_const = crate::constant::mir_operand_get_const_val(fx, kind).expect("llvm.x86.sse2.cmp.* kind not const"); - let flt_cc = match kind_const.try_to_bits(Size::from_bytes(1)).unwrap_or_else(|| panic!("kind not scalar: {:?}", kind_const)) { + 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, @@ -73,32 +73,30 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( kind => unreachable!("kind {:?}", kind), }; - simd_pair_for_each_lane(fx, x, y, ret, |fx, lane_layout, res_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.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_layout.ty), + _ => unreachable!("{:?}", lane_ty), }; - bool_to_zero_or_max_uint(fx, res_lane_layout, res_lane) + bool_to_zero_or_max_uint(fx, res_lane_ty, res_lane) }); }; "llvm.x86.sse2.psrli.d", (c a, o imm8) { 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_layout, res_lane_layout, lane| { - let res_lane = match imm8.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) { + 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), - }; - CValue::by_val(res_lane, res_lane_layout) + } }); }; "llvm.x86.sse2.pslli.d", (c a, o imm8) { 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_layout, res_lane_layout, lane| { - let res_lane = match imm8.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) { + 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), - }; - CValue::by_val(res_lane, res_lane_layout) + } }); }; "llvm.x86.sse2.storeu.dq", (v mem_addr, c a) { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 42717ad0ae0e1..4dfb13476c287 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -9,7 +9,8 @@ pub(crate) use cpuid::codegen_cpuid_call; pub(crate) use llvm::codegen_llvm_intrinsic_call; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_span::symbol::{kw, sym}; +use rustc_middle::ty::subst::SubstsRef; +use rustc_span::symbol::{kw, sym, Symbol}; use crate::prelude::*; use cranelift_codegen::ir::AtomicRmwOp; @@ -30,116 +31,52 @@ macro intrinsic_pat { } macro intrinsic_arg { - (o $fx:expr, $arg:ident) => { - $arg - }, + (o $fx:expr, $arg:ident) => {}, (c $fx:expr, $arg:ident) => { - codegen_operand($fx, $arg) + let $arg = codegen_operand($fx, $arg); }, (v $fx:expr, $arg:ident) => { - codegen_operand($fx, $arg).load_scalar($fx) - } -} - -macro intrinsic_substs { - ($substs:expr, $index:expr,) => {}, - ($substs:expr, $index:expr, $first:ident $(,$rest:ident)*) => { - let $first = $substs.type_at($index); - intrinsic_substs!($substs, $index+1, $($rest),*); + let $arg = codegen_operand($fx, $arg).load_scalar($fx); } } macro intrinsic_match { - ($fx:expr, $intrinsic:expr, $substs:expr, $args:expr, + ($fx:expr, $intrinsic:expr, $args:expr, _ => $unknown:block; $( - $($($name:tt).*)|+ $(if $cond:expr)?, $(<$($subst:ident),*>)? ($($a:ident $arg:ident),*) $content:block; + $($($name:tt).*)|+ $(if $cond:expr)?, ($($a:ident $arg:ident),*) $content:block; )*) => { - let _ = $substs; // Silence warning when substs is unused. match $intrinsic { $( $(intrinsic_pat!($($name).*))|* $(if $cond)? => { - #[allow(unused_parens, non_snake_case)] - { - $( - intrinsic_substs!($substs, 0, $($subst),*); - )? - if let [$($arg),*] = $args { - let ($($arg,)*) = ( - $(intrinsic_arg!($a $fx, $arg),)* - ); - #[warn(unused_parens, non_snake_case)] - { - $content - } - } else { - bug!("wrong number of args for intrinsic {:?}", $intrinsic); - } - } - } - )* - _ => $unknown, - } - } -} - -macro call_intrinsic_match { - ($fx:expr, $intrinsic:expr, $substs:expr, $ret:expr, $destination:expr, $args:expr, $( - $name:ident($($arg:ident),*) -> $ty:ident => $func:ident, - )*) => { - match $intrinsic { - $( - sym::$name => { - assert!($substs.is_empty()); - if let [$(ref $arg),*] = *$args { - let ($($arg,)*) = ( - $(codegen_operand($fx, $arg),)* - ); - let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty); - $ret.write_cvalue($fx, res); - - if let Some((_, dest)) = $destination { - let ret_block = $fx.get_block(dest); - $fx.bcx.ins().jump(ret_block, &[]); - return; - } else { - unreachable!(); - } + if let [$($arg),*] = $args { + $(intrinsic_arg!($a $fx, $arg);)* + $content } else { bug!("wrong number of args for intrinsic {:?}", $intrinsic); } } )* - _ => {} - } - } -} - -macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) { - match $ty.kind() { - ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} - _ => { - $fx.tcx.sess.span_err( - $span, - &format!( - "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`", - $intrinsic, $ty - ), - ); - // Prevent verifier error - crate::trap::trap_unreachable($fx, "compilation should not have succeeded"); - return; + _ => $unknown, } } } -macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) { - if !$ty.is_simd() { - $fx.tcx.sess.span_err($span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", $intrinsic, $ty)); - // Prevent verifier error - crate::trap::trap_unreachable($fx, "compilation should not have succeeded"); - return; - } +fn report_atomic_type_validation_error<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + intrinsic: Symbol, + span: Span, + ty: Ty<'tcx>, +) { + fx.tcx.sess.span_err( + span, + &format!( + "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`", + intrinsic, ty + ), + ); + // Prevent verifier error + crate::trap::trap_unreachable(fx, "compilation should not have succeeded"); } pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option { @@ -159,12 +96,7 @@ fn simd_for_each_lane<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, val: CValue<'tcx>, ret: CPlace<'tcx>, - f: impl Fn( - &mut FunctionCx<'_, '_, 'tcx>, - TyAndLayout<'tcx>, - TyAndLayout<'tcx>, - Value, - ) -> CValue<'tcx>, + f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value) -> Value, ) { let layout = val.layout(); @@ -177,7 +109,8 @@ fn simd_for_each_lane<'tcx>( for lane_idx in 0..lane_count { let lane = val.value_lane(fx, lane_idx).load_scalar(fx); - let res_lane = f(fx, lane_layout, ret_lane_layout, lane); + let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, lane); + let res_lane = CValue::by_val(res_lane, ret_lane_layout); ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane); } @@ -188,13 +121,7 @@ fn simd_pair_for_each_lane<'tcx>( x: CValue<'tcx>, y: CValue<'tcx>, ret: CPlace<'tcx>, - f: impl Fn( - &mut FunctionCx<'_, '_, 'tcx>, - TyAndLayout<'tcx>, - TyAndLayout<'tcx>, - Value, - Value, - ) -> CValue<'tcx>, + f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value, Value) -> Value, ) { assert_eq!(x.layout(), y.layout()); let layout = x.layout(); @@ -209,7 +136,8 @@ fn simd_pair_for_each_lane<'tcx>( let x_lane = x.value_lane(fx, lane_idx).load_scalar(fx); let y_lane = y.value_lane(fx, lane_idx).load_scalar(fx); - let res_lane = f(fx, lane_layout, ret_lane_layout, x_lane, y_lane); + let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, x_lane, y_lane); + let res_lane = CValue::by_val(res_lane, ret_lane_layout); ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane); } @@ -220,7 +148,7 @@ fn simd_reduce<'tcx>( val: CValue<'tcx>, acc: Option, ret: CPlace<'tcx>, - f: impl Fn(&mut FunctionCx<'_, '_, 'tcx>, TyAndLayout<'tcx>, Value, Value) -> Value, + f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Value, Value) -> Value, ) { let (lane_count, lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx); let lane_layout = fx.layout_of(lane_ty); @@ -230,7 +158,7 @@ fn simd_reduce<'tcx>( if let Some(acc) = acc { (acc, 0) } else { (val.value_lane(fx, 0).load_scalar(fx), 1) }; for lane_idx in start_lane..lane_count { let lane = val.value_lane(fx, lane_idx).load_scalar(fx); - res_val = f(fx, lane_layout, res_val, lane); + res_val = f(fx, lane_layout.ty, res_val, lane); } let res = CValue::by_val(res_val, lane_layout); ret.write_cvalue(fx, res); @@ -241,7 +169,7 @@ fn simd_reduce_bool<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, val: CValue<'tcx>, ret: CPlace<'tcx>, - f: impl Fn(&mut FunctionCx<'_, '_, 'tcx>, Value, Value) -> Value, + f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Value, Value) -> Value, ) { let (lane_count, _lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx); assert!(ret.layout().ty.is_bool()); @@ -264,10 +192,10 @@ fn simd_reduce_bool<'tcx>( fn bool_to_zero_or_max_uint<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - layout: TyAndLayout<'tcx>, + ty: Ty<'tcx>, val: Value, -) -> CValue<'tcx> { - let ty = fx.clif_type(layout.ty).unwrap(); +) -> Value { + let ty = fx.clif_type(ty).unwrap(); let int_ty = match ty { types::F32 => types::I32, @@ -282,122 +210,7 @@ fn bool_to_zero_or_max_uint<'tcx>( res = fx.bcx.ins().bitcast(ty, res); } - CValue::by_val(res, layout) -} - -macro simd_cmp { - ($fx:expr, $cc:ident|$cc_f:ident($x:ident, $y:ident) -> $ret:ident) => { - let vector_ty = clif_vector_type($fx.tcx, $x.layout()); - - if let Some(vector_ty) = vector_ty { - let x = $x.load_scalar($fx); - let y = $y.load_scalar($fx); - let val = if vector_ty.lane_type().is_float() { - $fx.bcx.ins().fcmp(FloatCC::$cc_f, x, y) - } else { - $fx.bcx.ins().icmp(IntCC::$cc, x, y) - }; - - // HACK This depends on the fact that icmp for vectors represents bools as 0 and !0, not 0 and 1. - let val = $fx.bcx.ins().raw_bitcast(vector_ty, val); - - $ret.write_cvalue($fx, CValue::by_val(val, $ret.layout())); - } else { - simd_pair_for_each_lane( - $fx, - $x, - $y, - $ret, - |fx, lane_layout, res_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Uint(_) | ty::Int(_) => fx.bcx.ins().icmp(IntCC::$cc, x_lane, y_lane), - ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::$cc_f, x_lane, y_lane), - _ => unreachable!("{:?}", lane_layout.ty), - }; - bool_to_zero_or_max_uint(fx, res_lane_layout, res_lane) - }, - ); - } - }, - ($fx:expr, $cc_u:ident|$cc_s:ident|$cc_f:ident($x:ident, $y:ident) -> $ret:ident) => { - // FIXME use vector icmp when possible - simd_pair_for_each_lane( - $fx, - $x, - $y, - $ret, - |fx, lane_layout, res_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Uint(_) => fx.bcx.ins().icmp(IntCC::$cc_u, x_lane, y_lane), - ty::Int(_) => fx.bcx.ins().icmp(IntCC::$cc_s, x_lane, y_lane), - ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::$cc_f, x_lane, y_lane), - _ => unreachable!("{:?}", lane_layout.ty), - }; - bool_to_zero_or_max_uint(fx, res_lane_layout, res_lane) - }, - ); - }, -} - -macro simd_int_binop { - ($fx:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) => { - simd_int_binop!($fx, $op|$op($x, $y) -> $ret); - }, - ($fx:expr, $op_u:ident|$op_s:ident($x:ident, $y:ident) -> $ret:ident) => { - simd_pair_for_each_lane( - $fx, - $x, - $y, - $ret, - |fx, lane_layout, ret_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Uint(_) => fx.bcx.ins().$op_u(x_lane, y_lane), - ty::Int(_) => fx.bcx.ins().$op_s(x_lane, y_lane), - _ => unreachable!("{:?}", lane_layout.ty), - }; - CValue::by_val(res_lane, ret_lane_layout) - }, - ); - }, -} - -macro simd_int_flt_binop { - ($fx:expr, $op:ident|$op_f:ident($x:ident, $y:ident) -> $ret:ident) => { - simd_int_flt_binop!($fx, $op|$op|$op_f($x, $y) -> $ret); - }, - ($fx:expr, $op_u:ident|$op_s:ident|$op_f:ident($x:ident, $y:ident) -> $ret:ident) => { - simd_pair_for_each_lane( - $fx, - $x, - $y, - $ret, - |fx, lane_layout, ret_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Uint(_) => fx.bcx.ins().$op_u(x_lane, y_lane), - ty::Int(_) => fx.bcx.ins().$op_s(x_lane, y_lane), - ty::Float(_) => fx.bcx.ins().$op_f(x_lane, y_lane), - _ => unreachable!("{:?}", lane_layout.ty), - }; - CValue::by_val(res_lane, ret_lane_layout) - }, - ); - }, -} - -macro simd_flt_binop($fx:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) { - simd_pair_for_each_lane( - $fx, - $x, - $y, - $ret, - |fx, lane_layout, ret_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Float(_) => fx.bcx.ins().$op(x_lane, y_lane), - _ => unreachable!("{:?}", lane_layout.ty), - }; - CValue::by_val(res_lane, ret_lane_layout) - }, - ); + res } pub(crate) fn codegen_intrinsic_call<'tcx>( @@ -428,59 +241,111 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; if intrinsic.as_str().starts_with("simd_") { - self::simd::codegen_simd_intrinsic_call(fx, instance, args, ret, span); + self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, span); let ret_block = fx.get_block(destination.expect("SIMD intrinsics don't diverge").1); fx.bcx.ins().jump(ret_block, &[]); - return; + } else if codegen_float_intrinsic_call(fx, intrinsic, args, ret) { + let ret_block = fx.get_block(destination.expect("Float intrinsics don't diverge").1); + fx.bcx.ins().jump(ret_block, &[]); + } else { + codegen_regular_intrinsic_call( + fx, + instance, + intrinsic, + substs, + args, + ret, + span, + destination, + ); } +} - let usize_layout = fx.layout_of(fx.tcx.types.usize); +fn codegen_float_intrinsic_call<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + intrinsic: Symbol, + args: &[mir::Operand<'tcx>], + ret: CPlace<'tcx>, +) -> bool { + let (name, arg_count, ty) = match intrinsic { + sym::expf32 => ("expf", 1, fx.tcx.types.f32), + sym::expf64 => ("exp", 1, fx.tcx.types.f64), + sym::exp2f32 => ("exp2f", 1, fx.tcx.types.f32), + sym::exp2f64 => ("exp2", 1, fx.tcx.types.f64), + sym::sqrtf32 => ("sqrtf", 1, fx.tcx.types.f32), + sym::sqrtf64 => ("sqrt", 1, fx.tcx.types.f64), + sym::powif32 => ("__powisf2", 2, fx.tcx.types.f32), // compiler-builtins + sym::powif64 => ("__powidf2", 2, fx.tcx.types.f64), // compiler-builtins + sym::powf32 => ("powf", 2, fx.tcx.types.f32), + sym::powf64 => ("pow", 2, fx.tcx.types.f64), + sym::logf32 => ("logf", 1, fx.tcx.types.f32), + sym::logf64 => ("log", 1, fx.tcx.types.f64), + sym::log2f32 => ("log2f", 1, fx.tcx.types.f32), + sym::log2f64 => ("log2", 1, fx.tcx.types.f64), + sym::log10f32 => ("log10f", 1, fx.tcx.types.f32), + sym::log10f64 => ("log10", 1, fx.tcx.types.f64), + sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32), + sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64), + sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32), + sym::fmaf64 => ("fma", 3, fx.tcx.types.f64), + sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32), + sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64), + sym::floorf32 => ("floorf", 1, fx.tcx.types.f32), + sym::floorf64 => ("floor", 1, fx.tcx.types.f64), + sym::ceilf32 => ("ceilf", 1, fx.tcx.types.f32), + sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64), + sym::truncf32 => ("truncf", 1, fx.tcx.types.f32), + sym::truncf64 => ("trunc", 1, fx.tcx.types.f64), + sym::roundf32 => ("roundf", 1, fx.tcx.types.f32), + sym::roundf64 => ("round", 1, fx.tcx.types.f64), + sym::sinf32 => ("sinf", 1, fx.tcx.types.f32), + sym::sinf64 => ("sin", 1, fx.tcx.types.f64), + sym::cosf32 => ("cosf", 1, fx.tcx.types.f32), + sym::cosf64 => ("cos", 1, fx.tcx.types.f64), + _ => return false, + }; - call_intrinsic_match! { - fx, intrinsic, substs, ret, destination, args, - expf32(flt) -> f32 => expf, - expf64(flt) -> f64 => exp, - exp2f32(flt) -> f32 => exp2f, - exp2f64(flt) -> f64 => exp2, - sqrtf32(flt) -> f32 => sqrtf, - sqrtf64(flt) -> f64 => sqrt, - powif32(a, x) -> f32 => __powisf2, // compiler-builtins - powif64(a, x) -> f64 => __powidf2, // compiler-builtins - powf32(a, x) -> f32 => powf, - powf64(a, x) -> f64 => pow, - logf32(flt) -> f32 => logf, - logf64(flt) -> f64 => log, - log2f32(flt) -> f32 => log2f, - log2f64(flt) -> f64 => log2, - log10f32(flt) -> f32 => log10f, - log10f64(flt) -> f64 => log10, - fabsf32(flt) -> f32 => fabsf, - fabsf64(flt) -> f64 => fabs, - fmaf32(x, y, z) -> f32 => fmaf, - fmaf64(x, y, z) -> f64 => fma, - copysignf32(x, y) -> f32 => copysignf, - copysignf64(x, y) -> f64 => copysign, - - // rounding variants - // FIXME use clif insts - floorf32(flt) -> f32 => floorf, - floorf64(flt) -> f64 => floor, - ceilf32(flt) -> f32 => ceilf, - ceilf64(flt) -> f64 => ceil, - truncf32(flt) -> f32 => truncf, - truncf64(flt) -> f64 => trunc, - roundf32(flt) -> f32 => roundf, - roundf64(flt) -> f64 => round, - - // trigonometry - sinf32(flt) -> f32 => sinf, - sinf64(flt) -> f64 => sin, - cosf32(flt) -> f32 => cosf, - cosf64(flt) -> f64 => cos, + if args.len() != arg_count { + bug!("wrong number of args for intrinsic {:?}", intrinsic); } + let (a, b, c); + let args = match args { + [x] => { + a = [codegen_operand(fx, x)]; + &a as &[_] + } + [x, y] => { + b = [codegen_operand(fx, x), codegen_operand(fx, y)]; + &b + } + [x, y, z] => { + c = [codegen_operand(fx, x), codegen_operand(fx, y), codegen_operand(fx, z)]; + &c + } + _ => unreachable!(), + }; + + let res = fx.easy_call(name, &args, ty); + ret.write_cvalue(fx, res); + + true +} + +fn codegen_regular_intrinsic_call<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + instance: Instance<'tcx>, + intrinsic: Symbol, + substs: SubstsRef<'tcx>, + args: &[mir::Operand<'tcx>], + ret: CPlace<'tcx>, + span: Span, + destination: Option<(CPlace<'tcx>, BasicBlock)>, +) { + let usize_layout = fx.layout_of(fx.tcx.types.usize); + intrinsic_match! { - fx, intrinsic, substs, args, + fx, intrinsic, args, _ => { fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic)); }; @@ -492,7 +357,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( breakpoint, () { fx.bcx.ins().debugtrap(); }; - copy | copy_nonoverlapping, (v src, v dst, v count) { + copy | copy_nonoverlapping, (v src, v dst, v count) { + let elem_ty = substs.type_at(0); let elem_size: u64 = fx.layout_of(elem_ty).size.bytes(); assert_eq!(args.len(), 3); let byte_amount = if elem_size != 1 { @@ -510,7 +376,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( } }; // NOTE: the volatile variants have src and dst swapped - volatile_copy_memory | volatile_copy_nonoverlapping_memory, (v dst, v src, v count) { + volatile_copy_memory | volatile_copy_nonoverlapping_memory, (v dst, v src, v count) { + let elem_ty = substs.type_at(0); let elem_size: u64 = fx.layout_of(elem_ty).size.bytes(); assert_eq!(args.len(), 3); let byte_amount = if elem_size != 1 { @@ -528,8 +395,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount); } }; - size_of_val, (c ptr) { - let layout = fx.layout_of(T); + size_of_val, (c ptr) { + let layout = fx.layout_of(substs.type_at(0)); let size = if layout.is_unsized() { let (_ptr, info) = ptr.load_scalar_pair(fx); let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout, info); @@ -542,8 +409,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; ret.write_cvalue(fx, CValue::by_val(size, usize_layout)); }; - min_align_of_val, (c ptr) { - let layout = fx.layout_of(T); + min_align_of_val, (c ptr) { + let layout = fx.layout_of(substs.type_at(0)); let align = if layout.is_unsized() { let (_ptr, info) = ptr.load_scalar_pair(fx); let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout, info); @@ -557,12 +424,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ret.write_cvalue(fx, CValue::by_val(align, usize_layout)); }; - unchecked_add | unchecked_sub | unchecked_div | exact_div | unchecked_rem + unchecked_add | unchecked_sub | unchecked_mul | unchecked_div | exact_div | unchecked_rem | unchecked_shl | unchecked_shr, (c x, c y) { // FIXME trap on overflow let bin_op = match intrinsic { sym::unchecked_add => BinOp::Add, sym::unchecked_sub => BinOp::Sub, + sym::unchecked_mul => BinOp::Mul, sym::unchecked_div | sym::exact_div => BinOp::Div, sym::unchecked_rem => BinOp::Rem, sym::unchecked_shl => BinOp::Shl, @@ -589,7 +457,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ); ret.write_cvalue(fx, res); }; - saturating_add | saturating_sub, (c lhs, c rhs) { + saturating_add | saturating_sub, (c lhs, c rhs) { assert_eq!(lhs.layout().ty, rhs.layout().ty); let bin_op = match intrinsic { sym::saturating_add => BinOp::Add, @@ -597,7 +465,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( _ => unreachable!(), }; - let signed = type_sign(T); + let signed = type_sign(lhs.layout().ty); let checked_res = crate::num::codegen_checked_int_binop( fx, @@ -607,7 +475,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ); let (val, has_overflow) = checked_res.load_scalar_pair(fx); - let clif_ty = fx.clif_type(T).unwrap(); + let clif_ty = fx.clif_type(lhs.layout().ty).unwrap(); let (min, max) = type_min_max_value(&mut fx.bcx, clif_ty, signed); @@ -629,17 +497,19 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( _ => unreachable!(), }; - let res = CValue::by_val(val, fx.layout_of(T)); + let res = CValue::by_val(val, lhs.layout()); ret.write_cvalue(fx, res); }; - rotate_left, (v x, v y) { - let layout = fx.layout_of(T); + rotate_left, (c x, v y) { + let layout = x.layout(); + let x = x.load_scalar(fx); let res = fx.bcx.ins().rotl(x, y); ret.write_cvalue(fx, CValue::by_val(res, layout)); }; - rotate_right, (v x, v y) { - let layout = fx.layout_of(T); + rotate_right, (c x, v y) { + let layout = x.layout(); + let x = x.load_scalar(fx); let res = fx.bcx.ins().rotr(x, y); ret.write_cvalue(fx, CValue::by_val(res, layout)); }; @@ -675,29 +545,33 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( // FIXME use emit_small_memset fx.bcx.call_memset(fx.target_config, dst_ptr, val, count); }; - ctlz | ctlz_nonzero, (v arg) { + ctlz | ctlz_nonzero, (c arg) { + let val = arg.load_scalar(fx); // FIXME trap on `ctlz_nonzero` with zero arg. - let res = fx.bcx.ins().clz(arg); - let res = CValue::by_val(res, fx.layout_of(T)); + let res = fx.bcx.ins().clz(val); + let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); }; - cttz | cttz_nonzero, (v arg) { + cttz | cttz_nonzero, (c arg) { + let val = arg.load_scalar(fx); // FIXME trap on `cttz_nonzero` with zero arg. - let res = fx.bcx.ins().ctz(arg); - let res = CValue::by_val(res, fx.layout_of(T)); + let res = fx.bcx.ins().ctz(val); + let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); }; - ctpop, (v arg) { - let res = fx.bcx.ins().popcnt(arg); - let res = CValue::by_val(res, fx.layout_of(T)); + ctpop, (c arg) { + let val = arg.load_scalar(fx); + let res = fx.bcx.ins().popcnt(val); + let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); }; - bitreverse, (v arg) { - let res = fx.bcx.ins().bitrev(arg); - let res = CValue::by_val(res, fx.layout_of(T)); + bitreverse, (c arg) { + let val = arg.load_scalar(fx); + let res = fx.bcx.ins().bitrev(val); + let res = CValue::by_val(res, arg.layout()); ret.write_cvalue(fx, res); }; - bswap, (v arg) { + bswap, (c arg) { // FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift fn swap(bcx: &mut FunctionBuilder<'_>, v: Value) -> Value { match bcx.func.dfg.value_type(v) { @@ -773,16 +647,17 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ty => unreachable!("bswap {}", ty), } } - let res = CValue::by_val(swap(&mut fx.bcx, arg), fx.layout_of(T)); + let val = arg.load_scalar(fx); + let res = CValue::by_val(swap(&mut fx.bcx, val), arg.layout()); ret.write_cvalue(fx, res); }; - assert_inhabited | assert_zero_valid | assert_uninit_valid, () { - let layout = fx.layout_of(T); + assert_inhabited | assert_zero_valid | assert_uninit_valid, () { + let layout = fx.layout_of(substs.type_at(0)); if layout.abi.is_uninhabited() { with_no_trimmed_paths!({ crate::base::codegen_panic( fx, - &format!("attempted to instantiate uninhabited type `{}`", T), + &format!("attempted to instantiate uninhabited type `{}`", layout.ty), span, ) }); @@ -793,7 +668,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( with_no_trimmed_paths!({ crate::base::codegen_panic( fx, - &format!("attempted to zero-initialize type `{}`, which is invalid", T), + &format!("attempted to zero-initialize type `{}`, which is invalid", layout.ty), span, ); }); @@ -804,7 +679,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( with_no_trimmed_paths!({ crate::base::codegen_panic( fx, - &format!("attempted to leave type `{}` uninitialized, which is invalid", T), + &format!("attempted to leave type `{}` uninitialized, which is invalid", layout.ty), span, ) }); @@ -838,10 +713,11 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ret.write_cvalue(fx, val); }; - ptr_offset_from, (v ptr, v base) { + ptr_offset_from, (v ptr, v base) { + let ty = substs.type_at(0); let isize_layout = fx.layout_of(fx.tcx.types.isize); - let pointee_size: u64 = fx.layout_of(T).size.bytes(); + let pointee_size: u64 = fx.layout_of(ty).size.bytes(); let diff = fx.bcx.ins().isub(ptr, base); // FIXME this can be an exact division. let val = CValue::by_val(fx.bcx.ins().sdiv_imm(diff, pointee_size as i64), isize_layout); @@ -870,17 +746,31 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( // FIXME use a compiler fence once Cranelift supports it fx.bcx.ins().fence(); }; - _ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) { - validate_atomic_type!(fx, intrinsic, span, T); - let ty = fx.clif_type(T).unwrap(); + _ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) { + let ty = substs.type_at(0); + match ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, ty); + return; + } + } + let clif_ty = fx.clif_type(ty).unwrap(); - let val = fx.bcx.ins().atomic_load(ty, MemFlags::trusted(), ptr); + let val = fx.bcx.ins().atomic_load(clif_ty, MemFlags::trusted(), ptr); - let val = CValue::by_val(val, fx.layout_of(T)); + let val = CValue::by_val(val, fx.layout_of(ty)); ret.write_cvalue(fx, val); }; _ if intrinsic.as_str().starts_with("atomic_store"), (v ptr, c val) { - validate_atomic_type!(fx, intrinsic, span, val.layout().ty); + let ty = substs.type_at(0); + match ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, ty); + return; + } + } let val = val.load_scalar(fx); @@ -888,7 +778,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_xchg"), (v ptr, c new) { let layout = new.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let new = new.load_scalar(fx); @@ -900,7 +796,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_cxchg"), (v ptr, c test_old, c new) { // both atomic_cxchg_* and atomic_cxchgweak_* let layout = new.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let test_old = test_old.load_scalar(fx); let new = new.load_scalar(fx); @@ -914,7 +816,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( _ if intrinsic.as_str().starts_with("atomic_xadd"), (v ptr, c amount) { let layout = amount.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let amount = amount.load_scalar(fx); @@ -926,7 +834,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_xsub"), (v ptr, c amount) { let layout = amount.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let amount = amount.load_scalar(fx); @@ -938,7 +852,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_and"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -950,7 +870,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_or"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -962,7 +888,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_xor"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -974,7 +906,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_nand"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -986,7 +924,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_max"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -998,7 +942,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_umax"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -1010,7 +960,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_min"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -1022,7 +978,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; _ if intrinsic.as_str().starts_with("atomic_umin"), (v ptr, c src) { let layout = src.layout(); - validate_atomic_type!(fx, intrinsic, span, layout.ty); + match layout.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} + _ => { + report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + return; + } + } let ty = fx.clif_type(layout.ty).unwrap(); let src = src.load_scalar(fx); @@ -1107,18 +1069,14 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ret.write_cvalue(fx, CValue::by_val(res, ret.layout())); }; - raw_eq, (v lhs_ref, v rhs_ref) { - fn type_by_size(size: Size) -> Option { - Type::int(size.bits().try_into().ok()?) - } - - let size = fx.layout_of(T).layout.size; + raw_eq, (v lhs_ref, v rhs_ref) { + let size = fx.layout_of(substs.type_at(0)).layout.size; // FIXME add and use emit_small_memcmp let is_eq_value = if size == Size::ZERO { // No bytes means they're trivially equal fx.bcx.ins().iconst(types::I8, 1) - } else if let Some(clty) = type_by_size(size) { + } else if let Some(clty) = size.bits().try_into().ok().and_then(Type::int) { // Can't use `trusted` for these loads; they could be unaligned. let mut flags = MemFlags::new(); flags.set_notrap(); @@ -1141,6 +1099,16 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout())); }; + const_allocate, (c _size, c _align) { + // returns a null pointer at runtime. + let null = fx.bcx.ins().iconst(fx.pointer_type, 0); + ret.write_cvalue(fx, CValue::by_val(null, ret.layout())); + }; + + const_deallocate, (c _ptr, c _size, c _align) { + // nop at runtime. + }; + black_box, (c a) { // FIXME implement black_box semantics ret.write_cvalue(fx, a); diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 6c0631d9ecbd0..4153bc08e8ad4 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -1,71 +1,116 @@ //! Codegen `extern "platform-intrinsic"` intrinsics. +use rustc_middle::ty::subst::SubstsRef; +use rustc_span::Symbol; + use super::*; use crate::prelude::*; +fn report_simd_type_validation_error( + fx: &mut FunctionCx<'_, '_, '_>, + intrinsic: Symbol, + span: Span, + ty: Ty<'_>, +) { + fx.tcx.sess.span_err(span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty)); + // Prevent verifier error + crate::trap::trap_unreachable(fx, "compilation should not have succeeded"); +} + pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - instance: Instance<'tcx>, + intrinsic: Symbol, + _substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], ret: CPlace<'tcx>, span: Span, ) { - let def_id = instance.def_id(); - let substs = instance.substs; - - let intrinsic = fx.tcx.item_name(def_id); - intrinsic_match! { - fx, intrinsic, substs, args, + fx, intrinsic, args, _ => { fx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic)); }; simd_cast, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, lane_layout, ret_lane_layout, lane| { - let ret_lane_ty = fx.clif_type(ret_lane_layout.ty).unwrap(); + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_for_each_lane(fx, a, ret, &|fx, lane_ty, ret_lane_ty, lane| { + let ret_lane_clif_ty = fx.clif_type(ret_lane_ty).unwrap(); - let from_signed = type_sign(lane_layout.ty); - let to_signed = type_sign(ret_lane_layout.ty); + let from_signed = type_sign(lane_ty); + let to_signed = type_sign(ret_lane_ty); - let ret_lane = clif_int_or_float_cast(fx, lane, from_signed, ret_lane_ty, to_signed); - CValue::by_val(ret_lane, ret_lane_layout) + clif_int_or_float_cast(fx, lane, from_signed, ret_lane_clif_ty, to_signed) }); }; - simd_eq, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!(fx, Equal|Equal(x, y) -> ret); - }; - simd_ne, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!(fx, NotEqual|NotEqual(x, y) -> ret); - }; - simd_lt, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!(fx, UnsignedLessThan|SignedLessThan|LessThan(x, y) -> ret); - }; - simd_le, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!(fx, UnsignedLessThanOrEqual|SignedLessThanOrEqual|LessThanOrEqual(x, y) -> ret); - }; - simd_gt, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!(fx, UnsignedGreaterThan|SignedGreaterThan|GreaterThan(x, y) -> ret); - }; - simd_ge, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_cmp!( - fx, - UnsignedGreaterThanOrEqual|SignedGreaterThanOrEqual|GreaterThanOrEqual - (x, y) -> ret - ); + simd_eq | simd_ne | simd_lt | simd_le | simd_gt | simd_ge, (c x, c y) { + if !x.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty); + return; + } + + // FIXME use vector instructions when possible + 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(), intrinsic) { + (ty::Uint(_), sym::simd_eq) => fx.bcx.ins().icmp(IntCC::Equal, x_lane, y_lane), + (ty::Uint(_), sym::simd_ne) => fx.bcx.ins().icmp(IntCC::NotEqual, x_lane, y_lane), + (ty::Uint(_), sym::simd_lt) => { + fx.bcx.ins().icmp(IntCC::UnsignedLessThan, x_lane, y_lane) + } + (ty::Uint(_), sym::simd_le) => { + fx.bcx.ins().icmp(IntCC::UnsignedLessThanOrEqual, x_lane, y_lane) + } + (ty::Uint(_), sym::simd_gt) => { + fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, x_lane, y_lane) + } + (ty::Uint(_), sym::simd_ge) => { + fx.bcx.ins().icmp(IntCC::UnsignedGreaterThanOrEqual, x_lane, y_lane) + } + + (ty::Int(_), sym::simd_eq) => fx.bcx.ins().icmp(IntCC::Equal, x_lane, y_lane), + (ty::Int(_), sym::simd_ne) => fx.bcx.ins().icmp(IntCC::NotEqual, x_lane, y_lane), + (ty::Int(_), sym::simd_lt) => fx.bcx.ins().icmp(IntCC::SignedLessThan, x_lane, y_lane), + (ty::Int(_), sym::simd_le) => { + fx.bcx.ins().icmp(IntCC::SignedLessThanOrEqual, x_lane, y_lane) + } + (ty::Int(_), sym::simd_gt) => { + fx.bcx.ins().icmp(IntCC::SignedGreaterThan, x_lane, y_lane) + } + (ty::Int(_), sym::simd_ge) => { + fx.bcx.ins().icmp(IntCC::SignedGreaterThanOrEqual, x_lane, y_lane) + } + + (ty::Float(_), sym::simd_eq) => fx.bcx.ins().fcmp(FloatCC::Equal, x_lane, y_lane), + (ty::Float(_), sym::simd_ne) => fx.bcx.ins().fcmp(FloatCC::NotEqual, x_lane, y_lane), + (ty::Float(_), sym::simd_lt) => fx.bcx.ins().fcmp(FloatCC::LessThan, x_lane, y_lane), + (ty::Float(_), sym::simd_le) => { + fx.bcx.ins().fcmp(FloatCC::LessThanOrEqual, x_lane, y_lane) + } + (ty::Float(_), sym::simd_gt) => fx.bcx.ins().fcmp(FloatCC::GreaterThan, x_lane, y_lane), + (ty::Float(_), sym::simd_ge) => { + fx.bcx.ins().fcmp(FloatCC::GreaterThanOrEqual, x_lane, y_lane) + } + + _ => 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) + }); }; // simd_shuffle32(x: T, y: T, idx: [u32; 32]) -> U _ if intrinsic.as_str().starts_with("simd_shuffle"), (c x, c y, o idx) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); + if !x.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty); + return; + } // If this intrinsic is the older "simd_shuffleN" form, simply parse the integer. // If there is no suffix, use the index array length. @@ -167,7 +212,11 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_extract, (c v, o idx) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) { idx_const } else { @@ -195,95 +244,82 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_neg, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, lane_layout, ret_lane_layout, lane| { - let ret_lane = match lane_layout.ty.kind() { + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_for_each_lane(fx, a, ret, &|fx, lane_ty, _ret_lane_ty, lane| { + match lane_ty.kind() { ty::Int(_) => fx.bcx.ins().ineg(lane), ty::Float(_) => fx.bcx.ins().fneg(lane), _ => unreachable!(), - }; - CValue::by_val(ret_lane, ret_lane_layout) + } }); }; - simd_fabs, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, _lane_layout, ret_lane_layout, lane| { - let ret_lane = fx.bcx.ins().fabs(lane); - CValue::by_val(ret_lane, ret_lane_layout) - }); - }; + simd_add | simd_sub | simd_mul | simd_div | simd_rem + | simd_shl | simd_shr | simd_and | simd_or | simd_xor, (c x, c y) { + if !x.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty); + return; + } - simd_fsqrt, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, _lane_layout, ret_lane_layout, lane| { - let ret_lane = fx.bcx.ins().sqrt(lane); - CValue::by_val(ret_lane, ret_lane_layout) + // FIXME use vector instructions when possible + simd_pair_for_each_lane(fx, x, y, ret, &|fx, lane_ty, _ret_lane_ty, x_lane, y_lane| match ( + lane_ty.kind(), + intrinsic, + ) { + (ty::Uint(_), sym::simd_add) => fx.bcx.ins().iadd(x_lane, y_lane), + (ty::Uint(_), sym::simd_sub) => fx.bcx.ins().isub(x_lane, y_lane), + (ty::Uint(_), sym::simd_mul) => fx.bcx.ins().imul(x_lane, y_lane), + (ty::Uint(_), sym::simd_div) => fx.bcx.ins().udiv(x_lane, y_lane), + (ty::Uint(_), sym::simd_rem) => fx.bcx.ins().urem(x_lane, y_lane), + + (ty::Int(_), sym::simd_add) => fx.bcx.ins().iadd(x_lane, y_lane), + (ty::Int(_), sym::simd_sub) => fx.bcx.ins().isub(x_lane, y_lane), + (ty::Int(_), sym::simd_mul) => fx.bcx.ins().imul(x_lane, y_lane), + (ty::Int(_), sym::simd_div) => fx.bcx.ins().sdiv(x_lane, y_lane), + (ty::Int(_), sym::simd_rem) => fx.bcx.ins().srem(x_lane, y_lane), + + (ty::Float(_), sym::simd_add) => fx.bcx.ins().fadd(x_lane, y_lane), + (ty::Float(_), sym::simd_sub) => fx.bcx.ins().fsub(x_lane, y_lane), + (ty::Float(_), sym::simd_mul) => fx.bcx.ins().fmul(x_lane, y_lane), + (ty::Float(_), sym::simd_div) => fx.bcx.ins().fdiv(x_lane, y_lane), + (ty::Float(FloatTy::F32), sym::simd_rem) => fx.lib_call( + "fmodf", + vec![AbiParam::new(types::F32), AbiParam::new(types::F32)], + vec![AbiParam::new(types::F32)], + &[x_lane, y_lane], + )[0], + (ty::Float(FloatTy::F64), sym::simd_rem) => fx.lib_call( + "fmod", + vec![AbiParam::new(types::F64), AbiParam::new(types::F64)], + vec![AbiParam::new(types::F64)], + &[x_lane, y_lane], + )[0], + + (ty::Uint(_), sym::simd_shl) => fx.bcx.ins().ishl(x_lane, y_lane), + (ty::Uint(_), sym::simd_shr) => fx.bcx.ins().ushr(x_lane, y_lane), + (ty::Uint(_), sym::simd_and) => fx.bcx.ins().band(x_lane, y_lane), + (ty::Uint(_), sym::simd_or) => fx.bcx.ins().bor(x_lane, y_lane), + (ty::Uint(_), sym::simd_xor) => fx.bcx.ins().bxor(x_lane, y_lane), + + (ty::Int(_), sym::simd_shl) => fx.bcx.ins().ishl(x_lane, y_lane), + (ty::Int(_), sym::simd_shr) => fx.bcx.ins().sshr(x_lane, y_lane), + (ty::Int(_), sym::simd_and) => fx.bcx.ins().band(x_lane, y_lane), + (ty::Int(_), sym::simd_or) => fx.bcx.ins().bor(x_lane, y_lane), + (ty::Int(_), sym::simd_xor) => fx.bcx.ins().bxor(x_lane, y_lane), + + _ => unreachable!(), }); }; - simd_add, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_flt_binop!(fx, iadd|fadd(x, y) -> ret); - }; - simd_sub, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_flt_binop!(fx, isub|fsub(x, y) -> ret); - }; - simd_mul, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_flt_binop!(fx, imul|fmul(x, y) -> ret); - }; - simd_div, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_flt_binop!(fx, udiv|sdiv|fdiv(x, y) -> ret); - }; - simd_rem, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_pair_for_each_lane(fx, x, y, ret, |fx, lane_layout, ret_lane_layout, x_lane, y_lane| { - let res_lane = match lane_layout.ty.kind() { - ty::Uint(_) => fx.bcx.ins().urem(x_lane, y_lane), - ty::Int(_) => fx.bcx.ins().srem(x_lane, y_lane), - ty::Float(FloatTy::F32) => fx.lib_call( - "fmodf", - vec![AbiParam::new(types::F32), AbiParam::new(types::F32)], - vec![AbiParam::new(types::F32)], - &[x_lane, y_lane], - )[0], - ty::Float(FloatTy::F64) => fx.lib_call( - "fmod", - vec![AbiParam::new(types::F64), AbiParam::new(types::F64)], - vec![AbiParam::new(types::F64)], - &[x_lane, y_lane], - )[0], - _ => unreachable!("{:?}", lane_layout.ty), - }; - CValue::by_val(res_lane, ret_lane_layout) - }); - }; - simd_shl, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_binop!(fx, ishl(x, y) -> ret); - }; - simd_shr, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_binop!(fx, ushr|sshr(x, y) -> ret); - }; - simd_and, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_binop!(fx, band(x, y) -> ret); - }; - simd_or, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_binop!(fx, bor(x, y) -> ret); - }; - simd_xor, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_int_binop!(fx, bxor(x, y) -> ret); - }; - simd_fma, (c a, c b, c c) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } assert_eq!(a.layout(), b.layout()); assert_eq!(a.layout(), c.layout()); let layout = a.layout(); @@ -305,19 +341,34 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( } }; - simd_fmin, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_flt_binop!(fx, fmin(x, y) -> ret); - }; - simd_fmax, (c x, c y) { - validate_simd_type!(fx, intrinsic, span, x.layout().ty); - simd_flt_binop!(fx, fmax(x, y) -> ret); + simd_fmin | simd_fmax, (c x, c y) { + if !x.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty); + return; + } + + // FIXME use vector instructions when possible + simd_pair_for_each_lane(fx, x, y, ret, &|fx, lane_ty, _ret_lane_ty, x_lane, y_lane| { + match lane_ty.kind() { + ty::Float(_) => {}, + _ => unreachable!("{:?}", lane_ty), + } + match intrinsic { + sym::simd_fmin => fx.bcx.ins().fmin(x_lane, y_lane), + sym::simd_fmax => fx.bcx.ins().fmax(x_lane, y_lane), + _ => unreachable!(), + } + }); }; simd_round, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, lane_layout, ret_lane_layout, lane| { - let res_lane = match lane_layout.ty.kind() { + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_for_each_lane(fx, a, ret, &|fx, lane_ty, _ret_lane_ty, lane| { + match lane_ty.kind() { ty::Float(FloatTy::F32) => fx.lib_call( "roundf", vec![AbiParam::new(types::F32)], @@ -330,37 +381,41 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( vec![AbiParam::new(types::F64)], &[lane], )[0], - _ => unreachable!("{:?}", lane_layout.ty), - }; - CValue::by_val(res_lane, ret_lane_layout) - }); - }; - simd_ceil, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, _lane_layout, ret_lane_layout, lane| { - let ret_lane = fx.bcx.ins().ceil(lane); - CValue::by_val(ret_lane, ret_lane_layout) - }); - }; - simd_floor, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, _lane_layout, ret_lane_layout, lane| { - let ret_lane = fx.bcx.ins().floor(lane); - CValue::by_val(ret_lane, ret_lane_layout) + _ => unreachable!("{:?}", lane_ty), + } }); }; - simd_trunc, (c a) { - validate_simd_type!(fx, intrinsic, span, a.layout().ty); - simd_for_each_lane(fx, a, ret, |fx, _lane_layout, ret_lane_layout, lane| { - let ret_lane = fx.bcx.ins().trunc(lane); - CValue::by_val(ret_lane, ret_lane_layout) + + simd_fabs | simd_fsqrt | simd_ceil | simd_floor | simd_trunc, (c a) { + if !a.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty); + return; + } + + simd_for_each_lane(fx, a, ret, &|fx, lane_ty, _ret_lane_ty, lane| { + match lane_ty.kind() { + ty::Float(_) => {}, + _ => unreachable!("{:?}", lane_ty), + } + match intrinsic { + sym::simd_fabs => fx.bcx.ins().fabs(lane), + sym::simd_fsqrt => fx.bcx.ins().sqrt(lane), + sym::simd_ceil => fx.bcx.ins().ceil(lane), + sym::simd_floor => fx.bcx.ins().floor(lane), + sym::simd_trunc => fx.bcx.ins().trunc(lane), + _ => unreachable!(), + } }); }; simd_reduce_add_ordered | simd_reduce_add_unordered, (c v, v acc) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, Some(acc), ret, |fx, lane_layout, a, b| { - if lane_layout.ty.is_floating_point() { + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, Some(acc), ret, &|fx, lane_ty, a, b| { + if lane_ty.is_floating_point() { fx.bcx.ins().fadd(a, b) } else { fx.bcx.ins().iadd(a, b) @@ -369,9 +424,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_mul_ordered | simd_reduce_mul_unordered, (c v, v acc) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, Some(acc), ret, |fx, lane_layout, a, b| { - if lane_layout.ty.is_floating_point() { + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, Some(acc), ret, &|fx, lane_ty, a, b| { + if lane_ty.is_floating_point() { fx.bcx.ins().fmul(a, b) } else { fx.bcx.ins().imul(a, b) @@ -380,34 +439,58 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_all, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce_bool(fx, v, ret, |fx, a, b| fx.bcx.ins().band(a, b)); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce_bool(fx, v, ret, &|fx, a, b| fx.bcx.ins().band(a, b)); }; simd_reduce_any, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce_bool(fx, v, ret, |fx, a, b| fx.bcx.ins().bor(a, b)); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce_bool(fx, v, ret, &|fx, a, b| fx.bcx.ins().bor(a, b)); }; simd_reduce_and, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, None, ret, |fx, _layout, a, b| fx.bcx.ins().band(a, b)); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| fx.bcx.ins().band(a, b)); }; simd_reduce_or, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, None, ret, |fx, _layout, a, b| fx.bcx.ins().bor(a, b)); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| fx.bcx.ins().bor(a, b)); }; simd_reduce_xor, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, None, ret, |fx, _layout, a, b| fx.bcx.ins().bxor(a, b)); + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| fx.bcx.ins().bxor(a, b)); }; simd_reduce_min, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, None, ret, |fx, layout, a, b| { - let lt = match layout.ty.kind() { + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, ty, a, b| { + let lt = match ty.kind() { ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedLessThan, a, b), ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedLessThan, a, b), ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::LessThan, a, b), @@ -418,9 +501,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_max, (c v) { - validate_simd_type!(fx, intrinsic, span, v.layout().ty); - simd_reduce(fx, v, None, ret, |fx, layout, a, b| { - let gt = match layout.ty.kind() { + if !v.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); + return; + } + + simd_reduce(fx, v, None, ret, &|fx, ty, a, b| { + let gt = match ty.kind() { ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedGreaterThan, a, b), ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, a, b), ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::GreaterThan, a, b), @@ -431,8 +518,14 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_select, (c m, c a, c b) { - validate_simd_type!(fx, intrinsic, span, m.layout().ty); - validate_simd_type!(fx, intrinsic, span, a.layout().ty); + if !m.layout().ty.is_simd() { + report_simd_type_validation_error(fx, intrinsic, span, m.layout().ty); + return; + } + 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); diff --git a/src/main_shim.rs b/src/main_shim.rs index 8fd1e4f5811f5..9ce727279c27c 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -1,4 +1,3 @@ -use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_hir::LangItem; use rustc_middle::ty::subst::GenericArg; use rustc_middle::ty::AssocKind; @@ -152,8 +151,7 @@ pub(crate) fn maybe_create_entry_wrapper( bcx.seal_all_blocks(); bcx.finalize(); } - m.define_function(cmain_func_id, &mut ctx, &mut NullTrapSink {}, &mut NullStackMapSink {}) - .unwrap(); + m.define_function(cmain_func_id, &mut ctx).unwrap(); unwind_context.add_function(cmain_func_id, &ctx, m.isa()); } } diff --git a/src/optimize/mod.rs b/src/optimize/mod.rs index 61033d85a1274..d1f89adb3bb91 100644 --- a/src/optimize/mod.rs +++ b/src/optimize/mod.rs @@ -15,6 +15,6 @@ pub(crate) fn optimize_function<'tcx>( ) { // FIXME classify optimizations over opt levels once we have more - crate::pretty_clif::write_clif_file(tcx, "preopt", isa, instance, &ctx, &*clif_comments); + crate::pretty_clif::write_clif_file(tcx, "preopt", isa, instance, &ctx.func, &*clif_comments); crate::base::verify_func(tcx, &*clif_comments, &ctx.func); } diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 4dffb89e10570..ca7116b887d5a 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -234,7 +234,7 @@ pub(crate) fn write_clif_file<'tcx>( postfix: &str, isa: &dyn cranelift_codegen::isa::TargetIsa, instance: Instance<'tcx>, - context: &cranelift_codegen::Context, + func: &cranelift_codegen::ir::Function, mut clif_comments: &CommentWriter, ) { write_ir_file( @@ -242,12 +242,8 @@ pub(crate) fn write_clif_file<'tcx>( || format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix), |file| { let mut clif = String::new(); - cranelift_codegen::write::decorate_function( - &mut clif_comments, - &mut clif, - &context.func, - ) - .unwrap(); + cranelift_codegen::write::decorate_function(&mut clif_comments, &mut clif, func) + .unwrap(); for flag in isa.flags().iter() { writeln!(file, "set {}", flag)?; diff --git a/y.rs b/y.rs index 98b114de91078..18528d5429729 100755 --- a/y.rs +++ b/y.rs @@ -23,136 +23,9 @@ exec ${0/.rs/.bin} $@ //! //! The name `y.rs` was chosen to not conflict with rustc's `x.py`. -use std::env; -use std::path::PathBuf; -use std::process; - -#[path = "build_system/build_backend.rs"] -mod build_backend; -#[path = "build_system/build_sysroot.rs"] -mod build_sysroot; -#[path = "build_system/config.rs"] -mod config; -#[path = "build_system/prepare.rs"] -mod prepare; -#[path = "build_system/rustc_info.rs"] -mod rustc_info; -#[path = "build_system/utils.rs"] -mod utils; - -fn usage() { - eprintln!("Usage:"); - eprintln!(" ./y.rs prepare"); - eprintln!( - " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" - ); -} - -macro_rules! arg_error { - ($($err:tt)*) => {{ - eprintln!($($err)*); - usage(); - std::process::exit(1); - }}; -} - -enum Command { - Build, -} - -#[derive(Copy, Clone)] -enum SysrootKind { - None, - Clif, - Llvm, -} +#[path = "build_system/mod.rs"] +mod build_system; 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"); - - let mut args = env::args().skip(1); - let command = match args.next().as_deref() { - Some("prepare") => { - if args.next().is_some() { - arg_error!("./x.rs prepare doesn't expect arguments"); - } - prepare::prepare(); - process::exit(0); - } - Some("build") => Command::Build, - Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), - Some(command) => arg_error!("Unknown command {}", command), - None => { - usage(); - process::exit(0); - } - }; - - let mut target_dir = PathBuf::from("build"); - 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"); - })) - } - "--debug" => channel = "debug", - "--sysroot" => { - sysroot_kind = match args.next().as_deref() { - Some("none") => SysrootKind::None, - Some("clif") => SysrootKind::Clif, - Some("llvm") => SysrootKind::Llvm, - Some(arg) => arg_error!("Unknown sysroot kind {}", arg), - None => arg_error!("--sysroot requires argument"), - } - } - "--no-unstable-features" => use_unstable_features = false, - flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), - arg => arg_error!("Unexpected argument {}", arg), - } - } - - let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { - host_triple - } else if let Some(host_triple) = crate::config::get_value("host") { - host_triple - } else { - rustc_info::get_host_triple() - }; - let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { - if target_triple != "" { - target_triple - } else { - host_triple.clone() // Empty target triple can happen on GHA - } - } else if let Some(target_triple) = crate::config::get_value("target") { - target_triple - } else { - 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); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - &target_dir, - cg_clif_build_dir, - &host_triple, - &target_triple, - ); + build_system::main(); } From 69bd5324ca06078231b2d55d444ca592e7898179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 23 Feb 2022 00:00:00 +0000 Subject: [PATCH 02/44] Normalize main return type during mono item collection & codegen --- src/main_shim.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main_shim.rs b/src/main_shim.rs index 9ce727279c27c..2f71a70a44946 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -51,7 +51,10 @@ pub(crate) fn maybe_create_entry_wrapper( // late-bound regions, since late-bound // regions must appear in the argument // listing. - let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap()); + let main_ret_ty = tcx.normalize_erasing_regions( + ty::ParamEnv::reveal_all(), + main_ret_ty.no_bound_vars().unwrap(), + ); let cmain_sig = Signature { params: vec![ From 346108202d8fb663343c1d48740b0763aef5ca66 Mon Sep 17 00:00:00 2001 From: mark Date: Sun, 23 Jan 2022 12:34:26 -0600 Subject: [PATCH 03/44] rename ErrorReported -> ErrorGuaranteed --- src/constant.rs | 4 ++-- src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 274fb211b7bbb..66adc1a2ce96d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -1,7 +1,7 @@ //! Handling of `static`s, `const`s and promoted allocations use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::ErrorReported; +use rustc_errors::ErrorGuaranteed; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, @@ -54,7 +54,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { { all_constants_ok = false; match err { - ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => { + ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => { fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); } ErrorHandled::TooGeneric => { diff --git a/src/lib.rs b/src/lib.rs index cb18f42f741d8..331e3e8f5dfc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ use std::cell::Cell; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; -use rustc_errors::ErrorReported; +use rustc_errors::ErrorGuaranteed; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::config::OutputFilenames; @@ -209,7 +209,7 @@ impl CodegenBackend for CraneliftCodegenBackend { ongoing_codegen: Box, _sess: &Session, _outputs: &OutputFilenames, - ) -> Result<(CodegenResults, FxHashMap), ErrorReported> { + ) -> Result<(CodegenResults, FxHashMap), ErrorGuaranteed> { Ok(*ongoing_codegen .downcast::<(CodegenResults, FxHashMap)>() .unwrap()) @@ -220,7 +220,7 @@ impl CodegenBackend for CraneliftCodegenBackend { sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames, - ) -> Result<(), ErrorReported> { + ) -> Result<(), ErrorGuaranteed> { use rustc_codegen_ssa::back::link::link_binary; link_binary::>(sess, &codegen_results, outputs) From e29149552e2afd1a524d562a910b20b996c31ec7 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 6 Oct 2021 15:52:54 +0100 Subject: [PATCH 04/44] Add -Z oom={panic,abort} command-line option --- src/allocator.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index 82247b47888e7..c3b99b64263f2 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -4,6 +4,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; +use rustc_session::config::OomStrategy; /// Returns whether an allocator shim was created pub(crate) fn codegen( @@ -18,7 +19,13 @@ pub(crate) fn codegen( if any_dynamic_crate { false } else if let Some(kind) = tcx.allocator_kind(()) { - codegen_inner(module, unwind_context, kind, tcx.lang_items().oom().is_some()); + codegen_inner( + module, + unwind_context, + kind, + tcx.lang_items().oom().is_some(), + tcx.sess.opts.debugging_opts.oom, + ); true } else { false @@ -30,6 +37,7 @@ fn codegen_inner( unwind_context: &mut UnwindContext, kind: AllocatorKind, has_alloc_error_handler: bool, + oom_strategy: OomStrategy, ) { let usize_ty = module.target_config().pointer_type(); @@ -129,4 +137,11 @@ fn codegen_inner( } module.define_function(func_id, &mut ctx).unwrap(); unwind_context.add_function(func_id, &ctx, module.isa()); + + let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap(); + let mut data_ctx = DataContext::new(); + data_ctx.set_align(1); + let val = oom_strategy.should_panic(); + data_ctx.define(Box::new([val])); + module.define_data(data_id, &data_ctx).unwrap(); } From c5ec4d353cc41c25f51b0726a3fa5b112eacfa8a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 4 Mar 2022 20:45:04 +0100 Subject: [PATCH 05/44] Fix typo --- src/debuginfo/unwind.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index e4f28338096e1..cc9ccbaf43f49 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -99,7 +99,7 @@ impl UnwindContext { let (eh_frame, eh_frame_len, _) = Vec::into_raw_parts(eh_frame); // ======================================================================= - // Everything after this line up to the end of the file is loosly based on + // Everything after this line up to the end of the file is loosely based on // https://github.com/bytecodealliance/wasmtime/blob/4471a82b0c540ff48960eca6757ccce5b1b5c3e4/crates/jit/src/unwind/systemv.rs #[cfg(target_os = "macos")] { From 7c1a318c7b801e7020918b238428f484f0f13aa7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 2 Mar 2022 07:15:04 +1100 Subject: [PATCH 06/44] Introduce `ConstAllocation`. Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems. --- src/constant.rs | 19 ++++++++++++------- src/intrinsics/simd.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 66adc1a2ce96d..aff3603303a98 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::ErrorGuaranteed; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ - read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, + read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, }; use rustc_middle::ty::ConstKind; use rustc_span::DUMMY_SP; @@ -202,7 +202,7 @@ pub(crate) fn codegen_const_value<'tcx>( &mut fx.constants_cx, fx.module, alloc_id, - alloc.mutability, + alloc.inner().mutability, ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); @@ -257,11 +257,15 @@ pub(crate) fn codegen_const_value<'tcx>( pub(crate) fn pointer_for_allocation<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - alloc: &'tcx Allocation, + alloc: ConstAllocation<'tcx>, ) -> crate::pointer::Pointer { let alloc_id = fx.tcx.create_memory_alloc(alloc); - let data_id = - data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, alloc.mutability); + let data_id = data_id_for_alloc_id( + &mut fx.constants_cx, + &mut *fx.module, + alloc_id, + alloc.inner().mutability, + ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); if fx.clif_comments.enabled() { @@ -361,7 +365,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.mutability == rustc_hir::Mutability::Mut, + alloc.inner().mutability == rustc_hir::Mutability::Mut, false, ) .unwrap() @@ -386,6 +390,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } let mut data_ctx = DataContext::new(); + let alloc = alloc.inner(); data_ctx.set_align(alloc.align.bytes()); if let Some(section_name) = section_name { @@ -429,7 +434,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant continue; } GlobalAlloc::Memory(target_alloc) => { - data_id_for_alloc_id(cx, module, alloc_id, target_alloc.mutability) + data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability) } GlobalAlloc::Static(def_id) => { if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 4153bc08e8ad4..49022ebd3e26f 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -159,7 +159,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let idx_bytes = match idx_const { ConstValue::ByRef { alloc, offset } => { let size = Size::from_bytes(4 * ret_lane_count /* size_of([u32; ret_lane_count]) */); - alloc.get_bytes(fx, alloc_range(offset, size)).unwrap() + alloc.inner().get_bytes(fx, alloc_range(offset, size)).unwrap() } _ => unreachable!("{:?}", idx_const), }; From 8723fe0b6b6f8563c2ca0f15c83adf309e780d2a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 4 Mar 2022 13:46:56 +1100 Subject: [PATCH 07/44] Clarify `Layout` interning. `Layout` is another type that is sometimes interned, sometimes not, and we always use references to refer to it so we can't take any advantage of the uniqueness properties for hashing or equality checks. This commit renames `Layout` as `LayoutS`, and then introduces a new `Layout` that is a newtype around an `Interned`. It also interns more layouts than before. Previously layouts within layouts (via the `variants` field) were never interned, but now they are. Hence the lifetime on the new `Layout` type. Unlike other interned types, these ones are in `rustc_target` instead of `rustc_middle`. This reflects the existing structure of the code, which does layout-specific stuff in `rustc_target` while `TyAndLayout` is generic over the `Ty`, allowing the type-specific stuff to occur in `rustc_middle`. The commit also adds a `HashStable` impl for `Interned`, which was needed. It hashes the contents, unlike the `Hash` impl which hashes the pointer. --- src/abi/comments.rs | 10 ++++++++-- src/intrinsics/mod.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/abi/comments.rs b/src/abi/comments.rs index 5fbaed7283a67..37d2679c10d70 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -82,8 +82,14 @@ pub(super) fn add_local_place_comments<'tcx>( return; } let TyAndLayout { ty, layout } = place.layout(); - let rustc_target::abi::Layout { size, align, abi: _, variants: _, fields: _, largest_niche: _ } = - layout; + let rustc_target::abi::LayoutS { + size, + align, + abi: _, + variants: _, + fields: _, + largest_niche: _, + } = layout.0.0; let (kind, extra) = match *place.inner() { CPlaceInner::Var(place_local, var) => { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4dfb13476c287..6489b96be4b2d 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1070,7 +1070,7 @@ fn codegen_regular_intrinsic_call<'tcx>( }; raw_eq, (v lhs_ref, v rhs_ref) { - let size = fx.layout_of(substs.type_at(0)).layout.size; + let size = fx.layout_of(substs.type_at(0)).layout.size(); // FIXME add and use emit_small_memcmp let is_eq_value = if size == Size::ZERO { From 1b75d1146f91b84f40f052f04251654b8f3affbe Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Mar 2022 11:29:17 +0100 Subject: [PATCH 08/44] Rustup to rustc 1.61.0-nightly (03918badd 2022-03-07) --- ...8-sysroot-Disable-long-running-tests.patch | 26 ++++++++++--------- rust-toolchain | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/patches/0028-sysroot-Disable-long-running-tests.patch b/patches/0028-sysroot-Disable-long-running-tests.patch index bf74a74c7c4b8..dc1beae6d2e71 100644 --- a/patches/0028-sysroot-Disable-long-running-tests.patch +++ b/patches/0028-sysroot-Disable-long-running-tests.patch @@ -1,30 +1,32 @@ -From 0ffdd8eda8df364391c8ac6e1ce92c73ba9254d4 Mon Sep 17 00:00:00 2001 +From eb703e627e7a84f1cd8d0d87f0f69da1f0acf765 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 3 Dec 2021 12:16:30 +0100 Subject: [PATCH] Disable long running tests --- - library/core/tests/slice.rs | 3 +++ - 1 file changed, 3 insertions(+) + library/core/tests/slice.rs | 2 ++ + 1 file changed, 2 insertions(+) diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 2c8f00a..44847ee 100644 +index 8402833..84592e0 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs -@@ -2332,7 +2332,8 @@ macro_rules! empty_max_mut { - }; - } +@@ -2462,6 +2462,7 @@ take_tests! { + #[cfg(not(miri))] // unused in Miri + const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; +/* - #[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) - take_tests! { - slice: &[(); usize::MAX], method: take, - (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), -@@ -2345,3 +2347,4 @@ take_tests! { + // can't be a constant due to const mutability rules + #[cfg(not(miri))] // unused in Miri + macro_rules! empty_max_mut { +@@ -2485,6 +2486,7 @@ take_tests! { (take_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()), (take_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()), } +*/ + + #[test] + fn test_slice_from_ptr_range() { -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index 1019b1f069e50..c5d2c4b17a9b3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-02-23" +channel = "nightly-2022-03-08" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 5841caa6ef290c6a6dd8ace37df574ae1464cbb3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Mar 2022 12:13:33 +0100 Subject: [PATCH 09/44] Fix compiletest compilation --- scripts/setup_rust_fork.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 73600faa1e9c2..18eb3fb569274 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -38,6 +38,21 @@ index d95b5b7f17f..00b6f0e3635 100644 [dev-dependencies] rand = "0.7" rand_xorshift = "0.2" +diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs +index 887d27fd6dca4..2c2239f2b83d1 100644 +--- a/src/tools/compiletest/src/header.rs ++++ b/src/tools/compiletest/src/header.rs +@@ -806,8 +806,8 @@ pub fn make_test_description( + cfg: Option<&str>, + ) -> test::TestDesc { + let mut ignore = false; + #[cfg(not(bootstrap))] +- let ignore_message: Option = None; ++ let ignore_message: Option<&str> = None; + let mut should_fail = false; + + let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some(); + EOF cat > config.toml < Date: Tue, 8 Mar 2022 20:00:11 +0100 Subject: [PATCH 10/44] Fix Box deref for non-ZST allocators --- example/mini_core.rs | 15 ++++++++++++--- example/mini_core_hello_world.rs | 6 ------ src/base.rs | 11 +++++++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index c4834c8040871..de6aea4c697da 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -483,8 +483,17 @@ pub trait Deref { fn deref(&self) -> &Self::Target; } +pub struct Unique { + pub pointer: *const T, + pub _marker: PhantomData, +} + +impl CoerceUnsized> for Unique where T: Unsize {} + +impl DispatchFromDyn> for Unique where T: Unsize {} + #[lang = "owned_box"] -pub struct Box(*mut T); +pub struct Box(Unique, ()); impl, U: ?Sized> CoerceUnsized> for Box {} @@ -508,8 +517,8 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { } #[lang = "box_free"] -unsafe fn box_free(ptr: *mut T) { - libc::free(ptr as *mut u8); +unsafe fn box_free(ptr: Unique, alloc: ()) { + libc::free(ptr.pointer as *mut u8); } #[lang = "drop"] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index ef3b575d39314..02af6fb78f718 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -105,12 +105,6 @@ fn start( static mut NUM: u8 = 6 * 7; static NUM_REF: &'static u8 = unsafe { &NUM }; -struct Unique { - pointer: *const T, - _marker: PhantomData, -} - -impl CoerceUnsized> for Unique where T: Unsize {} unsafe fn zeroed() -> T { let mut uninit = MaybeUninit { uninit: () }; diff --git a/src/base.rs b/src/base.rs index 0a6ef6441fa03..c7c9c5eefad1b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -25,7 +25,7 @@ pub(crate) fn codegen_fn<'tcx>( let mir = tcx.instance_mir(instance.def); let _mir_guard = crate::PrintOnPanic(|| { let mut buf = Vec::new(); - rustc_middle::mir::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap(); + rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf).unwrap(); String::from_utf8_lossy(&buf).into_owned() }); @@ -813,7 +813,14 @@ pub(crate) fn codegen_place<'tcx>( for elem in place.projection { match elem { PlaceElem::Deref => { - cplace = cplace.place_deref(fx); + if cplace.layout().ty.is_box() { + cplace = cplace + .place_field(fx, Field::new(0)) // Box -> Unique + .place_field(fx, Field::new(0)) // Unique -> *const T + .place_deref(fx); + } else { + cplace = cplace.place_deref(fx); + } } PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); From 3ccf12acdd9cc9409049ce214d77df27dd914bdf Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Mar 2022 20:01:48 +0100 Subject: [PATCH 11/44] Update Cranelift to 0.82.0 --- Cargo.lock | 40 ++++++++++++++++++++-------------------- Cargo.toml | 12 ++++++------ src/lib.rs | 5 ++++- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f15e319e3b807..02b657fd69fa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,18 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71447555acc6c875c52c407d572fc1327dc5c34cba72b4b2e7ad048aa4e4fd19" +checksum = "6888db2229fb6bbaf83ae89068609a6318af704926710bf815b5aa5327935e52" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec9a10261891a7a919b0d4f6aa73582e88441d9a8f6173c88efbe4a5a362ea67" +checksum = "bb6d411726fb6eef630dbfb544736e2334cef2ba7476bfba552d018d28f211f5" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -59,30 +59,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "815755d76fcbcf6e17ab888545b28ab775f917cb12ce0797e60cd41a2288692c" +checksum = "eeb1f26cde43be393eb3f3bf026d5e2d0cf356246039008d0a4452b2868964dd" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea92f2a67335a2e4d3c9c65624c3b14ae287d595b0650822c41824febab66b" +checksum = "93e2ad9068b111c4df96517f42e257eee38d0b2239b1be346a10b4de007327f4" [[package]] name = "cranelift-entity" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd25847875e388c500ad3624b4d2e14067955c93185194a7222246a25b91c975" +checksum = "6f7009e6aa5153759283240333935d9ffb7dcaeb00cc2bccb5cead0e431cc35f" [[package]] name = "cranelift-frontend" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308bcfb7eb47bdf5ff6e1ace262af4ed39ec19f204c751fffb037e0e82a0c8bf" +checksum = "99032c765ec601b4fcba100c4e9c11afe5d943e6813fc486df02a70a1104bd21" dependencies = [ "cranelift-codegen", "log", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f560b3a314b8d15facf411e5d29b917c3e787a2bbc3fcdc5183bc0c5b7d4fe01" +checksum = "d64476c2c7c661c4272e6c74bafa7a19ad641492d1a3c37ce48a6e56930a4bf6" dependencies = [ "anyhow", "cranelift-codegen", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a57aba9e603d694d1430ff38bd914bae23ef9c2e44b25a65e318905807e654c" +checksum = "de94b601cd8330fb82325eae31a4ca2a57883a9f22fe8bc0dad5e374c80ee06a" dependencies = [ "anyhow", "cranelift-codegen", @@ -120,9 +120,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cdc799aee673be2317e631d4569a1ba0a7e77a07a7ce45557086d2e02e9514" +checksum = "e201f5a4f270b2ab70570cc4e255d1eeff437fa49726416b9c81afc2535197b6" dependencies = [ "cranelift-codegen", "libc", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.81.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502a7333836052fcdf4425d7f7a21264d99f862d32b9c3a0e47cd920487a9b60" +checksum = "065431a085080ca85b6680aa90dff3ff07af8a7767d6424d8df50964fb05084e" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/Cargo.toml b/Cargo.toml index 178404af42d67..f0d39db382c2d 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.81.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.81.0" -cranelift-module = "0.81.0" -cranelift-native = "0.81.0" -cranelift-jit = { version = "0.81.0", optional = true } -cranelift-object = "0.81.0" +cranelift-codegen = { version = "0.82.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.82.0" +cranelift-module = "0.82.0" +cranelift-native = "0.82.0" +cranelift-jit = { version = "0.82.0", optional = true } +cranelift-object = "0.82.0" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } diff --git a/src/lib.rs b/src/lib.rs index 331e3e8f5dfc3..5eab2b70f4eb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -301,7 +301,10 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box target_isa, + Err(err) => sess.fatal(&format!("failed to build TargetIsa: {}", err)), + } } /// This is the entrypoint for a hot plugged rustc_codegen_cranelift From 01ffb98db5b00d683b31a62c0c50a1b6e7065117 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Mar 2022 20:08:50 +0100 Subject: [PATCH 12/44] Update dependencies --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02b657fd69fa2..165e2eaf87104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" [[package]] name = "ar" @@ -15,9 +15,9 @@ source = "git+https://github.com/bjorn3/rust-ar.git?branch=do_not_remove_cg_clif [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if", ] @@ -179,9 +179,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.116" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" [[package]] name = "libloading" @@ -284,9 +284,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "target-lexicon" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" +checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1" [[package]] name = "winapi" From 54920ff25e632259b54a496693d984143a35ece6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 9 Mar 2022 19:33:55 +0100 Subject: [PATCH 13/44] Add missing clif ir comment --- src/abi/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index a249e5fa8ac9c..2aa80e4d10d0e 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -94,6 +94,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv }; let func_id = self.module.declare_function(name, Linkage::Import, &sig).unwrap(); let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func); + if self.clif_comments.enabled() { + self.add_comment(func_ref, format!("{:?}", name)); + } let call_inst = self.bcx.ins().call(func_ref, args); if self.clif_comments.enabled() { self.add_comment(call_inst, format!("easy_call {}", name)); From d2026d679e33252cf6e2569ae052b0c54518e24a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Mar 2022 14:50:09 +0100 Subject: [PATCH 14/44] Update Cranelift to 0.82.1 This fixes a miscompilation --- Cargo.lock | 40 ++++++++++++++++++++-------------------- Cargo.toml | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 165e2eaf87104..f226a03672c9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,18 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6888db2229fb6bbaf83ae89068609a6318af704926710bf815b5aa5327935e52" +checksum = "d16922317bd7dd104d509a373887822caa0242fc1def00de66abb538db221db4" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6d411726fb6eef630dbfb544736e2334cef2ba7476bfba552d018d28f211f5" +checksum = "8b80bf40380256307b68a3dcbe1b91cac92a533e212b5b635abc3e4525781a0a" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -59,30 +59,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb1f26cde43be393eb3f3bf026d5e2d0cf356246039008d0a4452b2868964dd" +checksum = "703d0ed7d3bc6c7a814ca12858175bf4e93167a3584127858c686e4b5dd6e432" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93e2ad9068b111c4df96517f42e257eee38d0b2239b1be346a10b4de007327f4" +checksum = "80f52311e1c90de12dcf8c4b9999c6ebfd1ed360373e88c357160936844511f6" [[package]] name = "cranelift-entity" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f7009e6aa5153759283240333935d9ffb7dcaeb00cc2bccb5cead0e431cc35f" +checksum = "66bc82ef522c1f643baf7d4d40b7c52643ee4549d8960b0e6a047daacb83f897" [[package]] name = "cranelift-frontend" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99032c765ec601b4fcba100c4e9c11afe5d943e6813fc486df02a70a1104bd21" +checksum = "3cc35e4251864b17515845ba47447bca88fec9ca1a4186b19fe42526e36140e8" dependencies = [ "cranelift-codegen", "log", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d64476c2c7c661c4272e6c74bafa7a19ad641492d1a3c37ce48a6e56930a4bf6" +checksum = "93c66d594ad3bfe4e58b1fbd8d17877a7c6564a5f2d6f78cbbf4b0182af1927f" dependencies = [ "anyhow", "cranelift-codegen", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de94b601cd8330fb82325eae31a4ca2a57883a9f22fe8bc0dad5e374c80ee06a" +checksum = "bf356697c40232aa09e1e3fb8a350ee894e849ccecc4eac56ff0570a4575c325" dependencies = [ "anyhow", "cranelift-codegen", @@ -120,9 +120,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e201f5a4f270b2ab70570cc4e255d1eeff437fa49726416b9c81afc2535197b6" +checksum = "b882b2251c9845d509d92aebfdb6c8bb3b3b48e207ac951f21fbd20cfe7f90b3" dependencies = [ "cranelift-codegen", "libc", @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.82.0" +version = "0.82.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065431a085080ca85b6680aa90dff3ff07af8a7767d6424d8df50964fb05084e" +checksum = "2d3f1a88e654e567d2591169239ed157ab290811a729a6468f53999c01001263" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/Cargo.toml b/Cargo.toml index f0d39db382c2d..02a67d1844159 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.82.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.82.0" -cranelift-module = "0.82.0" -cranelift-native = "0.82.0" -cranelift-jit = { version = "0.82.0", optional = true } -cranelift-object = "0.82.0" +cranelift-codegen = { version = "0.82.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.82.1" +cranelift-module = "0.82.1" +cranelift-native = "0.82.1" +cranelift-jit = { version = "0.82.1", optional = true } +cranelift-object = "0.82.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From e439761b8fe67f39c1a987fae10433b9a29c045a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 5 Mar 2022 07:28:41 +1100 Subject: [PATCH 15/44] Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. --- src/common.rs | 2 +- src/unsize.rs | 4 ++-- src/value_and_place.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index d3e36be3244f1..89fd0bfa8bbfa 100644 --- a/src/common.rs +++ b/src/common.rs @@ -67,7 +67,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { + ty::Adt(adt_def, _) if adt_def.repr().simd() => { let (element, count) = match &tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().abi { Abi::Vector { element, count } => (element.clone(), *count), diff --git a/src/unsize.rs b/src/unsize.rs index 8cae506e0cb62..fd63c3ecddbdf 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -127,7 +127,7 @@ pub(crate) fn coerce_unsized_into<'tcx>( (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); - for i in 0..def_a.variants[VariantIdx::new(0)].fields.len() { + for i in 0..def_a.variant(VariantIdx::new(0)).fields.len() { let src_f = src.value_field(fx, mir::Field::new(i)); let dst_f = dst.place_field(fx, mir::Field::new(i)); @@ -200,7 +200,7 @@ pub(crate) fn size_and_align_of_dst<'tcx>( // Packed types ignore the alignment of their fields. if let ty::Adt(def, _) = layout.ty.kind() { - if def.repr.packed() { + if def.repr().packed() { unsized_align = sized_align; } } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index b016af5174e01..afe8797a03009 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -24,7 +24,7 @@ fn codegen_field<'tcx>( } match field_layout.ty.kind() { ty::Slice(..) | ty::Str | ty::Foreign(..) => simple(fx), - ty::Adt(def, _) if def.repr.packed() => { + ty::Adt(def, _) if def.repr().packed() => { assert_eq!(layout.align.abi.bytes(), 1); simple(fx) } @@ -816,7 +816,7 @@ pub(crate) fn assert_assignable<'tcx>( // dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed } (&ty::Adt(adt_def_a, substs_a), &ty::Adt(adt_def_b, substs_b)) - if adt_def_a.did == adt_def_b.did => + if adt_def_a.did() == adt_def_b.did() => { let mut types_a = substs_a.types(); let mut types_b = substs_b.types(); From e937265673c79fdf6d8641d38b18958d3bc06a1f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 15:04:33 +0100 Subject: [PATCH 16/44] Rustup to rustc 1.61.0-nightly (f103b2969 2022-03-12) --- example/mini_core.rs | 1 + rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index de6aea4c697da..134934bbffea2 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -55,6 +55,7 @@ unsafe impl Copy for i16 {} unsafe impl Copy for i32 {} unsafe impl Copy for isize {} unsafe impl Copy for f32 {} +unsafe impl Copy for f64 {} unsafe impl Copy for char {} unsafe impl<'a, T: ?Sized> Copy for &'a T {} unsafe impl Copy for *const T {} diff --git a/rust-toolchain b/rust-toolchain index c5d2c4b17a9b3..b7928a5dac2af 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-08" +channel = "nightly-2022-03-13" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From cfc1a2cd6832f62aed7be6292a89e31dc29da056 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 15:19:48 +0100 Subject: [PATCH 17/44] Remove decl_macro usage This reduces the amount of unstable features used by cg_clif --- src/compiler_builtins.rs | 24 +++++++++++--------- src/intrinsics/mod.rs | 48 ++++++++++++++++++++-------------------- src/lib.rs | 2 +- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 100c3b43160bb..c6a247cf59eed 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -1,16 +1,18 @@ -macro builtin_functions($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) { - #[cfg(feature = "jit")] - #[allow(improper_ctypes)] - extern "C" { - $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)* - } +macro_rules! builtin_functions { + ($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) => { + #[cfg(feature = "jit")] + #[allow(improper_ctypes)] + extern "C" { + $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)* + } - #[cfg(feature = "jit")] - pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { - for (name, val) in [$((stringify!($name), $name as *const u8)),*] { - builder.symbol(name, val); + #[cfg(feature = "jit")] + pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { + for (name, val) in [$((stringify!($name), $name as *const u8)),*] { + builder.symbol(name, val); + } } - } + }; } builtin_functions! { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 6489b96be4b2d..8411ec0e035c9 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1,46 +1,32 @@ //! Codegen of intrinsics. This includes `extern "rust-intrinsic"`, `extern "platform-intrinsic"` //! and LLVM intrinsics that have symbol names starting with `llvm.`. -mod cpuid; -mod llvm; -mod simd; - -pub(crate) use cpuid::codegen_cpuid_call; -pub(crate) use llvm::codegen_llvm_intrinsic_call; - -use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::subst::SubstsRef; -use rustc_span::symbol::{kw, sym, Symbol}; - -use crate::prelude::*; -use cranelift_codegen::ir::AtomicRmwOp; - -macro intrinsic_pat { +macro_rules! intrinsic_pat { (_) => { _ - }, + }; ($name:ident) => { sym::$name - }, + }; (kw.$name:ident) => { kw::$name - }, + }; ($name:literal) => { $name - }, + }; } -macro intrinsic_arg { - (o $fx:expr, $arg:ident) => {}, +macro_rules! intrinsic_arg { + (o $fx:expr, $arg:ident) => {}; (c $fx:expr, $arg:ident) => { let $arg = codegen_operand($fx, $arg); - }, + }; (v $fx:expr, $arg:ident) => { let $arg = codegen_operand($fx, $arg).load_scalar($fx); - } + }; } -macro intrinsic_match { +macro_rules! intrinsic_match { ($fx:expr, $intrinsic:expr, $args:expr, _ => $unknown:block; $( @@ -62,6 +48,20 @@ macro intrinsic_match { } } +mod cpuid; +mod llvm; +mod simd; + +pub(crate) use cpuid::codegen_cpuid_call; +pub(crate) use llvm::codegen_llvm_intrinsic_call; + +use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_middle::ty::subst::SubstsRef; +use rustc_span::symbol::{kw, sym, Symbol}; + +use crate::prelude::*; +use cranelift_codegen::ir::AtomicRmwOp; + fn report_atomic_type_validation_error<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, intrinsic: Symbol, diff --git a/src/lib.rs b/src/lib.rs index 5eab2b70f4eb5..8b517104df260 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(rustc_private, decl_macro)] +#![feature(rustc_private)] #![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] From fef517eae74336ef290c3982ab5543458b7b9b5a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 15:31:34 +0100 Subject: [PATCH 18/44] Remove almost all remaining feature gates Only rustc_private is still enabled as cg_clif by definition needs to use internal rustc api's. --- Cargo.lock | 7 +++++++ Cargo.toml | 3 ++- src/debuginfo/unwind.rs | 11 ++++++----- src/driver/jit.rs | 7 ++++--- src/lib.rs | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f226a03672c9a..30e9627c48d74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,6 +228,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + [[package]] name = "regalloc" version = "0.0.34" @@ -272,6 +278,7 @@ dependencies = [ "indexmap", "libloading", "object", + "once_cell", "smallvec", "target-lexicon", ] diff --git a/Cargo.toml b/Cargo.toml index 02a67d1844159..dbe370d9f013b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ object = { version = "0.27.0", default-features = false, features = ["std", "rea ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.8.0" libloading = { version = "0.6.0", optional = true } +once_cell = { version = "1.10.0", optional = true } smallvec = "1.6.1" [patch.crates-io] @@ -37,7 +38,7 @@ smallvec = "1.6.1" [features] # Enable features not ready to be enabled when compiling as part of rustc unstable-features = ["jit", "inline_asm"] -jit = ["cranelift-jit", "libloading"] +jit = ["cranelift-jit", "libloading", "once_cell"] inline_asm = [] # Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index cc9ccbaf43f49..d26392c4913b5 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -81,6 +81,8 @@ impl UnwindContext { #[cfg(all(feature = "jit", not(windows)))] pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { + use std::mem::ManuallyDrop; + let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); @@ -95,8 +97,7 @@ impl UnwindContext { // FIXME support unregistering unwind tables once cranelift-jit supports deallocating // individual functions - #[allow(unused_variables)] - let (eh_frame, eh_frame_len, _) = Vec::into_raw_parts(eh_frame); + let eh_frame = ManuallyDrop::new(eh_frame); // ======================================================================= // Everything after this line up to the end of the file is loosely based on @@ -104,8 +105,8 @@ impl UnwindContext { #[cfg(target_os = "macos")] { // On macOS, `__register_frame` takes a pointer to a single FDE - let start = eh_frame; - let end = start.add(eh_frame_len); + let start = eh_frame.as_ptr(); + let end = start.add(eh_frame.len()); let mut current = start; // Walk all of the entries in the frame table and register them @@ -124,7 +125,7 @@ impl UnwindContext { #[cfg(not(target_os = "macos"))] { // On other platforms, `__register_frame` will walk the FDEs until an entry of length 0 - __register_frame(eh_frame); + __register_frame(eh_frame.as_ptr()); } } } diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 9e07528313dd8..6c22296db716d 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -3,7 +3,6 @@ use std::cell::RefCell; use std::ffi::CString; -use std::lazy::SyncOnceCell; use std::os::raw::{c_char, c_int}; use std::sync::{mpsc, Mutex}; @@ -14,6 +13,9 @@ use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; +// FIXME use std::lazy::SyncOnceCell once it stabilizes +use once_cell::sync::OnceCell; + use crate::{prelude::*, BackendConfig}; use crate::{CodegenCx, CodegenMode}; @@ -27,8 +29,7 @@ thread_local! { } /// The Sender owned by the rustc thread -static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = - SyncOnceCell::new(); +static GLOBAL_MESSAGE_SENDER: OnceCell>> = OnceCell::new(); /// A message that is sent from the jitted runtime to the rustc thread. /// Senders are responsible for upholding `Send` semantics. diff --git a/src/lib.rs b/src/lib.rs index 8b517104df260..a3c794fb156b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![feature(rustc_private)] -#![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))] +// Note: please avoid adding other feature gates where possible #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -196,7 +196,7 @@ impl CodegenBackend for CraneliftCodegenBackend { CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module), CodegenMode::Jit | CodegenMode::JitLazy => { #[cfg(feature = "jit")] - let _: ! = driver::jit::run_jit(tcx, config); + driver::jit::run_jit(tcx, config); #[cfg(not(feature = "jit"))] tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift"); From a48fea6dda1890d2b2061dd680091d842c79ce0a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 15:46:25 +0100 Subject: [PATCH 19/44] Add and remove some fixmes --- build_system/prepare.rs | 1 + scripts/tests.sh | 1 - src/debuginfo/line_info.rs | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4a7df2cebbcb6..90b3390626db4 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -14,6 +14,7 @@ pub(crate) fn prepare() { eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); + // FIXME download source archives where possible instead clone_repo( "rand", "https://github.com/rust-random/rand.git", diff --git a/scripts/tests.sh b/scripts/tests.sh index bdb3de0936dc9..fee1012c8f1dc 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -57,7 +57,6 @@ function base_sysroot_tests() { fi echo "[AOT] dst_field_align" - # FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed. $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false) diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index c7e15f81e0301..476d6a54e1256 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -110,7 +110,6 @@ impl<'tcx> DebugContext<'tcx> { entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id))); entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(loc.line as u64)); - // FIXME: probably omit this entry.set(gimli::DW_AT_decl_column, AttributeValue::Udata(loc.col.to_usize() as u64)); } From 7eb454124f356b8ac1bf60b6474f4458f5be428b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 18:22:25 +0100 Subject: [PATCH 20/44] Update list of ignores rustc tests --- scripts/test_rustc_tests.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index b146ea360376a..f2e1bb69c1422 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -80,12 +80,17 @@ rm src/test/ui/consts/min_const_fn/address_of_const.rs # same rm src/test/ui/consts/issue-miri-1910.rs # same rm src/test/ui/generic-associated-types/bugs/issue-80626.rs # same rm src/test/ui/generic-associated-types/bugs/issue-89008.rs # same +rm src/test/ui/chalkify/bugs/async.rs # same rm src/test/ui/type-alias-impl-trait/cross_crate_ice*.rs # requires removed aux dep rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition rm src/test/ui/cfg/cfg-panic.rs rm -r src/test/ui/hygiene/ +rm src/test/ui/mir/ssa-analysis-regression-50041.rs # uses old definition of Box + +rm src/test/ui/target-feature/missing-plusminus.rs # error not implemented + rm -r src/test/ui/polymorphization/ # polymorphization not yet supported rm src/test/codegen-units/polymorphization/unused_type_parameters.rs # same From 90f8aefe7142d23a64ae95b5ae5a292a6e0519db Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 15:51:39 +0100 Subject: [PATCH 21/44] Mark cold blocks --- src/abi/mod.rs | 5 ++++- src/base.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 2aa80e4d10d0e..3d527bd72b6f0 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -370,7 +370,10 @@ pub(crate) fn codegen_terminator_call<'tcx>( .map(|inst| fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)) .unwrap_or(false); if is_cold { - // FIXME Mark current_block block as cold once Cranelift supports it + fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); + if let Some((_place, destination_block)) = destination { + fx.bcx.set_cold_block(fx.get_block(destination_block)); + } } // Unpack arguments tuple for closures diff --git a/src/base.rs b/src/base.rs index c7c9c5eefad1b..59e9e23d882b2 100644 --- a/src/base.rs +++ b/src/base.rs @@ -303,7 +303,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { let target = fx.get_block(*target); let failure = fx.bcx.create_block(); - // FIXME Mark failure block as cold once Cranelift supports it + fx.bcx.set_cold_block(failure); if *expected { fx.bcx.ins().brz(cond, failure, &[]); From d8e7501584b49c772b0603b61a14a7f468f0f4de Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Mar 2022 17:29:25 +0100 Subject: [PATCH 22/44] Replace a lot of print+trap with plain trap This reduces binary sizes by a decent amount: libstd.so: 17% reduction mini_core_hello_world: 27% reduction simple-raytracer: 27% reduction This also improves compile time of simple-raytracer by 0.5s (4% +- 2%) In addition it is also a pre-requisite for building standalone binaries. --- src/abi/mod.rs | 2 +- src/base.rs | 14 ++++++-------- src/discriminant.rs | 9 ++++----- src/intrinsics/llvm.rs | 9 +++------ src/intrinsics/mod.rs | 4 ++-- src/lib.rs | 1 - src/trap.rs | 21 --------------------- 7 files changed, 16 insertions(+), 44 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 3d527bd72b6f0..ef56fb191bff5 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -507,7 +507,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } else { - trap_unreachable(fx, "[corruption] Diverging function returned"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } } diff --git a/src/base.rs b/src/base.rs index 59e9e23d882b2..0a0d17a69c593 100644 --- a/src/base.rs +++ b/src/base.rs @@ -90,7 +90,7 @@ pub(crate) fn codegen_fn<'tcx>( } else if arg_uninhabited { fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); - crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } else { tcx.sess.time("codegen clif ir", || { tcx.sess @@ -424,18 +424,16 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { fx.bcx.ins().jump(destination_block, &[]); } None => { - crate::trap::trap_unreachable( - fx, - "[corruption] Returned from noreturn inline asm", - ); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } } } TerminatorKind::Resume | TerminatorKind::Abort => { - trap_unreachable(fx, "[corruption] Unwinding bb reached."); + // FIXME implement unwinding + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Unreachable => { - trap_unreachable(fx, "[corruption] Hit unreachable code."); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Yield { .. } | TerminatorKind::FalseEdge { .. } @@ -925,5 +923,5 @@ pub(crate) fn codegen_panic_inner<'tcx>( args, ); - crate::trap::trap_unreachable(fx, "panic lang item returned"); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } diff --git a/src/discriminant.rs b/src/discriminant.rs index 3326f87f00075..6b2893fdaeb29 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -68,11 +68,10 @@ pub(crate) fn codegen_get_discriminant<'tcx>( let layout = value.layout(); if layout.abi == Abi::Uninhabited { - return trap_unreachable_ret_value( - fx, - dest_layout, - "[panic] Tried to get discriminant for uninhabited type.", - ); + let true_ = fx.bcx.ins().iconst(types::I32, 1); + fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached); + // Return a dummy value + return CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout); } let (tag_scalar, tag_field, tag_encoding) = match &layout.variants { diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index 098862b0662f3..0e4f7ee907a51 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -126,12 +126,9 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( }; } - if let Some((_, dest)) = destination { - let ret_block = fx.get_block(dest); - fx.bcx.ins().jump(ret_block, &[]); - } else { - trap_unreachable(fx, "[corruption] Diverging intrinsic returned."); - } + let dest = destination.expect("all llvm intrinsics used by stdlib should return").1; + let ret_block = fx.get_block(dest); + fx.bcx.ins().jump(ret_block, &[]); } // llvm.x86.avx2.vperm2i128 diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 8411ec0e035c9..eeda0dd6f7040 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -229,7 +229,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( // Insert non returning intrinsics here match intrinsic { sym::abort => { - trap_abort(fx, "Called intrinsic::abort."); + fx.bcx.ins().trap(TrapCode::User(0)); } sym::transmute => { crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", span); @@ -1119,6 +1119,6 @@ fn codegen_regular_intrinsic_call<'tcx>( let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } else { - trap_unreachable(fx, "[corruption] Diverging intrinsic returned."); + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } } diff --git a/src/lib.rs b/src/lib.rs index a3c794fb156b4..878b9390e1318 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,6 @@ mod prelude { pub(crate) use crate::common::*; pub(crate) use crate::debuginfo::{DebugContext, UnwindContext}; pub(crate) use crate::pointer::Pointer; - pub(crate) use crate::trap::*; pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue}; } diff --git a/src/trap.rs b/src/trap.rs index 99b5366e34993..923269c4de9ab 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -25,12 +25,6 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { fx.bcx.ins().call(puts, &[msg_ptr]); } -/// Trap code: user1 -pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef) { - codegen_print(fx, msg.as_ref()); - fx.bcx.ins().trap(TrapCode::User(1)); -} - /// Use this for example when a function call should never return. This will fill the current block, /// so you can **not** add instructions to it afterwards. /// @@ -39,21 +33,6 @@ pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef< codegen_print(fx, msg.as_ref()); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } - -/// Like `trap_unreachable` but returns a fake value of the specified type. -/// -/// Trap code: user65535 -pub(crate) fn trap_unreachable_ret_value<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - dest_layout: TyAndLayout<'tcx>, - msg: impl AsRef, -) -> CValue<'tcx> { - codegen_print(fx, msg.as_ref()); - let true_ = fx.bcx.ins().iconst(types::I32, 1); - fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached); - CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout) -} - /// Use this when something is unimplemented, but `libcore` or `libstd` requires it to codegen. /// Unlike `trap_unreachable` this will not fill the current block, so you **must** add instructions /// to it afterwards. From af008bdc66a4c38d4c4f02481838dfdb3ba73f7b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 15 Mar 2022 11:21:42 +0100 Subject: [PATCH 23/44] Rustup to rustc 1.61.0-nightly (285fa7ecd 2022-03-14) --- 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 b97863951429c..151adaddaaa6e 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.119" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index b7928a5dac2af..56adaa6a5553b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-13" +channel = "nightly-2022-03-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From a900a5229a40dbffee2b7b6a7df3ec94b6577c35 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 15 Mar 2022 12:06:51 +0100 Subject: [PATCH 24/44] Download tarballs from github instead of cloning full repos This saves 40-50s on CI as the repo history can be skipped --- build_system/prepare.rs | 91 ++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 90b3390626db4..133aea2acc081 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -14,30 +14,33 @@ pub(crate) fn prepare() { eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); - // FIXME download source archives where possible instead - clone_repo( + clone_repo_shallow_github( + "rand", + "rust-random", "rand", - "https://github.com/rust-random/rand.git", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", ); apply_patches("rand", Path::new("rand")); - clone_repo( + clone_repo_shallow_github( + "regex", + "rust-lang", "regex", - "https://github.com/rust-lang/regex.git", "341f207c1071f7290e3f228c710817c280c8dca1", ); - clone_repo( + clone_repo_shallow_github( + "portable-simd", + "rust-lang", "portable-simd", - "https://github.com/rust-lang/portable-simd", "b8d6b6844602f80af79cd96401339ec594d472d8", ); apply_patches("portable-simd", Path::new("portable-simd")); - clone_repo( + clone_repo_shallow_github( + "simple-raytracer", + "ebobby", "simple-raytracer", - "https://github.com/ebobby/simple-raytracer", "804a7a21b9e673a482797aa289a18ed480e4d813", ); @@ -75,29 +78,20 @@ fn prepare_sysroot() { git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); spawn_and_wait(git_init_cmd); - let mut git_add_cmd = Command::new("git"); - git_add_cmd.arg("add").arg(".").current_dir(&sysroot_src); - 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(&sysroot_src); - spawn_and_wait(git_commit_cmd); + init_git_repo(&sysroot_src); apply_patches("sysroot", &sysroot_src); - clone_repo( + clone_repo_shallow_github( "build_sysroot/compiler-builtins", - "https://github.com/rust-lang/compiler-builtins.git", + "rust-lang", + "compiler-builtins", "0.1.70", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } +#[allow(dead_code)] fn clone_repo(target_dir: &str, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); // Ignore exit code as the repo may already have been checked out @@ -112,6 +106,57 @@ fn clone_repo(target_dir: &str, repo: &str, rev: &str) { spawn_and_wait(checkout_cmd); } +fn clone_repo_shallow_github(target_dir: &str, username: &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); + 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); + + eprintln!("[DOWNLOAD] {}/{} from {}", username, 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); + + // Download zip archive + let mut download_cmd = Command::new("curl"); + download_cmd.arg("--location").arg("--output").arg(&archive_file).arg(archive_url); + spawn_and_wait(download_cmd); + + // Unpack tar archive + let mut unpack_cmd = Command::new("tar"); + unpack_cmd.arg("xf").arg(&archive_file); + spawn_and_wait(unpack_cmd); + + // Rename unpacked dir to the expected name + std::fs::rename(archive_dir, target_dir).unwrap(); + + init_git_repo(Path::new(target_dir)); + + // Cleanup + std::fs::remove_file(archive_file).unwrap(); +} + +fn init_git_repo(repo_dir: &Path) { + let mut git_init_cmd = Command::new("git"); + git_init_cmd.arg("init").arg("-q").current_dir(repo_dir); + spawn_and_wait(git_init_cmd); + + let mut git_add_cmd = Command::new("git"); + git_add_cmd.arg("add").arg(".").current_dir(repo_dir); + 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); + spawn_and_wait(git_commit_cmd); +} + fn get_patches(crate_name: &str) -> Vec { let mut patches: Vec<_> = fs::read_dir("patches") .unwrap() From 88c3719c683b6a9ffe8f9d595e50b686651a7f70 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 15 Mar 2022 17:42:51 +0100 Subject: [PATCH 25/44] Avoid once_cell unstable feature in cg_clif.rs --- Cargo.toml | 4 ++-- src/bin/cg_clif.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbe370d9f013b..70c03da3f29fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ object = { version = "0.27.0", default-features = false, features = ["std", "rea ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.8.0" libloading = { version = "0.6.0", optional = true } -once_cell = { version = "1.10.0", optional = true } +once_cell = "1.10.0" smallvec = "1.6.1" [patch.crates-io] @@ -38,7 +38,7 @@ smallvec = "1.6.1" [features] # Enable features not ready to be enabled when compiling as part of rustc unstable-features = ["jit", "inline_asm"] -jit = ["cranelift-jit", "libloading", "once_cell"] +jit = ["cranelift-jit", "libloading"] inline_asm = [] # Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index b924f2085a0fc..a8fb09e69b7ef 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -1,4 +1,4 @@ -#![feature(rustc_private, once_cell)] +#![feature(rustc_private)] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -9,7 +9,6 @@ extern crate rustc_interface; extern crate rustc_session; extern crate rustc_target; -use std::lazy::SyncLazy; use std::panic; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; @@ -18,10 +17,13 @@ use rustc_session::config::ErrorOutputType; use rustc_session::early_error; use rustc_target::spec::PanicStrategy; +// FIXME use std::lazy::SyncLazy once it stabilizes +use once_cell::sync::Lazy; + const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new"; -static DEFAULT_HOOK: SyncLazy) + Sync + Send + 'static>> = - SyncLazy::new(|| { +static DEFAULT_HOOK: Lazy) + Sync + Send + 'static>> = + Lazy::new(|| { let hook = panic::take_hook(); panic::set_hook(Box::new(|info| { // Invoke the default handler, which prints the actual panic message and optionally a backtrace @@ -61,7 +63,7 @@ fn main() { let start_rss = get_resident_set_size(); rustc_driver::init_rustc_env_logger(); let mut callbacks = CraneliftPassesCallbacks::default(); - SyncLazy::force(&DEFAULT_HOOK); // Install ice hook + Lazy::force(&DEFAULT_HOOK); // Install ice hook let exit_code = rustc_driver::catch_with_exit_code(|| { let args = std::env::args_os() .enumerate() From 5c666ea7ec1de153297a9325a5c36f132087b6b7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 15 Mar 2022 19:10:25 +0100 Subject: [PATCH 26/44] Remove some unused feature gates --- .../arbitrary_self_types_pointers_and_wrappers.rs | 1 - example/mini_core.rs | 13 ++++++++++--- example/mini_core_hello_world.rs | 4 ---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs index ddeb752f93ed7..e9876837dd81a 100644 --- a/example/arbitrary_self_types_pointers_and_wrappers.rs +++ b/example/arbitrary_self_types_pointers_and_wrappers.rs @@ -1,7 +1,6 @@ // Adapted from rustc run-pass test suite #![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)] -#![feature(rustc_attrs)] use std::{ ops::{Deref, CoerceUnsized, DispatchFromDyn}, diff --git a/example/mini_core.rs b/example/mini_core.rs index 134934bbffea2..7efc8dc785a19 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -1,7 +1,14 @@ #![feature( - no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types, - untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits, - thread_local, + no_core, + lang_items, + intrinsics, + unboxed_closures, + extern_types, + decl_macro, + rustc_attrs, + transparent_unions, + auto_traits, + thread_local )] #![no_core] #![allow(dead_code)] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 02af6fb78f718..c4730581335ec 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -7,10 +7,6 @@ extern crate mini_core; use mini_core::*; use mini_core::libc::*; -unsafe extern "C" fn my_puts(s: *const i8) { - puts(s); -} - macro_rules! assert { ($e:expr) => { if !$e { From d08d32fa5d47be5563247a706a8dd37e7aa15b3d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 15 Mar 2022 19:11:05 +0100 Subject: [PATCH 27/44] Trim down alloc_system.rs It is used only by a single test. Also remove the dependency on the libc crate. --- example/alloc_system.rs | 142 +++++++++------------------------------- 1 file changed, 30 insertions(+), 112 deletions(-) diff --git a/example/alloc_system.rs b/example/alloc_system.rs index 5f66ca67f2d40..cf95c89bc3156 100644 --- a/example/alloc_system.rs +++ b/example/alloc_system.rs @@ -8,33 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. #![no_std] -#![feature(allocator_api, rustc_private)] -#![cfg_attr(any(unix, target_os = "redox"), feature(libc))] - -// The minimum alignment guaranteed by the architecture. This value is used to -// add fast paths for low alignment values. -#[cfg(all(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "powerpc", - target_arch = "powerpc64")))] -const MIN_ALIGN: usize = 8; -#[cfg(all(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")))] -const MIN_ALIGN: usize = 16; pub struct System; + #[cfg(any(windows, unix, target_os = "redox"))] mod realloc_fallback { use core::alloc::{GlobalAlloc, Layout}; use core::cmp; use core::ptr; impl super::System { - pub(crate) unsafe fn realloc_fallback(&self, ptr: *mut u8, old_layout: Layout, - new_size: usize) -> *mut u8 { + pub(crate) unsafe fn realloc_fallback( + &self, + ptr: *mut u8, + old_layout: Layout, + new_size: usize, + ) -> *mut u8 { // Docs for GlobalAlloc::realloc require this to be valid: let new_layout = Layout::from_size_align_unchecked(new_size, old_layout.align()); let new_ptr = GlobalAlloc::alloc(self, new_layout); @@ -49,97 +37,47 @@ mod realloc_fallback { } #[cfg(any(unix, target_os = "redox"))] mod platform { - extern crate libc; + use core::alloc::{GlobalAlloc, Layout}; + use core::ffi::c_void; use core::ptr; - use MIN_ALIGN; use System; - use core::alloc::{GlobalAlloc, Layout}; + extern "C" { + fn posix_memalign(memptr: *mut *mut c_void, align: usize, size: usize) -> i32; + fn free(p: *mut c_void); + } unsafe impl GlobalAlloc for System { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { - libc::malloc(layout.size()) as *mut u8 - } else { - #[cfg(target_os = "macos")] - { - if layout.align() > (1 << 31) { - return ptr::null_mut() - } - } - aligned_malloc(&layout) - } + aligned_malloc(&layout) } #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { - libc::calloc(layout.size(), 1) as *mut u8 - } else { - let ptr = self.alloc(layout.clone()); - if !ptr.is_null() { - ptr::write_bytes(ptr, 0, layout.size()); - } - ptr + let ptr = self.alloc(layout.clone()); + if !ptr.is_null() { + ptr::write_bytes(ptr, 0, layout.size()); } + ptr } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { - libc::free(ptr as *mut libc::c_void) + free(ptr as *mut c_void) } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - if layout.align() <= MIN_ALIGN && layout.align() <= new_size { - libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 - } else { - self.realloc_fallback(ptr, layout, new_size) - } + self.realloc_fallback(ptr, layout, new_size) } } - #[cfg(any(target_os = "android", - target_os = "hermit", - target_os = "redox", - target_os = "solaris"))] - #[inline] - unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { - // On android we currently target API level 9 which unfortunately - // doesn't have the `posix_memalign` API used below. Instead we use - // `memalign`, but this unfortunately has the property on some systems - // where the memory returned cannot be deallocated by `free`! - // - // Upon closer inspection, however, this appears to work just fine with - // Android, so for this platform we should be fine to call `memalign` - // (which is present in API level 9). Some helpful references could - // possibly be chromium using memalign [1], attempts at documenting that - // memalign + free is ok [2] [3], or the current source of chromium - // which still uses memalign on android [4]. - // - // [1]: https://codereview.chromium.org/10796020/ - // [2]: https://code.google.com/p/android/issues/detail?id=35391 - // [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=138579 - // [4]: https://chromium.googlesource.com/chromium/src/base/+/master/ - // /memory/aligned_memory.cc - libc::memalign(layout.align(), layout.size()) as *mut u8 - } - #[cfg(not(any(target_os = "android", - target_os = "hermit", - target_os = "redox", - target_os = "solaris")))] - #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let mut out = ptr::null_mut(); - let ret = libc::posix_memalign(&mut out, layout.align(), layout.size()); - if ret != 0 { - ptr::null_mut() - } else { - out as *mut u8 - } + let ret = posix_memalign(&mut out, layout.align(), layout.size()); + if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } } #[cfg(windows)] #[allow(nonstandard_style)] mod platform { - use MIN_ALIGN; - use System; use core::alloc::{GlobalAlloc, Layout}; + use System; type LPVOID = *mut u8; type HANDLE = LPVOID; type SIZE_T = usize; @@ -165,18 +103,9 @@ mod platform { } #[inline] unsafe fn allocate_with_flags(layout: Layout, flags: DWORD) -> *mut u8 { - let ptr = if layout.align() <= MIN_ALIGN { - HeapAlloc(GetProcessHeap(), flags, layout.size()) - } else { - let size = layout.size() + layout.align(); - let ptr = HeapAlloc(GetProcessHeap(), flags, size); - if ptr.is_null() { - ptr - } else { - align_ptr(ptr, layout.align()) - } - }; - ptr as *mut u8 + let size = layout.size() + layout.align(); + let ptr = HeapAlloc(GetProcessHeap(), flags, size); + (if ptr.is_null() { ptr } else { align_ptr(ptr, layout.align()) }) as *mut u8 } unsafe impl GlobalAlloc for System { #[inline] @@ -189,24 +118,13 @@ mod platform { } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - if layout.align() <= MIN_ALIGN { - let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID); - debug_assert!(err != 0, "Failed to free heap memory: {}", - GetLastError()); - } else { - let header = get_header(ptr); - let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID); - debug_assert!(err != 0, "Failed to free heap memory: {}", - GetLastError()); - } + let header = get_header(ptr); + let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID); + debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError()); } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - if layout.align() <= MIN_ALIGN { - HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, new_size) as *mut u8 - } else { - self.realloc_fallback(ptr, layout, new_size) - } + self.realloc_fallback(ptr, layout, new_size) } } } From 64bc2352ee5c7570f09e852023179a79fac35493 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 16 Mar 2022 12:05:02 +0100 Subject: [PATCH 28/44] Silence warning --- y.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/y.rs b/y.rs index 18528d5429729..e412288b93815 100755 --- a/y.rs +++ b/y.rs @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#![allow()] /*This line is ignored by bash +#![deny(unsafe_code)] /*This line is ignored by bash # This block is ignored by rustc set -e echo "[BUILD] y.rs" 1>&2 From c56a10ca3b5a72194034bb697ed8289e0635fb51 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 22 Jan 2022 18:49:12 -0600 Subject: [PATCH 29/44] rustc_error: make ErrorReported impossible to construct There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name. --- src/constant.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index aff3603303a98..4657791345b8e 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -1,7 +1,6 @@ //! Handling of `static`s, `const`s and promoted allocations use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::ErrorGuaranteed; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, @@ -54,7 +53,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { { all_constants_ok = false; match err { - ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => { + ErrorHandled::Reported(_) | ErrorHandled::Linted => { fx.tcx.sess.span_err(constant.span, "erroneous constant encountered"); } ErrorHandled::TooGeneric => { From 9a8da8c64a12bc564a938f3d2e0bd92f6f3f4b00 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 16 Mar 2022 19:21:24 +0100 Subject: [PATCH 30/44] Slightly speed up building of y.rs --- y.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/y.rs b/y.rs index e412288b93815..f177b91c2c487 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} -g +rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 exec ${0/.rs/.bin} $@ */ From ce577f7f121f22e01c390d34de23a9a0536964e5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Mar 2022 20:59:39 +0100 Subject: [PATCH 31/44] Fix and re-enable some rustc tests * Set `config.opts.trimmed_def_paths` to `GoodPath` to trim def paths in error messages as expected by the rustc test suite * Fix `$SRC_DIR` normalization for out of tree compiled standard library --- scripts/setup_rust_fork.sh | 19 +++++++++++++++++++ scripts/test_rustc_tests.sh | 8 -------- src/base.rs | 5 ++++- src/bin/cg_clif.rs | 4 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 18eb3fb569274..ddcf05ec25227 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -53,9 +53,28 @@ index 887d27fd6dca4..2c2239f2b83d1 100644 let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some(); +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,11 +3489,7 @@ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> S + .join("library"); + normalize_path(&src_dir, "$(echo '$SRC_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(&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 <) { if fx.clif_comments.enabled() { let mut terminator_head = "\n".to_string(); - bb_data.terminator().kind.fmt_head(&mut terminator_head).unwrap(); + with_no_trimmed_paths!({ + bb_data.terminator().kind.fmt_head(&mut terminator_head).unwrap(); + }); let inst = fx.bcx.func.layout.last_inst(block).unwrap(); fx.add_comment(inst, terminator_head); } diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index a8fb09e69b7ef..5984ec8412ad7 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -13,7 +13,7 @@ use std::panic; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_interface::interface; -use rustc_session::config::ErrorOutputType; +use rustc_session::config::{ErrorOutputType, TrimmedDefPaths}; use rustc_session::early_error; use rustc_target::spec::PanicStrategy; @@ -55,6 +55,8 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks { config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| { std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned() })); + + config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath; } } From fc80e8b9703d12abe69d77311462e663f075ef67 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Mar 2022 21:16:26 +0100 Subject: [PATCH 32/44] Re-enable fixed tests --- scripts/test_rustc_tests.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index c9f21d8f9cb40..be1f8c051534b 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -46,7 +46,6 @@ rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations rm src/test/ui/codegen/init-large-type.rs # same rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected rm src/test/ui/issues/issue-33992.rs # unsupported linkages -rm src/test/ui/issues/issue-51947.rs # same rm src/test/incremental/hashes/function_interfaces.rs # same rm src/test/incremental/hashes/statics.rs # same rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result @@ -63,7 +62,6 @@ rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and n rm src/test/incremental/hashes/inline_asm.rs # inline asm rm src/test/incremental/issue-72386.rs # same rm src/test/incremental/lto.rs # requires lto -rm src/test/incremental/dirty_clean.rs # TODO rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same @@ -72,12 +70,10 @@ rm -r src/test/run-make/emit-named-files # requires full --emit support rm -r src/test/run-pass-valgrind/unsized-locals -rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # same -rm src/test/ui/type-alias-impl-trait/cross_crate_ice*.rs # requires removed aux dep +rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition rm src/test/ui/cfg/cfg-panic.rs -rm -r src/test/ui/hygiene/ rm src/test/ui/mir/ssa-analysis-regression-50041.rs # uses old definition of Box @@ -90,8 +86,6 @@ rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support -rm src/test/ui/command/command-current-dir.rs # can't find libstd.so - rm src/test/ui/abi/stack-protector.rs # requires stack protector support rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code From d1c8cf76b0222e43e55a76125aeffc05f55c83f9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 15:38:58 +0100 Subject: [PATCH 33/44] Run tests with warnings --- scripts/test_rustc_tests.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index be1f8c051534b..2748469c34bc9 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -15,7 +15,7 @@ for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// nee rm $test done -for test in $(rg -i --files-with-matches "//(\[\w+\])?~|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" src/test/ui); do +for test in $(rg -i --files-with-matches "//(\[\w+\])?~[^\|]*\s*ERR|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" src/test/ui); do rm $test done @@ -95,6 +95,8 @@ rm src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs # gives a stackoverf rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM +rm src/test/ui/unsafe/union.rs # has UB caught by cg_clif. see rust-lang/rust#95075 + echo "[TEST] rustc test suite" RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui,incremental} popd From afd59464a927d97b80435b8bc45603bf6f76d0b3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 16:38:28 +0100 Subject: [PATCH 34/44] Reorganize test list --- scripts/test_rustc_tests.sh | 85 +++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 2748469c34bc9..b4ce2abb18c94 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -21,7 +21,10 @@ done git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed -# these all depend on unwinding support +# missing features +# ================ + +# requires stack unwinding rm src/test/ui/backtrace.rs rm src/test/ui/array-slice-vec/box-of-array-of-drop-*.rs rm src/test/ui/array-slice-vec/slice-panic-*.rs @@ -42,59 +45,79 @@ rm src/test/ui/runtime/rt-explody-panic-payloads.rs rm src/test/incremental/change_crate_dep_kind.rs rm src/test/ui/threads-sendsync/unwind-resource.rs -rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations -rm src/test/ui/codegen/init-large-type.rs # same +# requires compiling with -Cpanic=unwind +rm src/test/ui/cfg/cfg-panic.rs +rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" +rm src/test/ui/async-await/async-fn-size-moved-locals.rs # -Cpanic=abort shrinks some generator by one byte +rm src/test/ui/async-await/async-fn-size-uninit-locals.rs # same +rm src/test/ui/generator/size-moved-locals.rs # same + +# vendor intrinsics rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected +rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics + +# inline asm +rm src/test/incremental/hashes/inline_asm.rs # inline asm +rm src/test/incremental/issue-72386.rs # same + +# exotic linkages rm src/test/ui/issues/issue-33992.rs # unsupported linkages rm src/test/incremental/hashes/function_interfaces.rs # same rm src/test/incremental/hashes/statics.rs # same + +# LTO +rm src/test/incremental/lto.rs # requires lt + +# variadic arguments +rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs +rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support + +# unsized locals +rm -r src/test/run-pass-valgrind/unsized-locals + +# misc unimplemented things +rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and nearbyintf64 intrinsics +rm src/test/ui/target-feature/missing-plusminus.rs # error not implemented +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 + +# optimization tests +# ================== +rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations +rm src/test/ui/codegen/init-large-type.rs # same +rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization + +# backend specific tests +# ====================== +rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM +rm src/test/ui/abi/stack-protector.rs # requires stack protector support + +# giving different but possibly correct results +# ============================================= rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result 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/async-await/async-fn-size-moved-locals.rs # -Cpanic=abort shrinks some generator by one byte -rm src/test/ui/async-await/async-fn-size-uninit-locals.rs # same -rm src/test/ui/generator/size-moved-locals.rs # same -rm src/test/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment -rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" -rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and nearbyintf64 intrinsics - -rm src/test/incremental/hashes/inline_asm.rs # inline asm -rm src/test/incremental/issue-72386.rs # same -rm src/test/incremental/lto.rs # requires lto rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/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/emit-named-files # requires full --emit support - -rm -r src/test/run-pass-valgrind/unsized-locals - -rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics +# genuine bugs +# ============ rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition -rm src/test/ui/cfg/cfg-panic.rs - -rm src/test/ui/mir/ssa-analysis-regression-50041.rs # uses old definition of Box - -rm src/test/ui/target-feature/missing-plusminus.rs # error not implemented rm -r src/test/ui/polymorphization/ # polymorphization not yet supported rm src/test/codegen-units/polymorphization/unused_type_parameters.rs # same -rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization -rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs -rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support - -rm src/test/ui/abi/stack-protector.rs # requires stack protector support - rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code 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 +rm src/test/ui/mir/ssa-analysis-regression-50041.rs # produces ICE -rm src/test/incremental/thinlto/cgu_invalidated_when_import_{added,removed}.rs # requires LLVM - +# bugs in the test suite +# ====================== rm src/test/ui/unsafe/union.rs # has UB caught by cg_clif. see rust-lang/rust#95075 echo "[TEST] rustc test suite" From dab7fc6155f3f487f29b25bc1ad89b69e283cad7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 20:51:53 +0100 Subject: [PATCH 35/44] Remove no longer necessary rand patch --- ...1-rand-Enable-c2-chacha-simd-feature.patch | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 patches/0001-rand-Enable-c2-chacha-simd-feature.patch diff --git a/patches/0001-rand-Enable-c2-chacha-simd-feature.patch b/patches/0001-rand-Enable-c2-chacha-simd-feature.patch deleted file mode 100644 index 01dc0fcc53761..0000000000000 --- a/patches/0001-rand-Enable-c2-chacha-simd-feature.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 9c5663e36391fa20becf84f3af2e82afa5bb720b Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sat, 15 Aug 2020 19:56:03 +0200 -Subject: [PATCH] [rand] Enable c2-chacha simd feature - ---- - rand_chacha/Cargo.toml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml -index 9190b7f..872cca2 100644 ---- a/rand_chacha/Cargo.toml -+++ b/rand_chacha/Cargo.toml -@@ -24,5 +24,5 @@ ppv-lite86 = { version = "0.2.8", default-features = false } - - [features] - default = ["std"] --std = ["ppv-lite86/std"] -+std = ["ppv-lite86/std", "ppv-lite86/simd"] - simd = [] # deprecated --- -2.20.1 - From 6b0c411fe737a87d10e9c6060328242fa15bfc06 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 20:59:51 +0100 Subject: [PATCH 36/44] Cleanup rand test disable patch --- patches/0002-rand-Disable-failing-test.patch | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/patches/0002-rand-Disable-failing-test.patch b/patches/0002-rand-Disable-failing-test.patch index 19fd20d726901..ae13ab3b0ca63 100644 --- a/patches/0002-rand-Disable-failing-test.patch +++ b/patches/0002-rand-Disable-failing-test.patch @@ -4,27 +4,18 @@ Date: Sat, 15 Aug 2020 20:04:38 +0200 Subject: [PATCH] [rand] Disable failing test --- - src/distributions/uniform.rs | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) + src/distributions/uniform.rs | 1 + + 1 file changed, 1 insertion(+), 0 deletions(-) diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 480b859..c80bb6f 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs -@@ -1085,7 +1085,7 @@ mod tests { - _ => panic!("`UniformDurationMode` was not serialized/deserialized correctly") - } - } -- -+ - #[test] - #[cfg(feature = "serde1")] - fn test_uniform_serialization() { @@ -1314,6 +1314,7 @@ mod tests { not(target_arch = "wasm32"), not(target_arch = "asmjs") ))] -+ #[ignore] // FIXME ++ #[ignore] // Requires unwinding fn test_float_assertions() { use super::SampleUniform; use std::panic::catch_unwind; From 31329f98412b70f034e41420dba28cb8d14ec4a9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Mar 2022 21:19:37 +0100 Subject: [PATCH 37/44] Enable rand based libcore tests Part of #806 --- ...-sysroot-Disable-not-compiling-tests.patch | 37 ++----------------- ...8-sysroot-Disable-long-running-tests.patch | 16 ++++++++ 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/patches/0022-sysroot-Disable-not-compiling-tests.patch b/patches/0022-sysroot-Disable-not-compiling-tests.patch index 1c45c7573c813..108a97bd7c600 100644 --- a/patches/0022-sysroot-Disable-not-compiling-tests.patch +++ b/patches/0022-sysroot-Disable-not-compiling-tests.patch @@ -18,7 +18,7 @@ new file mode 100644 index 0000000..46fd999 --- /dev/null +++ b/library/core/tests/Cargo.toml -@@ -0,0 +1,8 @@ +@@ -0,0 +1,11 @@ +[package] +name = "core" +version = "0.0.0" @@ -27,18 +27,9 @@ index 0000000..46fd999 +[lib] +name = "coretests" +path = "lib.rs" -diff --git a/library/core/tests/num/flt2dec/mod.rs b/library/core/tests/num/flt2dec/mod.rs -index a35897e..f0bf645 100644 ---- a/library/core/tests/num/flt2dec/mod.rs -+++ b/library/core/tests/num/flt2dec/mod.rs -@@ -13,7 +13,6 @@ mod strategy { - mod dragon; - mod grisu; - } --mod random; - - pub fn decode_finite(v: T) -> Decoded { - match decode(v).1 { ++ ++[dependencies] ++rand = "0.7" diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 1a6be3a..42dbd59 100644 --- a/library/core/tests/ptr.rs @@ -59,25 +50,5 @@ index 1a6be3a..42dbd59 100644 #[test] fn write_unaligned_drop() { -diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 6609bc3..241b497 100644 ---- a/library/core/tests/slice.rs -+++ b/library/core/tests/slice.rs -@@ -1209,6 +1209,7 @@ fn brute_force_rotate_test_1() { - } - } - -+/* - #[test] - #[cfg(not(target_arch = "wasm32"))] - fn sort_unstable() { -@@ -1394,6 +1395,7 @@ fn partition_at_index() { - v.select_nth_unstable(0); - assert!(v == [0xDEADBEEF]); - } -+*/ - - #[test] - #[should_panic(expected = "index 0 greater than length of slice")] -- 2.21.0 (Apple Git-122) diff --git a/patches/0028-sysroot-Disable-long-running-tests.patch b/patches/0028-sysroot-Disable-long-running-tests.patch index dc1beae6d2e71..d804a78cc1061 100644 --- a/patches/0028-sysroot-Disable-long-running-tests.patch +++ b/patches/0028-sysroot-Disable-long-running-tests.patch @@ -11,6 +11,22 @@ diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 8402833..84592e0 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs +@@ -1809,6 +1809,7 @@ fn sort_unstable() { + assert!(v == [0xDEADBEEF]); + } + ++/* + #[test] + #[cfg(not(target_arch = "wasm32"))] + #[cfg_attr(miri, ignore)] // Miri is too slow +@@ -1914,6 +1915,7 @@ fn select_nth_unstable() { + v.select_nth_unstable(0); + assert!(v == [0xDEADBEEF]); + } ++*/ + + #[test] + #[should_panic(expected = "index 0 greater than length of slice")] @@ -2462,6 +2462,7 @@ take_tests! { #[cfg(not(miri))] // unused in Miri const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; From ef4512b7dcaf2ae10e80e3aeb9b014c4128364b2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 10:44:56 +0100 Subject: [PATCH 38/44] Codegen 128bit atomic loads and stores for compiler builtins as trap 128bit atomics are unstable and only enabled on AArch64 and x86_64 macOS. Cranelift doesn't support 128bit atomics yet. --- build_sysroot/Cargo.lock | 2 + build_sysroot/Cargo.toml | 12 ++++- build_system/prepare.rs | 8 ---- ...ins-Disable-128bit-atomic-operations.patch | 48 ------------------- scripts/setup_rust_fork.sh | 12 ----- src/intrinsics/mod.rs | 32 ++++++++++--- 6 files changed, 39 insertions(+), 75 deletions(-) delete mode 100644 patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 151adaddaaa6e..815826d8497d2 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -57,6 +57,8 @@ dependencies = [ [[package]] name = "compiler_builtins" version = "0.1.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80873f979f0a344a4ade87c2f70d9ccf5720b83b10c97ec7cd745895d021e85a" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_sysroot/Cargo.toml b/build_sysroot/Cargo.toml index f25d87e60c0c1..d0e5fc4a3b9f1 100644 --- a/build_sysroot/Cargo.toml +++ b/build_sysroot/Cargo.toml @@ -14,7 +14,6 @@ compiler_builtins = { version = "0.1.39", default-features = false, features = [ rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" } rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" } rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" } -compiler_builtins = { path = "./compiler-builtins" } [profile.dev] lto = "off" @@ -23,3 +22,14 @@ lto = "off" debug = true incremental = true lto = "off" + +# Mandatory for correctly compiling compiler-builtins +[profile.dev.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 + +[profile.release.package.compiler_builtins] +debug-assertions = false +overflow-checks = false +codegen-units = 10000 diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 133aea2acc081..8bb00352d3fe3 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -81,14 +81,6 @@ fn prepare_sysroot() { init_git_repo(&sysroot_src); apply_patches("sysroot", &sysroot_src); - - clone_repo_shallow_github( - "build_sysroot/compiler-builtins", - "rust-lang", - "compiler-builtins", - "0.1.70", - ); - apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } #[allow(dead_code)] diff --git a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch deleted file mode 100644 index 460e42d1d8cc3..0000000000000 --- a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:30:55 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - src/mem/mod.rs | 12 ------------ - 1 file changed, 12 deletions(-) - -diff --git a/src/mem/mod.rs b/src/mem/mod.rs -index 107762c..2d1ae10 100644 ---- a/src/mem/mod.rs -+++ b/src/mem/mod.rs -@@ -137,10 +137,6 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memcpy_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memcpy_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { -@@ -158,10 +154,6 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memmove_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memmove_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { -@@ -179,8 +171,4 @@ intrinsics! { - pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { - memset_element_unordered_atomic(s, c, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub unsafe extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { -- memset_element_unordered_atomic(s, c, bytes); -- } - } --- -2.26.2.7.g19db9cfb68 - diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index ddcf05ec25227..85c0109c6f61e 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -12,18 +12,6 @@ git checkout -- . git checkout "$(rustc -V | cut -d' ' -f3 | tr -d '(')" git apply - <( _ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) { let ty = substs.type_at(0); match ty.kind() { + ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { + // FIXME implement 128bit atomics + if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { + // special case for compiler-builtins to avoid having to patch it + crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported"); + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); + return; + } else { + fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + } + } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, span, ty); @@ -765,6 +777,18 @@ fn codegen_regular_intrinsic_call<'tcx>( _ if intrinsic.as_str().starts_with("atomic_store"), (v ptr, c val) { let ty = substs.type_at(0); match ty.kind() { + ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { + // FIXME implement 128bit atomics + if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { + // special case for compiler-builtins to avoid having to patch it + crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported"); + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); + return; + } else { + fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + } + } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, span, ty); @@ -1115,10 +1139,6 @@ fn codegen_regular_intrinsic_call<'tcx>( }; } - if let Some((_, dest)) = destination { - let ret_block = fx.get_block(dest); - fx.bcx.ins().jump(ret_block, &[]); - } else { - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); - } + let ret_block = fx.get_block(destination.unwrap().1); + fx.bcx.ins().jump(ret_block, &[]); } From 8afa50c4825b0e6494be9d731da28669e716564e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 13:36:25 +0100 Subject: [PATCH 39/44] Rustup to rustc 1.61.0-nightly (1bfe40d11 2022-03-18) --- 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 815826d8497d2..f584f54e106ac 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.70" +version = "0.1.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80873f979f0a344a4ade87c2f70d9ccf5720b83b10c97ec7cd745895d021e85a" +checksum = "163437f05ca8f29d7e9128ea728dedf5eb620e445fbca273641d3a3050305f23" dependencies = [ "rustc-std-workspace-core", ] @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.120" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 56adaa6a5553b..84d90e5db0253 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-03-15" +channel = "nightly-2022-03-19" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 215905cdc8accbc8abe26da8650d6959e86cf9e0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 16:54:51 +0100 Subject: [PATCH 40/44] Wrap write_mir_fn call in with_no_trimmed_paths!() --- src/base.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index fe5d80b2a9239..a9ff710c91ed6 100644 --- a/src/base.rs +++ b/src/base.rs @@ -26,7 +26,10 @@ pub(crate) fn codegen_fn<'tcx>( let mir = tcx.instance_mir(instance.def); let _mir_guard = crate::PrintOnPanic(|| { let mut buf = Vec::new(); - rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf).unwrap(); + with_no_trimmed_paths!({ + rustc_middle::mir::pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf) + .unwrap(); + }); String::from_utf8_lossy(&buf).into_owned() }); From e7e5016207c40f3520e0bc55a34ada3a2a778ac2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 15:48:19 +0100 Subject: [PATCH 41/44] Move test and clarify problem of some other tests --- scripts/test_rustc_tests.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index b4ce2abb18c94..ebc3f80d62073 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -44,6 +44,7 @@ rm src/test/ui/numbers-arithmetic/issue-8460.rs rm src/test/ui/runtime/rt-explody-panic-payloads.rs rm src/test/incremental/change_crate_dep_kind.rs rm src/test/ui/threads-sendsync/unwind-resource.rs +rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) # requires compiling with -Cpanic=unwind rm src/test/ui/cfg/cfg-panic.rs @@ -99,6 +100,9 @@ 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 +# 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/unstable-flag-required # same rm -r src/test/run-make/rustdoc-* # same @@ -110,7 +114,6 @@ rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oo rm -r src/test/ui/polymorphization/ # polymorphization not yet supported rm src/test/codegen-units/polymorphization/unused_type_parameters.rs # same -rm src/test/incremental/issue-80691-bad-eval-cache.rs # wrong exit code 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 From 636fb020c445baf1b3172d7df2dab745b46093c3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 16:11:53 +0100 Subject: [PATCH 42/44] Ignore rustc tests with needs-unwind directive --- scripts/test_rustc_tests.sh | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index ebc3f80d62073..e9b8c297a3909 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,8 +10,8 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -rm -r src/test/ui/{extern/,panics/,unsized-locals/,lto/,simd*,linkage*,unwind-*.rs} || true -for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// needs-asm-support" src/test/ui); do +rm -r src/test/ui/{extern/,unsized-locals/,lto/,simd*,linkage*} || true +for test in $(rg --files-with-matches "asm!|lto|// needs-asm-support|// needs-unwind" src/test/{ui,incremental}); do rm $test done @@ -26,28 +26,15 @@ git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR # requires stack unwinding rm src/test/ui/backtrace.rs -rm src/test/ui/array-slice-vec/box-of-array-of-drop-*.rs -rm src/test/ui/array-slice-vec/slice-panic-*.rs -rm src/test/ui/array-slice-vec/nested-vec-3.rs -rm src/test/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs -rm src/test/ui/issues/issue-26655.rs -rm src/test/ui/issues/issue-29485.rs -rm src/test/ui/issues/issue-30018-panic.rs rm src/test/ui/process/multi-panic.rs -rm src/test/ui/sepcomp/sepcomp-unwind.rs -rm src/test/ui/structs-enums/unit-like-struct-drop-run.rs -rm src/test/ui/drop/terminate-in-initializer.rs -rm src/test/ui/threads-sendsync/task-stderr.rs -rm src/test/ui/numbers-arithmetic/int-abs-overflow.rs -rm src/test/ui/drop/drop-trait-enum.rs rm src/test/ui/numbers-arithmetic/issue-8460.rs -rm src/test/ui/runtime/rt-explody-panic-payloads.rs rm src/test/incremental/change_crate_dep_kind.rs -rm src/test/ui/threads-sendsync/unwind-resource.rs rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abort instead of exit(101) +rm src/test/ui/panic-while-printing.rs +rm src/test/ui/test-attrs/test-panic-while-printing.rs +rm src/test/ui/test-attrs/test-type.rs # requires compiling with -Cpanic=unwind -rm src/test/ui/cfg/cfg-panic.rs rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process" rm src/test/ui/async-await/async-fn-size-moved-locals.rs # -Cpanic=abort shrinks some generator by one byte rm src/test/ui/async-await/async-fn-size-uninit-locals.rs # same @@ -57,18 +44,11 @@ rm src/test/ui/generator/size-moved-locals.rs # same rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics -# inline asm -rm src/test/incremental/hashes/inline_asm.rs # inline asm -rm src/test/incremental/issue-72386.rs # same - # exotic linkages rm src/test/ui/issues/issue-33992.rs # unsupported linkages rm src/test/incremental/hashes/function_interfaces.rs # same rm src/test/incremental/hashes/statics.rs # same -# LTO -rm src/test/incremental/lto.rs # requires lt - # variadic arguments rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support From 370c397ec9169809e5ad270079712e0043514240 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Mar 2022 16:32:07 +0100 Subject: [PATCH 43/44] Run part of the simd test suite --- scripts/test_rustc_tests.sh | 15 ++++++++++++++- src/intrinsics/simd.rs | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index e9b8c297a3909..a32e6df220832 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,7 +10,7 @@ pushd rust command -v rg >/dev/null 2>&1 || cargo install ripgrep -rm -r src/test/ui/{extern/,unsized-locals/,lto/,simd*,linkage*} || true +rm -r src/test/ui/{extern/,unsized-locals/,lto/,linkage*} || true for test in $(rg --files-with-matches "asm!|lto|// needs-asm-support|// needs-unwind" src/test/{ui,incremental}); do rm $test done @@ -43,6 +43,16 @@ rm src/test/ui/generator/size-moved-locals.rs # same # vendor intrinsics rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # requires x86_64 vendor intrinsics +rm src/test/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant" +rm src/test/ui/simd/intrinsic/generic-bitmask-pass.rs # simd_bitmask unimplemented +rm src/test/ui/simd/intrinsic/generic-as.rs # simd_as unimplemented +rm src/test/ui/simd/intrinsic/generic-arithmetic-saturating-pass.rs # simd_saturating_add unimplemented +rm src/test/ui/simd/intrinsic/float-math-pass.rs # simd_fcos unimplemented +rm src/test/ui/simd/intrinsic/generic-gather-pass.rs # simd_gather unimplemented +rm src/test/ui/simd/intrinsic/generic-select-pass.rs # simd_select_bitmask unimplemented +rm src/test/ui/simd/issue-85915-simd-ptrs.rs # simd_gather unimplemented +rm src/test/ui/simd/issue-89193.rs # simd_gather unimplemented +rm src/test/ui/simd/simd-bitmask.rs # simd_bitmask unimplemented # exotic linkages rm src/test/ui/issues/issue-33992.rs # unsupported linkages @@ -76,6 +86,7 @@ rm src/test/ui/abi/stack-protector.rs # requires stack protector support # giving different but possibly correct results # ============================================= rm src/test/ui/numbers-arithmetic/saturating-float-casts.rs # intrinsic gives different but valid result +rm src/test/ui/simd/intrinsic/float-minmax-pass.rs # same 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 @@ -99,6 +110,8 @@ 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 rm src/test/ui/mir/ssa-analysis-regression-50041.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 + # bugs in the test suite # ====================== rm src/test/ui/unsafe/union.rs # has UB caught by cg_clif. see rust-lang/rust#95075 diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 49022ebd3e26f..bc21d73616627 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -409,6 +409,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_add_ordered | simd_reduce_add_unordered, (c v, v acc) { + // FIXME there must be no acc param for integer vectors if !v.layout().ty.is_simd() { report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); return; @@ -424,6 +425,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_mul_ordered | simd_reduce_mul_unordered, (c v, v acc) { + // FIXME there must be no acc param for integer vectors if !v.layout().ty.is_simd() { report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty); return; From ce7f5ecad70175acb0d34860978adafb195f68c5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Mar 2022 17:01:32 +0100 Subject: [PATCH 44/44] Add once_cell as allowed cg_clif dependency --- src/tools/tidy/src/deps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index d6e36c2e7db40..ab4be43e49549 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -258,6 +258,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "mach", "memchr", "object", + "once_cell", "regalloc", "region", "rustc-hash",