From d9025cebac5dc98cc96b72b6e17dd8ad1c77929a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 15 May 2022 12:32:19 +0200 Subject: [PATCH 01/77] Merge commit '63734fcdd718cca089f84c42f3a42c0096cfd431' into sync_cg_clif-2022-05-15 --- .github/workflows/main.yml | 6 +- .github/workflows/nightly-cranelift.yml | 4 +- .github/workflows/rustc.yml | 4 +- .vscode/settings.json | 2 +- Cargo.toml | 10 -- build_sysroot/Cargo.lock | 12 +-- build_system/build_backend.rs | 12 --- build_system/build_sysroot.rs | 86 ++++++++--------- build_system/mod.rs | 1 + docs/usage.md | 6 +- ...027-sysroot-128bit-atomic-operations.patch | 10 +- rust-toolchain | 2 +- scripts/cargo-clif.rs | 26 ++--- scripts/config.sh | 6 -- scripts/ext_config.sh | 32 ------- scripts/filter_profile.rs | 3 +- scripts/rustc-clif.rs | 36 +++++++ scripts/setup_rust_fork.sh | 18 +--- scripts/test_rustc_tests.sh | 3 +- scripts/tests.sh | 53 +++++++++-- src/abi/mod.rs | 30 +++--- src/base.rs | 26 +++-- src/bin/cg_clif.rs | 94 ------------------- src/bin/cg_clif_build_sysroot.rs | 93 ------------------ src/common.rs | 52 +++++++--- src/driver/jit.rs | 4 +- src/intrinsics/mod.rs | 62 ++++++------ src/value_and_place.rs | 1 + 28 files changed, 269 insertions(+), 425 deletions(-) delete mode 100644 scripts/config.sh delete mode 100644 scripts/ext_config.sh create mode 100644 scripts/rustc-clif.rs delete mode 100644 src/bin/cg_clif.rs delete mode 100644 src/bin/cg_clif_build_sysroot.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3aba528abfd6d..aa556a21bf8c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: timeout-minutes: 10 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install rustfmt run: | @@ -39,7 +39,7 @@ jobs: TARGET_TRIPLE: aarch64-unknown-linux-gnu steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache cargo installed crates uses: actions/cache@v2 @@ -127,7 +127,7 @@ jobs: timeout-minutes: 60 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 #- name: Cache cargo installed crates # uses: actions/cache@v2 diff --git a/.github/workflows/nightly-cranelift.yml b/.github/workflows/nightly-cranelift.yml index a019793edd8d2..0a3e7ca073b45 100644 --- a/.github/workflows/nightly-cranelift.yml +++ b/.github/workflows/nightly-cranelift.yml @@ -11,7 +11,7 @@ jobs: timeout-minutes: 60 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache cargo installed crates uses: actions/cache@v2 @@ -34,7 +34,7 @@ jobs: sed -i 's/cranelift-jit = { version = "\w*.\w*.\w*", optional = true }/cranelift-jit = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git", optional = true }/' Cargo.toml sed -i 's/cranelift-object = "\w*.\w*.\w*"/cranelift-object = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml - sed -i 's/gimli = { version = "0.25.0", default-features = false, features = \["write"\]}/gimli = { version = "0.26.1", default-features = false, features = ["write"] }/' Cargo.toml + sed -i 's/object = { version = "0.27.0"/object = { version = "0.28.0"/' Cargo.toml cat Cargo.toml diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index 1c08e5ece33d2..b8a98b83ebe5e 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache cargo installed crates uses: actions/cache@v2 @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Cache cargo installed crates uses: actions/cache@v2 diff --git a/.vscode/settings.json b/.vscode/settings.json index 74fde9c27c0e4..ecb20f22d8c92 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,7 @@ "rust-analyzer.assist.importEnforceGranularity": true, "rust-analyzer.assist.importPrefix": "crate", "rust-analyzer.cargo.runBuildScripts": true, - "rust-analyzer.cargo.features": ["unstable-features"] + "rust-analyzer.cargo.features": ["unstable-features"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", //"./build_sysroot/sysroot_src/src/libstd/Cargo.toml", diff --git a/Cargo.toml b/Cargo.toml index 74f50808a980a..18d7f41cf408a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,15 +41,5 @@ unstable-features = ["jit", "inline_asm"] jit = ["cranelift-jit", "libloading"] inline_asm = [] -# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the -# execution time of build scripts is so fast that optimizing them slows down the total build time. -[profile.release.build-override] -opt-level = 0 -debug = false - -[profile.release.package.cranelift-codegen-meta] -opt-level = 0 -debug = false - [package.metadata.rust-analyzer] rustc_private = true diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 51ba0dbfcc792..efee6ef3f3780 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -134,18 +134,18 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.124" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" dependencies = [ "rustc-std-workspace-core", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 0a56eb131ed30..48faec8bc4b94 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -34,18 +34,6 @@ pub(crate) fn build_backend( _ => unreachable!(), } - // Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing - // LD_LIBRARY_PATH - if cfg!(unix) { - if cfg!(target_os = "macos") { - rustflags += " -Csplit-debuginfo=unpacked \ - -Clink-arg=-Wl,-rpath,@loader_path/../lib \ - -Zosx-rpath-install-name"; - } else { - rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib "; - } - } - cmd.env("RUSTFLAGS", rustflags); eprintln!("[BUILD] rustc_codegen_cranelift"); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index c9c003d461095..8682204f4fd30 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,4 +1,3 @@ -use std::env; use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; @@ -22,35 +21,28 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - for file in ["cg_clif", "cg_clif_build_sysroot"] { - try_hard_link( - cg_clif_build_dir.join(get_file_name(file, "bin")), - target_dir.join("bin").join(get_file_name(file, "bin")), - ); - } - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); - try_hard_link( - cg_clif_build_dir.join(&cg_clif_dylib), - target_dir - .join(if cfg!(windows) { - // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the - // binaries. - "bin" - } else { - "lib" - }) - .join(cg_clif_dylib), - ); - - // Build and copy cargo wrapper - let mut build_cargo_wrapper_cmd = Command::new("rustc"); - build_cargo_wrapper_cmd - .arg("scripts/cargo-clif.rs") - .arg("-o") - .arg(target_dir.join("cargo-clif")) - .arg("-g"); - spawn_and_wait(build_cargo_wrapper_cmd); + let cg_clif_dylib_path = target_dir + .join(if cfg!(windows) { + // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the + // binaries. + "bin" + } else { + "lib" + }) + .join(&cg_clif_dylib); + try_hard_link(cg_clif_build_dir.join(cg_clif_dylib), &cg_clif_dylib_path); + + // Build and copy rustc and cargo wrappers + for wrapper in ["rustc-clif", "cargo-clif"] { + let mut build_cargo_wrapper_cmd = Command::new("rustc"); + build_cargo_wrapper_cmd + .arg(PathBuf::from("scripts").join(format!("{wrapper}.rs"))) + .arg("-o") + .arg(target_dir.join(wrapper)) + .arg("-g"); + spawn_and_wait(build_cargo_wrapper_cmd); + } let default_sysroot = super::rustc_info::get_default_sysroot(); @@ -117,7 +109,13 @@ pub(crate) fn build_sysroot( } } SysrootKind::Clif => { - build_clif_sysroot_for_triple(channel, target_dir, host_triple, None); + build_clif_sysroot_for_triple( + channel, + target_dir, + host_triple, + &cg_clif_dylib_path, + None, + ); if host_triple != target_triple { // When cross-compiling it is often necessary to manually pick the right linker @@ -126,14 +124,21 @@ pub(crate) fn build_sysroot( } else { None }; - build_clif_sysroot_for_triple(channel, target_dir, target_triple, linker); + build_clif_sysroot_for_triple( + channel, + target_dir, + target_triple, + &cg_clif_dylib_path, + linker, + ); } // Copy std for the host to the lib dir. This is necessary for the jit mode to find // libstd. for file in fs::read_dir(host_rustlib_lib).unwrap() { let file = file.unwrap().path(); - if file.file_name().unwrap().to_str().unwrap().contains("std-") { + let filename = file.file_name().unwrap().to_str().unwrap(); + if filename.contains("std-") && !filename.contains(".rlib") { try_hard_link(&file, target_dir.join("lib").join(file.file_name().unwrap())); } } @@ -145,6 +150,7 @@ fn build_clif_sysroot_for_triple( channel: &str, target_dir: &Path, triple: &str, + cg_clif_dylib_path: &Path, linker: Option<&str>, ) { match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) { @@ -168,18 +174,18 @@ fn build_clif_sysroot_for_triple( let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); 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() { - fs::remove_dir_all(build_dir.join(dir)).unwrap(); - } + // Cleanup the deps dir, but keep build scripts and the incremental cache for faster + // recompilation as they are not affected by changes in cg_clif. + if build_dir.join("deps").exists() { + fs::remove_dir_all(build_dir.join("deps")).unwrap(); } } // Build sysroot let mut build_cmd = Command::new("cargo"); build_cmd.arg("build").arg("--target").arg(triple).current_dir("build_sysroot"); - let mut rustflags = "--clif -Zforce-unstable-if-unmarked".to_string(); + let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string(); + rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap())); if channel == "release" { build_cmd.arg("--release"); rustflags.push_str(" -Zmir-opt-level=3"); @@ -189,10 +195,6 @@ fn build_clif_sysroot_for_triple( write!(rustflags, " -Clinker={}", linker).unwrap(); } build_cmd.env("RUSTFLAGS", rustflags); - build_cmd.env( - "RUSTC", - env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"), - ); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); spawn_and_wait(build_cmd); diff --git a/build_system/mod.rs b/build_system/mod.rs index b228da3981fdb..b897b7fbacfcd 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -86,6 +86,7 @@ pub fn main() { arg => arg_error!("Unexpected argument {}", arg), } } + target_dir = std::env::current_dir().unwrap().join(target_dir); let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { host_triple diff --git a/docs/usage.md b/docs/usage.md index 785c738378374..33f146e7ba27a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -19,7 +19,7 @@ This will build your project with rustc_codegen_cranelift instead of the usual L > You should prefer using the Cargo method. ```bash -$ $cg_clif_dir/build/bin/cg_clif my_crate.rs +$ $cg_clif_dir/build/rustc-clif my_crate.rs ``` ## Jit mode @@ -38,7 +38,7 @@ $ $cg_clif_dir/build/cargo-clif jit or ```bash -$ $cg_clif_dir/build/bin/cg_clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs +$ $cg_clif_dir/build/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs ``` There is also an experimental lazy jit mode. In this mode functions are only compiled once they are @@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell ```bash function jit_naked() { - echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic + echo "$@" | $cg_clif_dir/build/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic } function jit() { diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch index 8e6652af3747b..ce1c6c99b40c8 100644 --- a/patches/0027-sysroot-128bit-atomic-operations.patch +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -21,7 +21,7 @@ index 092b7cf..158cf71 100644 -#[cfg(target_has_atomic_load_store = "128")] -#[unstable(feature = "integer_atomics", issue = "32976")] -impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} - + #[cfg(target_has_atomic_load_store = "ptr")] #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] @@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {} @@ -31,14 +31,14 @@ index 092b7cf..158cf71 100644 -#[cfg(target_has_atomic_load_store = "128")] -#[unstable(feature = "integer_atomics", issue = "32976")] -impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} - + #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index d9de37e..8293fce 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs -@@ -2234,44 +2234,6 @@ atomic_int! { +@@ -2234,46 +2234,6 @@ atomic_int! { "AtomicU64::new(0)", u64 AtomicU64 ATOMIC_U64_INIT } @@ -54,6 +54,7 @@ index d9de37e..8293fce 100644 - unstable(feature = "integer_atomics", issue = "32976"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), - unstable(feature = "integer_atomics", issue = "32976"), +- cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"), - "i128", - "#![feature(integer_atomics)]\n\n", - atomic_min, atomic_max, @@ -73,6 +74,7 @@ index d9de37e..8293fce 100644 - unstable(feature = "integer_atomics", issue = "32976"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), - unstable(feature = "integer_atomics", issue = "32976"), +- cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"), - "u128", - "#![feature(integer_atomics)]\n\n", - atomic_umin, atomic_umax, @@ -98,6 +100,6 @@ index b735957..ea728b6 100644 #[cfg(target_has_atomic = "ptr")] assert_eq!(align_of::(), size_of::()); #[cfg(target_has_atomic = "ptr")] --- +-- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index 966097c248b6f..e98e92e468e93 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-04-21" +channel = "nightly-2022-05-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index 41d82b581cd8c..9362b47fa6d83 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -5,20 +5,11 @@ use std::path::PathBuf; use std::process::Command; fn main() { - if env::var("RUSTC_WRAPPER").map_or(false, |wrapper| wrapper.contains("sccache")) { - eprintln!( - "\x1b[1;93m=== Warning: Unsetting RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m" - ); - env::remove_var("RUSTC_WRAPPER"); - } - let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap()); - env::set_var("RUSTC", sysroot.join("bin/cg_clif".to_string() + env::consts::EXE_SUFFIX)); - - let mut rustdoc_flags = env::var("RUSTDOCFLAGS").unwrap_or(String::new()); - rustdoc_flags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend="); - rustdoc_flags.push_str( + let mut rustflags = String::new(); + rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend="); + rustflags.push_str( sysroot .join(if cfg!(windows) { "bin" } else { "lib" }) .join( @@ -29,9 +20,10 @@ fn main() { .to_str() .unwrap(), ); - rustdoc_flags.push_str(" --sysroot "); - rustdoc_flags.push_str(sysroot.to_str().unwrap()); - env::set_var("RUSTDOCFLAGS", rustdoc_flags); + rustflags.push_str(" --sysroot "); + rustflags.push_str(sysroot.to_str().unwrap()); + env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags); + env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags); // Ensure that the right toolchain is used env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); @@ -46,7 +38,7 @@ fn main() { .chain(env::args().skip(2)) .chain([ "--".to_string(), - "-Zunstable-features".to_string(), + "-Zunstable-options".to_string(), "-Cllvm-args=mode=jit".to_string(), ]) .collect() @@ -60,7 +52,7 @@ fn main() { .chain(env::args().skip(2)) .chain([ "--".to_string(), - "-Zunstable-features".to_string(), + "-Zunstable-options".to_string(), "-Cllvm-args=mode=jit-lazy".to_string(), ]) .collect() diff --git a/scripts/config.sh b/scripts/config.sh deleted file mode 100644 index 53ada369b089a..0000000000000 --- a/scripts/config.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Note to people running shellcheck: this file should only be sourced, not executed directly. - -set -e - -export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH" -export DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH" diff --git a/scripts/ext_config.sh b/scripts/ext_config.sh deleted file mode 100644 index 11d6c4c831867..0000000000000 --- a/scripts/ext_config.sh +++ /dev/null @@ -1,32 +0,0 @@ -# Note to people running shellcheck: this file should only be sourced, not executed directly. - -# Various env vars that should only be set for the build system - -set -e - -export CG_CLIF_DISPLAY_CG_TIME=1 -export CG_CLIF_DISABLE_INCR_CACHE=1 - -export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ") -export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE} - -export RUN_WRAPPER='' -export JIT_SUPPORTED=1 -if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then - export JIT_SUPPORTED=0 - if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then - # We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. - export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS - export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu' - elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then - # We are cross-compiling for Windows. Run tests in wine. - export RUN_WRAPPER='wine' - else - echo "Unknown non-native platform" - fi -fi - -# FIXME fix `#[linkage = "extern_weak"]` without this -if [[ "$(uname)" == 'Darwin' ]]; then - export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" -fi diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index f4e863e5494b5..e6f60d1c0cb23 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -2,8 +2,7 @@ #![forbid(unsafe_code)]/* This line is ignored by bash # This block is ignored by rustc pushd $(dirname "$0")/../ -source scripts/config.sh -RUSTC="$(pwd)/build/bin/cg_clif" +RUSTC="$(pwd)/build/rustc-clif" popd PROFILE=$1 OUTPUT=$2 exec $RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic $0 #*/ diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs new file mode 100644 index 0000000000000..3abfcd8ddc824 --- /dev/null +++ b/scripts/rustc-clif.rs @@ -0,0 +1,36 @@ +use std::env; +use std::ffi::OsString; +#[cfg(unix)] +use std::os::unix::process::CommandExt; +use std::path::PathBuf; +use std::process::Command; + +fn main() { + let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap()); + + let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join( + env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX, + ); + + let mut args = std::env::args_os().skip(1).collect::>(); + args.push(OsString::from("-Cpanic=abort")); + args.push(OsString::from("-Zpanic-abort-tests")); + let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); + codegen_backend_arg.push(cg_clif_dylib_path); + args.push(codegen_backend_arg); + if !args.contains(&OsString::from("--sysroot")) { + args.push(OsString::from("--sysroot")); + args.push(OsString::from(sysroot.to_str().unwrap())); + } + + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + + #[cfg(unix)] + Command::new("rustc").args(args).exec(); + + #[cfg(not(unix))] + std::process::exit( + Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + ); +} diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index cabbaaa892251..4d0dfa16c5ecf 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -2,7 +2,6 @@ set -e ./y.rs build --no-unstable-features -source scripts/config.sh echo "[SETUP] Rust fork" git clone https://github.com/rust-lang/rust.git || true @@ -26,21 +25,6 @@ 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(); - 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 @@ -67,7 +51,7 @@ changelog-seen = 2 ninja = false [build] -rustc = "$(pwd)/../build/bin/cg_clif" +rustc = "$(pwd)/../build/rustc-clif" cargo = "$(rustup which cargo)" full-bootstrap = true local-rebuild = true diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 4cf24c02235df..9bdb9f22c549a 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -101,11 +101,10 @@ 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/ui/type-alias-impl-trait/assoc-projection-ice.rs # produces ICE rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors -rm src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs # wrong result from `Location::caller()` - # bugs in the test suite # ====================== rm src/test/ui/backtrace.rs # TODO warning diff --git a/scripts/tests.sh b/scripts/tests.sh index aae626081f62b..9b5ffa4096049 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -2,10 +2,43 @@ set -e -source scripts/config.sh -source scripts/ext_config.sh -export RUSTC=false # ensure that cg_llvm isn't accidentally used -MY_RUSTC="$(pwd)/build/bin/cg_clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2" +export CG_CLIF_DISPLAY_CG_TIME=1 +export CG_CLIF_DISABLE_INCR_CACHE=1 + +export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ") +export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE} + +export RUN_WRAPPER='' + +case "$TARGET_TRIPLE" in + x86_64*) + export JIT_SUPPORTED=1 + ;; + *) + export JIT_SUPPORTED=0 + ;; +esac + +if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then + export JIT_SUPPORTED=0 + if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then + # We are cross-compiling for aarch64. Use the correct linker and run tests in qemu. + export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS + export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu' + elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then + # We are cross-compiling for Windows. Run tests in wine. + export RUN_WRAPPER='wine' + else + echo "Unknown non-native platform" + fi +fi + +# FIXME fix `#[linkage = "extern_weak"]` without this +if [[ "$(uname)" == 'Darwin' ]]; then + export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" +fi + +MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2" function no_sysroot_tests() { echo "[BUILD] mini_core" @@ -39,7 +72,7 @@ function base_sysroot_tests() { $MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/issue_91827_extern_types - echo "[AOT] alloc_system" + echo "[BUILD] alloc_system" $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE" echo "[AOT] alloc_example" @@ -56,14 +89,14 @@ function base_sysroot_tests() { echo "[JIT] std_example (skipped)" fi - echo "[AOT] dst_field_align" - $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) - echo "[AOT] std_example" $MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/std_example arg + echo "[AOT] dst_field_align" + $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 "[AOT] subslice-patterns-const-eval" $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/subslice-patterns-const-eval @@ -97,7 +130,7 @@ function extended_sysroot_tests() { if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then echo "[BENCH COMPILE] ebobby/simple-raytracer" hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \ - "RUSTC=rustc RUSTFLAGS='' cargo build" \ + "RUSTFLAGS='' cargo build" \ "../build/cargo-clif build" echo "[BENCH RUN] ebobby/simple-raytracer" diff --git a/src/abi/mod.rs b/src/abi/mod.rs index ef56fb191bff5..b163a42619172 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -309,7 +309,7 @@ fn codegen_call_argument_operand<'tcx>( pub(crate) fn codegen_terminator_call<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - span: Span, + source_info: mir::SourceInfo, func: &Operand<'tcx>, args: &[Operand<'tcx>], mir_dest: Option<(Place<'tcx>, BasicBlock)>, @@ -340,7 +340,13 @@ pub(crate) fn codegen_terminator_call<'tcx>( match instance.def { InstanceDef::Intrinsic(_) => { - crate::intrinsics::codegen_intrinsic_call(fx, instance, args, destination, span); + crate::intrinsics::codegen_intrinsic_call( + fx, + instance, + args, + destination, + source_info, + ); return; } InstanceDef::DropGlue(_, None) => { @@ -402,7 +408,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( // Pass the caller location for `#[track_caller]`. if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) { - let caller_location = fx.get_caller_location(span); + let caller_location = fx.get_caller_location(source_info); args.push(CallArgument { value: caller_location, is_owned: false }); } @@ -479,9 +485,10 @@ pub(crate) fn codegen_terminator_call<'tcx>( // FIXME find a cleaner way to support varargs if fn_sig.c_variadic { if !matches!(fn_sig.abi, Abi::C { .. }) { - fx.tcx - .sess - .span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi)); + fx.tcx.sess.span_fatal( + source_info.span, + &format!("Variadic call for non-C abi {:?}", fn_sig.abi), + ); } let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap(); let abi_params = call_args @@ -490,9 +497,10 @@ pub(crate) fn codegen_terminator_call<'tcx>( let ty = fx.bcx.func.dfg.value_type(arg); if !ty.is_int() { // FIXME set %al to upperbound on float args once floats are supported - fx.tcx - .sess - .span_fatal(span, &format!("Non int ty {:?} for variadic call", ty)); + fx.tcx.sess.span_fatal( + source_info.span, + &format!("Non int ty {:?} for variadic call", ty), + ); } AbiParam::new(ty) }) @@ -513,7 +521,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( pub(crate) fn codegen_drop<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - span: Span, + source_info: mir::SourceInfo, drop_place: CPlace<'tcx>, ) { let ty = drop_place.layout().ty; @@ -560,7 +568,7 @@ pub(crate) fn codegen_drop<'tcx>( if drop_instance.def.requires_caller_location(fx.tcx) { // Pass the caller location for `#[track_caller]`. - let caller_location = fx.get_caller_location(span); + let caller_location = fx.get_caller_location(source_info); call_args.extend( adjust_arg_for_abi(fx, caller_location, &fn_abi.args[1], false).into_iter(), ); diff --git a/src/base.rs b/src/base.rs index 65346cb39622a..65e5812a8a5b0 100644 --- a/src/base.rs +++ b/src/base.rs @@ -325,7 +325,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { AssertKind::BoundsCheck { ref len, ref index } => { let len = codegen_operand(fx, len).load_scalar(fx); let index = codegen_operand(fx, index).load_scalar(fx); - let location = fx.get_caller_location(source_info.span).load_scalar(fx); + let location = fx.get_caller_location(source_info).load_scalar(fx); codegen_panic_inner( fx, @@ -336,7 +336,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { } _ => { let msg_str = msg.description(); - codegen_panic(fx, msg_str, source_info.span); + codegen_panic(fx, msg_str, source_info); } } } @@ -398,7 +398,13 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { from_hir_call: _, } => { fx.tcx.sess.time("codegen call", || { - crate::abi::codegen_terminator_call(fx, *fn_span, func, args, *destination) + crate::abi::codegen_terminator_call( + fx, + mir::SourceInfo { span: *fn_span, ..source_info }, + func, + args, + *destination, + ) }); } TerminatorKind::InlineAsm { @@ -450,7 +456,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { } TerminatorKind::Drop { place, target, unwind: _ } => { let drop_place = codegen_place(fx, *place); - crate::abi::codegen_drop(fx, source_info.span, drop_place); + crate::abi::codegen_drop(fx, source_info, drop_place); let target_block = fx.get_block(*target); fx.bcx.ins().jump(target_block, &[]); @@ -471,7 +477,7 @@ fn codegen_stmt<'tcx>( fx.set_debug_loc(stmt.source_info); - #[cfg(disabled)] + #[cfg(any())] // This is never true match &stmt.kind { StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful _ => { @@ -898,14 +904,18 @@ pub(crate) fn codegen_operand<'tcx>( } } -pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) { - let location = fx.get_caller_location(span).load_scalar(fx); +pub(crate) fn codegen_panic<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + msg_str: &str, + source_info: mir::SourceInfo, +) { + let location = fx.get_caller_location(source_info).load_scalar(fx); let msg_ptr = fx.anonymous_str(msg_str); let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap()); let args = [msg_ptr, msg_len, location]; - codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, span); + codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, source_info.span); } pub(crate) fn codegen_panic_inner<'tcx>( diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs deleted file mode 100644 index 5984ec8412ad7..0000000000000 --- a/src/bin/cg_clif.rs +++ /dev/null @@ -1,94 +0,0 @@ -#![feature(rustc_private)] -#![warn(rust_2018_idioms)] -#![warn(unused_lifetimes)] -#![warn(unreachable_pub)] - -extern crate rustc_data_structures; -extern crate rustc_driver; -extern crate rustc_interface; -extern crate rustc_session; -extern crate rustc_target; - -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, TrimmedDefPaths}; -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: 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 - (*DEFAULT_HOOK)(info); - - // Separate the output with an empty line - eprintln!(); - - // Print the ICE message - rustc_driver::report_ice(info, BUG_REPORT_URL); - })); - hook - }); - -#[derive(Default)] -pub struct CraneliftPassesCallbacks { - time_passes: bool, -} - -impl rustc_driver::Callbacks for CraneliftPassesCallbacks { - fn config(&mut self, config: &mut interface::Config) { - // If a --prints=... option has been given, we don't print the "total" - // time because it will mess up the --prints output. See #64339. - self.time_passes = config.opts.prints.is_empty() - && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time); - - config.opts.cg.panic = Some(PanicStrategy::Abort); - config.opts.debugging_opts.panic_abort_tests = true; - 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; - } -} - -fn main() { - let start_time = std::time::Instant::now(); - let start_rss = get_resident_set_size(); - rustc_driver::init_rustc_env_logger(); - let mut callbacks = CraneliftPassesCallbacks::default(); - Lazy::force(&DEFAULT_HOOK); // Install ice hook - let exit_code = rustc_driver::catch_with_exit_code(|| { - let args = std::env::args_os() - .enumerate() - .map(|(i, arg)| { - arg.into_string().unwrap_or_else(|arg| { - early_error( - ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), - ) - }) - }) - .collect::>(); - let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); - run_compiler.set_make_codegen_backend(Some(Box::new(move |_| { - Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None }) - }))); - run_compiler.run() - }); - - if callbacks.time_passes { - let end_rss = get_resident_set_size(); - print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss); - } - - std::process::exit(exit_code) -} diff --git a/src/bin/cg_clif_build_sysroot.rs b/src/bin/cg_clif_build_sysroot.rs deleted file mode 100644 index bde4d71b9a33c..0000000000000 --- a/src/bin/cg_clif_build_sysroot.rs +++ /dev/null @@ -1,93 +0,0 @@ -//! The only difference between this and cg_clif.rs is that this binary defaults to using cg_llvm -//! instead of cg_clif and requires `--clif` to use cg_clif and that this binary doesn't have JIT -//! support. -//! This is necessary as with Cargo `RUSTC` applies to both target crates and host crates. The host -//! crates must be built with cg_llvm as we are currently building a sysroot for cg_clif. -//! `RUSTFLAGS` however is only applied to target crates, so `--clif` would only be passed to the -//! target crates. - -#![feature(rustc_private)] -#![warn(rust_2018_idioms)] -#![warn(unused_lifetimes)] -#![warn(unreachable_pub)] - -extern crate rustc_driver; -extern crate rustc_interface; -extern crate rustc_session; -extern crate rustc_target; - -use std::path::PathBuf; - -use rustc_interface::interface; -use rustc_session::config::ErrorOutputType; -use rustc_session::early_error; -use rustc_target::spec::PanicStrategy; - -fn find_sysroot() -> String { - // Taken from https://github.com/Manishearth/rust-clippy/pull/911. - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - match (home, toolchain) { - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => option_env!("RUST_SYSROOT") - .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") - .to_owned(), - } -} - -pub struct CraneliftPassesCallbacks { - use_clif: bool, -} - -impl rustc_driver::Callbacks for CraneliftPassesCallbacks { - fn config(&mut self, config: &mut interface::Config) { - if !self.use_clif { - config.opts.maybe_sysroot = Some(PathBuf::from(find_sysroot())); - return; - } - - config.opts.cg.panic = Some(PanicStrategy::Abort); - config.opts.debugging_opts.panic_abort_tests = true; - config.opts.maybe_sysroot = - Some(std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned()); - } -} - -fn main() { - rustc_driver::init_rustc_env_logger(); - rustc_driver::install_ice_hook(); - let exit_code = rustc_driver::catch_with_exit_code(|| { - let mut use_clif = false; - - let args = std::env::args_os() - .enumerate() - .map(|(i, arg)| { - arg.into_string().unwrap_or_else(|arg| { - early_error( - ErrorOutputType::default(), - &format!("Argument {} is not valid Unicode: {:?}", i, arg), - ) - }) - }) - .filter(|arg| { - if arg == "--clif" { - use_clif = true; - false - } else { - true - } - }) - .collect::>(); - - let mut callbacks = CraneliftPassesCallbacks { use_clif }; - - let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); - if use_clif { - run_compiler.set_make_codegen_backend(Some(Box::new(move |_| { - Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None }) - }))); - } - run_compiler.run() - }); - std::process::exit(exit_code) -} diff --git a/src/common.rs b/src/common.rs index ffa629ca16c8b..f9dc1b5169e1a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -340,22 +340,46 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.bcx.set_srcloc(SourceLoc::new(index as u32)); } - pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> { - if let Some(loc) = self.caller_location { - // `#[track_caller]` is used; return caller location instead of current location. - return loc; + // Note: must be kept in sync with get_caller_location from cg_ssa + pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> { + let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| { + let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); + let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo()); + let const_loc = fx.tcx.const_caller_location(( + rustc_span::symbol::Symbol::intern( + &caller.file.name.prefer_remapped().to_string_lossy(), + ), + caller.line as u32, + caller.col_display as u32 + 1, + )); + crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty()) + }; + + // Walk up the `SourceScope`s, in case some of them are from MIR inlining. + // If so, the starting `source_info.span` is in the innermost inlined + // function, and will be replaced with outer callsite spans as long + // as the inlined functions were `#[track_caller]`. + loop { + let scope_data = &self.mir.source_scopes[source_info.scope]; + + if let Some((callee, callsite_span)) = scope_data.inlined { + // Stop inside the most nested non-`#[track_caller]` function, + // before ever reaching its caller (which is irrelevant). + if !callee.def.requires_caller_location(self.tcx) { + return span_to_caller_location(self, source_info.span); + } + source_info.span = callsite_span; + } + + // Skip past all of the parents with `inlined: None`. + match scope_data.inlined_parent_scope { + Some(parent) => source_info.scope = parent, + None => break, + } } - let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); - let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo()); - let const_loc = self.tcx.const_caller_location(( - rustc_span::symbol::Symbol::intern( - &caller.file.name.prefer_remapped().to_string_lossy(), - ), - caller.line as u32, - caller.col_display as u32 + 1, - )); - crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty()) + // No inlined `SourceScope`s, or all of them were `#[track_caller]`. + self.caller_location.unwrap_or_else(|| span_to_caller_location(self, source_info.span)) } pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 7f15bc75fda23..1b01f4edbb3f3 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -74,6 +74,7 @@ fn create_jit_module<'tcx>( jit_builder.hotswap(hotswap); crate::compiler_builtins::register_functions_for_jit(&mut jit_builder); jit_builder.symbols(imported_symbols); + jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8); let mut jit_module = JITModule::new(jit_builder); let mut cx = crate::CodegenCx::new( @@ -210,8 +211,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { } } -#[no_mangle] -extern "C" fn __clif_jit_fn( +extern "C" fn clif_jit_fn( instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8, ) -> *const u8 { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index f7a83373e870b..29b3f36b2bef2 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -218,7 +218,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( instance: Instance<'tcx>, args: &[mir::Operand<'tcx>], destination: Option<(CPlace<'tcx>, BasicBlock)>, - span: Span, + source_info: mir::SourceInfo, ) { let intrinsic = fx.tcx.item_name(instance.def_id()); let substs = instance.substs; @@ -232,7 +232,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( fx.bcx.ins().trap(TrapCode::User(0)); } sym::transmute => { - crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", span); + crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", source_info); } _ => unimplemented!("unsupported instrinsic {}", intrinsic), } @@ -241,7 +241,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( }; if intrinsic.as_str().starts_with("simd_") { - self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, span); + self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, source_info.span); let ret_block = fx.get_block(destination.expect("SIMD intrinsics don't diverge").1); fx.bcx.ins().jump(ret_block, &[]); } else if codegen_float_intrinsic_call(fx, intrinsic, args, ret) { @@ -255,7 +255,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( substs, args, ret, - span, + source_info, destination, ); } @@ -339,7 +339,7 @@ fn codegen_regular_intrinsic_call<'tcx>( substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], ret: CPlace<'tcx>, - span: Span, + source_info: mir::SourceInfo, destination: Option<(CPlace<'tcx>, BasicBlock)>, ) { let usize_layout = fx.layout_of(fx.tcx.types.usize); @@ -347,7 +347,7 @@ fn codegen_regular_intrinsic_call<'tcx>( intrinsic_match! { fx, intrinsic, args, _ => { - fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic)); + fx.tcx.sess.span_fatal(source_info.span, &format!("unsupported intrinsic {}", intrinsic)); }; assume, (c _a) {}; @@ -658,7 +658,7 @@ fn codegen_regular_intrinsic_call<'tcx>( crate::base::codegen_panic( fx, &format!("attempted to instantiate uninhabited type `{}`", layout.ty), - span, + source_info, ) }); return; @@ -669,7 +669,7 @@ fn codegen_regular_intrinsic_call<'tcx>( crate::base::codegen_panic( fx, &format!("attempted to zero-initialize type `{}`, which is invalid", layout.ty), - span, + source_info, ); }); return; @@ -680,7 +680,7 @@ fn codegen_regular_intrinsic_call<'tcx>( crate::base::codegen_panic( fx, &format!("attempted to leave type `{}` uninitialized, which is invalid", layout.ty), - span, + source_info, ) }); return; @@ -715,19 +715,19 @@ fn codegen_regular_intrinsic_call<'tcx>( ptr_offset_from | ptr_offset_from_unsigned, (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(ty).size.bytes(); let diff_bytes = fx.bcx.ins().isub(ptr, base); // FIXME this can be an exact division. - let diff = if intrinsic == sym::ptr_offset_from_unsigned { + let val = if intrinsic == sym::ptr_offset_from_unsigned { + let usize_layout = fx.layout_of(fx.tcx.types.usize); // Because diff_bytes ULE isize::MAX, this would be fine as signed, // but unsigned is slightly easier to codegen, so might as well. - fx.bcx.ins().udiv_imm(diff_bytes, pointee_size as i64) + CValue::by_val(fx.bcx.ins().udiv_imm(diff_bytes, pointee_size as i64), usize_layout) } else { - fx.bcx.ins().sdiv_imm(diff_bytes, pointee_size as i64) + let isize_layout = fx.layout_of(fx.tcx.types.isize); + CValue::by_val(fx.bcx.ins().sdiv_imm(diff_bytes, pointee_size as i64), isize_layout) }; - let val = CValue::by_val(diff, isize_layout); ret.write_cvalue(fx, val); }; @@ -742,7 +742,7 @@ fn codegen_regular_intrinsic_call<'tcx>( }; caller_location, () { - let caller_location = fx.get_caller_location(span); + let caller_location = fx.get_caller_location(source_info); ret.write_cvalue(fx, caller_location); }; @@ -765,12 +765,12 @@ fn codegen_regular_intrinsic_call<'tcx>( fx.bcx.ins().jump(ret_block, &[]); return; } else { - fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + fx.tcx.sess.span_fatal(source_info.span, "128bit atomics not yet supported"); } } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty); return; } } @@ -793,12 +793,12 @@ fn codegen_regular_intrinsic_call<'tcx>( fx.bcx.ins().jump(ret_block, &[]); return; } else { - fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported"); + fx.tcx.sess.span_fatal(source_info.span, "128bit atomics not yet supported"); } } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty); return; } } @@ -812,7 +812,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -830,7 +830,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -850,7 +850,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -868,7 +868,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -886,7 +886,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -904,7 +904,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -922,7 +922,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -940,7 +940,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -958,7 +958,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -976,7 +976,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -994,7 +994,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } @@ -1012,7 +1012,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match layout.ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { - report_atomic_type_validation_error(fx, intrinsic, span, layout.ty); + report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty); return; } } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 8f80b02ae0d4e..a68225de58b32 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -828,6 +828,7 @@ pub(crate) fn assert_assignable<'tcx>( } } } + (ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, *a, *b), _ => { assert_eq!( from_ty, to_ty, From 01ab51bb16f3b356f081b792a2dc9574d43b5449 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 17 May 2022 11:39:43 +0200 Subject: [PATCH 02/77] Rustup to rustc 1.63.0-nightly (c52b9c10b 2022-05-16) --- 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 efee6ef3f3780..d950fea90fbcb 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.125" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index e98e92e468e93..24af8c93d539a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-05-15" +channel = "nightly-2022-05-17" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 7a10059268e456ec89aa05e4df23a2b19b4d8395 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 18 May 2022 18:18:11 +0200 Subject: [PATCH 03/77] Fix symbol tables in case of multiple object files with the same name Fixes #1228 --- src/archive.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index a099e8b3a6af3..b54898cc02a0a 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -117,7 +117,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { let mut entries = Vec::new(); - for (entry_name, entry) in self.entries { + for (mut entry_name, entry) in self.entries { // FIXME only read the symbol table of the object files to avoid having to keep all // object files in memory at once, or read them twice. let data = match entry { @@ -140,6 +140,23 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { }; if !self.no_builtin_ranlib { + if symbol_table.contains_key(&entry_name) { + // The ar crate can't handle creating a symbol table in case of multiple archive + // members with the same name. Work around this by prepending a number until we + // get a unique name. + for i in 1.. { + let new_name = format!("{}_", i) + .into_bytes() + .into_iter() + .chain(entry_name.iter().copied()) + .collect::>(); + if !symbol_table.contains_key(&new_name) { + entry_name = new_name; + break; + } + } + } + match object::File::parse(&*data) { Ok(object) => { symbol_table.insert( From 6c9a06e37ddb4b769907b7508d09d341ffdca0b5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 20 May 2022 16:44:20 +0200 Subject: [PATCH 04/77] Update Cranelift and object --- Cargo.lock | 124 ++++++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 14 +++--- 2 files changed, 96 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b8e43b639f99..9e5c7dc028205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "anyhow" version = "1.0.56" @@ -25,6 +36,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cfg-if" version = "1.0.0" @@ -33,18 +50,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed44413e7e2fe3260d0ed73e6956ab188b69c10ee92b892e401e0f4f6808c68b" +checksum = "2fa7c3188913c2d11a361e0431e135742372a2709a99b103e79758e11a0a797e" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5d83f0f26bf213f971f45589d17e5b65e4861f9ed22392b0cbb6eaa5bd329c" +checksum = "29285f70fd396a8f64455a15a6e1d390322e4a5f5186de513141313211b0a23e" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -52,37 +69,37 @@ dependencies = [ "cranelift-entity", "gimli", "log", - "regalloc", + "regalloc2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6800dc386177df6ecc5a32680607ed8ba1fa0d31a2a59c8c61fbf44826b8191d" +checksum = "057eac2f202ec95aebfd8d495e88560ac085f6a415b3c6c28529dc5eb116a141" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c961f85070985ebc8fcdb81b838a5cf842294d1e6ed4852446161c7e246fd455" +checksum = "75d93869efd18874a9341cfd8ad66bcb08164e86357a694a0e939d29e87410b9" [[package]] name = "cranelift-entity" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2347b2b8d1d5429213668f2a8e36c85ee3c73984a2f6a79007e365d3e575e7ed" +checksum = "7e34bd7a1fefa902c90a921b36323f17a398b788fa56a75f07a29d83b6e28808" [[package]] name = "cranelift-frontend" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbcdbf7bed29e363568b778649b69dabc3d727256d5d25236096ef693757654" +checksum = "457018dd2d6ee300953978f63215b5edf3ae42dbdf8c7c038972f10394599f72" dependencies = [ "cranelift-codegen", "log", @@ -92,9 +109,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c769d4e0d76f59c8b2a3bf0477d89ee149bb0731b53fbb245ee081d49063095" +checksum = "2fa7749513eea849d9b32d45d4d0561e0ad5545a9b2f69aee00ffd79f165c01c" dependencies = [ "anyhow", "cranelift-codegen", @@ -110,9 +127,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab57d399a2401074bb0cc40b3031e420f3d66d46ec0cf21eeae53ac04bd73e2" +checksum = "734f00b74a59ffcb62e56f3d73cefdef91e87e56e0ce30f1365f678b0034d0e0" dependencies = [ "anyhow", "cranelift-codegen", @@ -120,9 +137,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4cdf93552e5ceb2e3c042829ebb4de4378492705f769eadc6a7c6c5251624c" +checksum = "bba027cc41bf1d0eee2ddf16caba2ee1be682d0214520fff0129d2c6557fda89" dependencies = [ "cranelift-codegen", "libc", @@ -131,9 +148,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.83.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8e65f4839c26e6237fc0744911d79b0a2ac5e76b4e4eebd14db2b8d849fd31" +checksum = "8e7b192ff72c1d5c0b0f6f51c914371b5606b69c01558670270dd1cc95c8a3a2" dependencies = [ "anyhow", "cranelift-codegen", @@ -152,6 +169,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getrandom" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.26.1" @@ -166,6 +203,9 @@ name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] [[package]] name = "indexmap" @@ -179,9 +219,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.119" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libloading" @@ -219,11 +259,12 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "object" -version = "0.27.1" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "crc32fast", + "hashbrown", "indexmap", "memchr", ] @@ -235,13 +276,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] -name = "regalloc" -version = "0.0.34" +name = "regalloc2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62446b1d3ebf980bdc68837700af1d77b37bc430e524bf95319c6eada2a4cc02" +checksum = "904196c12c9f55d3aea578613219f493ced8e05b3d0c6a42d11cb4142d8b4879" dependencies = [ + "fxhash", "log", - "rustc-hash", + "slice-group-by", "smallvec", ] @@ -257,12 +299,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_codegen_cranelift" version = "0.1.0" @@ -283,6 +319,12 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "slice-group-by" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" + [[package]] name = "smallvec" version = "1.8.0" @@ -295,6 +337,18 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 18d7f41cf408a..653e132451220 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,15 +8,15 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.83.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.83.0" -cranelift-module = "0.83.0" -cranelift-native = "0.83.0" -cranelift-jit = { version = "0.83.0", optional = true } -cranelift-object = "0.83.0" +cranelift-codegen = { version = "0.84.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.84.0" +cranelift-module = "0.84.0" +cranelift-native = "0.84.0" +cranelift-jit = { version = "0.84.0", optional = true } +cranelift-object = "0.84.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"] } +object = { version = "0.28.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.8.0" From 814ed4fa53f99a1739123c742c08dc5a1922c5de Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 20 May 2022 18:19:15 +0200 Subject: [PATCH 05/77] Rustup to rustc 1.63.0-nightly (c06728704 2022-05-19) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 24af8c93d539a..d0d3239d2d2df 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-05-17" +channel = "nightly-2022-05-20" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From e97e40de22ad93e16c0a2aa59433dabe16e4dc79 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 22 May 2022 20:35:24 +0200 Subject: [PATCH 06/77] Update rust-analyzer configuration --- .vscode/settings.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ecb20f22d8c92..d88309e412ed0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,9 @@ { // source for rustc_* is not included in the rust-src component; disable the errors about this "rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"], - "rust-analyzer.assist.importGranularity": "module", - "rust-analyzer.assist.importEnforceGranularity": true, - "rust-analyzer.assist.importPrefix": "crate", - "rust-analyzer.cargo.runBuildScripts": true, + "rust-analyzer.imports.granularity.enforce": true, + "rust-analyzer.imports.granularity.group": "module", + "rust-analyzer.imports.prefix": "crate", "rust-analyzer.cargo.features": ["unstable-features"], "rust-analyzer.linkedProjects": [ "./Cargo.toml", From 5011ae46a14fa30fd247b51ffe71e0bab1a63d04 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sat, 16 Apr 2022 09:27:54 -0400 Subject: [PATCH 07/77] Refactor call terminator to always hold a destination place --- src/abi/mod.rs | 18 ++++++++------ src/abi/returning.rs | 51 ++++++++++++++------------------------- src/base.rs | 2 ++ src/constant.rs | 4 +-- src/intrinsics/llvm.rs | 7 +++--- src/intrinsics/mod.rs | 55 ++++++++++++++++++++++++------------------ 6 files changed, 66 insertions(+), 71 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index b163a42619172..decb784199064 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -312,13 +312,14 @@ pub(crate) fn codegen_terminator_call<'tcx>( source_info: mir::SourceInfo, func: &Operand<'tcx>, args: &[Operand<'tcx>], - mir_dest: Option<(Place<'tcx>, BasicBlock)>, + destination: Place<'tcx>, + target: Option, ) { let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx)); let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx)); - let destination = mir_dest.map(|(place, bb)| (codegen_place(fx, place), bb)); + let ret_place = codegen_place(fx, destination); // Handle special calls like instrinsics and empty drop glue. let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() { @@ -333,7 +334,8 @@ pub(crate) fn codegen_terminator_call<'tcx>( &fx.tcx.symbol_name(instance).name, substs, args, - destination, + ret_place, + target, ); return; } @@ -344,14 +346,15 @@ pub(crate) fn codegen_terminator_call<'tcx>( fx, instance, args, - destination, + ret_place, + target, source_info, ); return; } InstanceDef::DropGlue(_, None) => { // empty drop glue - a nop. - let (_, dest) = destination.expect("Non terminating drop_in_place_real???"); + let dest = target.expect("Non terminating drop_in_place_real???"); let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); return; @@ -377,7 +380,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( .unwrap_or(false); if is_cold { fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); - if let Some((_place, destination_block)) = destination { + if let Some(destination_block) = target { fx.bcx.set_cold_block(fx.get_block(destination_block)); } } @@ -459,7 +462,6 @@ pub(crate) fn codegen_terminator_call<'tcx>( } }; - let ret_place = destination.map(|(place, _)| place); self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| { let call_args = return_ptr .into_iter() @@ -511,7 +513,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( call_inst }); - if let Some((_, dest)) = destination { + if let Some(dest) = target { let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } else { diff --git a/src/abi/returning.rs b/src/abi/returning.rs index c1bdba43e6ccb..ff3bb2dfd000f 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -56,23 +56,22 @@ pub(super) fn codegen_return_param<'tcx>( pub(super) fn codegen_with_call_return_arg<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, - ret_place: Option>, + ret_place: CPlace<'tcx>, f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option) -> Inst, ) { let (ret_temp_place, return_ptr) = match ret_arg_abi.mode { PassMode::Ignore => (None, None), - PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => match ret_place { - Some(ret_place) if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) => { + PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => { + if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) { // This is an optimization to prevent unnecessary copies of the return value when // the return place is already a memory place as opposed to a register. // This match arm can be safely removed. (None, Some(ret_place.to_ptr().get_addr(fx))) - } - _ => { + } else { let place = CPlace::new_stack_slot(fx, ret_arg_abi.layout); (Some(place), Some(place.to_ptr().get_addr(fx))) } - }, + } PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => { unreachable!("unsized return value") } @@ -84,39 +83,25 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( match ret_arg_abi.mode { PassMode::Ignore => {} PassMode::Direct(_) => { - if let Some(ret_place) = ret_place { - let ret_val = fx.bcx.inst_results(call_inst)[0]; - ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_arg_abi.layout)); - } + let ret_val = fx.bcx.inst_results(call_inst)[0]; + ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_arg_abi.layout)); } PassMode::Pair(_, _) => { - if let Some(ret_place) = ret_place { - let ret_val_a = fx.bcx.inst_results(call_inst)[0]; - let ret_val_b = fx.bcx.inst_results(call_inst)[1]; - ret_place.write_cvalue( - fx, - CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout), - ); - } + let ret_val_a = fx.bcx.inst_results(call_inst)[0]; + let ret_val_b = fx.bcx.inst_results(call_inst)[1]; + ret_place + .write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout)); } PassMode::Cast(cast) => { - if let Some(ret_place) = ret_place { - let results = fx - .bcx - .inst_results(call_inst) - .iter() - .copied() - .collect::>(); - let result = - super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast); - ret_place.write_cvalue(fx, result); - } + let results = + fx.bcx.inst_results(call_inst).iter().copied().collect::>(); + let result = + super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast); + ret_place.write_cvalue(fx, result); } PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => { - if let (Some(ret_place), Some(ret_temp_place)) = (ret_place, ret_temp_place) { - // Both ret_place and ret_temp_place must be Some. If ret_place is None, this is - // a non-returning call. If ret_temp_place is None, it is not necessary to copy the - // return value. + if let Some(ret_temp_place) = ret_temp_place { + // If ret_temp_place is None, it is not necessary to copy the return value. let ret_temp_value = ret_temp_place.to_cvalue(fx); ret_place.write_cvalue(fx, ret_temp_value); } diff --git a/src/base.rs b/src/base.rs index 65e5812a8a5b0..3fe112d794b44 100644 --- a/src/base.rs +++ b/src/base.rs @@ -393,6 +393,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { func, args, destination, + target, fn_span, cleanup: _, from_hir_call: _, @@ -404,6 +405,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { func, args, *destination, + *target, ) }); } diff --git a/src/constant.rs b/src/constant.rs index 57074f00210fe..7d2e3e52f3443 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -542,8 +542,8 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( | TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => unreachable!(), TerminatorKind::InlineAsm { .. } => return None, - TerminatorKind::Call { destination: Some((call_place, _)), .. } - if call_place == place => + TerminatorKind::Call { destination, target: Some(_), .. } + if destination == place => { return None; } diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index 0e4f7ee907a51..77ac46540a9ba 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -10,10 +10,9 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( intrinsic: &str, _substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], - destination: Option<(CPlace<'tcx>, BasicBlock)>, + ret: CPlace<'tcx>, + target: Option, ) { - let ret = destination.unwrap().0; - intrinsic_match! { fx, intrinsic, args, _ => { @@ -126,7 +125,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( }; } - let dest = destination.expect("all llvm intrinsics used by stdlib should return").1; + let dest = target.expect("all llvm intrinsics used by stdlib should return"); let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 29b3f36b2bef2..f8c69d46d1f67 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -217,35 +217,42 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, instance: Instance<'tcx>, args: &[mir::Operand<'tcx>], - destination: Option<(CPlace<'tcx>, BasicBlock)>, + destination: CPlace<'tcx>, + target: Option, source_info: mir::SourceInfo, ) { let intrinsic = fx.tcx.item_name(instance.def_id()); let substs = instance.substs; - let ret = match destination { - Some((place, _)) => place, - None => { - // Insert non returning intrinsics here - match intrinsic { - sym::abort => { - fx.bcx.ins().trap(TrapCode::User(0)); - } - sym::transmute => { - crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", source_info); - } - _ => unimplemented!("unsupported instrinsic {}", intrinsic), + let target = if let Some(target) = target { + target + } else { + // Insert non returning intrinsics here + match intrinsic { + sym::abort => { + fx.bcx.ins().trap(TrapCode::User(0)); } - return; + sym::transmute => { + crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", source_info); + } + _ => unimplemented!("unsupported instrinsic {}", intrinsic), } + return; }; if intrinsic.as_str().starts_with("simd_") { - self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, source_info.span); - let ret_block = fx.get_block(destination.expect("SIMD intrinsics don't diverge").1); + self::simd::codegen_simd_intrinsic_call( + fx, + intrinsic, + substs, + args, + destination, + source_info.span, + ); + let ret_block = fx.get_block(target); fx.bcx.ins().jump(ret_block, &[]); - } else if codegen_float_intrinsic_call(fx, intrinsic, args, ret) { - let ret_block = fx.get_block(destination.expect("Float intrinsics don't diverge").1); + } else if codegen_float_intrinsic_call(fx, intrinsic, args, destination) { + let ret_block = fx.get_block(target); fx.bcx.ins().jump(ret_block, &[]); } else { codegen_regular_intrinsic_call( @@ -254,9 +261,9 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( intrinsic, substs, args, - ret, - source_info, destination, + Some(target), + source_info, ); } } @@ -339,8 +346,8 @@ fn codegen_regular_intrinsic_call<'tcx>( substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], ret: CPlace<'tcx>, + destination: Option, source_info: mir::SourceInfo, - destination: Option<(CPlace<'tcx>, BasicBlock)>, ) { let usize_layout = fx.layout_of(fx.tcx.types.usize); @@ -761,7 +768,7 @@ fn codegen_regular_intrinsic_call<'tcx>( 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); + let ret_block = fx.get_block(destination.unwrap()); fx.bcx.ins().jump(ret_block, &[]); return; } else { @@ -789,7 +796,7 @@ fn codegen_regular_intrinsic_call<'tcx>( 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); + let ret_block = fx.get_block(destination.unwrap()); fx.bcx.ins().jump(ret_block, &[]); return; } else { @@ -1130,6 +1137,6 @@ fn codegen_regular_intrinsic_call<'tcx>( }; } - let ret_block = fx.get_block(destination.unwrap().1); + let ret_block = fx.get_block(destination.unwrap()); fx.bcx.ins().jump(ret_block, &[]); } From d27ec6c86d0c3464b5da71c86f0db53ff59242c0 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 23 May 2022 16:44:05 +0100 Subject: [PATCH 08/77] Add flag for stricter checks on uninit/zeroed --- src/intrinsics/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index f8c69d46d1f67..6937e658ed5ee 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -58,6 +58,7 @@ 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 rustc_target::abi::InitKind; use crate::prelude::*; use cranelift_codegen::ir::AtomicRmwOp; @@ -671,7 +672,12 @@ fn codegen_regular_intrinsic_call<'tcx>( return; } - if intrinsic == sym::assert_zero_valid && !layout.might_permit_raw_init(fx, /*zero:*/ true) { + if intrinsic == sym::assert_zero_valid + && !layout.might_permit_raw_init( + fx, + InitKind::Zero, + fx.tcx.sess.opts.debugging_opts.strict_init_checks) { + with_no_trimmed_paths!({ crate::base::codegen_panic( fx, @@ -682,7 +688,12 @@ fn codegen_regular_intrinsic_call<'tcx>( return; } - if intrinsic == sym::assert_uninit_valid && !layout.might_permit_raw_init(fx, /*zero:*/ false) { + if intrinsic == sym::assert_uninit_valid + && !layout.might_permit_raw_init( + fx, + InitKind::Uninit, + fx.tcx.sess.opts.debugging_opts.strict_init_checks) { + with_no_trimmed_paths!({ crate::base::codegen_panic( fx, From e2f90f7f74d805cd12d879feb3d3796acf088ae0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 29 May 2022 00:25:14 -0700 Subject: [PATCH 09/77] Add support for emitting functions with `coldcc` in LLVM The eventual goal is to try using this for things like the internal panicking stuff, to see whether it helps. --- src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index decb784199064..59a7316c1c028 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -22,7 +22,7 @@ fn clif_sig_from_fn_abi<'tcx>( fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> Signature { let call_conv = match fn_abi.conv { - Conv::Rust | Conv::C => default_call_conv, + Conv::Rust | Conv::C | Conv::RustCold => default_call_conv, Conv::X86_64SysV => CallConv::SystemV, Conv::X86_64Win64 => CallConv::WindowsFastcall, Conv::ArmAapcs From 4ee48c09ee913f9fe44c784e16f42feb7f30c4d0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 29 May 2022 10:50:51 -0700 Subject: [PATCH 10/77] Use CallConv::Cold in cranelift for extern "rust-cold" --- src/abi/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 59a7316c1c028..ffa5d747b1160 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -22,7 +22,8 @@ fn clif_sig_from_fn_abi<'tcx>( fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> Signature { let call_conv = match fn_abi.conv { - Conv::Rust | Conv::C | Conv::RustCold => default_call_conv, + Conv::Rust | Conv::C => default_call_conv, + Conv::RustCold => CallConv::Cold, Conv::X86_64SysV => CallConv::SystemV, Conv::X86_64Win64 => CallConv::WindowsFastcall, Conv::ArmAapcs From e60087505e8550fb6867fbcee2294fbfcf706f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 31 May 2022 00:00:00 +0000 Subject: [PATCH 11/77] Add a pointer to address cast kind A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable. --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 3fe112d794b44..7c59ce354c01a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -607,7 +607,7 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); } - Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => { + Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => { let operand = codegen_operand(fx, operand); let from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); From 722c724a9506bcfc445af4052b297e3c48838008 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 1 Jun 2022 13:24:44 -0400 Subject: [PATCH 12/77] =?UTF-8?q?rename=20PointerAddress=20=E2=86=92=20Poi?= =?UTF-8?q?nterExposeAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 7c59ce354c01a..58bec183c94aa 100644 --- a/src/base.rs +++ b/src/base.rs @@ -607,7 +607,11 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); } - Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => { + Rvalue::Cast( + CastKind::Misc | CastKind::PointerExposeAddress, + ref operand, + to_ty, + ) => { let operand = codegen_operand(fx, operand); let from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); From ede985e8b811af92bb07412c838f3d2bde23f92f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 2 Jun 2022 09:05:37 -0400 Subject: [PATCH 13/77] add cast kind of from_exposed_addr (int-to-ptr casts) --- src/base.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 58bec183c94aa..07136e1b76a9f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -608,7 +608,9 @@ fn codegen_stmt<'tcx>( lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); } Rvalue::Cast( - CastKind::Misc | CastKind::PointerExposeAddress, + CastKind::Misc + | CastKind::PointerExposeAddress + | CastKind::PointerFromExposedAddress, ref operand, to_ty, ) => { From d628444e480c0c62350a34cf8b26370f92238b6a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 2 Jun 2022 20:50:45 +0200 Subject: [PATCH 14/77] Remove workaround for bytecodealliance/wasmtime#3963 --- src/cast.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index e19070774c6e0..e8adf8246d1bd 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -149,17 +149,8 @@ pub(crate) fn clif_int_or_float_cast( } let is_not_nan = fx.bcx.ins().fcmp(FloatCC::Equal, from, from); - if to_ty == types::I128 { - // FIXME(bytecodealliance/wasmtime#3963): select.i128 on fcmp eq miscompiles - let (lsb, msb) = fx.bcx.ins().isplit(val); - let zero = fx.bcx.ins().iconst(types::I64, 0); - let lsb = fx.bcx.ins().select(is_not_nan, lsb, zero); - let msb = fx.bcx.ins().select(is_not_nan, msb, zero); - fx.bcx.ins().iconcat(lsb, msb) - } else { - let zero = fx.bcx.ins().iconst(to_ty, 0); - fx.bcx.ins().select(is_not_nan, val, zero) - } + let zero = fx.bcx.ins().iconst(to_ty, 0); + fx.bcx.ins().select(is_not_nan, val, zero) } else if from_ty.is_float() && to_ty.is_float() { // float -> float match (from_ty, to_ty) { From 7a8b96f89d40aeba3bdfdd517acc47a179fe7d98 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 3 Jun 2022 03:28:19 -0400 Subject: [PATCH 15/77] Make `std::mem::needs_drop` accept `?Sized` --- example/mini_core.rs | 2 +- example/mini_core_hello_world.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 8da705e0cb06d..489259d1a6bc6 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -567,7 +567,7 @@ pub mod intrinsics { pub fn copy(src: *const T, dst: *mut T, count: usize); pub fn transmute(e: T) -> U; pub fn ctlz_nonzero(x: T) -> T; - pub fn needs_drop() -> bool; + pub fn needs_drop() -> bool; pub fn bitreverse(x: T) -> T; pub fn bswap(x: T) -> T; pub fn write_bytes(dst: *mut T, val: u8, count: usize); diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 85ca908d0a266..059f62f7bf8ad 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -55,6 +55,11 @@ struct NoisyDrop { inner: NoisyDropInner, } +struct NoisyDropUnsized { + text: str, + inner: NoisyDropInner, +} + struct NoisyDropInner; impl Drop for NoisyDrop { @@ -170,7 +175,9 @@ fn main() { assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8); assert!(!intrinsics::needs_drop::()); + assert!(!intrinsics::needs_drop::<[u8]>()); assert!(intrinsics::needs_drop::()); + assert!(intrinsics::needs_drop::()); Unique { pointer: NonNull(1 as *mut &str), From eb5f23737bb8fd70f52b4359c9b6acd81f3d7909 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 3 Jun 2022 12:58:36 -0400 Subject: [PATCH 16/77] Fix unsized field order --- example/mini_core_hello_world.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 059f62f7bf8ad..0f1245c2758ed 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -56,8 +56,8 @@ struct NoisyDrop { } struct NoisyDropUnsized { - text: str, inner: NoisyDropInner, + text: str, } struct NoisyDropInner; From d5cb2bee82c8bb8553406a0c98f08fa1bf51aad7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 10:32:03 +0000 Subject: [PATCH 17/77] Rename CodegenUnit::work_product to previous_work_product It returns the previous work product or panics if there is none. This rename makes the purpose of this method clearer. --- src/driver/aot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 5e1e1c81d26ea..0faf1221c8399 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -85,7 +85,7 @@ fn reuse_workproduct_for_cgu( work_products: &mut FxHashMap, ) -> CompiledModule { let mut object = None; - let work_product = cgu.work_product(tcx); + let work_product = cgu.previous_work_product(tcx); if let Some(saved_file) = &work_product.saved_file { let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); From 5a1a111b52c26b4ecda7a81b1db5766c8b8f0a01 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 12:18:13 +0000 Subject: [PATCH 18/77] Avoid an unnecessary clone for copy_cgu_workproduct_to_incr_comp_cache_dir calls --- src/driver/aot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 0faf1221c8399..ef8fc14a5a00b 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -69,7 +69,7 @@ fn emit_module( rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir( tcx.sess, &name, - &Some(tmp_file.clone()), + Some(&tmp_file), ) }; From bbb850931fa5ccdb23eaaaead853084f49f9b2c6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 13 May 2022 12:20:32 +0000 Subject: [PATCH 19/77] Factor Option out of copy_cgu_workproduct_to_incr_comp_cache_dir call This improves clarity of the code a bit --- src/driver/aot.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index ef8fc14a5a00b..b652b58cb65a8 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -66,11 +66,7 @@ fn emit_module( let work_product = if backend_config.disable_incr_cache { None } else { - rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir( - tcx.sess, - &name, - Some(&tmp_file), - ) + rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file) }; ModuleCodegenResult( From 3d8e8546048cc94b9640c1f9e50ae1a0d75df9ce Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 15 May 2022 11:31:28 +0000 Subject: [PATCH 20/77] Make saved_file field of WorkProduct non-optional A WorkProduct without a saved file is useless --- src/driver/aot.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index b652b58cb65a8..05457ce15e9a7 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -80,21 +80,16 @@ fn reuse_workproduct_for_cgu( cgu: &CodegenUnit<'_>, work_products: &mut FxHashMap, ) -> CompiledModule { - let mut object = None; let work_product = cgu.previous_work_product(tcx); - if let Some(saved_file) = &work_product.saved_file { - let obj_out = - tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); - object = Some(obj_out.clone()); - let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file); - if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { - tcx.sess.err(&format!( - "unable to copy {} to {}: {}", - source_file.display(), - obj_out.display(), - err - )); - } + let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); + let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file); + if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { + tcx.sess.err(&format!( + "unable to copy {} to {}: {}", + source_file.display(), + obj_out.display(), + err + )); } work_products.insert(cgu.work_product_id(), work_product); @@ -102,7 +97,7 @@ fn reuse_workproduct_for_cgu( CompiledModule { name: cgu.name().to_string(), kind: ModuleKind::Regular, - object, + object: Some(obj_out), dwarf_object: None, bytecode: None, } From 875ffa19b11236a59ce08d688907cf337ddfcaed Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:25:44 +0200 Subject: [PATCH 21/77] Rustup to rustc 1.63.0-nightly (7466d5492 2022-06-08) --- 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 d950fea90fbcb..c38a2d1a389d6 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.72" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afdbb35d279238cf77f0c9e8d90ad50d6c7bff476ab342baafa29440f0f10bff" +checksum = "fe4879c339330c0ca526a52bc07500a4f5939c8d51481d58d443e10420a41547" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index d0d3239d2d2df..0d5f5692ab6c8 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-05-20" +channel = "nightly-2022-06-09" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From a298c6908e443fc689c474750df26d82301fd74f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:30:23 +0200 Subject: [PATCH 22/77] Mark extern rust-cold calls as cold --- src/abi/mod.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index ffa5d747b1160..60d5cdda12f78 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -376,9 +376,15 @@ pub(crate) fn codegen_terminator_call<'tcx>( RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), extra_args) }; - let is_cold = instance - .map(|inst| fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)) - .unwrap_or(false); + let is_cold = if fn_sig.abi == Abi::RustCold { + true + } else { + instance + .map(|inst| { + fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD) + }) + .unwrap_or(false) + }; if is_cold { fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); if let Some(destination_block) = target { From ec841f58d38e5763bc0ad9f405ed5fa075e3fd30 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Jun 2022 14:56:53 +0000 Subject: [PATCH 23/77] Fix running rustc tests There are still two failures due to incorrect test annotations --- scripts/setup_rust_fork.sh | 7 ++++--- scripts/test_rustc_tests.sh | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 4d0dfa16c5ecf..c730ae894356b 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -29,14 +29,15 @@ diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/ru 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')"); +@@ -3489,12 +3489,7 @@ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> S + let compiler_src_dir = base_dir.join("compiler"); + normalize_path(&compiler_src_dir, "$(echo '$COMPILER_DIR')"); - if let Some(virtual_rust_source_base_dir) = - option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) - { - normalize_path(&virtual_rust_source_base_dir.join("library"), "$(echo '$SRC_DIR')"); +- normalize_path(&virtual_rust_source_base_dir.join("compiler"), "$(echo '$COMPILER_DIR')"); - } + normalize_path(&Path::new("$(cd ../build_sysroot/sysroot_src/library; pwd)"), "$(echo '$SRC_DIR')"); diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 9bdb9f22c549a..d04461878e82a 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -89,6 +89,7 @@ rm src/test/ui/consts/issue-33537.rs # same 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/remap-path-prefix-dwarf # requires llvm-dwarfdump # genuine bugs # ============ From ce2b3a9b4c6084eddc4d1c61436b9d41bb1483e5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 10 Jun 2022 11:18:06 +1000 Subject: [PATCH 24/77] Rename the `ConstS::val` field as `kind`. And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant. --- src/base.rs | 2 +- src/constant.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base.rs b/src/base.rs index 07136e1b76a9f..fbe830b2b1030 100644 --- a/src/base.rs +++ b/src/base.rs @@ -710,7 +710,7 @@ fn codegen_stmt<'tcx>( let times = fx .monomorphize(times) .eval(fx.tcx, ParamEnv::reveal_all()) - .val() + .kind() .try_to_bits(fx.tcx.data_layout.pointer_size) .unwrap(); if operand.layout().size.bytes() == 0 { diff --git a/src/constant.rs b/src/constant.rs index 7d2e3e52f3443..3d14a0eca52bb 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -45,7 +45,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { ConstantKind::Ty(ct) => ct, ConstantKind::Val(..) => continue, }; - match const_.val() { + match const_.kind() { ConstKind::Value(_) => {} ConstKind::Unevaluated(unevaluated) => { if let Err(err) = @@ -126,7 +126,7 @@ pub(crate) fn codegen_constant<'tcx>( ConstantKind::Ty(ct) => ct, ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty), }; - let const_val = match const_.val() { + let const_val = match const_.kind() { ConstKind::Value(const_val) => const_val, ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => @@ -469,7 +469,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( match operand { Operand::Constant(const_) => match const_.literal { ConstantKind::Ty(const_) => { - fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val().try_to_value() + fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).kind().try_to_value() } ConstantKind::Val(val, _) => Some(val), }, From c431540544a03dc09577df4b97afd868deb167e5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:34:26 +0200 Subject: [PATCH 25/77] Rustup to rustc 1.63.0-nightly (ca122c7eb 2022-06-13) --- build_sysroot/Cargo.lock | 9 +++++---- rust-toolchain | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index c38a2d1a389d6..cdbe6bdd3fe8a 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.74" +version = "0.1.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4879c339330c0ca526a52bc07500a4f5939c8d51481d58d443e10420a41547" +checksum = "c6e3183e88f659a862835db8f4b67dbeed3d93e44dd4927eef78edb1c149d784" dependencies = [ "rustc-std-workspace-core", ] @@ -123,12 +123,13 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab7905ea95c6d9af62940f9d7dd9596d54c334ae2c15300c482051292d5637f" +checksum = "c71a9c6ee0d06d82b89ae2674096d2ba1b832a5ee0b1c9a5a6b013deeab5b11f" dependencies = [ "compiler_builtins", "libc", + "rustc-std-workspace-alloc", "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 0d5f5692ab6c8..6e76ecd48a19c 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-06-09" +channel = "nightly-2022-06-14" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 9096b3e44f6261791e79af851172eebf89a0c2cc Mon Sep 17 00:00:00 2001 From: b-naber Date: Wed, 16 Feb 2022 10:56:01 +0100 Subject: [PATCH 26/77] implement valtrees as the type-system representation for constant values --- src/constant.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 3d14a0eca52bb..ef72e6efb946b 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -127,7 +127,7 @@ pub(crate) fn codegen_constant<'tcx>( ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty), }; let const_val = match const_.kind() { - ConstKind::Value(const_val) => const_val, + ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)), ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => { @@ -468,9 +468,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( ) -> Option> { match operand { Operand::Constant(const_) => match const_.literal { - ConstantKind::Ty(const_) => { - fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).kind().try_to_value() - } + ConstantKind::Ty(const_) => fx + .monomorphize(const_) + .eval_for_mir(fx.tcx, ParamEnv::reveal_all()) + .try_to_value(fx.tcx), ConstantKind::Val(val, _) => Some(val), }, // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored From fc0c753c2d876b981cbd646b7eb9336844fa08ae Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:11:14 +0000 Subject: [PATCH 27/77] Remove src_files and remove_file They only apply to the main source archive and their role can be fulfilled through the skip argument of add_archive too. --- src/archive.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index a099e8b3a6af3..4822c7e03a99a 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -61,19 +61,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } } - fn src_files(&mut self) -> Vec { - self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect() - } - - fn remove_file(&mut self, name: &str) { - let index = self - .entries - .iter() - .position(|(entry_name, _)| entry_name == name.as_bytes()) - .expect("Tried to remove file not existing in src archive"); - self.entries.remove(index); - } - fn add_file(&mut self, file: &Path) { self.entries.push(( file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(), From 6d8c45064b0772814d931df4f274246060cb8acc Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 16 Jun 2022 19:39:39 +0400 Subject: [PATCH 28/77] Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock` --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 1b01f4edbb3f3..a56a91000596c 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -13,7 +13,7 @@ use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; -// FIXME use std::lazy::SyncOnceCell once it stabilizes +// FIXME use std::sync::OnceLock once it stabilizes use once_cell::sync::OnceCell; use crate::{prelude::*, BackendConfig}; From abb9b60f0965fe1cdc412369219d100022f39273 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:55:24 +0000 Subject: [PATCH 29/77] Fix "Remove src_files and remove_file" --- src/archive.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 4822c7e03a99a..e9b074e183796 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -92,7 +92,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { Ok(()) } - fn build(mut self) { + fn build(mut self) -> bool { enum BuilderKind { Bsd(ar::Builder), Gnu(ar::GnuBuilder), @@ -191,6 +191,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { ) }; + let any_members = !entries.is_empty(); + // Add all files for (entry_name, data) in entries.into_iter() { let header = ar::Header::new(entry_name, data.len() as u64); @@ -216,6 +218,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code())); } } + + any_members } fn inject_dll_import_lib( From 73b3ae0b8a5f84a231ec8fa850711ab5d6c027a3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:16:51 +0000 Subject: [PATCH 30/77] Remove the source archive functionality of ArchiveWriter We now build archives through strictly additive means rather than taking an existing archive and potentially substracting parts. --- src/archive.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index e9b074e183796..0812f930b5dea 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -30,25 +30,7 @@ pub(crate) struct ArArchiveBuilder<'a> { } impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { - fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self { - let (src_archives, entries) = if let Some(input) = input { - let read_cache = ReadCache::new(File::open(input).unwrap()); - let archive = ArchiveFile::parse(&read_cache).unwrap(); - let mut entries = Vec::new(); - - for entry in archive.members() { - let entry = entry.unwrap(); - entries.push(( - entry.name().to_vec(), - ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() }, - )); - } - - (vec![read_cache.into_inner()], entries) - } else { - (vec![], Vec::new()) - }; - + fn new(sess: &'a Session, output: &Path) -> Self { ArArchiveBuilder { sess, dst: output.to_path_buf(), @@ -56,8 +38,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { // FIXME fix builtin ranlib on macOS no_builtin_ranlib: sess.target.is_like_osx, - src_archives, - entries, + src_archives: vec![], + entries: vec![], } } From c58a11e935133c173f3262252c866c32df0e7038 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:58:55 +0200 Subject: [PATCH 31/77] Rustup to rustc 1.63.0-nightly (10f4ce324 2022-06-22) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 6e76ecd48a19c..173d105ecb1dd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-06-14" +channel = "nightly-2022-06-23" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 6d5e8f384362ed250f946ccd35bcc52a65817380 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Jun 2022 15:01:46 +0200 Subject: [PATCH 32/77] Adopt for "Remove dereferencing of Box from codegen" --- src/base.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/base.rs b/src/base.rs index fbe830b2b1030..7110edb0d6301 100644 --- a/src/base.rs +++ b/src/base.rs @@ -832,15 +832,7 @@ pub(crate) fn codegen_place<'tcx>( for elem in place.projection { match elem { PlaceElem::Deref => { - if cplace.layout().ty.is_box() { - cplace = cplace - .place_field(fx, Field::new(0)) // Box -> Unique - .place_field(fx, Field::new(0)) // Unique -> NonNull - .place_field(fx, Field::new(0)) // NonNull -> *mut T - .place_deref(fx); - } else { - cplace = cplace.place_deref(fx); - } + cplace = cplace.place_deref(fx); } PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); From 7c5fbacaf93f3dc8466f0ad5b91efe088af8afea Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Jun 2022 15:19:54 +0200 Subject: [PATCH 33/77] Update Cranelift to 0.85.0 --- Cargo.lock | 51 +++++++++++++++++++++++++++++---------------------- Cargo.toml | 12 ++++++------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e5c7dc028205..ecca4e38b1136 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,23 +50,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fa7c3188913c2d11a361e0431e135742372a2709a99b103e79758e11a0a797e" +checksum = "899dc8d22f7771e7f887fb8bafa0c0d3ac1dea0c7f2c0ded6e20a855a7a1e890" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29285f70fd396a8f64455a15a6e1d390322e4a5f5186de513141313211b0a23e" +checksum = "8dbdc03f695cf67e7bc45da57155528274f47390b85060af8107eb304ef167c4" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", + "cranelift-isle", "gimli", "log", "regalloc2", @@ -76,30 +77,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057eac2f202ec95aebfd8d495e88560ac085f6a415b3c6c28529dc5eb116a141" +checksum = "9ea66cbba3eb7fcb3ec9f42839a6d381bd40cf97780397e7167daf9725d4ffa0" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75d93869efd18874a9341cfd8ad66bcb08164e86357a694a0e939d29e87410b9" +checksum = "712fbebd119a476f59122b4ba51fdce893a66309b5c92bd5506bfb11a0587496" [[package]] name = "cranelift-entity" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e34bd7a1fefa902c90a921b36323f17a398b788fa56a75f07a29d83b6e28808" +checksum = "4cb8b95859c4e14c9e860db78d596a904fdbe9261990233b62bd526346cb56cb" [[package]] name = "cranelift-frontend" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "457018dd2d6ee300953978f63215b5edf3ae42dbdf8c7c038972f10394599f72" +checksum = "c7b91b19a7d1221a73f190c0e865c12be77a84f661cac89abfd4ab5820142886" dependencies = [ "cranelift-codegen", "log", @@ -107,11 +108,17 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-isle" +version = "0.85.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d4f53bc86fb458e59c695c6a95ce8346e6a8377ee7ffc058e3ac08b5f94cb1" + [[package]] name = "cranelift-jit" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fa7749513eea849d9b32d45d4d0561e0ad5545a9b2f69aee00ffd79f165c01c" +checksum = "7a96d5cb92e21c641267be5a3a8ba45bc443ef9aed10481d60c59b729fd5c37f" dependencies = [ "anyhow", "cranelift-codegen", @@ -127,9 +134,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734f00b74a59ffcb62e56f3d73cefdef91e87e56e0ce30f1365f678b0034d0e0" +checksum = "38a36a6d979f8031d642079fa567b1e9d0d2ad0c2694a3864f3f841654f466f4" dependencies = [ "anyhow", "cranelift-codegen", @@ -137,9 +144,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bba027cc41bf1d0eee2ddf16caba2ee1be682d0214520fff0129d2c6557fda89" +checksum = "592f035d0ed41214dfeeb37abd536233536a27be6b4c2d39f380cd402f0cff4f" dependencies = [ "cranelift-codegen", "libc", @@ -148,9 +155,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.84.0" +version = "0.85.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e7b192ff72c1d5c0b0f6f51c914371b5606b69c01558670270dd1cc95c8a3a2" +checksum = "3303142d9deb0a5b02904800c9db152f0c81e7bebf3400a24bd36b5b19317950" dependencies = [ "anyhow", "cranelift-codegen", @@ -277,9 +284,9 @@ checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] name = "regalloc2" -version = "0.1.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904196c12c9f55d3aea578613219f493ced8e05b3d0c6a42d11cb4142d8b4879" +checksum = "0d37148700dbb38f994cd99a1431613057f37ed934d7e4d799b7ab758c482461" dependencies = [ "fxhash", "log", diff --git a/Cargo.toml b/Cargo.toml index 653e132451220..60ea324a4eea8 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.84.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.84.0" -cranelift-module = "0.84.0" -cranelift-native = "0.84.0" -cranelift-jit = { version = "0.84.0", optional = true } -cranelift-object = "0.84.0" +cranelift-codegen = { version = "0.85.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.85.0" +cranelift-module = "0.85.0" +cranelift-native = "0.85.0" +cranelift-jit = { version = "0.85.0", optional = true } +cranelift-object = "0.85.0" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.28.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From 439c323f9cea37cd2fbae8df624f8502d4ad7b6b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 16 Aug 2021 15:07:35 +0200 Subject: [PATCH 34/77] Disable DWARF debuginfo on Windows Windows uses PDB instead of DWARF and using DWARF debuginfo causes the linker to give an error --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9d2e12f98984a..e456aa7a04c59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -141,7 +141,11 @@ impl<'tcx> CodegenCx<'tcx> { let unwind_context = UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot)); - let debug_context = if debug_info { Some(DebugContext::new(tcx, isa)) } else { None }; + let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows { + Some(DebugContext::new(tcx, isa)) + } else { + None + }; CodegenCx { tcx, global_asm: String::new(), From 8a4557e01cab2166a825ff897c8f01874ffaba48 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:32:08 +0000 Subject: [PATCH 35/77] Update for changes to the rustc test suite --- scripts/test_rustc_tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d04461878e82a..d253718eeb83e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -33,6 +33,7 @@ rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-typ 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 -r src/test/ui/macros/rfc-2011-nicer-assert-messages/ # vendor intrinsics rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected @@ -68,7 +69,7 @@ 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/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 From f516ba224065b21378a8897699320a0cfdfe1cfb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 27 Jun 2022 08:48:55 +1000 Subject: [PATCH 36/77] Update `smallvec` to 1.8.1. This pulls in https://github.com/servo/rust-smallvec/pull/282, which gives some small wins for rustc. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b8e43b639f99..da18ac7eacbfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,9 +285,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2" [[package]] name = "target-lexicon" diff --git a/Cargo.toml b/Cargo.toml index 18d7f41cf408a..ec2c1f2ca71b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg indexmap = "1.8.0" libloading = { version = "0.6.0", optional = true } once_cell = "1.10.0" -smallvec = "1.6.1" +smallvec = "1.8.1" [patch.crates-io] # Uncomment to use local checkout of cranelift From f060ae9d3d677110125793cfef346c417283358f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:52:21 +0200 Subject: [PATCH 37/77] Update to Cranelift 0.85.1 This fixes a miscompilation --- Cargo.lock | 48 ++++++++++++++++++++++++------------------------ Cargo.toml | 12 ++++++------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecca4e38b1136..728847686c6ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,18 +50,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899dc8d22f7771e7f887fb8bafa0c0d3ac1dea0c7f2c0ded6e20a855a7a1e890" +checksum = "7901fbba05decc537080b07cb3f1cadf53be7b7602ca8255786288a8692ae29a" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dbdc03f695cf67e7bc45da57155528274f47390b85060af8107eb304ef167c4" +checksum = "37ba1b45d243a4a28e12d26cd5f2507da74e77c45927d40de8b6ffbf088b46b5" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -77,30 +77,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea66cbba3eb7fcb3ec9f42839a6d381bd40cf97780397e7167daf9725d4ffa0" +checksum = "54cc30032171bf230ce22b99c07c3a1de1221cb5375bd6dbe6dbe77d0eed743c" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712fbebd119a476f59122b4ba51fdce893a66309b5c92bd5506bfb11a0587496" +checksum = "a23f2672426d2bb4c9c3ef53e023076cfc4d8922f0eeaebaf372c92fae8b5c69" [[package]] name = "cranelift-entity" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cb8b95859c4e14c9e860db78d596a904fdbe9261990233b62bd526346cb56cb" +checksum = "886c59a5e0de1f06dbb7da80db149c75de10d5e2caca07cdd9fef8a5918a6336" [[package]] name = "cranelift-frontend" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7b91b19a7d1221a73f190c0e865c12be77a84f661cac89abfd4ab5820142886" +checksum = "ace74eeca11c439a9d4ed1a5cb9df31a54cd0f7fbddf82c8ce4ea8e9ad2a8fe0" dependencies = [ "cranelift-codegen", "log", @@ -110,15 +110,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d4f53bc86fb458e59c695c6a95ce8346e6a8377ee7ffc058e3ac08b5f94cb1" +checksum = "db1ae52a5cc2cad0d86fdd3dcb16b7217d2f1e65ab4f5814aa4f014ad335fa43" [[package]] name = "cranelift-jit" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a96d5cb92e21c641267be5a3a8ba45bc443ef9aed10481d60c59b729fd5c37f" +checksum = "e2305c9ab672e746f62d135655d29039357aafa725d9736e27f50f1aa4eac7bc" dependencies = [ "anyhow", "cranelift-codegen", @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a36a6d979f8031d642079fa567b1e9d0d2ad0c2694a3864f3f841654f466f4" +checksum = "ff1fa24c991e97166915594e5cb8752c45e026b47df5f79ae4305f5b88948529" dependencies = [ "anyhow", "cranelift-codegen", @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592f035d0ed41214dfeeb37abd536233536a27be6b4c2d39f380cd402f0cff4f" +checksum = "dadcfb7852900780d37102bce5698bcd401736403f07b52e714ff7a180e0e22f" dependencies = [ "cranelift-codegen", "libc", @@ -155,9 +155,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.85.0" +version = "0.85.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3303142d9deb0a5b02904800c9db152f0c81e7bebf3400a24bd36b5b19317950" +checksum = "3e25c4513d4175039d907056c032e755e3ae6eee0bee6126fbd7d9b9e9e44830" dependencies = [ "anyhow", "cranelift-codegen", @@ -284,9 +284,9 @@ checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] name = "regalloc2" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d37148700dbb38f994cd99a1431613057f37ed934d7e4d799b7ab758c482461" +checksum = "4a8d23b35d7177df3b9d31ed8a9ab4bf625c668be77a319d4f5efd4a5257701c" dependencies = [ "fxhash", "log", diff --git a/Cargo.toml b/Cargo.toml index 60ea324a4eea8..0f3aaa27539e6 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.85.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.85.0" -cranelift-module = "0.85.0" -cranelift-native = "0.85.0" -cranelift-jit = { version = "0.85.0", optional = true } -cranelift-object = "0.85.0" +cranelift-codegen = { version = "0.85.1", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.85.1" +cranelift-module = "0.85.1" +cranelift-native = "0.85.1" +cranelift-jit = { version = "0.85.1", optional = true } +cranelift-object = "0.85.1" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.28.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From 56c5c09618ed0cbdb10fe24d3a2061d74d0d75ec Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:53:40 +0200 Subject: [PATCH 38/77] Run regalloc checker on CI This would have caught the issue that required releasing Cranelift 0.85.1 --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index e456aa7a04c59..dfbe72118453e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -247,6 +247,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box "elf_gd", From c1ac2df0c39ed12a4f4590319fb7b8045a5db5e5 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:55:37 +0200 Subject: [PATCH 39/77] Allow building the sysroot with --emit llvm-ir --- build_system/build_sysroot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 8682204f4fd30..16cce83dd9c85 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -205,7 +205,7 @@ fn build_clif_sysroot_for_triple( { let entry = entry.unwrap(); if let Some(ext) = entry.path().extension() { - if ext == "rmeta" || ext == "d" || ext == "dSYM" { + if ext == "rmeta" || ext == "d" || ext == "dSYM" || ext == "clif" { continue; } } else { From 45b6cd6a8a2a3b364d22d4fabc0d72f9e37e3e50 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 28 Jun 2022 14:31:32 +0000 Subject: [PATCH 40/77] Fix a crash for 11 single byte fields passed through the C abi Fixes #1234 --- example/mini_core_hello_world.rs | 31 +++++++++++++++++++++++++++++++ src/abi/pass_mode.rs | 26 ++++++-------------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 0f1245c2758ed..6111e0352828e 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -124,6 +124,23 @@ fn call_return_u128_pair() { return_u128_pair(); } +#[repr(C)] +pub struct bool_11 { + field0: bool, + field1: bool, + field2: bool, + field3: bool, + field4: bool, + field5: bool, + field6: bool, + field7: bool, + field8: bool, + field9: bool, + field10: bool, +} + +extern "C" fn bool_struct_in_11(arg0: bool_11) {} + #[allow(unreachable_code)] // FIXME false positive fn main() { take_unique(Unique { @@ -134,6 +151,20 @@ fn main() { call_return_u128_pair(); + bool_struct_in_11(bool_11 { + field0: true, + field1: true, + field2: true, + field3: true, + field4: true, + field5: true, + field6: true, + field7: true, + field8: true, + field9: true, + field10: true, + }); + let slice = &[0, 1] as &[i32]; let slice_ptr = slice as *const [i32] as *const i32; diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 9f0bd31e95fcc..33c5f3283be59 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -18,9 +18,9 @@ fn reg_to_abi_param(reg: Reg) -> AbiParam { let clif_ty = match (reg.kind, reg.size.bytes()) { (RegKind::Integer, 1) => types::I8, (RegKind::Integer, 2) => types::I16, - (RegKind::Integer, 4) => types::I32, - (RegKind::Integer, 8) => types::I64, - (RegKind::Integer, 16) => types::I128, + (RegKind::Integer, 3..=4) => types::I32, + (RegKind::Integer, 5..=8) => types::I64, + (RegKind::Integer, 9..=16) => types::I128, (RegKind::Float, 4) => types::F32, (RegKind::Float, 8) => types::F64, (RegKind::Vector, size) => types::I8.by(u16::try_from(size).unwrap()).unwrap(), @@ -48,23 +48,9 @@ fn cast_target_to_abi_params(cast: CastTarget) -> SmallVec<[AbiParam; 2]> { ) }; - if cast.prefix.iter().all(|x| x.is_none()) { - // Simplify to a single unit when there is no prefix and size <= unit size - if cast.rest.total <= cast.rest.unit.size { - let clif_ty = match (cast.rest.unit.kind, cast.rest.unit.size.bytes()) { - (RegKind::Integer, 1) => types::I8, - (RegKind::Integer, 2) => types::I16, - (RegKind::Integer, 3..=4) => types::I32, - (RegKind::Integer, 5..=8) => types::I64, - (RegKind::Integer, 9..=16) => types::I128, - (RegKind::Float, 4) => types::F32, - (RegKind::Float, 8) => types::F64, - (RegKind::Vector, size) => types::I8.by(u16::try_from(size).unwrap()).unwrap(), - _ => unreachable!("{:?}", cast.rest.unit), - }; - return smallvec![AbiParam::new(clif_ty)]; - } - } + // Note: Unlike the LLVM equivalent of this code we don't have separate branches for when there + // is no prefix as a single unit, an array and a heterogeneous struct are not represented using + // different types in Cranelift IR. Instead a single array of primitive types is used. // Create list of fields in the main structure let mut args = cast From 846eecb1a40210b287b92ea1750aedcf478067ae Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 29 Jun 2022 14:18:55 +0000 Subject: [PATCH 41/77] Change enum->int casts to not go through MIR casts. Instead we generate a discriminant rvalue and cast the result of that. --- src/base.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/base.rs b/src/base.rs index fbe830b2b1030..a07ed405aa4c6 100644 --- a/src/base.rs +++ b/src/base.rs @@ -635,29 +635,6 @@ fn codegen_stmt<'tcx>( let (ptr, _extra) = operand.load_scalar_pair(fx); lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout)) } - } else if let ty::Adt(adt_def, _substs) = from_ty.kind() { - // enum -> discriminant value - assert!(adt_def.is_enum()); - match to_ty.kind() { - ty::Uint(_) | ty::Int(_) => {} - _ => unreachable!("cast adt {} -> {}", from_ty, to_ty), - } - let to_clif_ty = fx.clif_type(to_ty).unwrap(); - - let discriminant = crate::discriminant::codegen_get_discriminant( - fx, - operand, - fx.layout_of(operand.layout().ty.discriminant_ty(fx.tcx)), - ) - .load_scalar(fx); - - let res = crate::cast::clif_intcast( - fx, - discriminant, - to_clif_ty, - to_ty.is_signed(), - ); - lval.write_cvalue(fx, CValue::by_val(res, dest_layout)); } else { let to_clif_ty = fx.clif_type(to_ty).unwrap(); let from = operand.load_scalar(fx); From a71e691e74e06d0f3d50daee7510ce240f2b1783 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 4 Feb 2022 23:18:28 +0100 Subject: [PATCH 42/77] Recover when failing to normalize closure signature. --- src/base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base.rs b/src/base.rs index fbe830b2b1030..fa4ea42638561 100644 --- a/src/base.rs +++ b/src/base.rs @@ -686,6 +686,7 @@ fn codegen_stmt<'tcx>( substs, ty::ClosureKind::FnOnce, ) + .expect("failed to normalize and resolve closure during codegen") .polymorphize(fx.tcx); let func_ref = fx.get_function_ref(instance); let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref); From 14b2f8f98d2df5287662d1d43b38bf7efc839f4f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 2 Jul 2022 19:38:23 +0200 Subject: [PATCH 43/77] Add code to print clif ir on panics during define_function --- src/base.rs | 29 ++++++++++++++++++++++++++++- src/pretty_clif.rs | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index 7110edb0d6301..bdcf2f806eb09 100644 --- a/src/base.rs +++ b/src/base.rs @@ -175,10 +175,37 @@ fn compile_fn<'tcx>( ); }); + #[cfg(any())] // This is never true + let _clif_guard = { + use std::fmt::Write; + + let func_clone = context.func.clone(); + let clif_comments_clone = clif_comments.clone(); + let mut clif = String::new(); + for flag in module.isa().flags().iter() { + writeln!(clif, "set {}", flag).unwrap(); + } + write!(clif, "target {}", module.isa().triple().architecture.to_string()).unwrap(); + for isa_flag in module.isa().isa_flags().iter() { + write!(clif, " {}", isa_flag).unwrap(); + } + writeln!(clif, "\n").unwrap(); + crate::PrintOnPanic(move || { + let mut clif = clif.clone(); + ::cranelift_codegen::write::decorate_function( + &mut &clif_comments_clone, + &mut clif, + &func_clone, + ) + .unwrap(); + clif + }) + }; + // Define function tcx.sess.time("define function", || { context.want_disasm = crate::pretty_clif::should_write_ir(tcx); - module.define_function(func_id, context).unwrap() + module.define_function(func_id, context).unwrap(); }); // Write optimized function to file for debugging diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index ca7116b887d5a..1d1ec21680e30 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -66,7 +66,7 @@ use rustc_session::config::OutputType; use crate::prelude::*; -#[derive(Debug)] +#[derive(Clone, Debug)] pub(crate) struct CommentWriter { enabled: bool, global_comments: Vec, @@ -237,6 +237,7 @@ pub(crate) fn write_clif_file<'tcx>( func: &cranelift_codegen::ir::Function, mut clif_comments: &CommentWriter, ) { + // FIXME work around filename too long errors write_ir_file( tcx, || format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix), From 8720683936ce210a7ff9f1d62657bfc2aa897abf Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 3 Jul 2022 15:07:25 +0200 Subject: [PATCH 44/77] Rustup to rustc 1.64.0-nightly (f2d93935f 2022-07-02) --- 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 cdbe6bdd3fe8a..86ea1a08ea36d 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -123,9 +123,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71a9c6ee0d06d82b89ae2674096d2ba1b832a5ee0b1c9a5a6b013deeab5b11f" +checksum = "d37fb7dc756218a0559bfc21e4381f03cbb696cdaf959e7e95e927496f0564cd" dependencies = [ "compiler_builtins", "libc", diff --git a/rust-toolchain b/rust-toolchain index 173d105ecb1dd..9c7d75939c9e9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-06-23" +channel = "nightly-2022-07-03" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From b8aab374644ba5aa269f7d9f9da80fdf4fb33684 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 3 Jul 2022 13:41:29 +0000 Subject: [PATCH 45/77] Update for changes to the rustc test suite --- scripts/test_rustc_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d253718eeb83e..3e5d91c2da302 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -66,11 +66,13 @@ rm src/test/ui/intrinsics/intrinsic-nearby.rs # unimplemented nearbyintf32 and n 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 +rm src/test/ui/abi/stack-probes.rs # stack probes not yet implemented # optimization tests # ================== rm src/test/ui/codegen/issue-28950.rs # depends on stack size optimizations rm src/test/ui/codegen/init-large-type.rs # same +rm src/test/ui/issues/issue-40883.rs # same rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization # backend specific tests @@ -90,6 +92,8 @@ rm src/test/ui/consts/issue-33537.rs # same 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/issue-88756-default-output # same +rm -r src/test/run-make/issue-88756-opt-help # same rm -r src/test/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump # genuine bugs From 44c2558504f79c3f30b484c51df1b202696cd42c Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Fri, 17 Jun 2022 13:15:00 +0100 Subject: [PATCH 46/77] Update TypeVisitor paths --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9d2e12f98984a..be2d3108c5fa9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ mod prelude { pub(crate) use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout}; pub(crate) use rustc_middle::ty::{ self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, - TypeFoldable, UintTy, + TypeFoldable, TypeVisitable, UintTy, }; pub(crate) use rustc_target::abi::{Abi, Scalar, Size, VariantIdx}; From 69d0c1e9ac7f7ea074eae2bac6a1a63cb4af005a Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 4 Jul 2022 14:38:42 +0100 Subject: [PATCH 47/77] incr: cache dwarf objects in work products Cache DWARF objects alongside object files in work products when those exist so that DWARF object files are available for thorin in packed mode in incremental scenarios. Signed-off-by: David Wood --- src/driver/aot.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 05457ce15e9a7..50d8fc30d7d7c 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -66,7 +66,11 @@ fn emit_module( let work_product = if backend_config.disable_incr_cache { None } else { - rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file) + rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir( + tcx.sess, + &name, + &[("o", &tmp_file)], + ) }; ModuleCodegenResult( @@ -82,7 +86,10 @@ fn reuse_workproduct_for_cgu( ) -> CompiledModule { let work_product = cgu.previous_work_product(tcx); let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); - let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file); + let source_file = rustc_incremental::in_incr_comp_dir_sess( + &tcx.sess, + &work_product.saved_files.get("o").expect("no saved object file in work product"), + ); if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { tcx.sess.err(&format!( "unable to copy {} to {}: {}", From c413617ca5e617625e40930dcf173f7c69726ff2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 8 Jul 2022 17:52:04 -0400 Subject: [PATCH 48/77] Update integer_atomics tracking issue Updates #32976. Updates #99069. --- ...027-sysroot-128bit-atomic-operations.patch | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch index ce1c6c99b40c8..77f437974c2d6 100644 --- a/patches/0027-sysroot-128bit-atomic-operations.patch +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -19,7 +19,7 @@ index 092b7cf..158cf71 100644 #[stable(feature = "integer_atomics_stable", since = "1.34.0")] impl RefUnwindSafe for crate::sync::atomic::AtomicI64 {} -#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "32976")] +-#[unstable(feature = "integer_atomics", issue = "99069")] -impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} #[cfg(target_has_atomic_load_store = "ptr")] @@ -29,7 +29,7 @@ index 092b7cf..158cf71 100644 #[stable(feature = "integer_atomics_stable", since = "1.34.0")] impl RefUnwindSafe for crate::sync::atomic::AtomicU64 {} -#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "32976")] +-#[unstable(feature = "integer_atomics", issue = "99069")] -impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} #[cfg(target_has_atomic_load_store = "8")] @@ -46,14 +46,14 @@ index d9de37e..8293fce 100644 -atomic_int! { - cfg(target_has_atomic = "128"), - cfg(target_has_atomic_equal_alignment = "128"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), -- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "99069"), - cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"), - "i128", - "#![feature(integer_atomics)]\n\n", @@ -66,14 +66,14 @@ index d9de37e..8293fce 100644 -atomic_int! { - cfg(target_has_atomic = "128"), - cfg(target_has_atomic_equal_alignment = "128"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), +- unstable(feature = "integer_atomics", issue = "99069"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), -- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "99069"), - cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"), - "u128", - "#![feature(integer_atomics)]\n\n", From e9442b60e0516d7edd66cddc47ac363aab0cd69b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 5 Jul 2022 16:53:48 -0400 Subject: [PATCH 49/77] fix cranelift and gcc backends --- src/constant.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/constant.rs b/src/constant.rs index ef72e6efb946b..f90ad5349702d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -167,6 +167,7 @@ pub(crate) fn codegen_const_value<'tcx>( } match const_val { + ConstValue::ZST => unreachable!(), // we already handles ZST above ConstValue::Scalar(x) => match x { Scalar::Int(int) => { if fx.clif_type(layout.ty).is_some() { From f44d5feb5b7b98bed2806238cc9a6b3ce40aa831 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 5 Jul 2022 17:38:46 -0400 Subject: [PATCH 50/77] review feedback --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index f90ad5349702d..0739061fdbd7c 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -167,7 +167,7 @@ pub(crate) fn codegen_const_value<'tcx>( } match const_val { - ConstValue::ZST => unreachable!(), // we already handles ZST above + ConstValue::Zst => unreachable!(), // we already handles ZST above ConstValue::Scalar(x) => match x { Scalar::Int(int) => { if fx.clif_type(layout.ty).is_some() { From c78b43878f33c242354fadb39030a46e0b2d9812 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 6 Jul 2022 10:14:46 -0400 Subject: [PATCH 51/77] tweak names and output and bless --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index 0739061fdbd7c..48972321a9f40 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -167,7 +167,7 @@ pub(crate) fn codegen_const_value<'tcx>( } match const_val { - ConstValue::Zst => unreachable!(), // we already handles ZST above + ConstValue::ZeroSized => unreachable!(), // we already handles ZST above ConstValue::Scalar(x) => match x { Scalar::Int(int) => { if fx.clif_type(layout.ty).is_some() { From 743cee6ca9c406fb489ffcff34bc068ce3d895f3 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 29 May 2022 18:01:26 +0200 Subject: [PATCH 52/77] Partially stabilize const_slice_from_raw_parts This doesn't stabilize methods working on mutable pointers. --- example/issue-91827-extern-types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/example/issue-91827-extern-types.rs b/example/issue-91827-extern-types.rs index cf8fada5320f9..2ecc8b8238b18 100644 --- a/example/issue-91827-extern-types.rs +++ b/example/issue-91827-extern-types.rs @@ -6,7 +6,6 @@ // Regression test for issue #91827. #![feature(const_ptr_offset_from)] -#![feature(const_slice_from_raw_parts)] #![feature(extern_types)] use std::ptr::addr_of; From a7347a941bc45e2d1488045689bb5606ea156576 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Mon, 11 Jul 2022 14:26:58 +0100 Subject: [PATCH 53/77] Keep unstable target features for asm feature checking Inline assembly uses the target features to determine which registers are available on the current target. However it needs to be able to access unstable target features for this. Fixes #99071 --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9d2e12f98984a..da6e788700624 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,7 @@ impl CodegenBackend for CraneliftCodegenBackend { } } - fn target_features(&self, _sess: &Session) -> Vec { + fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec { vec![] } From 9efccc97e2a495660fe2915f3b333293f01ed2a9 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 13 Jun 2022 16:37:41 +0300 Subject: [PATCH 54/77] add new rval, pull deref early --- src/base.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/base.rs b/src/base.rs index f71d749df629c..63cd4d6de4c3e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -503,6 +503,11 @@ fn codegen_stmt<'tcx>( let val = codegen_operand(fx, operand); lval.write_cvalue(fx, val); } + Rvalue::CopyForDeref(place) => { + let cplace = codegen_place(fx, place); + let val = cplace.to_cvalue(fx); + lval.write_cvalue(fx, val) + } Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { let place = codegen_place(fx, place); let ref_ = place.place_ref(fx, lval.layout()); From b2ae24e6a1bce9197246e86281ba7d1b04084d9d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 6 Jul 2022 07:44:47 -0500 Subject: [PATCH 55/77] Rename `debugging_opts` to `unstable_opts` This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear. --- src/allocator.rs | 2 +- src/cast.rs | 2 +- src/debuginfo/line_info.rs | 2 +- src/driver/aot.rs | 2 +- src/intrinsics/mod.rs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index c3b99b64263f2..6d321c7b298a7 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -24,7 +24,7 @@ pub(crate) fn codegen( unwind_context, kind, tcx.lang_items().oom().is_some(), - tcx.sess.opts.debugging_opts.oom, + tcx.sess.opts.unstable_opts.oom, ); true } else { diff --git a/src/cast.rs b/src/cast.rs index e19070774c6e0..b24e49e94c91e 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -144,7 +144,7 @@ pub(crate) fn clif_int_or_float_cast( fx.bcx.ins().fcvt_to_uint_sat(to_ty, from) }; - if let Some(false) = fx.tcx.sess.opts.debugging_opts.saturating_float_casts { + if let Some(false) = fx.tcx.sess.opts.unstable_opts.saturating_float_casts { return val; } diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index 476d6a54e1256..bbcb9591373dd 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -140,7 +140,7 @@ impl<'tcx> DebugContext<'tcx> { // In order to have a good line stepping behavior in debugger, we overwrite debug // locations of macro expansions with that of the outermost expansion site // (unless the crate is being compiled with `-Z debug-macros`). - let span = if !span.from_expansion() || tcx.sess.opts.debugging_opts.debug_macros { + let span = if !span.from_expansion() || tcx.sess.opts.unstable_opts.debug_macros { span } else { // Walk up the macro expansion chain until we reach a non-expanded span. diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 50d8fc30d7d7c..3cd1ef5639ef9 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -33,7 +33,7 @@ fn make_module(sess: &Session, isa: Box, name: String) -> ObjectM // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections // can easily double the amount of time necessary to perform linking. - builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false)); + builder.per_function_section(sess.opts.unstable_opts.function_sections.unwrap_or(false)); ObjectModule::new(builder) } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 6937e658ed5ee..eafae1cdc8af0 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -676,7 +676,7 @@ fn codegen_regular_intrinsic_call<'tcx>( && !layout.might_permit_raw_init( fx, InitKind::Zero, - fx.tcx.sess.opts.debugging_opts.strict_init_checks) { + fx.tcx.sess.opts.unstable_opts.strict_init_checks) { with_no_trimmed_paths!({ crate::base::codegen_panic( @@ -692,7 +692,7 @@ fn codegen_regular_intrinsic_call<'tcx>( && !layout.might_permit_raw_init( fx, InitKind::Uninit, - fx.tcx.sess.opts.debugging_opts.strict_init_checks) { + fx.tcx.sess.opts.unstable_opts.strict_init_checks) { with_no_trimmed_paths!({ crate::base::codegen_panic( From 5a81bf7ad2495de1d13813db7fb8bead5ce6685e Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Thu, 14 Jul 2022 22:42:47 +0100 Subject: [PATCH 56/77] Use constant eval to do strict validity checks --- src/intrinsics/mod.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index eafae1cdc8af0..4b2207f375879 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -58,7 +58,6 @@ 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 rustc_target::abi::InitKind; use crate::prelude::*; use cranelift_codegen::ir::AtomicRmwOp; @@ -672,12 +671,7 @@ fn codegen_regular_intrinsic_call<'tcx>( return; } - if intrinsic == sym::assert_zero_valid - && !layout.might_permit_raw_init( - fx, - InitKind::Zero, - fx.tcx.sess.opts.unstable_opts.strict_init_checks) { - + if intrinsic == sym::assert_zero_valid && !fx.tcx.permits_zero_init(layout) { with_no_trimmed_paths!({ crate::base::codegen_panic( fx, @@ -688,12 +682,7 @@ fn codegen_regular_intrinsic_call<'tcx>( return; } - if intrinsic == sym::assert_uninit_valid - && !layout.might_permit_raw_init( - fx, - InitKind::Uninit, - fx.tcx.sess.opts.unstable_opts.strict_init_checks) { - + if intrinsic == sym::assert_uninit_valid && !fx.tcx.permits_uninit_init(layout) { with_no_trimmed_paths!({ crate::base::codegen_panic( fx, From 9ea9c093e5ff345305b1236a553cc5999b570a55 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 22 Jun 2022 15:28:28 +0000 Subject: [PATCH 57/77] Introduce opaque type to hidden type projection --- src/base.rs | 1 + src/value_and_place.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/base.rs b/src/base.rs index 63cd4d6de4c3e..54652623d9401 100644 --- a/src/base.rs +++ b/src/base.rs @@ -825,6 +825,7 @@ pub(crate) fn codegen_place<'tcx>( cplace = cplace.place_deref(fx); } } + PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty), PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index a68225de58b32..8ff35d2f76dbf 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -615,6 +615,14 @@ impl<'tcx> CPlace<'tcx> { } } + pub(crate) fn place_opaque_cast( + self, + fx: &mut FunctionCx<'_, '_, 'tcx>, + ty: Ty<'tcx>, + ) -> CPlace<'tcx> { + CPlace { inner: self.inner, layout: fx.layout_of(ty) } + } + pub(crate) fn place_field( self, fx: &mut FunctionCx<'_, '_, 'tcx>, From f750d8ba56f78ddd7b6a70e1b409ee4049256128 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 14 Jul 2022 10:13:52 -0700 Subject: [PATCH 58/77] Upgrade indexmap and thorin-dwp to use hashbrown 0.12 This removes the last dependencies on hashbrown 0.11. --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da18ac7eacbfc..655da407924df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,15 +163,15 @@ 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" [[package]] name = "indexmap" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", diff --git a/Cargo.toml b/Cargo.toml index ec2c1f2ca71b3..ff71d7a209e4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ 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" } -indexmap = "1.8.0" +indexmap = "1.9.1" libloading = { version = "0.6.0", optional = true } once_cell = "1.10.0" smallvec = "1.8.1" From ec469526fd7d9c92003f5da07823d50fa3318a9a Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 17 Jul 2022 13:23:26 +0200 Subject: [PATCH 59/77] Upgrade hashbrown to 0.12.3 This fixes a double-free in the `clone_from` function if dropping an existing element in the table panics. See https://github.com/rust-lang/hashbrown/pull/348 for more details. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 655da407924df..2f5d1c0432f55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,9 +163,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "indexmap" From bc061fa31983e1b36305051c3eaa1e893d223d9d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:59:42 +0200 Subject: [PATCH 60/77] Rustup to rustc 1.64.0-nightly (263edd43c 2022-07-17) --- build_sysroot/Cargo.lock | 4 ++-- example/mini_core.rs | 6 +++--- rust-toolchain | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 86ea1a08ea36d..247303951a828 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", diff --git a/example/mini_core.rs b/example/mini_core.rs index 489259d1a6bc6..8b6042a3d6638 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -458,7 +458,7 @@ pub trait FnMut: FnOnce { #[lang = "panic"] #[track_caller] -pub fn panic(_msg: &str) -> ! { +pub fn panic(_msg: &'static str) -> ! { unsafe { libc::puts("Panicking\n\0" as *const str as *const i8); intrinsics::abort(); @@ -497,7 +497,7 @@ pub trait Deref { #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -pub struct NonNull(pub *mut T); +pub struct NonNull(pub *const T); impl CoerceUnsized> for NonNull where T: Unsize {} impl DispatchFromDyn> for NonNull where T: Unsize {} @@ -521,7 +521,7 @@ impl Drop for Box { } } -impl Deref for Box { +impl Deref for Box { type Target = T; fn deref(&self) -> &Self::Target { diff --git a/rust-toolchain b/rust-toolchain index 9c7d75939c9e9..5c8cab5f13808 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-07-03" +channel = "nightly-2022-07-18" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 5fcedf62df66c9b197d5a1d2bc8694e35cef1772 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:57:22 +0000 Subject: [PATCH 61/77] Update for changes to the rustc test suite --- scripts/setup_rust_fork.sh | 3 +++ scripts/test_rustc_tests.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index c730ae894356b..091bfa1e9926f 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -63,3 +63,6 @@ deny-warnings = false verbose-tests = false EOF popd + +# FIXME remove once inline asm is fully supported +export RUSTFLAGS="$RUSTFLAGS --cfg=rustix_use_libc" diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 3e5d91c2da302..90293a04cb548 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -93,7 +93,6 @@ rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in b rm -r src/test/run-make/unstable-flag-required # same rm -r src/test/run-make/rustdoc-* # same rm -r src/test/run-make/issue-88756-default-output # same -rm -r src/test/run-make/issue-88756-opt-help # same rm -r src/test/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump # genuine bugs @@ -117,6 +116,8 @@ rm src/test/ui/backtrace.rs # TODO warning rm src/test/ui/empty_global_asm.rs # TODO add needs-asm-support rm src/test/ui/simple_global_asm.rs # TODO add needs-asm-support rm src/test/ui/test-attrs/test-type.rs # TODO panic message on stderr. correct stdout +# not sure if this is actually a bug in the test suite, but the symbol list shows the function without leading _ for some reason +rm -r src/test/run-make/native-link-modifier-bundle 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} From 22a0a2eac27d4c0409b1424ff873d89710bfa746 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 20 Jul 2022 07:55:58 +0000 Subject: [PATCH 62/77] Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" This reverts commit 6f8fb911ad504b77549cf3256a09465621beab9d, reversing changes made to 7210e46dc69a4b197a313d093fe145722c248b7d. --- src/base.rs | 1 - src/value_and_place.rs | 8 -------- 2 files changed, 9 deletions(-) diff --git a/src/base.rs b/src/base.rs index 54652623d9401..63cd4d6de4c3e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -825,7 +825,6 @@ pub(crate) fn codegen_place<'tcx>( cplace = cplace.place_deref(fx); } } - PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty), PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 8ff35d2f76dbf..a68225de58b32 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -615,14 +615,6 @@ impl<'tcx> CPlace<'tcx> { } } - pub(crate) fn place_opaque_cast( - self, - fx: &mut FunctionCx<'_, '_, 'tcx>, - ty: Ty<'tcx>, - ) -> CPlace<'tcx> { - CPlace { inner: self.inner, layout: fx.layout_of(ty) } - } - pub(crate) fn place_field( self, fx: &mut FunctionCx<'_, '_, 'tcx>, From 1c77e2b9224f063659e50732938052690fc73264 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Jul 2022 11:36:37 -0400 Subject: [PATCH 63/77] add a Vtable kind of symbolic allocations --- src/constant.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 48972321a9f40..389ff7231b0af 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -195,9 +195,13 @@ pub(crate) fn codegen_const_value<'tcx>( } Scalar::Ptr(ptr, _size) => { let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative - let alloc_kind = fx.tcx.get_global_alloc(alloc_id); - let base_addr = match alloc_kind { - Some(GlobalAlloc::Memory(alloc)) => { + // For vtables, get the underlying data allocation. + let alloc_id = match fx.tcx.global_alloc(alloc_id) { + GlobalAlloc::Vtable(ty, trait_ref) => fx.tcx.vtable_allocation((ty, trait_ref)), + _ => alloc_id, + }; + let base_addr = match fx.tcx.global_alloc(alloc_id) { + GlobalAlloc::Memory(alloc) => { let data_id = data_id_for_alloc_id( &mut fx.constants_cx, fx.module, @@ -211,13 +215,14 @@ pub(crate) fn codegen_const_value<'tcx>( } fx.bcx.ins().global_value(fx.pointer_type, local_data_id) } - Some(GlobalAlloc::Function(instance)) => { + GlobalAlloc::Function(instance) => { let func_id = crate::abi::import_function(fx.tcx, fx.module, instance); let local_func_id = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } - Some(GlobalAlloc::Static(def_id)) => { + GlobalAlloc::Vtable(..) => bug!("vtables are already handled"), + GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); let local_data_id = @@ -227,7 +232,6 @@ pub(crate) fn codegen_const_value<'tcx>( } fx.bcx.ins().global_value(fx.pointer_type, local_data_id) } - None => bug!("missing allocation {:?}", alloc_id), }; let val = if offset.bytes() != 0 { fx.bcx.ins().iadd_imm(base_addr, i64::try_from(offset.bytes()).unwrap()) @@ -360,7 +364,9 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant //println!("alloc_id {}", alloc_id); let alloc = match tcx.get_global_alloc(alloc_id).unwrap() { GlobalAlloc::Memory(alloc) => alloc, - GlobalAlloc::Function(_) | GlobalAlloc::Static(_) => unreachable!(), + GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::Vtable(..) => { + unreachable!() + } }; let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| { module @@ -424,7 +430,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant read_target_uint(endianness, bytes).unwrap() }; - let reloc_target_alloc = tcx.get_global_alloc(alloc_id).unwrap(); + let reloc_target_alloc = tcx.global_alloc(alloc_id); let data_id = match reloc_target_alloc { GlobalAlloc::Function(instance) => { assert_eq!(addend, 0); @@ -436,6 +442,10 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant GlobalAlloc::Memory(target_alloc) => { data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability) } + GlobalAlloc::Vtable(ty, trait_ref) => { + let alloc_id = tcx.vtable_allocation((ty, trait_ref)); + data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not) + } GlobalAlloc::Static(def_id) => { if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { From b5cce742787315bbd974a08718a3020cb1fe3eaf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Jul 2022 11:40:34 -0400 Subject: [PATCH 64/77] rename get_global_alloc to try_get_global_alloc --- src/constant.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index 389ff7231b0af..a1508d7c72b42 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -362,7 +362,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant let (data_id, alloc, section_name) = match todo_item { TodoItem::Alloc(alloc_id) => { //println!("alloc_id {}", alloc_id); - let alloc = match tcx.get_global_alloc(alloc_id).unwrap() { + let alloc = match tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => alloc, GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::Vtable(..) => { unreachable!() From a1b172224c0bc88ae2132726941ab267877a95b9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 19 Jul 2022 19:57:44 -0400 Subject: [PATCH 65/77] consistently use VTable over Vtable (matching stable stdlib API RawWakerVTable) --- src/constant.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index a1508d7c72b42..2380f3e1df022 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -197,7 +197,7 @@ pub(crate) fn codegen_const_value<'tcx>( let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative // For vtables, get the underlying data allocation. let alloc_id = match fx.tcx.global_alloc(alloc_id) { - GlobalAlloc::Vtable(ty, trait_ref) => fx.tcx.vtable_allocation((ty, trait_ref)), + GlobalAlloc::VTable(ty, trait_ref) => fx.tcx.vtable_allocation((ty, trait_ref)), _ => alloc_id, }; let base_addr = match fx.tcx.global_alloc(alloc_id) { @@ -221,7 +221,7 @@ pub(crate) fn codegen_const_value<'tcx>( fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } - GlobalAlloc::Vtable(..) => bug!("vtables are already handled"), + GlobalAlloc::VTable(..) => bug!("vtables are already handled"), GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); @@ -364,7 +364,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant //println!("alloc_id {}", alloc_id); let alloc = match tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => alloc, - GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::Vtable(..) => { + GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => { unreachable!() } }; @@ -442,7 +442,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant GlobalAlloc::Memory(target_alloc) => { data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability) } - GlobalAlloc::Vtable(ty, trait_ref) => { + GlobalAlloc::VTable(ty, trait_ref) => { let alloc_id = tcx.vtable_allocation((ty, trait_ref)); data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not) } From 6c9abfa0f3e4cfb458362d4ece0641542f99b22d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 19 Jul 2022 20:19:15 -0400 Subject: [PATCH 66/77] slightly cleaner, if more verbose, vtable handling in codegen backends --- src/constant.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 2380f3e1df022..b5a143485893f 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -195,11 +195,6 @@ pub(crate) fn codegen_const_value<'tcx>( } Scalar::Ptr(ptr, _size) => { let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative - // For vtables, get the underlying data allocation. - let alloc_id = match fx.tcx.global_alloc(alloc_id) { - GlobalAlloc::VTable(ty, trait_ref) => fx.tcx.vtable_allocation((ty, trait_ref)), - _ => alloc_id, - }; let base_addr = match fx.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { let data_id = data_id_for_alloc_id( @@ -221,7 +216,20 @@ pub(crate) fn codegen_const_value<'tcx>( fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } - GlobalAlloc::VTable(..) => bug!("vtables are already handled"), + GlobalAlloc::VTable(ty, trait_ref) => { + let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref)); + let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory(); + // FIXME: factor this common code with the `Memory` arm into a function? + let data_id = data_id_for_alloc_id( + &mut fx.constants_cx, + fx.module, + alloc_id, + alloc.inner().mutability, + ); + let local_data_id = + fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + } GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); From f8feed7d2713c25a5ef216d185eaa73044cb9318 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 20 Jul 2022 13:36:58 +0000 Subject: [PATCH 67/77] Implement vtable_size and vtable_align intrinsics for cg_clif --- src/intrinsics/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4b2207f375879..d5a79e254a891 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -431,6 +431,16 @@ fn codegen_regular_intrinsic_call<'tcx>( ret.write_cvalue(fx, CValue::by_val(align, usize_layout)); }; + vtable_size, (v vtable) { + let size = crate::vtable::size_of_obj(fx, vtable); + ret.write_cvalue(fx, CValue::by_val(size, usize_layout)); + }; + + vtable_align, (v vtable) { + let align = crate::vtable::min_align_of_obj(fx, vtable); + ret.write_cvalue(fx, CValue::by_val(align, usize_layout)); + }; + unchecked_add | unchecked_sub | unchecked_mul | unchecked_div | exact_div | unchecked_rem | unchecked_shl | unchecked_shr, (c x, c y) { // FIXME trap on overflow From d07ed027839a40e5db04a058ce61d139d8497cf9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Jul 2022 10:47:49 -0400 Subject: [PATCH 68/77] various nits from review --- src/constant.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/constant.rs b/src/constant.rs index b5a143485893f..94a2fb2fbddc2 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -369,7 +369,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant while let Some(todo_item) = cx.todo.pop() { let (data_id, alloc, section_name) = match todo_item { TodoItem::Alloc(alloc_id) => { - //println!("alloc_id {}", alloc_id); let alloc = match tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => alloc, GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => { From cd96988436c2ad6ca6654af073170df5e12e077a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 22 Jul 2022 18:03:24 +0000 Subject: [PATCH 69/77] Don't crash when local variables are too big to store on the stack --- src/value_and_place.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 8ff35d2f76dbf..d82de1d3d8d35 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -324,6 +324,12 @@ impl<'tcx> CPlace<'tcx> { }; } + if layout.size.bytes() >= u64::from(u32::MAX - 16) { + fx.tcx + .sess + .fatal(&format!("values of type {} are too big to store on the stack", layout.ty)); + } + let stack_slot = fx.bcx.create_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to From a6b602dc327e3df294d000d65b8ac186ee8fa792 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 22 Jul 2022 18:42:51 +0000 Subject: [PATCH 70/77] Fix inline asm codegen for empty template --- src/inline_asm.rs | 170 ++++++++++++++++++++++++---------------------- 1 file changed, 90 insertions(+), 80 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index deac5dfd3ec1a..241de5e36530c 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -18,86 +18,96 @@ pub(crate) fn codegen_inline_asm<'tcx>( ) { // FIXME add .eh_frame unwind info directives - if template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string()) { - let true_ = fx.bcx.ins().iconst(types::I32, 1); - fx.bcx.ins().trapnz(true_, TrapCode::User(1)); - return; - } else if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string()) - && matches!( - template[1], - InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ } - ) - && template[2] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[3] == InlineAsmTemplatePiece::String("cpuid".to_string()) - && template[4] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string()) - && matches!( - template[6], - InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ } - ) - { - assert_eq!(operands.len(), 4); - let (leaf, eax_place) = match operands[1] { - InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { - assert_eq!( - reg, - InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)) - ); - ( - crate::base::codegen_operand(fx, in_value).load_scalar(fx), - crate::base::codegen_place(fx, out_place.unwrap()), - ) - } - _ => unreachable!(), - }; - let ebx_place = match operands[0] { - InlineAsmOperand::Out { reg, late: true, place } => { - assert_eq!( - reg, - InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86( - X86InlineAsmRegClass::reg - )) - ); - crate::base::codegen_place(fx, place.unwrap()) - } - _ => unreachable!(), - }; - let (sub_leaf, ecx_place) = match operands[2] { - InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { - assert_eq!( - reg, - InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)) - ); - ( - crate::base::codegen_operand(fx, in_value).load_scalar(fx), - crate::base::codegen_place(fx, out_place.unwrap()), - ) - } - _ => unreachable!(), - }; - let edx_place = match operands[3] { - InlineAsmOperand::Out { reg, late: true, place } => { - assert_eq!( - reg, - InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)) - ); - crate::base::codegen_place(fx, place.unwrap()) - } - _ => unreachable!(), - }; - - let (eax, ebx, ecx, edx) = crate::intrinsics::codegen_cpuid_call(fx, leaf, sub_leaf); - - eax_place.write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32))); - ebx_place.write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32))); - ecx_place.write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32))); - edx_place.write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32))); - return; - } else if fx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") { - // ___chkstk, ___chkstk_ms and __alloca are only used on Windows - crate::trap::trap_unimplemented(fx, "Stack probes are not supported"); - } else if fx.tcx.symbol_name(fx.instance).name == "__alloca" { - crate::trap::trap_unimplemented(fx, "Alloca is not supported"); + if !template.is_empty() { + if template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string()) { + let true_ = fx.bcx.ins().iconst(types::I32, 1); + fx.bcx.ins().trapnz(true_, TrapCode::User(1)); + return; + } else if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string()) + && matches!( + template[1], + InlineAsmTemplatePiece::Placeholder { + operand_idx: 0, + modifier: Some('r'), + span: _ + } + ) + && template[2] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[3] == InlineAsmTemplatePiece::String("cpuid".to_string()) + && template[4] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string()) + && matches!( + template[6], + InlineAsmTemplatePiece::Placeholder { + operand_idx: 0, + modifier: Some('r'), + span: _ + } + ) + { + assert_eq!(operands.len(), 4); + let (leaf, eax_place) = match operands[1] { + InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)) + ); + ( + crate::base::codegen_operand(fx, in_value).load_scalar(fx), + crate::base::codegen_place(fx, out_place.unwrap()), + ) + } + _ => unreachable!(), + }; + let ebx_place = match operands[0] { + InlineAsmOperand::Out { reg, late: true, place } => { + assert_eq!( + reg, + InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86( + X86InlineAsmRegClass::reg + )) + ); + crate::base::codegen_place(fx, place.unwrap()) + } + _ => unreachable!(), + }; + let (sub_leaf, ecx_place) = match operands[2] { + InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)) + ); + ( + crate::base::codegen_operand(fx, in_value).load_scalar(fx), + crate::base::codegen_place(fx, out_place.unwrap()), + ) + } + _ => unreachable!(), + }; + let edx_place = match operands[3] { + InlineAsmOperand::Out { reg, late: true, place } => { + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)) + ); + crate::base::codegen_place(fx, place.unwrap()) + } + _ => unreachable!(), + }; + + let (eax, ebx, ecx, edx) = crate::intrinsics::codegen_cpuid_call(fx, leaf, sub_leaf); + + eax_place.write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32))); + ebx_place.write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32))); + ecx_place.write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32))); + edx_place.write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32))); + return; + } else if fx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") { + // ___chkstk, ___chkstk_ms and __alloca are only used on Windows + crate::trap::trap_unimplemented(fx, "Stack probes are not supported"); + } else if fx.tcx.symbol_name(fx.instance).name == "__alloca" { + crate::trap::trap_unimplemented(fx, "Alloca is not supported"); + } } let mut inputs = Vec::new(); From 3207c9faec8e85b702854d4fed13263a5e772813 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:03:06 +0000 Subject: [PATCH 71/77] Report an error on incompatible symbol definitions --- src/abi/mod.rs | 13 ++++++++++++- src/constant.rs | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 60d5cdda12f78..6f12d9ca5312d 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -4,6 +4,7 @@ mod comments; mod pass_mode; mod returning; +use cranelift_module::ModuleError; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty::layout::FnAbiOf; use rustc_target::abi::call::{Conv, FnAbi}; @@ -69,7 +70,17 @@ pub(crate) fn import_function<'tcx>( ) -> FuncId { let name = tcx.symbol_name(inst).name; let sig = get_function_sig(tcx, module.isa().triple(), inst); - module.declare_function(name, Linkage::Import, &sig).unwrap() + match module.declare_function(name, Linkage::Import, &sig) { + Ok(func_id) => func_id, + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + "attempt to declare `{name}` as function, but it was already declared as static" + )), + Err(ModuleError::IncompatibleSignature(_, prev_sig, new_sig)) => tcx.sess.fatal(&format!( + "attempt to declare `{name}` with signature {new_sig:?}, \ + but it was already declared with signature {prev_sig:?}" + )), + Err(err) => Err::<_, _>(err).unwrap(), + } } impl<'tcx> FunctionCx<'_, '_, 'tcx> { diff --git a/src/constant.rs b/src/constant.rs index a18b9da1fdd6d..9a8139053f147 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -316,14 +316,18 @@ fn data_id_for_static( let attrs = tcx.codegen_fn_attrs(def_id); - let data_id = module - .declare_data( - &*symbol_name, - linkage, - is_mutable, - attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), - ) - .unwrap(); + let data_id = match module.declare_data( + &*symbol_name, + linkage, + is_mutable, + attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), + ) { + Ok(data_id) => data_id, + Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(&format!( + "attempt to declare `{symbol_name}` as static, but it was already declared as function" + )), + Err(err) => Err::<_, _>(err).unwrap(), + }; if rlinkage.is_some() { // Comment copied from https://github.com/rust-lang/rust/blob/45060c2a66dfd667f88bd8b94261b28a58d85bd5/src/librustc_codegen_llvm/consts.rs#L141 From 39ee14d25346aa82e75e9818e92e3c43571c6757 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 11:18:34 +0000 Subject: [PATCH 72/77] Error when trying to define variadic functions They aren't yet supported by Cranelift --- src/abi/mod.rs | 9 +++++++++ src/intrinsics/mod.rs | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 6f12d9ca5312d..815450f689e4a 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -193,6 +193,15 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_ } let fn_abi = fx.fn_abi.take().unwrap(); + + // FIXME implement variadics in cranelift + if fn_abi.c_variadic { + fx.tcx.sess.span_fatal( + fx.mir.span, + "Defining variadic functions is not yet supported by Cranelift", + ); + } + let mut arg_abis_iter = fn_abi.args.iter(); let func_params = fx diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4b2207f375879..eb58cfbb356de 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1135,6 +1135,20 @@ fn codegen_regular_intrinsic_call<'tcx>( // FIXME implement black_box semantics ret.write_cvalue(fx, a); }; + + // FIXME implement variadics in cranelift + va_copy, (o _dest, o _src) { + fx.tcx.sess.span_fatal( + source_info.span, + "Defining variadic functions is not yet supported by Cranelift", + ); + }; + va_arg | va_end, (o _valist) { + fx.tcx.sess.span_fatal( + source_info.span, + "Defining variadic functions is not yet supported by Cranelift", + ); + }; } let ret_block = fx.get_block(destination.unwrap()); From 7ef2ba8f7b2b3076d906567bb107b0437c45be48 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 11:35:24 +0000 Subject: [PATCH 73/77] Fix size_of_val and min_align_of_val for truly unsized types --- example/mini_core_hello_world.rs | 11 +++++++++++ example/std_example.rs | 19 +++++++++++++++++++ src/intrinsics/mod.rs | 8 ++++++-- src/unsize.rs | 6 +----- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 6111e0352828e..aa1f239bae23e 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -330,6 +330,17 @@ fn main() { static REF1: &u8 = &42; static REF2: &u8 = REF1; assert_eq!(*REF1, *REF2); + + extern "C" { + type A; + } + + fn main() { + let x: &A = unsafe { &*(1usize as *const A) }; + + assert_eq!(unsafe { intrinsics::size_of_val(x) }, 0); + assert_eq!(unsafe { intrinsics::min_align_of_val(x) }, 1); +} } #[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] diff --git a/example/std_example.rs b/example/std_example.rs index 0a2bce2621d96..0b5b6cd55d720 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -128,6 +128,25 @@ fn main() { 0 => loop {}, v => panic(v), }; + + if black_box(false) { + // Based on https://github.com/rust-lang/rust/blob/2f320a224e827b400be25966755a621779f797cc/src/test/ui/debuginfo/debuginfo_with_uninhabitable_field_and_unsized.rs + let _ = Foo::::new(); + + #[allow(dead_code)] + struct Foo { + base: Never, + value: T, + } + + impl Foo { + pub fn new() -> Box> { + todo!() + } + } + + enum Never {} + } } fn panic(_: u128) { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index eb58cfbb356de..537aade8b86a4 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -404,7 +404,9 @@ fn codegen_regular_intrinsic_call<'tcx>( }; size_of_val, (c ptr) { let layout = fx.layout_of(substs.type_at(0)); - let size = if layout.is_unsized() { + // Note: Can't use is_unsized here as truly unsized types need to take the fixed size + // branch + let size = if let Abi::ScalarPair(_, _) = ptr.layout().abi { let (_ptr, info) = ptr.load_scalar_pair(fx); let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout, info); size @@ -418,7 +420,9 @@ fn codegen_regular_intrinsic_call<'tcx>( }; min_align_of_val, (c ptr) { let layout = fx.layout_of(substs.type_at(0)); - let align = if layout.is_unsized() { + // Note: Can't use is_unsized here as truly unsized types need to take the fixed size + // branch + let align = if let Abi::ScalarPair(_, _) = ptr.layout().abi { let (_ptr, info) = ptr.load_scalar_pair(fx); let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout, info); align diff --git a/src/unsize.rs b/src/unsize.rs index fd63c3ecddbdf..052ca0a082b3c 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -153,11 +153,7 @@ pub(crate) fn size_and_align_of_dst<'tcx>( layout: TyAndLayout<'tcx>, info: Value, ) -> (Value, Value) { - if !layout.is_unsized() { - let size = fx.bcx.ins().iconst(fx.pointer_type, layout.size.bytes() as i64); - let align = fx.bcx.ins().iconst(fx.pointer_type, layout.align.abi.bytes() as i64); - return (size, align); - } + assert!(layout.is_unsized() || layout.abi == Abi::Uninhabited); match layout.ty.kind() { ty::Dynamic(..) => { // load size/align from vtable From fd2669d1e91027c4ce31f9a3690ce6dab7d8619a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:17:53 +0000 Subject: [PATCH 74/77] Fix -Zpolymorphize --- scripts/test_rustc_tests.sh | 3 --- src/abi/pass_mode.rs | 2 +- src/constant.rs | 3 ++- src/main_shim.rs | 3 ++- src/value_and_place.rs | 51 ++++++++++++++++++++++++++++++++----- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 90293a04cb548..944787612d8bc 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -99,9 +99,6 @@ rm -r src/test/run-make/remap-path-prefix-dwarf # requires llvm-dwarfdump # ============ rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition -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/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 diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 33c5f3283be59..6c10baa53d415 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -216,7 +216,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>( arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, is_owned: bool, ) -> SmallVec<[Value; 2]> { - assert_assignable(fx, arg.layout().ty, arg_abi.layout.ty); + assert_assignable(fx, arg.layout().ty, arg_abi.layout.ty, 16); match arg_abi.mode { PassMode::Ignore => smallvec![], PassMode::Direct(_) => smallvec![arg.load_scalar(fx)], diff --git a/src/constant.rs b/src/constant.rs index 9a8139053f147..c83dab951bc47 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -432,7 +432,8 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant let data_id = match reloc_target_alloc { GlobalAlloc::Function(instance) => { assert_eq!(addend, 0); - let func_id = crate::abi::import_function(tcx, module, instance); + let func_id = + crate::abi::import_function(tcx, module, instance.polymorphize(tcx)); let local_func_id = module.declare_func_in_data(func_id, &mut data_ctx); data_ctx.write_function_addr(offset.bytes() as u32, local_func_id); continue; diff --git a/src/main_shim.rs b/src/main_shim.rs index 2f71a70a44946..c67b6e98b32c7 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -109,7 +109,8 @@ pub(crate) fn maybe_create_entry_wrapper( tcx.mk_substs([GenericArg::from(main_ret_ty)].iter()), ) .unwrap() - .unwrap(); + .unwrap() + .polymorphize(tcx); let report_name = tcx.symbol_name(report).name; let report_sig = get_function_sig(tcx, m.isa().triple(), report); diff --git a/src/value_and_place.rs b/src/value_and_place.rs index d82de1d3d8d35..6674099e9a23b 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -426,7 +426,7 @@ impl<'tcx> CPlace<'tcx> { } pub(crate) fn write_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>) { - assert_assignable(fx, from.layout().ty, self.layout().ty); + assert_assignable(fx, from.layout().ty, self.layout().ty, 16); self.write_cvalue_maybe_transmute(fx, from, "write_cvalue"); } @@ -788,18 +788,25 @@ pub(crate) fn assert_assignable<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, + limit: usize, ) { + if limit == 0 { + // assert_assignable exists solely to catch bugs in cg_clif. it isn't necessary for + // soundness. don't attempt to check deep types to avoid exponential behavior in certain + // cases. + return; + } match (from_ty.kind(), to_ty.kind()) { (ty::Ref(_, a, _), ty::Ref(_, b, _)) | ( ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }), ty::RawPtr(TypeAndMut { ty: b, mutbl: _ }), ) => { - assert_assignable(fx, *a, *b); + assert_assignable(fx, *a, *b, limit - 1); } (ty::Ref(_, a, _), ty::RawPtr(TypeAndMut { ty: b, mutbl: _ })) | (ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }), ty::Ref(_, b, _)) => { - assert_assignable(fx, *a, *b); + assert_assignable(fx, *a, *b, limit - 1); } (ty::FnPtr(_), ty::FnPtr(_)) => { let from_sig = fx.tcx.normalize_erasing_late_bound_regions( @@ -829,6 +836,17 @@ pub(crate) fn assert_assignable<'tcx>( } // dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed } + (&ty::Tuple(types_a), &ty::Tuple(types_b)) => { + let mut types_a = types_a.iter(); + let mut types_b = types_b.iter(); + loop { + match (types_a.next(), types_b.next()) { + (Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1), + (None, None) => return, + (Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty), + } + } + } (&ty::Adt(adt_def_a, substs_a), &ty::Adt(adt_def_b, substs_b)) if adt_def_a.did() == adt_def_b.did() => { @@ -836,18 +854,37 @@ pub(crate) fn assert_assignable<'tcx>( let mut types_b = substs_b.types(); loop { match (types_a.next(), types_b.next()) { - (Some(a), Some(b)) => assert_assignable(fx, a, b), + (Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1), (None, None) => return, (Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty), } } } - (ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, *a, *b), + (ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, *a, *b, limit - 1), + (&ty::Closure(def_id_a, substs_a), &ty::Closure(def_id_b, substs_b)) + if def_id_a == def_id_b => + { + let mut types_a = substs_a.types(); + let mut types_b = substs_b.types(); + loop { + match (types_a.next(), types_b.next()) { + (Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1), + (None, None) => return, + (Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty), + } + } + } + (ty::Param(_), _) | (_, ty::Param(_)) if fx.tcx.sess.opts.unstable_opts.polymorphize => { + // No way to check if it is correct or not with polymorphization enabled + } _ => { assert_eq!( - from_ty, to_ty, + from_ty, + to_ty, "Can't write value with incompatible type {:?} to place with type {:?}\n\n{:#?}", - from_ty, to_ty, fx, + from_ty.kind(), + to_ty.kind(), + fx, ); } } From d7fc56323e869ab20c6e2fa14966e35cf60124f1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:50:43 +0000 Subject: [PATCH 75/77] Update Cranelift to 0.85.3 This fixes a couple of potential miscompilations. None affect cg_clif on x86_64, but one may affect cg_clif on AArch64. --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- Cargo.toml | 12 ++++++------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51e088b618bab..8ab6955e17c7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,18 +50,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7901fbba05decc537080b07cb3f1cadf53be7b7602ca8255786288a8692ae29a" +checksum = "749d0d6022c9038dccf480bdde2a38d435937335bf2bb0f14e815d94517cdce8" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ba1b45d243a4a28e12d26cd5f2507da74e77c45927d40de8b6ffbf088b46b5" +checksum = "e94370cc7b37bf652ccd8bb8f09bd900997f7ccf97520edfc75554bb5c4abbea" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -77,30 +77,30 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54cc30032171bf230ce22b99c07c3a1de1221cb5375bd6dbe6dbe77d0eed743c" +checksum = "e0a3cea8fdab90e44018c5b9a1dfd460d8ee265ac354337150222a354628bdb6" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23f2672426d2bb4c9c3ef53e023076cfc4d8922f0eeaebaf372c92fae8b5c69" +checksum = "5ac72f76f2698598951ab26d8c96eaa854810e693e7dd52523958b5909fde6b2" [[package]] name = "cranelift-entity" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "886c59a5e0de1f06dbb7da80db149c75de10d5e2caca07cdd9fef8a5918a6336" +checksum = "09eaeacfcd2356fe0e66b295e8f9d59fdd1ac3ace53ba50de14d628ec902f72d" [[package]] name = "cranelift-frontend" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace74eeca11c439a9d4ed1a5cb9df31a54cd0f7fbddf82c8ce4ea8e9ad2a8fe0" +checksum = "dba69c9980d5ffd62c18a2bde927855fcd7c8dc92f29feaf8636052662cbd99c" dependencies = [ "cranelift-codegen", "log", @@ -110,15 +110,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db1ae52a5cc2cad0d86fdd3dcb16b7217d2f1e65ab4f5814aa4f014ad335fa43" +checksum = "d2920dc1e05cac40304456ed3301fde2c09bd6a9b0210bcfa2f101398d628d5b" [[package]] name = "cranelift-jit" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2305c9ab672e746f62d135655d29039357aafa725d9736e27f50f1aa4eac7bc" +checksum = "1c3c5ed067f2c81577e431f3039148a9c187b33cc79e0d1731fede27d801ec56" dependencies = [ "anyhow", "cranelift-codegen", @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1fa24c991e97166915594e5cb8752c45e026b47df5f79ae4305f5b88948529" +checksum = "eee6784303bf9af235237a4885f7417e09a35df896d38ea969a0081064b3ede4" dependencies = [ "anyhow", "cranelift-codegen", @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dadcfb7852900780d37102bce5698bcd401736403f07b52e714ff7a180e0e22f" +checksum = "f04dfa45f9b2a6f587c564d6b63388e00cd6589d2df6ea2758cf79e1a13285e6" dependencies = [ "cranelift-codegen", "libc", @@ -155,9 +155,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.85.1" +version = "0.85.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e25c4513d4175039d907056c032e755e3ae6eee0bee6126fbd7d9b9e9e44830" +checksum = "0bf38b2c505db749276793116c0cb30bd096206c7810e471677a453134881881" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/Cargo.toml b/Cargo.toml index 04f2125950cb2..74a440094a6ee 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.85.1", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.85.1" -cranelift-module = "0.85.1" -cranelift-native = "0.85.1" -cranelift-jit = { version = "0.85.1", optional = true } -cranelift-object = "0.85.1" +cranelift-codegen = { version = "0.85.3", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.85.3" +cranelift-module = "0.85.3" +cranelift-native = "0.85.3" +cranelift-jit = { version = "0.85.3", optional = true } +cranelift-object = "0.85.3" target-lexicon = "0.12.0" gimli = { version = "0.26.0", default-features = false, features = ["write"]} object = { version = "0.28.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From c19edfd71a1d0ddef86c2c67fdb40718d40a72b4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 16:06:39 +0200 Subject: [PATCH 76/77] Rustup to rustc 1.64.0-nightly (7fe022f5a 2022-07-24) --- 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 247303951a828..7b2cdd273366f 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -123,9 +123,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37fb7dc756218a0559bfc21e4381f03cbb696cdaf959e7e95e927496f0564cd" +checksum = "7668753748e445859e4e373c3d41117235d9feed578392f5a3a73efdc751ca4a" dependencies = [ "compiler_builtins", "libc", diff --git a/rust-toolchain b/rust-toolchain index 5c8cab5f13808..3ab395d89d50e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2022-07-18" +channel = "nightly-2022-07-25" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 9dc4ed8d905ec4c676137e2714a245eabc06727c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 25 Jul 2022 17:08:20 +0200 Subject: [PATCH 77/77] Update list of allowed dependencies Cranelift started depending on a couple of new crates --- src/tools/tidy/src/deps.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index ea7eff1a4148e..333f85f6d62b8 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -55,12 +55,13 @@ const EXCEPTIONS_CRANELIFT: &[(&str, &str)] = &[ ("cranelift-codegen-shared", "Apache-2.0 WITH LLVM-exception"), ("cranelift-entity", "Apache-2.0 WITH LLVM-exception"), ("cranelift-frontend", "Apache-2.0 WITH LLVM-exception"), + ("cranelift-isle", "Apache-2.0 WITH LLVM-exception"), ("cranelift-jit", "Apache-2.0 WITH LLVM-exception"), ("cranelift-module", "Apache-2.0 WITH LLVM-exception"), ("cranelift-native", "Apache-2.0 WITH LLVM-exception"), ("cranelift-object", "Apache-2.0 WITH LLVM-exception"), ("mach", "BSD-2-Clause"), - ("regalloc", "Apache-2.0 WITH LLVM-exception"), + ("regalloc2", "Apache-2.0 WITH LLVM-exception"), ("target-lexicon", "Apache-2.0 WITH LLVM-exception"), ]; @@ -258,10 +259,12 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ ]; const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ + "ahash", "anyhow", "ar", "autocfg", "bitflags", + "byteorder", "cfg-if", "cranelift-bforest", "cranelift-codegen", @@ -269,11 +272,14 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "cranelift-codegen-shared", "cranelift-entity", "cranelift-frontend", + "cranelift-isle", "cranelift-jit", "cranelift-module", "cranelift-native", "cranelift-object", "crc32fast", + "fxhash", + "getrandom", "gimli", "hashbrown", "indexmap", @@ -284,11 +290,13 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "memchr", "object", "once_cell", - "regalloc", + "regalloc2", "region", - "rustc-hash", + "slice-group-by", "smallvec", "target-lexicon", + "version_check", + "wasi", "winapi", "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",