From 32b608a439ef0015251b7339b4ab33d72be2397e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:20:46 +0000 Subject: [PATCH 01/59] Merge commit '6d35b4c9a04580366fd800692a5b5db79d766530' into sync_cg_clif-2024-09-22 --- .cirrus.yml | 2 +- .github/workflows/main.yml | 3 +- Cargo.lock | 64 +++++----- Cargo.toml | 14 +-- build_system/abi_cafe.rs | 9 +- build_system/bench.rs | 37 +++++- build_system/build_backend.rs | 17 +-- build_system/build_sysroot.rs | 85 ++++++-------- build_system/main.rs | 7 -- build_system/path.rs | 5 +- build_system/prepare.rs | 98 +++++----------- build_system/tests.rs | 43 ++----- build_system/usage.txt | 16 +-- build_system/utils.rs | 110 ++++++------------ clean_all.sh | 5 +- example/neon.rs | 43 +++++++ example/std_example.rs | 28 +++++ ...-simd-Disable-broken-reduce_sum-test.patch | 26 +++++ ...oretests-Disable-not-compiling-tests.patch | 2 +- ...7-coretests-128bit-atomic-operations.patch | 5 +- ...coretests-Disable-long-running-tests.patch | 20 ++++ rust-toolchain | 2 +- scripts/setup_rust_fork.sh | 3 + scripts/test_rustc_tests.sh | 92 +++++++++++++++ src/abi/mod.rs | 5 +- src/constant.rs | 5 + src/intrinsics/llvm_aarch64.rs | 38 ++++++ src/intrinsics/mod.rs | 4 +- src/intrinsics/simd.rs | 42 +++---- test.sh | 2 +- y.sh | 2 +- 31 files changed, 487 insertions(+), 347 deletions(-) create mode 100644 patches/0001-portable-simd-Disable-broken-reduce_sum-test.patch diff --git a/.cirrus.yml b/.cirrus.yml index 5a464bfac3644..1ec99eb3d17a5 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -3,7 +3,7 @@ task: freebsd_instance: image: freebsd-13-2-release-amd64 setup_rust_script: - - pkg install -y git bash binutils + - pkg install -y git-tiny binutils - curl https://sh.rustup.rs -sSf --output rustup.sh - sh rustup.sh --default-toolchain none -y --profile=minimal target_cache: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 896a5c34c3eff..2ee94146c1a4e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -279,8 +279,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 if: ${{ github.ref == 'refs/heads/master' }} - # FIXME add the bench job back to the dependency list once rust-lang/rust#125493 gets merged - needs: [rustfmt, test, dist] + needs: [rustfmt, test, bench, dist] permissions: contents: write # for creating the dev tag and release diff --git a/Cargo.lock b/Cargo.lock index 02d4d98dc4212..1c2ca95b075ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,24 +46,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "effa84ab2023f7138045ece6b326588c17447ca22e66db71ec15cb0a6c0c4ad2" +checksum = "b80c3a50b9c4c7e5b5f73c0ed746687774fc9e36ef652b110da8daebf0c6e0e6" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a1dfc50dca188a15d938867c4400589530bcb0138f7022aae6d059d1d8c309" +checksum = "38778758c2ca918b05acb2199134e0c561fb577c50574259b26190b6c2d95ded" [[package]] name = "cranelift-codegen" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "821c20c639350158ecca928dc2a244d0d1c9cef2377a378fc62a445a286eb1ca" +checksum = "58258667ad10e468bfc13a8d620f50dfcd4bb35d668123e97defa2549b9ad397" dependencies = [ "bumpalo", "cranelift-bforest", @@ -84,42 +84,42 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064473f2fd59b44fa2c9aaa60de1f9c44db5e13521e28bc85d2b92ee535ef625" +checksum = "043f0b702e529dcb07ff92bd7d40e7d5317b5493595172c5eb0983343751ee06" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f39b9ebfd2febdc2acfb9a0fca110665bcd5a6839502576307735ed07b2177" +checksum = "7763578888ab53eca5ce7da141953f828e82c2bfadcffc106d10d1866094ffbb" [[package]] name = "cranelift-control" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e125c189c3a1ca8dfe209fc6f46edba058a6d24e0b92aff69459a15f4711e7" +checksum = "32db15f08c05df570f11e8ab33cb1ec449a64b37c8a3498377b77650bef33d8b" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea62eb109baec2247e1a6fa7b74c0f584b1e76e289cfd7017385b4b031fc8450" +checksum = "5289cdb399381a27e7bbfa1b42185916007c3d49aeef70b1d01cb4caa8010130" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722b089357aacb6c7528b2e59a5fe00917d61ce63448b25a3e477a5b7819fac8" +checksum = "31ba8ab24eb9470477e98ddfa3c799a649ac5a0d9a2042868c4c952133c234e8" dependencies = [ "cranelift-codegen", "log", @@ -129,15 +129,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4b5005a48288e7fc2a2991a377831c534e26929b063c379c018060727785a9b" +checksum = "2b72a3c5c166a70426dcb209bdd0bb71a787c1ea76023dc0974fbabca770e8f9" [[package]] name = "cranelift-jit" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f843932baf8d1025c5f114b929eda172d74b7163d058e0de2597c308b567c7e9" +checksum = "df32578a47582e49b4fc1f9a5786839d9be1fedaa9f00bea7612c54425663c6b" dependencies = [ "anyhow", "cranelift-codegen", @@ -155,9 +155,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449819ef1c4af139cf1b9717916fcaea0e23248853d3e95135139773a842d3eb" +checksum = "96094a758cdb543c9143f70817cd31069fecd49f50981a0fac06820ac011dc2f" dependencies = [ "anyhow", "cranelift-codegen", @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ae2d48f38081a9e679ad795bd36bb29bedeb5552fc1c195185bf9885fa1b16e" +checksum = "46a42424c956bbc31fc5c2706073df896156c5420ae8fa2a5d48dbc7b295d71b" dependencies = [ "cranelift-codegen", "libc", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.110.1" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a39ee2cfd0ec485eca76f6b4dc17701a280fa406bc05137bb43f1635ed12c9f" +checksum = "1cf5e2484ab47fe38a3150747cdd2016535f13542a925acca152b63383a6591b" dependencies = [ "anyhow", "cranelift-codegen", @@ -213,9 +213,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" dependencies = [ "fallible-iterator", "indexmap", @@ -403,9 +403,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.15" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "unicode-ident" @@ -421,9 +421,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasmtime-jit-icache-coherence" -version = "23.0.1" +version = "24.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fddf3e2980fb1d123d1fcac55189e417fdd3dba4f62139b5a0a1f9efe5669d5" +checksum = "d15de8429db996f0d17a4163a35eccc3f874cbfb50f29c379951ea1bbb39452e" dependencies = [ "anyhow", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index a0df502dadc47..6594ffb5d66bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,14 +8,14 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.110.1", default-features = false, features = ["std", "unwind", "all-arch"] } -cranelift-frontend = { version = "0.110.1" } -cranelift-module = { version = "0.110.1" } -cranelift-native = { version = "0.110.1" } -cranelift-jit = { version = "0.110.1", optional = true } -cranelift-object = { version = "0.110.1" } +cranelift-codegen = { version = "0.111.0", default-features = false, features = ["std", "unwind", "all-arch"] } +cranelift-frontend = { version = "0.111.0" } +cranelift-module = { version = "0.111.0" } +cranelift-native = { version = "0.111.0" } +cranelift-jit = { version = "0.111.0", optional = true } +cranelift-object = { version = "0.111.0" } target-lexicon = "0.12.0" -gimli = { version = "0.28", default-features = false, features = ["write"]} +gimli = { version = "0.29", default-features = false, features = ["write"] } object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index c0873a20e535a..9292778806a2e 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -14,7 +14,6 @@ static ABI_CAFE_REPO: GitRepo = GitRepo::github( static ABI_CAFE: CargoProject = CargoProject::new(&ABI_CAFE_REPO.source_dir(), "abi_cafe_target"); pub(crate) fn run( - channel: &str, sysroot_kind: SysrootKind, dirs: &Dirs, cg_clif_dylib: &CodegenBackend, @@ -28,7 +27,6 @@ pub(crate) fn run( eprintln!("Building sysroot for abi-cafe"); build_sysroot::build_sysroot( dirs, - channel, sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, @@ -38,12 +36,11 @@ pub(crate) fn run( eprintln!("Running abi-cafe"); - let pairs = ["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"]; - let pairs = + let pairs: &[_] = if cfg!(not(any(target_os = "macos", all(target_os = "windows", target_env = "msvc")))) { - &pairs[..] + &["rustc_calls_cgclif", "cgclif_calls_rustc", "cgclif_calls_cc", "cc_calls_cgclif"] } else { - &pairs[..2] + &["rustc_calls_cgclif", "cgclif_calls_rustc"] }; let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs); diff --git a/build_system/bench.rs b/build_system/bench.rs index 501e128d18039..ebeb67722507a 100644 --- a/build_system/bench.rs +++ b/build_system/bench.rs @@ -1,11 +1,12 @@ use std::env; use std::io::Write; use std::path::Path; +use std::process::Command; use crate::path::{Dirs, RelPath}; use crate::prepare::GitRepo; use crate::rustc_info::get_file_name; -use crate::utils::{Compiler, hyperfine_command, spawn_and_wait}; +use crate::utils::{Compiler, spawn_and_wait}; static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( "ebobby", @@ -128,3 +129,37 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) { gha_step_summary.write_all(b"\n").unwrap(); } } + +#[must_use] +fn hyperfine_command( + warmup: u64, + runs: u64, + prepare: Option<&str>, + cmds: &[(&str, &str)], + markdown_export: &Path, +) -> Command { + let mut bench = Command::new("hyperfine"); + + bench.arg("--export-markdown").arg(markdown_export); + + if warmup != 0 { + bench.arg("--warmup").arg(warmup.to_string()); + } + + if runs != 0 { + bench.arg("--runs").arg(runs.to_string()); + } + + if let Some(prepare) = prepare { + bench.arg("--prepare").arg(prepare); + } + + for &(name, cmd) in cmds { + if name != "" { + bench.arg("-n").arg(name); + } + bench.arg(cmd); + } + + bench +} diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 129713e574ad0..02da89f737cf2 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -6,11 +6,10 @@ use crate::rustc_info::get_file_name; use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env}; use crate::utils::{CargoProject, Compiler, LogGroup}; -pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); +static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif"); pub(crate) fn build_backend( dirs: &Dirs, - channel: &str, bootstrap_host_compiler: &Compiler, use_unstable_features: bool, ) -> PathBuf { @@ -19,8 +18,8 @@ pub(crate) fn build_backend( let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs); let mut rustflags = rustflags_from_env("RUSTFLAGS"); - rustflags.push("-Zallow-features=rustc_private".to_owned()); + rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags); if env::var("CG_CLIF_EXPENSIVE_CHECKS").is_ok() { // Enabling debug assertions implicitly enables the clif ir verifier @@ -32,15 +31,7 @@ pub(crate) fn build_backend( cmd.arg("--features").arg("unstable-features"); } - match channel { - "debug" => {} - "release" => { - cmd.arg("--release"); - } - _ => unreachable!(), - } - - rustflags_to_cmd_env(&mut cmd, "RUSTFLAGS", &rustflags); + cmd.arg("--release"); eprintln!("[BUILD] rustc_codegen_cranelift"); crate::utils::spawn_and_wait(cmd); @@ -48,6 +39,6 @@ pub(crate) fn build_backend( CG_CLIF .target_dir(dirs) .join(&bootstrap_host_compiler.triple) - .join(channel) + .join("release") .join(get_file_name(&bootstrap_host_compiler.rustc, "rustc_codegen_cranelift", "dylib")) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index b11dc6a0eed8f..6a4f2a6c72c52 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,19 +3,15 @@ use std::process::Command; use std::{env, fs}; use crate::path::{Dirs, RelPath}; -use crate::rustc_info::get_file_name; +use crate::prepare::apply_patches; +use crate::rustc_info::{get_default_sysroot, get_file_name}; use crate::utils::{ - CargoProject, Compiler, LogGroup, remove_dir_if_exists, spawn_and_wait, try_hard_link, + ensure_empty_dir, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup, }; -use crate::{CodegenBackend, SysrootKind, config}; - -static DIST_DIR: RelPath = RelPath::DIST; -static BIN_DIR: RelPath = RelPath::DIST.join("bin"); -static LIB_DIR: RelPath = RelPath::DIST.join("lib"); +use crate::{config, CodegenBackend, SysrootKind}; pub(crate) fn build_sysroot( dirs: &Dirs, - channel: &str, sysroot_kind: SysrootKind, cg_clif_dylib_src: &CodegenBackend, bootstrap_host_compiler: &Compiler, @@ -26,9 +22,11 @@ pub(crate) fn build_sysroot( eprintln!("[BUILD] sysroot {:?}", sysroot_kind); - DIST_DIR.ensure_fresh(dirs); - BIN_DIR.ensure_exists(dirs); - LIB_DIR.ensure_exists(dirs); + let dist_dir = RelPath::DIST.to_path(dirs); + + ensure_empty_dir(&dist_dir); + fs::create_dir_all(dist_dir.join("bin")).unwrap(); + fs::create_dir_all(dist_dir.join("lib")).unwrap(); let is_native = bootstrap_host_compiler.triple == target_triple; @@ -38,11 +36,10 @@ pub(crate) fn build_sysroot( let cg_clif_dylib_path = if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the // binaries. - BIN_DIR + dist_dir.join("bin") } else { - LIB_DIR + dist_dir.join("lib") } - .to_path(dirs) .join(src_path.file_name().unwrap()); try_hard_link(src_path, &cg_clif_dylib_path); CodegenBackend::Local(cg_clif_dylib_path) @@ -56,7 +53,7 @@ pub(crate) fn build_sysroot( let wrapper_name = wrapper_base_name.replace("____", wrapper); let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); - let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name); + let wrapper_path = dist_dir.join(&wrapper_name); build_cargo_wrapper_cmd .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg("-o") @@ -79,22 +76,20 @@ pub(crate) fn build_sysroot( build_cargo_wrapper_cmd.env("BUILTIN_BACKEND", name); } spawn_and_wait(build_cargo_wrapper_cmd); - try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name)); + try_hard_link(wrapper_path, dist_dir.join("bin").join(wrapper_name)); } let host = build_sysroot_for_triple( dirs, - channel, bootstrap_host_compiler.clone(), &cg_clif_dylib_path, sysroot_kind, ); - host.install_into_sysroot(&DIST_DIR.to_path(dirs)); + host.install_into_sysroot(&dist_dir); if !is_native { build_sysroot_for_triple( dirs, - channel, { let mut bootstrap_target_compiler = bootstrap_host_compiler.clone(); bootstrap_target_compiler.triple = target_triple.clone(); @@ -104,7 +99,7 @@ pub(crate) fn build_sysroot( &cg_clif_dylib_path, sysroot_kind, ) - .install_into_sysroot(&DIST_DIR.to_path(dirs)); + .install_into_sysroot(&dist_dir); } // Copy std for the host to the lib dir. This is necessary for the jit mode to find @@ -112,16 +107,13 @@ pub(crate) fn build_sysroot( for lib in host.libs { let filename = lib.file_name().unwrap().to_str().unwrap(); if filename.contains("std-") && !filename.contains(".rlib") { - try_hard_link(&lib, LIB_DIR.to_path(dirs).join(lib.file_name().unwrap())); + try_hard_link(&lib, dist_dir.join("lib").join(lib.file_name().unwrap())); } } let mut target_compiler = { - let dirs: &Dirs = &dirs; - let rustc_clif = - RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif")); - let rustdoc_clif = - RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif")); + let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif")); + let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif")); Compiler { cargo: bootstrap_host_compiler.cargo.clone(), @@ -139,6 +131,7 @@ pub(crate) fn build_sysroot( target_compiler } +#[must_use] struct SysrootTarget { triple: String, libs: Vec, @@ -159,15 +152,13 @@ impl SysrootTarget { } } -pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib"); -pub(crate) static STANDARD_LIBRARY: CargoProject = +static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib"); +static STANDARD_LIBRARY: CargoProject = CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target"); -pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup"); +static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup"); -#[must_use] fn build_sysroot_for_triple( dirs: &Dirs, - channel: &str, compiler: Compiler, cg_clif_dylib_path: &CodegenBackend, sysroot_kind: SysrootKind, @@ -176,13 +167,10 @@ fn build_sysroot_for_triple( SysrootKind::None => build_rtstartup(dirs, &compiler) .unwrap_or(SysrootTarget { triple: compiler.triple, libs: vec![] }), SysrootKind::Llvm => build_llvm_sysroot_for_triple(compiler), - SysrootKind::Clif => { - build_clif_sysroot_for_triple(dirs, channel, compiler, cg_clif_dylib_path) - } + SysrootKind::Clif => build_clif_sysroot_for_triple(dirs, compiler, cg_clif_dylib_path), } } -#[must_use] fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget { let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc); @@ -216,10 +204,8 @@ fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget { target_libs } -#[must_use] fn build_clif_sysroot_for_triple( dirs: &Dirs, - channel: &str, mut compiler: Compiler, cg_clif_dylib_path: &CodegenBackend, ) -> SysrootTarget { @@ -231,12 +217,12 @@ fn build_clif_sysroot_for_triple( target_libs.libs.extend(rtstartup_target_libs.libs); } - let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join(channel); + let build_dir = STANDARD_LIBRARY.target_dir(dirs).join(&compiler.triple).join("release"); if !config::get_bool("keep_sysroot") { // 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. - remove_dir_if_exists(&build_dir.join("deps")); + ensure_empty_dir(&build_dir.join("deps")); } // Build sysroot @@ -252,12 +238,12 @@ fn build_clif_sysroot_for_triple( // Necessary for MinGW to find rsbegin.o and rsend.o rustflags.push("--sysroot".to_owned()); rustflags.push(RTSTARTUP_SYSROOT.to_path(dirs).to_str().unwrap().to_owned()); - if channel == "release" { - // Incremental compilation by default disables mir inlining. This leads to both a decent - // compile perf and a significant runtime perf regression. As such forcefully enable mir - // inlining. - rustflags.push("-Zinline-mir".to_owned()); - } + + // Incremental compilation by default disables mir inlining. This leads to both a decent + // compile perf and a significant runtime perf regression. As such forcefully enable mir + // inlining. + rustflags.push("-Zinline-mir".to_owned()); + if let Some(prefix) = env::var_os("CG_CLIF_STDLIB_REMAP_PATH_PREFIX") { rustflags.push("--remap-path-prefix".to_owned()); rustflags.push(format!( @@ -268,9 +254,7 @@ fn build_clif_sysroot_for_triple( } compiler.rustflags.extend(rustflags); let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs); - if channel == "release" { - build_cmd.arg("--release"); - } + build_cmd.arg("--release"); build_cmd.arg("--features").arg("backtrace panic-unwind compiler-builtins-no-f16-f128"); build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true"); build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); @@ -296,7 +280,10 @@ fn build_clif_sysroot_for_triple( fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option { if !config::get_bool("keep_sysroot") { - crate::prepare::prepare_stdlib(dirs, &compiler.rustc); + let sysroot_src_orig = get_default_sysroot(&compiler.rustc).join("lib/rustlib/src/rust"); + assert!(sysroot_src_orig.exists()); + + apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); } if !compiler.triple.ends_with("windows-gnu") { diff --git a/build_system/main.rs b/build_system/main.rs index 9ddeda583afd1..b68ac7c09267e 100644 --- a/build_system/main.rs +++ b/build_system/main.rs @@ -81,7 +81,6 @@ fn main() { let mut out_dir = PathBuf::from("."); let mut download_dir = None; - let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; let mut use_unstable_features = true; let mut frozen = false; @@ -99,7 +98,6 @@ fn main() { arg_error!("--download-dir requires argument"); }))); } - "--debug" => channel = "debug", "--sysroot" => { sysroot_kind = match args.next().as_deref() { Some("none") => SysrootKind::None, @@ -206,7 +204,6 @@ fn main() { } else { CodegenBackend::Local(build_backend::build_backend( &dirs, - channel, &bootstrap_host_compiler, use_unstable_features, )) @@ -218,7 +215,6 @@ fn main() { Command::Test => { tests::run_tests( &dirs, - channel, sysroot_kind, use_unstable_features, &skip_tests.iter().map(|test| &**test).collect::>(), @@ -234,7 +230,6 @@ fn main() { process::exit(1); } abi_cafe::run( - channel, sysroot_kind, &dirs, &cg_clif_dylib, @@ -245,7 +240,6 @@ fn main() { Command::Build => { build_sysroot::build_sysroot( &dirs, - channel, sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, @@ -256,7 +250,6 @@ fn main() { Command::Bench => { build_sysroot::build_sysroot( &dirs, - channel, sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, diff --git a/build_system/path.rs b/build_system/path.rs index 8572815fc55e4..35e7e81c5285d 100644 --- a/build_system/path.rs +++ b/build_system/path.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::PathBuf; -use crate::utils::remove_dir_if_exists; +use crate::utils::ensure_empty_dir; #[derive(Debug, Clone)] pub(crate) struct Dirs { @@ -64,7 +64,6 @@ impl RelPath { pub(crate) fn ensure_fresh(&self, dirs: &Dirs) { let path = self.to_path(dirs); - remove_dir_if_exists(&path); - fs::create_dir_all(path).unwrap(); + ensure_empty_dir(&path); } } diff --git a/build_system/prepare.rs b/build_system/prepare.rs index be0bed0f4e636..b9cfcd99a7772 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -4,12 +4,8 @@ use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use std::process::Command; -use crate::build_sysroot::STDLIB_SRC; use crate::path::{Dirs, RelPath}; -use crate::rustc_info::get_default_sysroot; -use crate::utils::{ - copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait, -}; +use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait}; pub(crate) fn prepare(dirs: &Dirs) { RelPath::DOWNLOAD.ensure_exists(dirs); @@ -17,13 +13,6 @@ pub(crate) fn prepare(dirs: &Dirs) { crate::tests::REGEX_REPO.fetch(dirs); } -pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) { - let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust"); - assert!(sysroot_src_orig.exists()); - - apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs)); -} - pub(crate) struct GitRepo { url: GitRepoUrl, rev: &'static str, @@ -119,7 +108,11 @@ impl GitRepo { match self.url { GitRepoUrl::Github { user, repo } => { - clone_repo_shallow_github(dirs, &download_dir, user, repo, self.rev); + clone_repo( + &download_dir, + &format!("https://github.com/{}/{}.git", user, repo), + self.rev, + ); } } @@ -154,7 +147,6 @@ impl GitRepo { } } -#[allow(dead_code)] fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); // Ignore exit code as the repo may already have been checked out @@ -171,55 +163,6 @@ fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { std::fs::remove_dir_all(download_dir.join(".git")).unwrap(); } -fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo: &str, rev: &str) { - if cfg!(windows) { - // Older windows doesn't have tar or curl by default. Fall back to using git. - clone_repo(download_dir, &format!("https://github.com/{}/{}.git", user, repo), rev); - return; - } - - let archive_url = format!("https://github.com/{}/{}/archive/{}.tar.gz", user, repo, rev); - let archive_file = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}.tar.gz", rev)); - let archive_dir = RelPath::DOWNLOAD.to_path(dirs).join(format!("{}-{}", repo, rev)); - - eprintln!("[DOWNLOAD] {}/{} from {}", user, repo, archive_url); - - // Remove previous results if they exists - let _ = std::fs::remove_file(&archive_file); - let _ = std::fs::remove_dir_all(&archive_dir); - let _ = std::fs::remove_dir_all(&download_dir); - - // Download zip archive - let mut download_cmd = Command::new("curl"); - download_cmd - .arg("--max-time") - .arg("600") - .arg("-y") - .arg("30") - .arg("-Y") - .arg("10") - .arg("--connect-timeout") - .arg("30") - .arg("--continue-at") - .arg("-") - .arg("--location") - .arg("--output") - .arg(&archive_file) - .arg(archive_url); - retry_spawn_and_wait(5, download_cmd); - - // Unpack tar archive - let mut unpack_cmd = Command::new("tar"); - unpack_cmd.arg("xf").arg(&archive_file).current_dir(RelPath::DOWNLOAD.to_path(dirs)); - spawn_and_wait(unpack_cmd); - - // Rename unpacked dir to the expected name - std::fs::rename(archive_dir, &download_dir).unwrap(); - - // Cleanup - std::fs::remove_file(archive_file).unwrap(); -} - fn init_git_repo(repo_dir: &Path) { let mut git_init_cmd = git_command(repo_dir, "init"); git_init_cmd.arg("-q"); @@ -259,14 +202,8 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta eprintln!("[COPY] {crate_name} source"); - remove_dir_if_exists(target_dir); - fs::create_dir_all(target_dir).unwrap(); - if crate_name == "stdlib" { - fs::create_dir(target_dir.join("library")).unwrap(); - copy_dir_recursively(&source_dir.join("library"), &target_dir.join("library")); - } else { - copy_dir_recursively(source_dir, target_dir); - } + ensure_empty_dir(target_dir); + copy_dir_recursively(source_dir, target_dir); init_git_repo(target_dir); @@ -285,3 +222,22 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta spawn_and_wait(apply_patch_cmd); } } + +#[must_use] +fn git_command<'a>(repo_dir: impl Into>, cmd: &str) -> Command { + let mut git_cmd = Command::new("git"); + git_cmd + .arg("-c") + .arg("user.name=Dummy") + .arg("-c") + .arg("user.email=dummy@example.com") + .arg("-c") + .arg("core.autocrlf=false") + .arg("-c") + .arg("commit.gpgSign=false") + .arg(cmd); + if let Some(repo_dir) = repo_dir.into() { + git_cmd.current_dir(repo_dir); + } + git_cmd +} diff --git a/build_system/tests.rs b/build_system/tests.rs index 602f7eccf2306..fd94e80f6312e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -117,7 +117,7 @@ pub(crate) static RAND_REPO: GitRepo = GitRepo::github( "rand", ); -pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target"); +static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target"); pub(crate) static REGEX_REPO: GitRepo = GitRepo::github( "rust-lang", @@ -127,12 +127,11 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github( "regex", ); -pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target"); +static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target"); -pub(crate) static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("coretests"); +static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("portable-simd"); -pub(crate) static PORTABLE_SIMD: CargoProject = - CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target"); +static PORTABLE_SIMD: CargoProject = CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target"); static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests"); @@ -230,13 +229,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ if runner.is_native { let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs); test_cmd.arg("-q"); - // FIXME remove after portable-simd update - test_cmd - .arg("--") - .arg("--skip") - .arg("core_simd::swizzle::simd_swizzle") - .arg("--skip") - .arg("core_simd::vector::Simd::lanes"); spawn_and_wait(test_cmd); } }), @@ -244,7 +236,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[ pub(crate) fn run_tests( dirs: &Dirs, - channel: &str, sysroot_kind: SysrootKind, use_unstable_features: bool, skip_tests: &[&str], @@ -260,7 +251,6 @@ pub(crate) fn run_tests( if config::get_bool("testsuite.no_sysroot") && !skip_tests.contains(&"testsuite.no_sysroot") { let target_compiler = build_sysroot::build_sysroot( dirs, - channel, SysrootKind::None, cg_clif_dylib, bootstrap_host_compiler, @@ -291,7 +281,6 @@ pub(crate) fn run_tests( if run_base_sysroot || run_extended_sysroot { let target_compiler = build_sysroot::build_sysroot( dirs, - channel, sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, @@ -443,7 +432,6 @@ impl<'a> TestRunner<'a> { cmd.arg("--target"); cmd.arg(&self.target_compiler.triple); cmd.arg("-Cpanic=abort"); - cmd.arg("-Zunstable-options"); cmd.arg("--check-cfg=cfg(jit)"); cmd.args(args); cmd @@ -458,26 +446,11 @@ impl<'a> TestRunner<'a> { } fn run_out_command(&self, name: &str, args: &[&str]) { - let mut full_cmd = vec![]; + let mut cmd = self + .target_compiler + .run_with_runner(BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name)); - // Prepend the RUN_WRAPPER's - if !self.target_compiler.runner.is_empty() { - full_cmd.extend(self.target_compiler.runner.iter().cloned()); - } - - full_cmd.push( - BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(), - ); - - for arg in args { - full_cmd.push(arg.to_string()); - } - - let mut cmd_iter = full_cmd.into_iter(); - let first = cmd_iter.next().unwrap(); - - let mut cmd = Command::new(first); - cmd.args(cmd_iter); + cmd.args(args); spawn_and_wait(cmd); } diff --git a/build_system/usage.txt b/build_system/usage.txt index f652599447bcf..5c333fe2db596 100644 --- a/build_system/usage.txt +++ b/build_system/usage.txt @@ -2,16 +2,12 @@ The build system of cg_clif. USAGE: ./y.sh prepare [--out-dir DIR] [--download-dir DIR] - ./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME] - ./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] - ./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh build [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh test [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] [--skip-test TESTNAME] + ./y.sh abi-cafe [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] + ./y.sh bench [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen] OPTIONS: - --debug - Build cg_clif and the standard library in debug mode rather than release mode. - Warning: An unoptimized cg_clif is very slow. - --sysroot none|clif|llvm Which sysroot libraries to use: `none` will not include any standard library in the sysroot. @@ -43,7 +39,5 @@ REQUIREMENTS: * Rustup: By default rustup is used to install the right nightly version. If you don't want to use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and point the CARGO, RUSTC and RUSTDOC env vars to the right executables. - * Git: Git is used for applying patches and on Windows for downloading test repos. - * Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for - repos. Git will be used to clone the whole repo when using Windows. + * Git: Git is used for downloading test repos and applying patches. * [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`. diff --git a/build_system/utils.rs b/build_system/utils.rs index 3c4b45e02cc25..22a9487a202d6 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -1,3 +1,4 @@ +use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -59,6 +60,18 @@ impl Compiler { } } } + + pub(crate) fn run_with_runner(&self, program: impl AsRef) -> Command { + if self.runner.is_empty() { + Command::new(program) + } else { + let mut runner_iter = self.runner.iter(); + let mut cmd = Command::new(runner_iter.next().unwrap()); + cmd.args(runner_iter); + cmd.arg(program); + cmd + } + } } pub(crate) struct CargoProject { @@ -141,59 +154,6 @@ impl CargoProject { } } -#[must_use] -pub(crate) fn hyperfine_command( - warmup: u64, - runs: u64, - prepare: Option<&str>, - cmds: &[(&str, &str)], - markdown_export: &Path, -) -> Command { - let mut bench = Command::new("hyperfine"); - - bench.arg("--export-markdown").arg(markdown_export); - - if warmup != 0 { - bench.arg("--warmup").arg(warmup.to_string()); - } - - if runs != 0 { - bench.arg("--runs").arg(runs.to_string()); - } - - if let Some(prepare) = prepare { - bench.arg("--prepare").arg(prepare); - } - - for &(name, cmd) in cmds { - if name != "" { - bench.arg("-n").arg(name); - } - bench.arg(cmd); - } - - bench -} - -#[must_use] -pub(crate) fn git_command<'a>(repo_dir: impl Into>, cmd: &str) -> Command { - let mut git_cmd = Command::new("git"); - git_cmd - .arg("-c") - .arg("user.name=Dummy") - .arg("-c") - .arg("user.email=dummy@example.com") - .arg("-c") - .arg("core.autocrlf=false") - .arg("-c") - .arg("commit.gpgSign=false") - .arg(cmd); - if let Some(repo_dir) = repo_dir.into() { - git_cmd.current_dir(repo_dir); - } - git_cmd -} - #[track_caller] pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { let src = src.as_ref(); @@ -212,27 +172,33 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) { } } -// Based on the retry function in rust's src/ci/shared.sh -#[track_caller] -pub(crate) fn retry_spawn_and_wait(tries: u64, mut cmd: Command) { - for i in 1..tries + 1 { - if i != 1 { - eprintln!("Command failed. Attempt {i}/{tries}:"); - } - if cmd.spawn().unwrap().wait().unwrap().success() { +/// Create the specified directory if it doesn't exist yet and delete all contents. +pub(crate) fn ensure_empty_dir(path: &Path) { + fs::create_dir_all(path).unwrap(); + let read_dir = match fs::read_dir(&path) { + Ok(read_dir) => read_dir, + Err(err) if err.kind() == io::ErrorKind::NotFound => { return; } - std::thread::sleep(std::time::Duration::from_secs(i * 5)); - } - eprintln!("The command has failed after {tries} attempts."); - process::exit(1); -} - -pub(crate) fn remove_dir_if_exists(path: &Path) { - match fs::remove_dir_all(&path) { - Ok(()) => {} - Err(err) if err.kind() == io::ErrorKind::NotFound => {} - Err(err) => panic!("Failed to remove {path}: {err}", path = path.display()), + Err(err) => { + panic!("Failed to read contents of {path}: {err}", path = path.display()) + } + }; + for entry in read_dir { + let entry = entry.unwrap(); + if entry.file_type().unwrap().is_dir() { + match fs::remove_dir_all(entry.path()) { + Ok(()) => {} + Err(err) if err.kind() == io::ErrorKind::NotFound => {} + Err(err) => panic!("Failed to remove {path}: {err}", path = entry.path().display()), + } + } else { + match fs::remove_file(entry.path()) { + Ok(()) => {} + Err(err) if err.kind() == io::ErrorKind::NotFound => {} + Err(err) => panic!("Failed to remove {path}: {err}", path = entry.path().display()), + } + } } } diff --git a/clean_all.sh b/clean_all.sh index 19405a53d1c65..4dbd9dac94a89 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -1,9 +1,10 @@ -#!/usr/bin/env bash +#!/bin/sh set -e -rm -rf target/ build_system/target download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb +rm -rf target/ build_system/target download/ build/ dist/ # Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh # FIXME remove at some point in the future +rm y.bin y.bin.dSYM y.exe y.pdb 2>/dev/null || true rm -rf rand/ regex/ simple-raytracer/ portable-simd/ abi-checker/ abi-cafe/ rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} diff --git a/example/neon.rs b/example/neon.rs index 00e437d7e546a..69ce17d3d752a 100644 --- a/example/neon.rs +++ b/example/neon.rs @@ -202,6 +202,44 @@ unsafe fn test_vqadd_u8() { assert_eq!(r, e); } +#[cfg(target_arch = "aarch64")] +unsafe fn test_vmaxq_f32() { + // AArch64 llvm intrinsic: llvm.aarch64.neon.fmax.v4f32 + let a = f32x4::from([0., -1., 2., -3.]); + let b = f32x4::from([-4., 5., -6., 7.]); + let e = f32x4::from([0., 5., 2., 7.]); + let r: f32x4 = transmute(vmaxq_f32(transmute(a), transmute(b))); + assert_eq!(r, e); +} + +#[cfg(target_arch = "aarch64")] +unsafe fn test_vminq_f32() { + // AArch64 llvm intrinsic: llvm.aarch64.neon.fmin.v4f32 + let a = f32x4::from([0., -1., 2., -3.]); + let b = f32x4::from([-4., 5., -6., 7.]); + let e = f32x4::from([-4., -1., -6., -3.]); + let r: f32x4 = transmute(vminq_f32(transmute(a), transmute(b))); + assert_eq!(r, e); +} + +#[cfg(target_arch = "aarch64")] +unsafe fn test_vaddvq_f32() { + // AArch64 llvm intrinsic: llvm.aarch64.neon.faddv.f32.v4f32 + let a = f32x4::from([0., 1., 2., 3.]); + let e = 6f32; + let r = vaddvq_f32(transmute(a)); + assert_eq!(r, e); +} + +#[cfg(target_arch = "aarch64")] +unsafe fn test_vrndnq_f32() { + // AArch64 llvm intrinsic: llvm.aarch64.neon.frintn.v4f32 + let a = f32x4::from([0.1, -1.9, 4.5, 5.5]); + let e = f32x4::from([0., -2., 4., 6.]); + let r: f32x4 = transmute(vrndnq_f32(transmute(a))); + assert_eq!(r, e); +} + #[cfg(target_arch = "aarch64")] fn main() { unsafe { @@ -229,6 +267,11 @@ fn main() { test_vqsub_u8(); test_vqadd_u8(); + + test_vmaxq_f32(); + test_vminq_f32(); + test_vaddvq_f32(); + test_vrndnq_f32(); } } diff --git a/example/std_example.rs b/example/std_example.rs index 602452d827602..ebaa9c69c810a 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -258,6 +258,9 @@ unsafe fn test_simd() { test_mm_insert_epi16(); test_mm_shuffle_epi8(); + #[cfg(not(jit))] + test_mm_cmpestri(); + test_mm256_shuffle_epi8(); test_mm256_permute2x128_si256(); test_mm256_permutevar8x32_epi32(); @@ -429,6 +432,31 @@ unsafe fn test_mm_shuffle_epi8() { assert_eq_m128i(r, expected); } +// Currently one cannot `load` a &[u8] that is less than 16 +// in length. This makes loading strings less than 16 in length +// a bit difficult. Rather than `load` and mutate the __m128i, +// it is easier to memcpy the given string to a local slice with +// length 16 and `load` the local slice. +#[cfg(not(jit))] +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "sse4.2")] +unsafe fn str_to_m128i(s: &[u8]) -> __m128i { + assert!(s.len() <= 16); + let slice = &mut [0u8; 16]; + std::ptr::copy_nonoverlapping(s.as_ptr(), slice.as_mut_ptr(), s.len()); + _mm_loadu_si128(slice.as_ptr() as *const _) +} + +#[cfg(not(jit))] +#[cfg(target_arch = "x86_64")] +#[target_feature(enable = "sse4.2")] +unsafe fn test_mm_cmpestri() { + let a = str_to_m128i(b"bar - garbage"); + let b = str_to_m128i(b"foobar"); + let i = _mm_cmpestri::<_SIDD_CMP_EQUAL_ORDERED>(a, 3, b, 6); + assert_eq!(3, i); +} + #[cfg(target_arch = "x86_64")] #[target_feature(enable = "avx2")] unsafe fn test_mm256_shuffle_epi8() { diff --git a/patches/0001-portable-simd-Disable-broken-reduce_sum-test.patch b/patches/0001-portable-simd-Disable-broken-reduce_sum-test.patch new file mode 100644 index 0000000000000..b1fd6224632be --- /dev/null +++ b/patches/0001-portable-simd-Disable-broken-reduce_sum-test.patch @@ -0,0 +1,26 @@ +From 5489384bc265e9e6fc2efaa63d93a4d51ebec2f5 Mon Sep 17 00:00:00 2001 +From: bjorn3 <17426603+bjorn3@users.noreply.github.com> +Date: Thu, 22 Aug 2024 19:22:58 +0000 +Subject: [PATCH] Disable broken reduce_sum test + +It was broken by an upstream change to the .sum() implementation on +float iterators. +--- + crates/core_simd/tests/ops_macros.rs | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs +index aa565a1..5e6ac41 100644 +--- a/crates/core_simd/tests/ops_macros.rs ++++ b/crates/core_simd/tests/ops_macros.rs +@@ -646,6 +646,7 @@ macro_rules! impl_float_tests { + } + + fn reduce_sum() { ++ return; + test_helpers::test_1(&|x| { + test_helpers::prop_assert_biteq! ( + Vector::::from_array(x).reduce_sum(), +-- +2.34.1 + diff --git a/patches/0022-coretests-Disable-not-compiling-tests.patch b/patches/0022-coretests-Disable-not-compiling-tests.patch index 8c404956bcc20..5117b04fd3447 100644 --- a/patches/0022-coretests-Disable-not-compiling-tests.patch +++ b/patches/0022-coretests-Disable-not-compiling-tests.patch @@ -38,7 +38,7 @@ index 42a26ae..5ac1042 100644 @@ -1,3 +1,4 @@ +#![cfg(test)] // tidy-alphabetical-start - #![cfg_attr(bootstrap, feature(offset_of_nested))] + #![cfg_attr(bootstrap, feature(const_mut_refs))] #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] -- 2.21.0 (Apple Git-122) diff --git a/patches/0027-coretests-128bit-atomic-operations.patch b/patches/0027-coretests-128bit-atomic-operations.patch index d579c9588f08a..efd721d9df885 100644 --- a/patches/0027-coretests-128bit-atomic-operations.patch +++ b/patches/0027-coretests-128bit-atomic-operations.patch @@ -14,14 +14,13 @@ diff --git a/lib.rs b/lib.rs index 1e336bf..35e6f54 100644 --- a/lib.rs +++ b/lib.rs -@@ -1,7 +1,6 @@ +@@ -1,6 +1,5 @@ #![cfg(test)] // tidy-alphabetical-start - #![cfg_attr(bootstrap, feature(offset_of_nested))] + #![cfg_attr(bootstrap, feature(const_mut_refs))] -#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] #![cfg_attr(test, feature(cfg_match))] #![feature(alloc_layout_extra)] - #![feature(array_chunks)] diff --git a/atomic.rs b/atomic.rs index b735957..ea728b6 100644 --- a/atomic.rs diff --git a/patches/0028-coretests-Disable-long-running-tests.patch b/patches/0028-coretests-Disable-long-running-tests.patch index 440177018f428..d7204add7a788 100644 --- a/patches/0028-coretests-Disable-long-running-tests.patch +++ b/patches/0028-coretests-Disable-long-running-tests.patch @@ -43,6 +43,26 @@ index 8402833..84592e0 100644 #[test] fn test_slice_from_ptr_range() { +diff --git a/lazy.rs b/lazy.rs +index 711511e..49c8d78 100644 +--- a/lazy.rs ++++ b/lazy.rs +@@ -113,6 +113,7 @@ fn lazy_type_inference() { + let _ = LazyCell::new(|| ()); + } + ++/* + #[test] + #[should_panic = "LazyCell instance has previously been poisoned"] + fn lazy_force_mut_panic() { +@@ -123,6 +124,7 @@ fn lazy_force_mut_panic() { + .unwrap_err(); + let _ = &*lazy; + } ++*/ + + #[test] + fn lazy_force_mut() { -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index 96c467e091cff..651770be3775d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-08-09" +channel = "nightly-2024-09-23" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 684a5d0729355..2f13b0b9cb834 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -25,6 +25,9 @@ git -c user.name=Dummy -c user.email=dummy@example.com -c commit.gpgSign=false \ cat > config.toml <) { + + let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); + +- if mode == "run-make" { +- let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host }); +- cmd.arg("--cargo-path").arg(cargo); +- } +- + // Avoid depending on rustdoc when we don't need it. + if mode == "rustdoc" + || mode == "run-make" +diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs +index 414f9f3a7f1..5c18179b6fe 100644 +--- a/src/tools/compiletest/src/common.rs ++++ b/src/tools/compiletest/src/common.rs +@@ -183,9 +183,6 @@ pub struct Config { + /// The rustc executable. + pub rustc_path: PathBuf, + +- /// The cargo executable. +- pub cargo_path: Option, +- + /// The rustdoc executable. + pub rustdoc_path: Option, + +diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs +index 3339116d542..250b5084d13 100644 +--- a/src/tools/compiletest/src/lib.rs ++++ b/src/tools/compiletest/src/lib.rs +@@ -47,7 +47,6 @@ pub fn parse_config(args: Vec) -> Config { + opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH") + .reqopt("", "run-lib-path", "path to target shared libraries", "PATH") + .reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH") +- .optopt("", "cargo-path", "path to cargo to use for compiling", "PATH") + .optopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH") + .optopt("", "coverage-dump-path", "path to coverage-dump to use in tests", "PATH") + .reqopt("", "python", "path to python to use for doc tests", "PATH") +@@ -261,7 +260,6 @@ fn make_absolute(path: PathBuf) -> PathBuf { + compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), + run_lib_path: make_absolute(opt_path(matches, "run-lib-path")), + rustc_path: opt_path(matches, "rustc-path"), +- cargo_path: matches.opt_str("cargo-path").map(PathBuf::from), + rustdoc_path: matches.opt_str("rustdoc-path").map(PathBuf::from), + coverage_dump_path: matches.opt_str("coverage-dump-path").map(PathBuf::from), + python: matches.opt_str("python").unwrap(), +@@ -366,7 +364,6 @@ pub fn log_config(config: &Config) { + logv(c, format!("compile_lib_path: {:?}", config.compile_lib_path)); + logv(c, format!("run_lib_path: {:?}", config.run_lib_path)); + logv(c, format!("rustc_path: {:?}", config.rustc_path.display())); +- logv(c, format!("cargo_path: {:?}", config.cargo_path)); + logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path)); + logv(c, format!("src_base: {:?}", config.src_base.display())); + logv(c, format!("build_base: {:?}", config.build_base.display())); +diff --git a/src/tools/compiletest/src/runtest/run_make.rs b/src/tools/compiletest/src/runtest/run_make.rs +index 75fe6a6baaf..852568ae925 100644 +--- a/src/tools/compiletest/src/runtest/run_make.rs ++++ b/src/tools/compiletest/src/runtest/run_make.rs +@@ -61,10 +61,6 @@ fn run_rmake_legacy_test(&self) { + .env_remove("MFLAGS") + .env_remove("CARGO_MAKEFLAGS"); + +- if let Some(ref cargo) = self.config.cargo_path { +- cmd.env("CARGO", cwd.join(cargo)); +- } +- + if let Some(ref rustdoc) = self.config.rustdoc_path { + cmd.env("RUSTDOC", cwd.join(rustdoc)); + } +@@ -413,10 +409,6 @@ fn run_rmake_v2_test(&self) { + // through a specific CI runner). + .env("LLVM_COMPONENTS", &self.config.llvm_components); + +- if let Some(ref cargo) = self.config.cargo_path { +- cmd.env("CARGO", source_root.join(cargo)); +- } +- + if let Some(ref rustdoc) = self.config.rustdoc_path { + cmd.env("RUSTDOC", source_root.join(rustdoc)); + } EOF echo "[TEST] rustc test suite" diff --git a/src/abi/mod.rs b/src/abi/mod.rs index cb74c59046be7..892ec3e95855e 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -508,7 +508,10 @@ pub(crate) fn codegen_terminator_call<'tcx>( let nop_inst = fx.bcx.ins().nop(); fx.add_comment( nop_inst, - format!("virtual call; self arg pass mode: {:?}", fn_abi.args[0]), + with_no_trimmed_paths!(format!( + "virtual call; self arg pass mode: {:?}", + fn_abi.args[0] + )), ); } diff --git a/src/constant.rs b/src/constant.rs index 8964230d6e2c8..6ba6a64c54486 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -490,6 +490,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant } /// Used only for intrinsic implementations that need a compile-time constant +/// +/// All uses of this function are a bug inside stdarch. [`eval_mir_constant`] +/// should be used everywhere, but for some vendor intrinsics stdarch forgets +/// to wrap the immediate argument in `const {}`, necesitating this hack to get +/// the correct value at compile time instead. pub(crate) fn mir_operand_get_const_val<'tcx>( fx: &FunctionCx<'_, '_, 'tcx>, operand: &Operand<'tcx>, diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs index f0fb18608e072..39f6763d9f2cb 100644 --- a/src/intrinsics/llvm_aarch64.rs +++ b/src/intrinsics/llvm_aarch64.rs @@ -91,6 +91,44 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>( ); } + _ if intrinsic.starts_with("llvm.aarch64.neon.fmax.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| fx.bcx.ins().fmax(x_lane, y_lane), + ); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.fmin.v") => { + intrinsic_args!(fx, args => (x, y); intrinsic); + + simd_pair_for_each_lane( + fx, + x, + y, + ret, + &|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| fx.bcx.ins().fmin(x_lane, y_lane), + ); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.faddv.f32.v") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_reduce(fx, v, None, ret, &|fx, _ty, a, b| fx.bcx.ins().fadd(a, b)); + } + + _ if intrinsic.starts_with("llvm.aarch64.neon.frintn.v") => { + intrinsic_args!(fx, args => (v); intrinsic); + + simd_for_each_lane(fx, v, ret, &|fx, _lane_ty, _res_lane_ty, lane| { + fx.bcx.ins().nearest(lane) + }); + } + _ if intrinsic.starts_with("llvm.aarch64.neon.smaxv.i") => { intrinsic_args!(fx, args => (v); intrinsic); diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 0740c84a53401..19e5adc253854 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -600,9 +600,11 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::ptr_mask => { intrinsic_args!(fx, args => (ptr, mask); intrinsic); + let ptr_layout = ptr.layout(); let ptr = ptr.load_scalar(fx); let mask = mask.load_scalar(fx); - fx.bcx.ins().band(ptr, mask); + let res = fx.bcx.ins().band(ptr, mask); + ret.write_cvalue(fx, CValue::by_val(res, ptr_layout)); } sym::write_bytes | sym::volatile_set_memory => { diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index f2bdf24d8abd9..ff4b0e847af6a 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -181,11 +181,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( // Make sure this is actually a SIMD vector. let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx)); - let n: u16 = if idx_ty.is_simd() - && matches!(idx_ty.simd_size_and_type(fx.tcx).1.kind(), ty::Uint(ty::UintTy::U32)) + if !idx_ty.is_simd() + || !matches!(idx_ty.simd_size_and_type(fx.tcx).1.kind(), ty::Uint(ty::UintTy::U32)) { - idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap() - } else { fx.tcx.dcx().span_err( span, format!("simd_shuffle index must be a SIMD vector of `u32`, got `{}`", idx_ty), @@ -194,6 +192,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); return; }; + let n: u16 = idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap(); assert_eq!(x.layout(), y.layout()); let layout = x.layout(); @@ -268,10 +267,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let val = codegen_operand(fx, &val.node); // FIXME validate - let idx_const = if let Some(idx_const) = - crate::constant::mir_operand_get_const_val(fx, &idx.node) - { - idx_const + let idx_const = if let Some(idx_const) = idx.node.constant() { + crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap() } else { fx.tcx.dcx().span_fatal(span, "Index argument for `simd_insert` is not a constant"); }; @@ -304,22 +301,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( return; } - let idx_const = if let Some(idx_const) = - crate::constant::mir_operand_get_const_val(fx, &idx.node) - { - idx_const + let idx_const = if let Some(idx_const) = idx.node.constant() { + crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap() } else { - fx.tcx.dcx().span_warn(span, "Index argument for `simd_extract` is not a constant"); - let trap_block = fx.bcx.create_block(); - let true_ = fx.bcx.ins().iconst(types::I8, 1); - let ret_block = fx.get_block(target); - fx.bcx.ins().brif(true_, trap_block, &[], ret_block, &[]); - fx.bcx.switch_to_block(trap_block); - crate::trap::trap_unimplemented( - fx, - "Index argument for `simd_extract` is not a constant", - ); - return; + fx.tcx + .dcx() + .span_fatal(span, "Index argument for `simd_extract` is not a constant"); }; let idx = idx_const.to_u32(); @@ -574,9 +561,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( (sym::simd_round, types::F64) => "round", _ => unreachable!("{:?}", intrinsic), }; - fx.lib_call(name, vec![AbiParam::new(lane_ty)], vec![AbiParam::new(lane_ty)], &[ - lane, - ])[0] + fx.lib_call( + name, + vec![AbiParam::new(lane_ty)], + vec![AbiParam::new(lane_ty)], + &[lane], + )[0] }); } diff --git a/test.sh b/test.sh index 6357eebf02696..6c07c512ef294 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ -#!/usr/bin/env bash +#!/bin/sh exec ./y.sh test "$@" diff --git a/y.sh b/y.sh index b9152d2cc6de0..a70d457341b93 100755 --- a/y.sh +++ b/y.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh set -e echo "[BUILD] build system" 1>&2 From f3ae4237ab90e3c3e8a135799e71e3ab425b7a58 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:02:30 +0000 Subject: [PATCH 02/59] Revert change to apply_patches to fix panic --- build_system/prepare.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b9cfcd99a7772..30bd7ae26a186 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -203,7 +203,12 @@ pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, ta eprintln!("[COPY] {crate_name} source"); ensure_empty_dir(target_dir); - copy_dir_recursively(source_dir, target_dir); + if crate_name == "stdlib" { + fs::create_dir(target_dir.join("library")).unwrap(); + copy_dir_recursively(&source_dir.join("library"), &target_dir.join("library")); + } else { + copy_dir_recursively(source_dir, target_dir); + } init_git_repo(target_dir); From 9d8572d33b22b0e045a0f485eb5c11ae4af12a30 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:28:15 +0000 Subject: [PATCH 03/59] Rustfmt --- build_system/build_sysroot.rs | 4 ++-- src/intrinsics/simd.rs | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 6a4f2a6c72c52..82558999aface 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -6,9 +6,9 @@ use crate::path::{Dirs, RelPath}; use crate::prepare::apply_patches; use crate::rustc_info::{get_default_sysroot, get_file_name}; use crate::utils::{ - ensure_empty_dir, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup, + CargoProject, Compiler, LogGroup, ensure_empty_dir, spawn_and_wait, try_hard_link, }; -use crate::{config, CodegenBackend, SysrootKind}; +use crate::{CodegenBackend, SysrootKind, config}; pub(crate) fn build_sysroot( dirs: &Dirs, diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index ff4b0e847af6a..cbe411d78d5fd 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -561,12 +561,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( (sym::simd_round, types::F64) => "round", _ => unreachable!("{:?}", intrinsic), }; - fx.lib_call( - name, - vec![AbiParam::new(lane_ty)], - vec![AbiParam::new(lane_ty)], - &[lane], - )[0] + fx.lib_call(name, vec![AbiParam::new(lane_ty)], vec![AbiParam::new(lane_ty)], &[ + lane, + ])[0] }); } From 631ab21ff01472c629c4bb5bb40338b0f04e8838 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 22 Sep 2024 20:00:01 -0400 Subject: [PATCH 04/59] Check vtable projections for validity in miri --- src/constant.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 6ba6a64c54486..ab78584332a05 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -161,13 +161,13 @@ 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(ty, trait_ref) => { + GlobalAlloc::VTable(ty, dyn_ty) => { let data_id = data_id_for_vtable( fx.tcx, &mut fx.constants_cx, fx.module, ty, - trait_ref, + dyn_ty.principal(), ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); @@ -456,8 +456,8 @@ 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) => { - data_id_for_vtable(tcx, cx, module, ty, trait_ref) + GlobalAlloc::VTable(ty, dyn_ty) => { + data_id_for_vtable(tcx, cx, module, ty, dyn_ty.principal()) } GlobalAlloc::Static(def_id) => { if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) From 1efad223399646cef0b5e3fd53da3b248804260f Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sun, 15 Sep 2024 16:47:42 +0200 Subject: [PATCH 05/59] unify dyn* coercions with other pointer coercions --- src/base.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index dc342e151f33c..876466e79bc07 100644 --- a/src/base.rs +++ b/src/base.rs @@ -770,7 +770,11 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); crate::unsize::coerce_unsized_into(fx, operand, lval); } - Rvalue::Cast(CastKind::DynStar, ref operand, _) => { + Rvalue::Cast( + CastKind::PointerCoercion(PointerCoercion::DynStar), + ref operand, + _, + ) => { let operand = codegen_operand(fx, operand); crate::unsize::coerce_dyn_star(fx, operand, lval); } From 25b66d80911b8c41feef25bac7c8a3c2aa14ebdd Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sun, 15 Sep 2024 19:35:06 +0200 Subject: [PATCH 06/59] be even more precise about "cast" vs "coercion" --- src/base.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index 876466e79bc07..1ce0aacab4998 100644 --- a/src/base.rs +++ b/src/base.rs @@ -652,7 +652,7 @@ fn codegen_stmt<'tcx>( lval.write_cvalue(fx, res); } Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer), + CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _), ref operand, to_ty, ) => { @@ -677,7 +677,7 @@ fn codegen_stmt<'tcx>( } } Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer), + CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer, _), ref operand, to_ty, ) => { @@ -688,6 +688,7 @@ fn codegen_stmt<'tcx>( Rvalue::Cast( CastKind::PointerCoercion( PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer, + _, ), .., ) => { @@ -741,7 +742,7 @@ fn codegen_stmt<'tcx>( } } Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)), + CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_), _), ref operand, _to_ty, ) => { @@ -763,7 +764,7 @@ fn codegen_stmt<'tcx>( } } Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::Unsize), + CastKind::PointerCoercion(PointerCoercion::Unsize, _), ref operand, _to_ty, ) => { @@ -771,7 +772,7 @@ fn codegen_stmt<'tcx>( crate::unsize::coerce_unsized_into(fx, operand, lval); } Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::DynStar), + CastKind::PointerCoercion(PointerCoercion::DynStar, _), ref operand, _, ) => { From 6fdc133daad5ea1a2fccd460fd3b65a715f0f272 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 23 Sep 2024 13:52:02 -0400 Subject: [PATCH 07/59] Add a debug assertion in codegen that unsize casts of the same principal trait def id are truly NOPs --- src/unsize.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/unsize.rs b/src/unsize.rs index 8cfe93b4d9c91..339628053a953 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -34,7 +34,22 @@ pub(crate) fn unsized_info<'tcx>( let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); if data_a.principal_def_id() == data_b.principal_def_id() { - // A NOP cast that doesn't actually change anything, should be allowed even with invalid vtables. + // Codegen takes advantage of the additional assumption, where if the + // principal trait def id of what's being casted doesn't change, + // then we don't need to adjust the vtable at all. This + // corresponds to the fact that `dyn Tr: Unsize>` + // requires that `A = B`; we don't allow *upcasting* objects + // between the same trait with different args. If we, for + // some reason, were to relax the `Unsize` trait, it could become + // unsound, so let's assert here that the trait refs are *equal*. + // + // We can use `assert_eq` because the binders should have been anonymized, + // and because higher-ranked equality now requires the binders are equal. + debug_assert_eq!( + data_a.principal(), + data_b.principal(), + "NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}" + ); return old_info; } From eccda6954433ed5f5d83a571857f5f15aac4c876 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:41:40 +0000 Subject: [PATCH 08/59] Rustup to rustc 1.83.0-nightly (9e394f551 2024-09-25) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 651770be3775d..093f5bdc4dae0 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-09-23" +channel = "nightly-2024-09-26" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 764f1ba5cd6c9eccf456748c39b26cbf78157cda Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:54:35 +0000 Subject: [PATCH 09/59] Fix running rustc tests --- scripts/test_rustc_tests.sh | 84 ------------------------------------- 1 file changed, 84 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 93512f82c8bf7..7c38792a6034f 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -180,90 +180,6 @@ index 9607ff02f96..b7d97caf9a2 100644 Self { cmd } } -diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs -index 2047345d78a..a7e9352bb1c 100644 ---- a/src/bootstrap/src/core/build_steps/test.rs -+++ b/src/bootstrap/src/core/build_steps/test.rs -@@ -1733,11 +1733,6 @@ fn run(self, builder: &Builder<'_>) { - - let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); - -- if mode == "run-make" { -- let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host }); -- cmd.arg("--cargo-path").arg(cargo); -- } -- - // Avoid depending on rustdoc when we don't need it. - if mode == "rustdoc" - || mode == "run-make" -diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs -index 414f9f3a7f1..5c18179b6fe 100644 ---- a/src/tools/compiletest/src/common.rs -+++ b/src/tools/compiletest/src/common.rs -@@ -183,9 +183,6 @@ pub struct Config { - /// The rustc executable. - pub rustc_path: PathBuf, - -- /// The cargo executable. -- pub cargo_path: Option, -- - /// The rustdoc executable. - pub rustdoc_path: Option, - -diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs -index 3339116d542..250b5084d13 100644 ---- a/src/tools/compiletest/src/lib.rs -+++ b/src/tools/compiletest/src/lib.rs -@@ -47,7 +47,6 @@ pub fn parse_config(args: Vec) -> Config { - opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH") - .reqopt("", "run-lib-path", "path to target shared libraries", "PATH") - .reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH") -- .optopt("", "cargo-path", "path to cargo to use for compiling", "PATH") - .optopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH") - .optopt("", "coverage-dump-path", "path to coverage-dump to use in tests", "PATH") - .reqopt("", "python", "path to python to use for doc tests", "PATH") -@@ -261,7 +260,6 @@ fn make_absolute(path: PathBuf) -> PathBuf { - compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), - run_lib_path: make_absolute(opt_path(matches, "run-lib-path")), - rustc_path: opt_path(matches, "rustc-path"), -- cargo_path: matches.opt_str("cargo-path").map(PathBuf::from), - rustdoc_path: matches.opt_str("rustdoc-path").map(PathBuf::from), - coverage_dump_path: matches.opt_str("coverage-dump-path").map(PathBuf::from), - python: matches.opt_str("python").unwrap(), -@@ -366,7 +364,6 @@ pub fn log_config(config: &Config) { - logv(c, format!("compile_lib_path: {:?}", config.compile_lib_path)); - logv(c, format!("run_lib_path: {:?}", config.run_lib_path)); - logv(c, format!("rustc_path: {:?}", config.rustc_path.display())); -- logv(c, format!("cargo_path: {:?}", config.cargo_path)); - logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path)); - logv(c, format!("src_base: {:?}", config.src_base.display())); - logv(c, format!("build_base: {:?}", config.build_base.display())); -diff --git a/src/tools/compiletest/src/runtest/run_make.rs b/src/tools/compiletest/src/runtest/run_make.rs -index 75fe6a6baaf..852568ae925 100644 ---- a/src/tools/compiletest/src/runtest/run_make.rs -+++ b/src/tools/compiletest/src/runtest/run_make.rs -@@ -61,10 +61,6 @@ fn run_rmake_legacy_test(&self) { - .env_remove("MFLAGS") - .env_remove("CARGO_MAKEFLAGS"); - -- if let Some(ref cargo) = self.config.cargo_path { -- cmd.env("CARGO", cwd.join(cargo)); -- } -- - if let Some(ref rustdoc) = self.config.rustdoc_path { - cmd.env("RUSTDOC", cwd.join(rustdoc)); - } -@@ -413,10 +409,6 @@ fn run_rmake_v2_test(&self) { - // through a specific CI runner). - .env("LLVM_COMPONENTS", &self.config.llvm_components); - -- if let Some(ref cargo) = self.config.cargo_path { -- cmd.env("CARGO", source_root.join(cargo)); -- } -- - if let Some(ref rustdoc) = self.config.rustdoc_path { - cmd.env("RUSTDOC", source_root.join(rustdoc)); - } EOF echo "[TEST] rustc test suite" From 9b31c68c0eaefe3257703101b2cc866c69d24fb8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 29 Sep 2024 07:32:08 +0200 Subject: [PATCH 10/59] fix cranelift CI --- patches/0027-stdlib-128bit-atomic-operations.patch | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/patches/0027-stdlib-128bit-atomic-operations.patch b/patches/0027-stdlib-128bit-atomic-operations.patch index a3f370af91699..646928893e96a 100644 --- a/patches/0027-stdlib-128bit-atomic-operations.patch +++ b/patches/0027-stdlib-128bit-atomic-operations.patch @@ -82,19 +82,6 @@ index d9de37e..8293fce 100644 #[cfg(target_has_atomic_load_store = "ptr")] macro_rules! atomic_int_ptr_sized { ( $($target_pointer_width:literal $align:literal)* ) => { $( -diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs -index 58b9ba4..91bbd0a 100644 ---- a/library/core/src/cell.rs -+++ b/library/core/src/cell.rs -@@ -2246,8 +2246,6 @@ unsafe_cell_primitive_into_inner! { - u32 "32" - i64 "64" - u64 "64" -- i128 "128" -- u128 "128" - isize "ptr" - usize "ptr" - } -- 2.26.2.7.g19db9cfb68 From d10a16ae409f5bc0f337415a5ba9b497ac0931c7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 28 Sep 2024 14:16:05 -0400 Subject: [PATCH 11/59] Relax a debug assertion in codegen --- src/unsize.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/unsize.rs b/src/unsize.rs index 339628053a953..5c297ebfadbfd 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -2,6 +2,7 @@ //! //! [`PointerCoercion::Unsize`]: `rustc_middle::ty::adjustment::PointerCoercion::Unsize` +use rustc_codegen_ssa::base::validate_trivial_unsize; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use crate::base::codegen_panic_nounwind; @@ -34,20 +35,8 @@ pub(crate) fn unsized_info<'tcx>( let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); if data_a.principal_def_id() == data_b.principal_def_id() { - // Codegen takes advantage of the additional assumption, where if the - // principal trait def id of what's being casted doesn't change, - // then we don't need to adjust the vtable at all. This - // corresponds to the fact that `dyn Tr: Unsize>` - // requires that `A = B`; we don't allow *upcasting* objects - // between the same trait with different args. If we, for - // some reason, were to relax the `Unsize` trait, it could become - // unsound, so let's assert here that the trait refs are *equal*. - // - // We can use `assert_eq` because the binders should have been anonymized, - // and because higher-ranked equality now requires the binders are equal. - debug_assert_eq!( - data_a.principal(), - data_b.principal(), + debug_assert!( + validate_trivial_unsize(fx.tcx, data_a, data_b), "NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}" ); return old_info; From 743a2e47acd141e0195972d3beb2fec6fa81a796 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:38:33 +0000 Subject: [PATCH 12/59] Update to Cranelift 0.112.0 --- Cargo.lock | 99 +++++++++++++++++++++++++++++------------------------- Cargo.toml | 12 +++---- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c2ca95b075ca..a4b9d958b3577 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,24 +46,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b80c3a50b9c4c7e5b5f73c0ed746687774fc9e36ef652b110da8daebf0c6e0e6" +checksum = "a6e376bd92bddd03dcfc443b14382611cae5d10012aa0b1628bbf18bb73f12f7" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38778758c2ca918b05acb2199134e0c561fb577c50574259b26190b6c2d95ded" +checksum = "45ecbe07f25a8100e5077933516200e97808f1d7196b5a073edb85fa08fde32e" [[package]] name = "cranelift-codegen" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58258667ad10e468bfc13a8d620f50dfcd4bb35d668123e97defa2549b9ad397" +checksum = "bc60913f32c1de18538c28bef74b8c87cf16de7841a1b0956fcf01b23237853a" dependencies = [ "bumpalo", "cranelift-bforest", @@ -74,8 +74,9 @@ dependencies = [ "cranelift-entity", "cranelift-isle", "gimli", - "hashbrown 0.14.5", + "hashbrown", "log", + "pulley-interpreter", "regalloc2", "rustc-hash", "smallvec", @@ -84,42 +85,42 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043f0b702e529dcb07ff92bd7d40e7d5317b5493595172c5eb0983343751ee06" +checksum = "bae009e7822f47aa55e7dcef846ccf3aa4eb102ca6b4bcb8a44b36f3f49aa85c" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7763578888ab53eca5ce7da141953f828e82c2bfadcffc106d10d1866094ffbb" +checksum = "0c78f01a852536c68e34444450f845ed6e0782a1f047f85397fe460b8fbce8f1" [[package]] name = "cranelift-control" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32db15f08c05df570f11e8ab33cb1ec449a64b37c8a3498377b77650bef33d8b" +checksum = "7a061b22e00a9e36b31f2660dfb05a9617b7775bd54b79754d3bb75a990dac06" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5289cdb399381a27e7bbfa1b42185916007c3d49aeef70b1d01cb4caa8010130" +checksum = "95e2b261a3e74ae42f4e606906d5ffa44ee2684e8b1ae23bdf75d21908dc9233" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ba8ab24eb9470477e98ddfa3c799a649ac5a0d9a2042868c4c952133c234e8" +checksum = "fe14abba0e6bab42aca0f9ce757f96880f9187e88bc6cb975ed6acd8a42f7770" dependencies = [ "cranelift-codegen", "log", @@ -129,15 +130,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b72a3c5c166a70426dcb209bdd0bb71a787c1ea76023dc0974fbabca770e8f9" +checksum = "311d91ae72b37d4262b51217baf8c9e01f1afd5148931468da1fdb7e9d011347" [[package]] name = "cranelift-jit" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df32578a47582e49b4fc1f9a5786839d9be1fedaa9f00bea7612c54425663c6b" +checksum = "1b8ea36cb2f092c71300eb1ffdb30b7e301fdc3c00479aabe36036bac53c5a5a" dependencies = [ "anyhow", "cranelift-codegen", @@ -155,9 +156,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96094a758cdb543c9143f70817cd31069fecd49f50981a0fac06820ac011dc2f" +checksum = "8e03d6e8524b5093252fb624a5bb7a0517a1f23d2d2a1418ef8bfd81290ef549" dependencies = [ "anyhow", "cranelift-codegen", @@ -166,9 +167,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a42424c956bbc31fc5c2706073df896156c5420ae8fa2a5d48dbc7b295d71b" +checksum = "2a3f84c75e578189ff7a716c24ad83740b553bf583f2510b323bfe4c1a74bb93" dependencies = [ "cranelift-codegen", "libc", @@ -177,9 +178,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.111.0" +version = "0.112.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cf5e2484ab47fe38a3150747cdd2016535f13542a925acca152b63383a6591b" +checksum = "bc18e6930ac086d1fe10da77d7019f29048feb7b73b236bddf8980b587ed89d7" dependencies = [ "anyhow", "cranelift-codegen", @@ -222,15 +223,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -247,7 +239,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -294,7 +286,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" dependencies = [ "crc32fast", - "hashbrown 0.14.5", + "hashbrown", "indexmap", "memchr", ] @@ -314,6 +306,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulley-interpreter" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70269a5a7464ccb9ab906534d44dfbd2e2f547d9fe74c08a528548d029ec641d" +dependencies = [ + "cranelift-bitset", + "log", + "sptr", +] + [[package]] name = "quote" version = "1.0.36" @@ -325,11 +328,11 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.9.3" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" +checksum = "12908dbeb234370af84d0579b9f68258a0f67e201412dd9a2814e6f45b2fc0f0" dependencies = [ - "hashbrown 0.13.2", + "hashbrown", "log", "rustc-hash", "slice-group-by", @@ -350,9 +353,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustc_codegen_cranelift" @@ -384,6 +387,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -421,9 +430,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasmtime-jit-icache-coherence" -version = "24.0.0" +version = "25.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15de8429db996f0d17a4163a35eccc3f874cbfb50f29c379951ea1bbb39452e" +checksum = "48011232c0da424f89c3752a378d0b7f512fae321ea414a43e1e7a302a6a1f7e" dependencies = [ "anyhow", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 6594ffb5d66bd..255f04d084d9c 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.111.0", default-features = false, features = ["std", "unwind", "all-arch"] } -cranelift-frontend = { version = "0.111.0" } -cranelift-module = { version = "0.111.0" } -cranelift-native = { version = "0.111.0" } -cranelift-jit = { version = "0.111.0", optional = true } -cranelift-object = { version = "0.111.0" } +cranelift-codegen = { version = "0.112.0", default-features = false, features = ["std", "unwind", "all-arch"] } +cranelift-frontend = { version = "0.112.0" } +cranelift-module = { version = "0.112.0" } +cranelift-native = { version = "0.112.0" } +cranelift-jit = { version = "0.112.0", optional = true } +cranelift-object = { version = "0.112.0" } target-lexicon = "0.12.0" gimli = { version = "0.29", default-features = false, features = ["write"] } object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From 9a48c44a272c46546ffce0ac50286ae9ea8c9469 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 11 Sep 2024 18:39:04 +0000 Subject: [PATCH 13/59] Remove pulley-interpreter dependency --- Cargo.lock | 18 ------------------ Cargo.toml | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4b9d958b3577..82640dafa6d23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,7 +76,6 @@ dependencies = [ "gimli", "hashbrown", "log", - "pulley-interpreter", "regalloc2", "rustc-hash", "smallvec", @@ -306,17 +305,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "pulley-interpreter" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70269a5a7464ccb9ab906534d44dfbd2e2f547d9fe74c08a528548d029ec641d" -dependencies = [ - "cranelift-bitset", - "log", - "sptr", -] - [[package]] name = "quote" version = "1.0.36" @@ -387,12 +375,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "sptr" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" - [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 255f04d084d9c..a30ed75c02646 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.112.0", default-features = false, features = ["std", "unwind", "all-arch"] } +# FIXME switch to native-arch instead of listing all archs on the next Cranelift update +cranelift-codegen = { version = "0.112.0", default-features = false, features = ["std", "unwind", "x86", "arm64", "s390x", "riscv64"] } cranelift-frontend = { version = "0.112.0" } cranelift-module = { version = "0.112.0" } cranelift-native = { version = "0.112.0" } From 0a9ce96e7a1d93b0b01aef48ab8ab07f2420ff60 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:13:20 +0000 Subject: [PATCH 14/59] Validate dir checksum during testing too Fixes rust-lang/rustc_codegen_cranelift#1394 --- build_system/prepare.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 30bd7ae26a186..ff1577116958e 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -89,6 +89,19 @@ impl GitRepo { } } + fn verify_checksum(&self, dirs: &Dirs) { + let download_dir = self.download_dir(dirs); + let actual_hash = format!("{:016x}", hash_dir(&download_dir)); + if actual_hash != self.content_hash { + eprintln!( + "Mismatched content hash for {download_dir}: {actual_hash} != {content_hash}. Please run ./y.sh prepare again.", + download_dir = download_dir.display(), + content_hash = self.content_hash, + ); + std::process::exit(1); + } + } + pub(crate) fn fetch(&self, dirs: &Dirs) { let download_dir = self.download_dir(dirs); @@ -126,18 +139,11 @@ impl GitRepo { assert!(target_lockfile.exists()); } - let actual_hash = format!("{:016x}", hash_dir(&download_dir)); - if actual_hash != self.content_hash { - eprintln!( - "Download of {download_dir} failed with mismatched content hash: {actual_hash} != {content_hash}", - download_dir = download_dir.display(), - content_hash = self.content_hash, - ); - std::process::exit(1); - } + self.verify_checksum(dirs); } pub(crate) fn patch(&self, dirs: &Dirs) { + self.verify_checksum(dirs); apply_patches( dirs, self.patch_name, From 0f1284cea736c11d9df3e952947a3d4d5a6a00ff Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:15:15 +0000 Subject: [PATCH 15/59] Fix ./y.sh prepare when the download dir is clobbered --- build_system/prepare.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index ff1577116958e..c6f979f02786f 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,8 +1,8 @@ use std::ffi::OsStr; -use std::fs; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use std::process::Command; +use std::{fs, io}; use crate::path::{Dirs, RelPath}; use crate::utils::{copy_dir_recursively, ensure_empty_dir, spawn_and_wait}; @@ -155,6 +155,13 @@ impl GitRepo { fn clone_repo(download_dir: &Path, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); + + match fs::remove_dir_all(download_dir) { + Ok(()) => {} + Err(err) if err.kind() == io::ErrorKind::NotFound => {} + Err(err) => panic!("Failed to remove {path}: {err}", path = download_dir.display()), + } + // Ignore exit code as the repo may already have been checked out git_command(None, "clone").arg(repo).arg(download_dir).spawn().unwrap().wait().unwrap(); From 0ba084514ad1229ccba0d4cd45c4b55f8de3d092 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:36:16 +0000 Subject: [PATCH 16/59] Also enable Cranelift optimizations with -Copt-level=1/2 --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f6b7981395a5f..1cc2eebc47c9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -298,8 +298,11 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc { flags_builder.set("opt_level", "none").unwrap(); } - OptLevel::Less | OptLevel::Default => {} - OptLevel::Size | OptLevel::SizeMin | OptLevel::Aggressive => { + OptLevel::Less + | OptLevel::Default + | OptLevel::Size + | OptLevel::SizeMin + | OptLevel::Aggressive => { flags_builder.set("opt_level", "speed_and_size").unwrap(); } } From a146874989856a377d3bf121e3f6390f1f1bed25 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:13:40 +0200 Subject: [PATCH 17/59] Couple of clif ir printing improvements around abi handling --- src/abi/mod.rs | 5 +++++ src/base.rs | 6 +++--- src/pretty_clif.rs | 13 +++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 892ec3e95855e..c0aa63eab7842 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -562,6 +562,11 @@ pub(crate) fn codegen_terminator_call<'tcx>( adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args); } + if fx.clif_comments.enabled() { + let nop_inst = fx.bcx.ins().nop(); + with_no_trimmed_paths!(fx.add_comment(nop_inst, format!("abi: {:?}", fn_abi))); + } + match func_ref { CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args), CallTarget::Indirect(sig, func_ptr) => { diff --git a/src/base.rs b/src/base.rs index 1ce0aacab4998..b95cd7ddd0ddd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -101,12 +101,12 @@ pub(crate) fn codegen_fn<'tcx>( let block_map: IndexVec = (0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect(); + let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()); + // Make FunctionCx let target_config = module.target_config(); let pointer_type = target_config.pointer_type(); - let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance); - - let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()); + let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance, fn_abi); let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context { Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span)) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 13877b3b1e9ae..282763279dd8a 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -62,9 +62,9 @@ use cranelift_codegen::entity::SecondaryMap; use cranelift_codegen::ir::Fact; use cranelift_codegen::ir::entities::AnyEntity; use cranelift_codegen::write::{FuncWriter, PlainWriter}; -use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::config::{OutputFilenames, OutputType}; +use rustc_target::abi::call::FnAbi; use crate::prelude::*; @@ -76,17 +76,18 @@ pub(crate) struct CommentWriter { } impl CommentWriter { - pub(crate) fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self { + pub(crate) fn new<'tcx>( + tcx: TyCtxt<'tcx>, + instance: Instance<'tcx>, + fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + ) -> Self { let enabled = should_write_ir(tcx); let global_comments = if enabled { with_no_trimmed_paths!({ vec![ format!("symbol {}", tcx.symbol_name(instance).name), format!("instance {:?}", instance), - format!( - "abi {:?}", - RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()) - ), + format!("abi {:?}", fn_abi), String::new(), ] }) From 0bd0b997299a919a00442f2f8c5a244b7b847d58 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 3 Oct 2024 15:05:23 +0200 Subject: [PATCH 18/59] Use wide pointers consistenly across the compiler --- example/std_example.rs | 4 ++-- src/base.rs | 10 +++++----- src/common.rs | 2 +- src/debuginfo/types.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/std_example.rs b/example/std_example.rs index ebaa9c69c810a..3078288c28615 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -168,7 +168,7 @@ fn main() { foo(I64X2([0, 0])); - transmute_fat_pointer(); + transmute_wide_pointer(); rust_call_abi(); @@ -192,7 +192,7 @@ type TwoPtrs = i64; #[cfg(target_pointer_width = "64")] type TwoPtrs = i128; -fn transmute_fat_pointer() -> TwoPtrs { +fn transmute_wide_pointer() -> TwoPtrs { unsafe { transmute::<_, TwoPtrs>("true !") } } diff --git a/src/base.rs b/src/base.rs index 1ce0aacab4998..0968062206940 100644 --- a/src/base.rs +++ b/src/base.rs @@ -713,17 +713,17 @@ fn codegen_stmt<'tcx>( let from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); - fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { + fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { ty.builtin_deref(true) .is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty)) } - if is_fat_ptr(fx, from_ty) { - if is_fat_ptr(fx, to_ty) { - // fat-ptr -> fat-ptr + if is_wide_ptr(fx, from_ty) { + if is_wide_ptr(fx, to_ty) { + // wide-ptr -> wide-ptr lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout)); } else { - // fat-ptr -> thin-ptr + // wide-ptr -> thin-ptr let (ptr, _extra) = operand.load_scalar_pair(fx); lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout)) } diff --git a/src/common.rs b/src/common.rs index e78ba5a341531..69a32cc3d43c9 100644 --- a/src/common.rs +++ b/src/common.rs @@ -101,7 +101,7 @@ fn clif_pair_type_from_ty<'tcx>( }) } -/// Is a pointer to this type a fat ptr? +/// Is a pointer to this type a wide ptr? pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { if ty.is_sized(tcx, ParamEnv::reveal_all()) { return false; diff --git a/src/debuginfo/types.rs b/src/debuginfo/types.rs index a710701e72c4b..714742aeaffe0 100644 --- a/src/debuginfo/types.rs +++ b/src/debuginfo/types.rs @@ -139,7 +139,7 @@ impl DebugContext { pointer_type_id } else { - // FIXME implement debuginfo for fat pointers + // FIXME implement debuginfo for wide pointers self.placeholder_for_type(tcx, type_dbg, ptr_type) } } From 2811ce715dee288f83a56bbb96aac8955efbcd93 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 5 Sep 2024 19:45:40 +0200 Subject: [PATCH 19/59] various fixes for `naked_asm!` implementation - fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch --- example/mini_core.rs | 6 ++++++ example/mini_core_hello_world.rs | 2 +- src/base.rs | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 5e535ff62e173..9fc0318df5dc0 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -726,6 +726,12 @@ pub macro global_asm() { /* compiler built-in */ } +#[rustc_builtin_macro] +#[rustc_macro_transparency = "semitransparent"] +pub macro naked_asm() { + /* compiler built-in */ +} + pub static A_STATIC: u8 = 42; #[lang = "panic_location"] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index ccbd5a78485d7..e47431e0f873a 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -390,7 +390,7 @@ global_asm! { #[naked] extern "C" fn naked_test() { unsafe { - asm!("ret", options(noreturn)); + naked_asm!("ret"); } } diff --git a/src/base.rs b/src/base.rs index 0968062206940..a681e6d9f3cd1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -8,6 +8,7 @@ use rustc_ast::InlineAsmOptions; use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization; use rustc_index::IndexVec; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_middle::mir::InlineAsmMacro; use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::layout::FnAbiOf; @@ -57,6 +58,7 @@ pub(crate) fn codegen_fn<'tcx>( match &mir.basic_blocks[START_BLOCK].terminator().kind { TerminatorKind::InlineAsm { + asm_macro: InlineAsmMacro::NakedAsm, template, operands, options, @@ -498,6 +500,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { "tail calls are not yet supported in `rustc_codegen_cranelift` backend" ), TerminatorKind::InlineAsm { + asm_macro: _, template, operands, options, From 48504415cff11ac421bce701be4c0188afed77ef Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 8 Oct 2024 17:26:42 -0700 Subject: [PATCH 20/59] cg_clif: Factor out rustc_target::abi --- src/discriminant.rs | 3 ++- src/lib.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/discriminant.rs b/src/discriminant.rs index e7ac084558a5a..d462dcd63a925 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -3,7 +3,8 @@ //! Adapted from //! () -use rustc_target::abi::{Int, TagEncoding, Variants}; +use rustc_abi::Primitive::Int; +use rustc_abi::{TagEncoding, Variants}; use crate::prelude::*; diff --git a/src/lib.rs b/src/lib.rs index f6b7981395a5f..b6f9ce8fc2988 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ extern crate jobserver; #[macro_use] extern crate rustc_middle; +extern crate rustc_abi; extern crate rustc_ast; extern crate rustc_codegen_ssa; extern crate rustc_data_structures; From 14f656ede3d56eb786efd785137406111d028a09 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:09:42 +0000 Subject: [PATCH 21/59] Compile all abi-cafe tests with debuginfo enabled --- patches/0002-abi-cafe-Disable-broken-tests.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/patches/0002-abi-cafe-Disable-broken-tests.patch b/patches/0002-abi-cafe-Disable-broken-tests.patch index 8a2565f1668ad..4c89d65234a4a 100644 --- a/patches/0002-abi-cafe-Disable-broken-tests.patch +++ b/patches/0002-abi-cafe-Disable-broken-tests.patch @@ -7,6 +7,18 @@ Subject: [PATCH] Disable broken tests src/report.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) +diff --git a/src/toolchains/rust.rs b/src/toolchains/rust.rs +index 0c50f7a..bfde2b1 100644 +--- a/src/toolchains/rust.rs ++++ b/src/toolchains/rust.rs +@@ -83,6 +83,7 @@ impl Toolchain for RustcToolchain { + .arg(out_dir) + .arg("--target") + .arg(built_info::TARGET) ++ .arg("-g") + .arg(format!("-Cmetadata={lib_name}")) + .arg(src_path); + if let Some(codegen_backend) = &self.codegen_backend { diff --git a/src/report.rs b/src/report.rs index 958ab43..dcf1044 100644 --- a/src/report.rs From 5d7d2518b38721251eee477f62078ea70c303d69 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:19:54 +0000 Subject: [PATCH 22/59] Rustup to rustc 1.83.0-nightly (eb4e23467 2024-10-09) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 093f5bdc4dae0..775402b2b5eba 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-09-26" +channel = "nightly-2024-10-10" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 76dfce7a6f8aaf421d32027f96ffb030a979bd79 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:32:42 +0000 Subject: [PATCH 23/59] Fix rustc test suite --- scripts/test_rustc_tests.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 7c38792a6034f..fbf4ce0223416 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -47,9 +47,6 @@ rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support rm tests/ui/delegation/fn-header.rs -# unsized locals -rm -r tests/run-pass-valgrind/unsized-locals - # misc unimplemented things rm tests/ui/target-feature/missing-plusminus.rs # error not implemented rm -r tests/run-make/repr128-dwarf # debuginfo test @@ -183,5 +180,5 @@ index 9607ff02f96..b7d97caf9a2 100644 EOF echo "[TEST] rustc test suite" -COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 --test-args=--nocapture tests/{codegen-units,run-make,run-pass-valgrind,ui,incremental} +COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 --test-args=--nocapture tests/{codegen-units,run-make,ui,incremental} popd From 270fb2130c979fe1d1e520dbb8474aa13257d16b Mon Sep 17 00:00:00 2001 From: Jed Brown Date: Fri, 5 Jan 2024 21:04:41 -0700 Subject: [PATCH 24/59] intrinsics.fmuladdf{16,32,64,128}: expose llvm.fmuladd.* semantics Add intrinsics `fmuladd{f16,f32,f64,f128}`. This computes `(a * b) + c`, to be fused if the code generator determines that (i) the target instruction set has support for a fused operation, and (ii) that the fused operation is more efficient than the equivalent, separate pair of `mul` and `add` instructions. https://llvm.org/docs/LangRef.html#llvm-fmuladd-intrinsic MIRI support is included for f32 and f64. The codegen_cranelift uses the `fma` function from libc, which is a correct implementation, but without the desired performance semantic. I think this requires an update to cranelift to expose a suitable instruction in its IR. I have not tested with codegen_gcc, but it should behave the same way (using `fma` from libc). --- src/intrinsics/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 19e5adc253854..35f0ccff3f99e 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -328,6 +328,9 @@ fn codegen_float_intrinsic_call<'tcx>( sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64), sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32), sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64), + // FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation + sym::fmuladdf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32), // TODO: use cranelift intrinsic analogous to llvm.fmuladd.f32 + sym::fmuladdf64 => ("fma", 3, fx.tcx.types.f64, types::F64), // TODO: use cranelift intrinsic analogous to llvm.fmuladd.f64 sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32, types::F32), sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64, types::F64), sym::floorf32 => ("floorf", 1, fx.tcx.types.f32, types::F32), @@ -381,7 +384,7 @@ fn codegen_float_intrinsic_call<'tcx>( let layout = fx.layout_of(ty); let res = match intrinsic { - sym::fmaf32 | sym::fmaf64 => { + sym::fmaf32 | sym::fmaf64 | sym::fmuladdf32 | sym::fmuladdf64 => { CValue::by_val(fx.bcx.ins().fma(args[0], args[1], args[2]), layout) } sym::copysignf32 | sym::copysignf64 => { From 47a7e994f2b7d8663b0559bc9327190fefe9e4ef Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:55:09 +0000 Subject: [PATCH 25/59] Rustup to rustc 1.84.0-nightly (798fb83f7 2024-10-16) --- patches/0022-coretests-Disable-not-compiling-tests.patch | 2 +- patches/0027-coretests-128bit-atomic-operations.patch | 2 +- patches/0028-coretests-Disable-long-running-tests.patch | 2 +- rust-toolchain | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/patches/0022-coretests-Disable-not-compiling-tests.patch b/patches/0022-coretests-Disable-not-compiling-tests.patch index 5117b04fd3447..161173d47650f 100644 --- a/patches/0022-coretests-Disable-not-compiling-tests.patch +++ b/patches/0022-coretests-Disable-not-compiling-tests.patch @@ -38,7 +38,7 @@ index 42a26ae..5ac1042 100644 @@ -1,3 +1,4 @@ +#![cfg(test)] // tidy-alphabetical-start - #![cfg_attr(bootstrap, feature(const_mut_refs))] #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] + #![cfg_attr(test, feature(cfg_match))] -- 2.21.0 (Apple Git-122) diff --git a/patches/0027-coretests-128bit-atomic-operations.patch b/patches/0027-coretests-128bit-atomic-operations.patch index efd721d9df885..5f5baae2fd655 100644 --- a/patches/0027-coretests-128bit-atomic-operations.patch +++ b/patches/0027-coretests-128bit-atomic-operations.patch @@ -17,10 +17,10 @@ index 1e336bf..35e6f54 100644 @@ -1,6 +1,5 @@ #![cfg(test)] // tidy-alphabetical-start - #![cfg_attr(bootstrap, feature(const_mut_refs))] -#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] #![cfg_attr(test, feature(cfg_match))] #![feature(alloc_layout_extra)] + #![feature(array_chunks)] diff --git a/atomic.rs b/atomic.rs index b735957..ea728b6 100644 --- a/atomic.rs diff --git a/patches/0028-coretests-Disable-long-running-tests.patch b/patches/0028-coretests-Disable-long-running-tests.patch index d7204add7a788..5009b24c9d08f 100644 --- a/patches/0028-coretests-Disable-long-running-tests.patch +++ b/patches/0028-coretests-Disable-long-running-tests.patch @@ -12,7 +12,7 @@ index 8402833..84592e0 100644 --- a/slice.rs +++ b/slice.rs @@ -1809,6 +1809,7 @@ fn sort_unstable() { - assert!(v == [0xDEADBEEF]); + } } +/* diff --git a/rust-toolchain b/rust-toolchain index 775402b2b5eba..0aa0f9e21cbff 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-10" +channel = "nightly-2024-10-17" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 16067fdea148adb7ad6c1414f0c253dc0592d809 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:57:34 +0200 Subject: [PATCH 26/59] Mark blocks as cold in a couple more places --- src/base.rs | 4 +++- src/intrinsics/mod.rs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index f336198947290..5d860bf6e0e20 100644 --- a/src/base.rs +++ b/src/base.rs @@ -379,7 +379,6 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { let target = fx.get_block(*target); let failure = fx.bcx.create_block(); - fx.bcx.set_cold_block(failure); if *expected { fx.bcx.ins().brif(cond, target, &[], failure, &[]); @@ -544,6 +543,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Unreachable => { + fx.bcx.set_cold_block(block); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } TerminatorKind::Yield { .. } @@ -1075,6 +1075,8 @@ fn codegen_panic_inner<'tcx>( args: &[Value], span: Option, ) { + fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); + let def_id = fx.tcx.require_lang_item(lang_item, span); let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx); diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 35f0ccff3f99e..e96ab1e90a21d 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -449,6 +449,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match intrinsic { sym::abort => { + fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); fx.bcx.ins().trap(TrapCode::User(0)); return Ok(()); } From bbaaecc250a8601a756686e72a97d463968282a4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:31:12 +0000 Subject: [PATCH 27/59] Stop copying libstd.so to dist/lib It is only necessary in dist/lib/rustlib/*/lib anymore. The jit mode now correctly find it there too. --- build_system/build_sysroot.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 82558999aface..f1f4489bcbc8d 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -102,15 +102,6 @@ pub(crate) fn build_sysroot( .install_into_sysroot(&dist_dir); } - // Copy std for the host to the lib dir. This is necessary for the jit mode to find - // libstd. - for lib in host.libs { - let filename = lib.file_name().unwrap().to_str().unwrap(); - if filename.contains("std-") && !filename.contains(".rlib") { - try_hard_link(&lib, dist_dir.join("lib").join(lib.file_name().unwrap())); - } - } - let mut target_compiler = { let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif")); let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif")); From 6666435b8ad7045446e170b155c4e419338c545a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:58:00 +0000 Subject: [PATCH 28/59] Fix rustc test suite (broken by prev commit) --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index fbf4ce0223416..035034e0fab85 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -145,6 +145,7 @@ rm tests/ui/intrinsics/panic-uninitialized-zeroed.rs # same rm tests/ui/process/process-panic-after-fork.rs # same cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist +cp $(../dist/rustc-clif --print target-libdir)/libstd-*.so ../dist/lib/ # prevent $(RUSTDOC) from picking up the sysroot built by x.py. It conflicts with the one used by # rustdoc-clif From 2f1b15f145a04e08bebbde522c9ece8f0cad3706 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 9 Aug 2023 00:31:26 +0000 Subject: [PATCH 29/59] Allow dropping dyn principal --- src/unsize.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unsize.rs b/src/unsize.rs index 5c297ebfadbfd..336934354e11b 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -34,7 +34,9 @@ pub(crate) fn unsized_info<'tcx>( { let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); - if data_a.principal_def_id() == data_b.principal_def_id() { + let b_principal_def_id = data_b.principal_def_id(); + if data_a.principal_def_id() == b_principal_def_id || b_principal_def_id.is_none() { + // A NOP cast that doesn't actually change anything, should be allowed even with invalid vtables. debug_assert!( validate_trivial_unsize(fx.tcx, data_a, data_b), "NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}" From 65201c20a6c7dddc4581b59c2cab46de86c299eb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 27 Sep 2024 16:15:30 -0400 Subject: [PATCH 30/59] Fix tests --- src/intrinsics/simd.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index cbe411d78d5fd..e7f9f894381cd 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -133,6 +133,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( .expect_const() .try_to_valtree() .expect("expected monomorphic const in codegen") + .0 .unwrap_branch(); assert_eq!(x.layout(), y.layout()); @@ -806,8 +807,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => m.load_scalar(fx), ty::Array(elem, len) if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) - && len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all()) - == Some(expected_bytes) => + && len + .try_to_target_usize(fx.tcx) + .expect("expected monomorphic const in codegen") + == expected_bytes => { m.force_stack(fx).0.load( fx, @@ -907,8 +910,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => {} ty::Array(elem, len) if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) - && len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all()) - == Some(expected_bytes) => {} + && len + .try_to_target_usize(fx.tcx) + .expect("expected monomorphic const in codegen") + == expected_bytes => {} _ => { fx.tcx.dcx().span_fatal( span, From 04f33cc8392c9f202f9c5cb02853e15980df51e7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:14:00 +0000 Subject: [PATCH 31/59] Rustup to rustc 1.84.0-nightly (da935398d 2024-10-19) --- ...coretests-Disable-long-running-tests.patch | 20 ------------------- rust-toolchain | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/patches/0028-coretests-Disable-long-running-tests.patch b/patches/0028-coretests-Disable-long-running-tests.patch index 5009b24c9d08f..b98326c54a67a 100644 --- a/patches/0028-coretests-Disable-long-running-tests.patch +++ b/patches/0028-coretests-Disable-long-running-tests.patch @@ -43,26 +43,6 @@ index 8402833..84592e0 100644 #[test] fn test_slice_from_ptr_range() { -diff --git a/lazy.rs b/lazy.rs -index 711511e..49c8d78 100644 ---- a/lazy.rs -+++ b/lazy.rs -@@ -113,6 +113,7 @@ fn lazy_type_inference() { - let _ = LazyCell::new(|| ()); - } - -+/* - #[test] - #[should_panic = "LazyCell instance has previously been poisoned"] - fn lazy_force_mut_panic() { -@@ -123,6 +124,7 @@ fn lazy_force_mut_panic() { - .unwrap_err(); - let _ = &*lazy; - } -+*/ - - #[test] - fn lazy_force_mut() { -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index 0aa0f9e21cbff..79b24f20dd9c1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-17" +channel = "nightly-2024-10-20" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 45c2002f08d7d2dfa0c4e197523c82575bdcd6e3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:23:12 +0000 Subject: [PATCH 32/59] Update abi-cafe test expectations for a recent fix of the rust abi --- .../0002-abi-cafe-Disable-broken-tests.patch | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/patches/0002-abi-cafe-Disable-broken-tests.patch b/patches/0002-abi-cafe-Disable-broken-tests.patch index 4c89d65234a4a..01b6a990b7202 100644 --- a/patches/0002-abi-cafe-Disable-broken-tests.patch +++ b/patches/0002-abi-cafe-Disable-broken-tests.patch @@ -23,7 +23,7 @@ diff --git a/src/report.rs b/src/report.rs index 958ab43..dcf1044 100644 --- a/src/report.rs +++ b/src/report.rs -@@ -48,6 +48,58 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn Toolchain, callee: &dyn Toolc +@@ -48,6 +48,40 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn Toolchain, callee: &dyn Toolc // // THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES @@ -31,10 +31,6 @@ index 958ab43..dcf1044 100644 + if test.test == "F32Array" && test.options.convention == CallingConvention::C { + result.check = Busted(Check); + } -+ -+ if test.test == "OptionU128" && test.options.convention == CallingConvention::Rust && test.options.repr == LangRepr::C { -+ result.check = Busted(Check); -+ } + } + + if cfg!(all(target_arch = "aarch64", target_os = "macos")) { @@ -51,21 +47,7 @@ index 958ab43..dcf1044 100644 + } + } + -+ if cfg!(all(target_arch = "x86_64", unix)) { -+ if test.test == "OptionU128" && test.options.convention == CallingConvention::Rust && test.options.repr == LangRepr::Rust { -+ result.check = Busted(Run); -+ } -+ } -+ + if cfg!(all(target_arch = "x86_64", windows)) { -+ if test.test == "OptionU128" && test.options.convention == CallingConvention::Rust { -+ result.check = Busted(Check); -+ } -+ -+ if test.test == "OptionU128" && test.options.convention == CallingConvention::Rust && (test.caller == "rustc" || test.options.repr == LangRepr::Rust) { -+ result.check = Busted(Run); -+ } -+ + if test.test == "simple" && test.options.convention == CallingConvention::Rust { + result.check = Busted(Check); + } From c5a5e86baaac94f44828ba557caef49c2957ec23 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 11 Sep 2024 12:27:08 +0000 Subject: [PATCH 33/59] Rename Receiver -> LegacyReceiver As part of the "arbitrary self types v2" project, we are going to replace the current `Receiver` trait with a new mechanism based on a new, different `Receiver` trait. This PR renames the old trait to get it out the way. Naming is hard. Options considered included: * HardCodedReceiver (because it should only be used for things in the standard library, and hence is sort-of hard coded) * LegacyReceiver * TargetLessReceiver * OldReceiver These are all bad names, but fortunately this will be temporary. Assuming the new mechanism proceeds to stabilization as intended, the legacy trait will be removed altogether. Although we expect this trait to be used only in the standard library, we suspect it may be in use elsehwere, so we're landing this change separately to identify any surprising breakages. It's known that this trait is used within the Rust for Linux project; a patch is in progress to remove their dependency. This is a part of the arbitrary self types v2 project, https://github.com/rust-lang/rfcs/pull/3519 https://github.com/rust-lang/rust/issues/44874 r? @wesleywiser --- example/mini_core.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 9fc0318df5dc0..42c7f5f0dc692 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -47,12 +47,12 @@ impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {} impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {} impl, U: ?Sized> DispatchFromDyn> for Box {} -#[lang = "receiver"] -pub trait Receiver {} +#[lang = "legacy_receiver"] +pub trait LegacyReceiver {} -impl Receiver for &T {} -impl Receiver for &mut T {} -impl Receiver for Box {} +impl LegacyReceiver for &T {} +impl LegacyReceiver for &mut T {} +impl LegacyReceiver for Box {} #[lang = "copy"] pub unsafe trait Copy {} From 3f06952be310094145a12912836c50d44a97c29e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:16:08 +0000 Subject: [PATCH 34/59] Rustup to rustc 1.84.0-nightly (4f2f477fd 2024-10-23) --- patches/0022-coretests-Disable-not-compiling-tests.patch | 4 ++-- patches/0027-coretests-128bit-atomic-operations.patch | 5 +++-- rust-toolchain | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/patches/0022-coretests-Disable-not-compiling-tests.patch b/patches/0022-coretests-Disable-not-compiling-tests.patch index 161173d47650f..6ed22c5a18e55 100644 --- a/patches/0022-coretests-Disable-not-compiling-tests.patch +++ b/patches/0022-coretests-Disable-not-compiling-tests.patch @@ -38,7 +38,7 @@ index 42a26ae..5ac1042 100644 @@ -1,3 +1,4 @@ +#![cfg(test)] // tidy-alphabetical-start - #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] - #![cfg_attr(test, feature(cfg_match))] + #![cfg_attr(bootstrap, feature(strict_provenance))] + #![cfg_attr(not(bootstrap), feature(strict_provenance_lints))] -- 2.21.0 (Apple Git-122) diff --git a/patches/0027-coretests-128bit-atomic-operations.patch b/patches/0027-coretests-128bit-atomic-operations.patch index 5f5baae2fd655..50a42aea322c0 100644 --- a/patches/0027-coretests-128bit-atomic-operations.patch +++ b/patches/0027-coretests-128bit-atomic-operations.patch @@ -14,9 +14,10 @@ diff --git a/lib.rs b/lib.rs index 1e336bf..35e6f54 100644 --- a/lib.rs +++ b/lib.rs -@@ -1,6 +1,5 @@ - #![cfg(test)] +@@ -2,7 +2,6 @@ // tidy-alphabetical-start + #![cfg_attr(bootstrap, feature(strict_provenance))] + #![cfg_attr(not(bootstrap), feature(strict_provenance_lints))] -#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] #![cfg_attr(test, feature(cfg_match))] #![feature(alloc_layout_extra)] diff --git a/rust-toolchain b/rust-toolchain index 79b24f20dd9c1..4eb104ed51173 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-20" +channel = "nightly-2024-10-24" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From c28d433bd98cdb29406e5b5f62a5c8eeb9f74723 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:12:17 +0000 Subject: [PATCH 35/59] Update Cranelift to 0.113 --- Cargo.lock | 105 ++++++++++++++++--------------------- Cargo.toml | 15 +++--- src/abi/mod.rs | 4 +- src/base.rs | 12 ++--- src/debuginfo/line_info.rs | 7 ++- src/debuginfo/mod.rs | 3 +- src/inline_asm.rs | 4 +- src/intrinsics/mod.rs | 4 +- src/intrinsics/simd.rs | 6 +-- src/trap.rs | 2 +- 10 files changed, 77 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82640dafa6d23..e4f77472802c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" @@ -46,24 +46,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6e376bd92bddd03dcfc443b14382611cae5d10012aa0b1628bbf18bb73f12f7" +checksum = "8ea5e7afe85cadb55c4c1176268a2ac046fdff8dfaeca39e18581b9dc319ca9e" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ecbe07f25a8100e5077933516200e97808f1d7196b5a073edb85fa08fde32e" +checksum = "8ab25ef3be935a80680e393183e1f94ef507e93a24a8369494d2c6818aedb3e3" [[package]] name = "cranelift-codegen" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc60913f32c1de18538c28bef74b8c87cf16de7841a1b0956fcf01b23237853a" +checksum = "900a19b84545924f1851cbfe386962edfc4ecbc3366a254825cf1ecbcda8ba08" dependencies = [ "bumpalo", "cranelift-bforest", @@ -84,42 +84,42 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae009e7822f47aa55e7dcef846ccf3aa4eb102ca6b4bcb8a44b36f3f49aa85c" +checksum = "08c73b2395ffe9e7b4fdf7e2ebc052e7e27af13f68a964985346be4da477a5fc" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c78f01a852536c68e34444450f845ed6e0782a1f047f85397fe460b8fbce8f1" +checksum = "7d9ed0854e96a4ff0879bff39d078de8dea7f002721c9494c1fdb4e1baa86ccc" [[package]] name = "cranelift-control" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a061b22e00a9e36b31f2660dfb05a9617b7775bd54b79754d3bb75a990dac06" +checksum = "b4aca921dd422e781409de0129c255768fec5dec1dae83239b497fb9138abb89" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e2b261a3e74ae42f4e606906d5ffa44ee2684e8b1ae23bdf75d21908dc9233" +checksum = "e2d770e6605eccee15b49decdd82cd26f2b6404767802471459ea49c57379a98" dependencies = [ "cranelift-bitset", ] [[package]] name = "cranelift-frontend" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe14abba0e6bab42aca0f9ce757f96880f9187e88bc6cb975ed6acd8a42f7770" +checksum = "29268711cb889cb39215b10faf88b9087d4c9e1d2633581e4f722a2bf4bb4ef9" dependencies = [ "cranelift-codegen", "log", @@ -129,15 +129,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311d91ae72b37d4262b51217baf8c9e01f1afd5148931468da1fdb7e9d011347" +checksum = "dc65156f010aed1985767ad1bff0eb8d186743b7b03e23d0c17604a253e3f356" [[package]] name = "cranelift-jit" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8ea36cb2f092c71300eb1ffdb30b7e301fdc3c00479aabe36036bac53c5a5a" +checksum = "40ba6b46367a4f466cfb1abe32793fa1a0f96d862251491b01a44726b8ed9445" dependencies = [ "anyhow", "cranelift-codegen", @@ -150,14 +150,14 @@ dependencies = [ "region", "target-lexicon", "wasmtime-jit-icache-coherence", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] name = "cranelift-module" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e03d6e8524b5093252fb624a5bb7a0517a1f23d2d2a1418ef8bfd81290ef549" +checksum = "007607022a4883ebdffc46c0925e2e10babf2a565ae78518034ade722aa825d2" dependencies = [ "anyhow", "cranelift-codegen", @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a3f84c75e578189ff7a716c24ad83740b553bf583f2510b323bfe4c1a74bb93" +checksum = "d8bf9b361eaf5a7627647270fabf1dc910d993edbeaf272a652c107861ebe9c2" dependencies = [ "cranelift-codegen", "libc", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.112.1" +version = "0.113.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc18e6930ac086d1fe10da77d7019f29048feb7b73b236bddf8980b587ed89d7" +checksum = "30ca5c38fa00c0cd943035391bdcc84ed00748f17c66c682e410f5a62f234d44" dependencies = [ "anyhow", "cranelift-codegen", @@ -213,9 +213,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" dependencies = [ "fallible-iterator", "indexmap", @@ -264,10 +264,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] -name = "mach" -version = "0.3.2" +name = "mach2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" dependencies = [ "libc", ] @@ -329,14 +329,14 @@ dependencies = [ [[package]] name = "region" -version = "2.2.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" +checksum = "e6b6ebd13bc009aef9cd476c1310d49ac354d36e240cf1bd753290f3dc7199a7" dependencies = [ "bitflags", "libc", - "mach", - "winapi", + "mach2", + "windows-sys 0.52.0", ] [[package]] @@ -412,43 +412,30 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasmtime-jit-icache-coherence" -version = "25.0.1" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48011232c0da424f89c3752a378d0b7f512fae321ea414a43e1e7a302a6a1f7e" +checksum = "6e458e6a1a010a53f86ac8d75837c0c6b2ce3e54b7503b2f1dc5629a4a541f5a" dependencies = [ "anyhow", "cfg-if", "libc", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets", ] -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] diff --git a/Cargo.toml b/Cargo.toml index a30ed75c02646..f352ef72cb058 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,15 +8,14 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -# FIXME switch to native-arch instead of listing all archs on the next Cranelift update -cranelift-codegen = { version = "0.112.0", default-features = false, features = ["std", "unwind", "x86", "arm64", "s390x", "riscv64"] } -cranelift-frontend = { version = "0.112.0" } -cranelift-module = { version = "0.112.0" } -cranelift-native = { version = "0.112.0" } -cranelift-jit = { version = "0.112.0", optional = true } -cranelift-object = { version = "0.112.0" } +cranelift-codegen = { version = "0.113.0", default-features = false, features = ["std", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.113.0" } +cranelift-module = { version = "0.113.0" } +cranelift-native = { version = "0.113.0" } +cranelift-jit = { version = "0.113.0", optional = true } +cranelift-object = { version = "0.113.0" } target-lexicon = "0.12.0" -gimli = { version = "0.29", default-features = false, features = ["write"] } +gimli = { version = "0.31", default-features = false, features = ["write"] } object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } indexmap = "2.0.0" diff --git a/src/abi/mod.rs b/src/abi/mod.rs index c0aa63eab7842..c532a3dfec2a5 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -389,7 +389,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( let callee = with_no_trimmed_paths!(fx.tcx.def_path_str(def_id)); fx.tcx.dcx().emit_err(CompilerBuiltinsCannotCall { caller, callee }); } else { - fx.bcx.ins().trap(TrapCode::User(0)); + fx.bcx.ins().trap(TrapCode::user(2).unwrap()); return; } } @@ -579,7 +579,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( let ret_block = fx.get_block(dest); fx.bcx.ins().jump(ret_block, &[]); } else { - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } fn adjust_call_for_c_variadic<'tcx>( diff --git a/src/base.rs b/src/base.rs index 5d860bf6e0e20..e7a67c11fe8d0 100644 --- a/src/base.rs +++ b/src/base.rs @@ -294,7 +294,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { if arg_uninhabited { fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); return; } fx.tcx @@ -311,7 +311,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { if !reachable_blocks.contains(bb) { // We want to skip this block, because it's not reachable. But we still create // the block so terminators in other blocks can reference it. - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); continue; } @@ -540,11 +540,11 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { } TerminatorKind::UnwindResume => { // FIXME implement unwinding - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } TerminatorKind::Unreachable => { fx.bcx.set_cold_block(block); - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } TerminatorKind::Yield { .. } | TerminatorKind::FalseEdge { .. } @@ -1082,7 +1082,7 @@ fn codegen_panic_inner<'tcx>( let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx); if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) { - fx.bcx.ins().trap(TrapCode::User(0)); + fx.bcx.ins().trap(TrapCode::user(2).unwrap()); return; } @@ -1095,5 +1095,5 @@ fn codegen_panic_inner<'tcx>( args, ); - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index c3d9d635084d6..fa7b39c836f64 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -50,7 +50,12 @@ fn make_file_info(hash: SourceFileHash) -> Option { if hash.kind == SourceFileHashAlgorithm::Md5 { let mut buf = [0u8; MD5_LEN]; buf.copy_from_slice(hash.hash_bytes()); - Some(FileInfo { timestamp: 0, size: 0, md5: buf }) + Some(FileInfo { + timestamp: 0, + size: 0, + md5: buf, + source: None, // FIXME implement -Zembed-source + }) } else { None } diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index f0b78e5d7c674..a877d8ca9c9eb 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -101,6 +101,7 @@ impl DebugContext { None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), }; + let file_has_md5 = file_info.is_some(); let mut line_program = LineProgram::new( encoding, LineEncoding::default(), @@ -108,7 +109,7 @@ impl DebugContext { LineString::new(name.as_bytes(), encoding, &mut dwarf.line_strings), file_info, ); - line_program.file_has_md5 = file_info.is_some(); + line_program.file_has_md5 = file_has_md5; dwarf.unit.line_program = line_program; diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 41f1b30d10b59..0fbd5a16830e3 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -47,7 +47,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( // asm!() by accident and breaks with the GNU assembler as well as global_asm!() for // the LLVM backend. if template.len() == 1 && template[0] == InlineAsmTemplatePiece::String("int $$0x29".into()) { - fx.bcx.ins().trap(TrapCode::User(1)); + fx.bcx.ins().trap(TrapCode::user(2).unwrap()); return; } @@ -137,7 +137,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( fx.bcx.ins().jump(destination_block, &[]); } None => { - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(0 /* unreachable */).unwrap()); } } } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index e96ab1e90a21d..6371b52720dfd 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -47,7 +47,7 @@ fn report_atomic_type_validation_error<'tcx>( ), ); // Prevent verifier error - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type { @@ -450,7 +450,7 @@ fn codegen_regular_intrinsic_call<'tcx>( match intrinsic { sym::abort => { fx.bcx.set_cold_block(fx.bcx.current_block().unwrap()); - fx.bcx.ins().trap(TrapCode::User(0)); + fx.bcx.ins().trap(TrapCode::user(2).unwrap()); return Ok(()); } sym::likely | sym::unlikely => { diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index e7f9f894381cd..16fb68a7bdfa4 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -14,7 +14,7 @@ fn report_simd_type_validation_error( ) { fx.tcx.dcx().span_err(span, format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty)); // Prevent verifier error - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); } pub(super) fn codegen_simd_intrinsic_call<'tcx>( @@ -190,7 +190,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( format!("simd_shuffle index must be a SIMD vector of `u32`, got `{}`", idx_ty), ); // Prevent verifier error - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap()); return; }; let n: u16 = idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap(); @@ -1135,7 +1135,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ => { fx.tcx.dcx().span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic)); // Prevent verifier error - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + fx.bcx.ins().trap(TrapCode::user(0 /* unreachable */).unwrap()); return; } } diff --git a/src/trap.rs b/src/trap.rs index a61e1e334eca1..9ef1a523d6d69 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -30,5 +30,5 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRe let one = fx.bcx.ins().iconst(types::I32, 1); fx.lib_call("exit", vec![AbiParam::new(types::I32)], vec![], &[one]); - fx.bcx.ins().trap(TrapCode::User(!0)); + fx.bcx.ins().trap(TrapCode::user(3).unwrap()); } From bcb7de3bb67d2ba26d6a41828debf837ffc62d11 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Sun, 29 Sep 2024 19:40:37 -0700 Subject: [PATCH 36/59] Don't panic about debug info for Arm64 Windows unwind info --- src/debuginfo/unwind.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index 9399230f292e0..362333d35a411 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -60,8 +60,8 @@ impl UnwindContext { self.frame_table .add_fde(self.cie_id.unwrap(), unwind_info.to_fde(address_for_func(func_id))); } - UnwindInfo::WindowsX64(_) => { - // FIXME implement this + UnwindInfo::WindowsX64(_) | UnwindInfo::WindowsArm64(_) => { + // Windows does not have debug info for its unwind info. } unwind_info => unimplemented!("{:?}", unwind_info), } From 6ca276df2ed5de4e272db2734f089bfa7e512b8d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 6 Oct 2024 19:59:19 +0200 Subject: [PATCH 37/59] Re-do recursive const stability checks Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required. --- patches/0027-stdlib-128bit-atomic-operations.patch | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/patches/0027-stdlib-128bit-atomic-operations.patch b/patches/0027-stdlib-128bit-atomic-operations.patch index 646928893e96a..3c81b04c0ead2 100644 --- a/patches/0027-stdlib-128bit-atomic-operations.patch +++ b/patches/0027-stdlib-128bit-atomic-operations.patch @@ -38,7 +38,7 @@ 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 -@@ -2996,42 +2996,6 @@ atomic_int! { +@@ -2996,44 +2996,6 @@ atomic_int! { 8, u64 AtomicU64 } @@ -52,7 +52,8 @@ index d9de37e..8293fce 100644 - 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"), +- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), +- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"), - "i128", - "#![feature(integer_atomics)]\n\n", @@ -70,7 +71,8 @@ index d9de37e..8293fce 100644 - 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"), +- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), +- rustc_const_unstable(feature = "integer_atomics", issue = "99069"), - cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"), - "u128", - "#![feature(integer_atomics)]\n\n", From 83f1121ebd43db170bf8ff995a3b757148d24711 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 26 Oct 2024 10:18:42 +0800 Subject: [PATCH 38/59] Effects cleanup - removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers --- src/debuginfo/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index f0b78e5d7c674..79d76925df9f6 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -210,7 +210,6 @@ impl DebugContext { type_names::push_generic_params( tcx, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args), - enclosing_fn_def_id, &mut name, ); From 988f49d04f0d9811aee75c4d54e8fe8f21835ca6 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 27 Oct 2024 22:32:40 -0700 Subject: [PATCH 39/59] cg_clif: Rename LayoutS to LayoutData --- src/abi/comments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/comments.rs b/src/abi/comments.rs index a318cae1722b6..daea789ee3eb4 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -79,7 +79,7 @@ pub(super) fn add_local_place_comments<'tcx>( return; } let TyAndLayout { ty, layout } = place.layout(); - let rustc_target::abi::LayoutS { size, align, .. } = layout.0.0; + let rustc_abi::LayoutData { size, align, .. } = layout.0.0; let (kind, extra) = place.debug_comment(); From e3c154705c33c87edd9fabee1c163429eaf7e876 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 29 Oct 2024 13:37:59 -0700 Subject: [PATCH 40/59] cg_clif: `rustc_abi::Abi` => `BackendRepr` --- src/abi/mod.rs | 2 +- src/abi/pass_mode.rs | 28 ++++++++++----------- src/base.rs | 8 +++--- src/discriminant.rs | 4 +-- src/intrinsics/mod.rs | 10 ++++---- src/lib.rs | 2 +- src/value_and_place.rs | 57 ++++++++++++++++++++++++------------------ src/vtable.rs | 4 +-- 8 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 892ec3e95855e..089b09d06aef2 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -193,7 +193,7 @@ fn make_local_place<'tcx>( ); } let place = if is_ssa { - if let rustc_target::abi::Abi::ScalarPair(_, _) = layout.abi { + if let BackendRepr::ScalarPair(_, _) = layout.backend_repr { CPlace::new_var_pair(fx, local, layout) } else { CPlace::new_var(fx, local, layout) diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 38c322b5e0450..ad0a13dc7e574 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -78,19 +78,19 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> { match self.mode { PassMode::Ignore => smallvec![], - PassMode::Direct(attrs) => match self.layout.abi { - Abi::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param( + PassMode::Direct(attrs) => match self.layout.backend_repr { + BackendRepr::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param( AbiParam::new(scalar_to_clif_type(tcx, scalar)), attrs )], - Abi::Vector { .. } => { + BackendRepr::Vector { .. } => { let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout); smallvec![AbiParam::new(vector_ty)] } - _ => unreachable!("{:?}", self.layout.abi), + _ => unreachable!("{:?}", self.layout.backend_repr), }, - PassMode::Pair(attrs_a, attrs_b) => match self.layout.abi { - Abi::ScalarPair(a, b) => { + PassMode::Pair(attrs_a, attrs_b) => match self.layout.backend_repr { + BackendRepr::ScalarPair(a, b) => { let a = scalar_to_clif_type(tcx, a); let b = scalar_to_clif_type(tcx, b); smallvec![ @@ -98,7 +98,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { apply_arg_attrs_to_abi_param(AbiParam::new(b), attrs_b), ] } - _ => unreachable!("{:?}", self.layout.abi), + _ => unreachable!("{:?}", self.layout.backend_repr), }, PassMode::Cast { ref cast, pad_i32 } => { assert!(!pad_i32, "padding support not yet implemented"); @@ -130,23 +130,23 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option, Vec) { match self.mode { PassMode::Ignore => (None, vec![]), - PassMode::Direct(_) => match self.layout.abi { - Abi::Scalar(scalar) => { + PassMode::Direct(_) => match self.layout.backend_repr { + BackendRepr::Scalar(scalar) => { (None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))]) } - Abi::Vector { .. } => { + BackendRepr::Vector { .. } => { let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout); (None, vec![AbiParam::new(vector_ty)]) } - _ => unreachable!("{:?}", self.layout.abi), + _ => unreachable!("{:?}", self.layout.backend_repr), }, - PassMode::Pair(_, _) => match self.layout.abi { - Abi::ScalarPair(a, b) => { + PassMode::Pair(_, _) => match self.layout.backend_repr { + BackendRepr::ScalarPair(a, b) => { let a = scalar_to_clif_type(tcx, a); let b = scalar_to_clif_type(tcx, b); (None, vec![AbiParam::new(a), AbiParam::new(b)]) } - _ => unreachable!("{:?}", self.layout.abi), + _ => unreachable!("{:?}", self.layout.backend_repr), }, PassMode::Cast { ref cast, .. } => { (None, cast_target_to_abi_params(cast).into_iter().collect()) diff --git a/src/base.rs b/src/base.rs index a681e6d9f3cd1..99e39971b7479 100644 --- a/src/base.rs +++ b/src/base.rs @@ -290,7 +290,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { let arg_uninhabited = fx .mir .args_iter() - .any(|arg| fx.layout_of(fx.monomorphize(fx.mir.local_decls[arg].ty)).abi.is_uninhabited()); + .any(|arg| fx.layout_of(fx.monomorphize(fx.mir.local_decls[arg].ty)).is_uninhabited()); if arg_uninhabited { fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]); fx.bcx.switch_to_block(fx.block_map[START_BLOCK]); @@ -644,9 +644,9 @@ fn codegen_stmt<'tcx>( _ => unreachable!("un op Neg for {:?}", layout.ty), } } - UnOp::PtrMetadata => match layout.abi { - Abi::Scalar(_) => CValue::zst(dest_layout), - Abi::ScalarPair(_, _) => { + UnOp::PtrMetadata => match layout.backend_repr { + BackendRepr::Scalar(_) => CValue::zst(dest_layout), + BackendRepr::ScalarPair(_, _) => { CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout) } _ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"), diff --git a/src/discriminant.rs b/src/discriminant.rs index d462dcd63a925..45794a4266589 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -14,7 +14,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>( variant_index: VariantIdx, ) { let layout = place.layout(); - if layout.for_variant(fx, variant_index).abi.is_uninhabited() { + if layout.for_variant(fx, variant_index).is_uninhabited() { return; } match layout.variants { @@ -80,7 +80,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>( ) { let layout = value.layout(); - if layout.abi.is_uninhabited() { + if layout.is_uninhabited() { return; } diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 35f0ccff3f99e..aae6794891d76 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -51,8 +51,8 @@ fn report_atomic_type_validation_error<'tcx>( } pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type { - let (element, count) = match layout.abi { - Abi::Vector { element, count } => (element, count), + let (element, count) = match layout.backend_repr { + BackendRepr::Vector { element, count } => (element, count), _ => unreachable!(), }; @@ -505,7 +505,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = fx.layout_of(generic_args.type_at(0)); // Note: Can't use is_unsized here as truly unsized types need to take the fixed size // branch - let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi { + let meta = if let BackendRepr::ScalarPair(_, _) = ptr.layout().backend_repr { Some(ptr.load_scalar_pair(fx).1) } else { None @@ -519,7 +519,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = fx.layout_of(generic_args.type_at(0)); // Note: Can't use is_unsized here as truly unsized types need to take the fixed size // branch - let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi { + let meta = if let BackendRepr::ScalarPair(_, _) = ptr.layout().backend_repr { Some(ptr.load_scalar_pair(fx).1) } else { None @@ -693,7 +693,7 @@ fn codegen_regular_intrinsic_call<'tcx>( let layout = fx.layout_of(ty); let msg_str = with_no_visible_paths!({ with_no_trimmed_paths!({ - if layout.abi.is_uninhabited() { + if layout.is_uninhabited() { // Use this error even for the other intrinsics as it is more precise. format!("attempted to instantiate uninhabited type `{}`", ty) } else if intrinsic == sym::assert_zero_valid { diff --git a/src/lib.rs b/src/lib.rs index b6f9ce8fc2988..602b1b9820023 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,7 @@ mod prelude { StackSlotData, StackSlotKind, TrapCode, Type, Value, types, }; pub(crate) use cranelift_module::{self, DataDescription, FuncId, Linkage, Module}; + pub(crate) use rustc_abi::{BackendRepr, FIRST_VARIANT, FieldIdx, Scalar, Size, VariantIdx}; pub(crate) use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE}; pub(crate) use rustc_index::Idx; @@ -101,7 +102,6 @@ mod prelude { self, FloatTy, Instance, InstanceKind, IntTy, ParamEnv, Ty, TyCtxt, UintTy, }; pub(crate) use rustc_span::Span; - pub(crate) use rustc_target::abi::{Abi, FIRST_VARIANT, FieldIdx, Scalar, Size, VariantIdx}; pub(crate) use crate::abi::*; pub(crate) use crate::base::{codegen_operand, codegen_place}; diff --git a/src/value_and_place.rs b/src/value_and_place.rs index fd77502224e4c..900d7e69714ea 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -131,8 +131,8 @@ impl<'tcx> CValue<'tcx> { match self.0 { CValueInner::ByRef(ptr, None) => { - let (a_scalar, b_scalar) = match self.1.abi { - Abi::ScalarPair(a, b) => (a, b), + let (a_scalar, b_scalar) = match self.1.backend_repr { + BackendRepr::ScalarPair(a, b) => (a, b), _ => unreachable!("dyn_star_force_data_on_stack({:?})", self), }; let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); @@ -164,15 +164,15 @@ impl<'tcx> CValue<'tcx> { } } - /// Load a value with layout.abi of scalar + /// Load a value with layout.backend_repr of scalar #[track_caller] pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> Value { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { - let clif_ty = match layout.abi { - Abi::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar), - Abi::Vector { element, count } => scalar_to_clif_type(fx.tcx, element) + let clif_ty = match layout.backend_repr { + BackendRepr::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar), + BackendRepr::Vector { element, count } => scalar_to_clif_type(fx.tcx, element) .by(u32::try_from(count).unwrap()) .unwrap(), _ => unreachable!("{:?}", layout.ty), @@ -187,14 +187,14 @@ impl<'tcx> CValue<'tcx> { } } - /// Load a value pair with layout.abi of scalar pair + /// Load a value pair with layout.backend_repr of scalar pair #[track_caller] pub(crate) fn load_scalar_pair(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Value, Value) { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { - let (a_scalar, b_scalar) = match layout.abi { - Abi::ScalarPair(a, b) => (a, b), + let (a_scalar, b_scalar) = match layout.backend_repr { + BackendRepr::ScalarPair(a, b) => (a, b), _ => unreachable!("load_scalar_pair({:?})", self), }; let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); @@ -222,8 +222,8 @@ impl<'tcx> CValue<'tcx> { let layout = self.1; match self.0 { CValueInner::ByVal(_) => unreachable!(), - CValueInner::ByValPair(val1, val2) => match layout.abi { - Abi::ScalarPair(_, _) => { + CValueInner::ByValPair(val1, val2) => match layout.backend_repr { + BackendRepr::ScalarPair(_, _) => { let val = match field.as_u32() { 0 => val1, 1 => val2, @@ -232,7 +232,7 @@ impl<'tcx> CValue<'tcx> { let field_layout = layout.field(&*fx, usize::from(field)); CValue::by_val(val, field_layout) } - _ => unreachable!("value_field for ByValPair with abi {:?}", layout.abi), + _ => unreachable!("value_field for ByValPair with abi {:?}", layout.backend_repr), }, CValueInner::ByRef(ptr, None) => { let (field_ptr, field_layout) = codegen_field(fx, ptr, None, layout, field); @@ -360,7 +360,7 @@ impl<'tcx> CValue<'tcx> { pub(crate) fn cast_pointer_to(self, layout: TyAndLayout<'tcx>) -> Self { assert!(matches!(self.layout().ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..))); assert!(matches!(layout.ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..))); - assert_eq!(self.layout().abi, layout.abi); + assert_eq!(self.layout().backend_repr, layout.backend_repr); CValue(self.0, layout) } } @@ -609,8 +609,8 @@ impl<'tcx> CPlace<'tcx> { let dst_layout = self.layout(); match self.inner { CPlaceInner::Var(_local, var) => { - let data = match from.1.abi { - Abi::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx), + let data = match from.1.backend_repr { + BackendRepr::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx), _ => { let (ptr, meta) = from.force_stack(fx); assert!(meta.is_none()); @@ -621,8 +621,10 @@ impl<'tcx> CPlace<'tcx> { transmute_scalar(fx, var, data, dst_ty); } CPlaceInner::VarPair(_local, var1, var2) => { - let (data1, data2) = match from.1.abi { - Abi::ScalarPair(_, _) => CValue(from.0, dst_layout).load_scalar_pair(fx), + let (data1, data2) = match from.1.backend_repr { + BackendRepr::ScalarPair(_, _) => { + CValue(from.0, dst_layout).load_scalar_pair(fx) + } _ => { let (ptr, meta) = from.force_stack(fx); assert!(meta.is_none()); @@ -635,7 +637,9 @@ impl<'tcx> CPlace<'tcx> { } CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self), CPlaceInner::Addr(to_ptr, None) => { - if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited { + if dst_layout.size == Size::ZERO + || dst_layout.backend_repr == BackendRepr::Uninhabited + { return; } @@ -646,23 +650,28 @@ impl<'tcx> CPlace<'tcx> { CValueInner::ByVal(val) => { to_ptr.store(fx, val, flags); } - CValueInner::ByValPair(val1, val2) => match from.layout().abi { - Abi::ScalarPair(a_scalar, b_scalar) => { + CValueInner::ByValPair(val1, val2) => match from.layout().backend_repr { + BackendRepr::ScalarPair(a_scalar, b_scalar) => { let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); to_ptr.store(fx, val1, flags); to_ptr.offset(fx, b_offset).store(fx, val2, flags); } - _ => bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi), + _ => { + bug!( + "Non ScalarPair repr {:?} for ByValPair CValue", + dst_layout.backend_repr + ) + } }, CValueInner::ByRef(from_ptr, None) => { - match from.layout().abi { - Abi::Scalar(_) => { + match from.layout().backend_repr { + BackendRepr::Scalar(_) => { let val = from.load_scalar(fx); to_ptr.store(fx, val, flags); return; } - Abi::ScalarPair(a_scalar, b_scalar) => { + BackendRepr::ScalarPair(a_scalar, b_scalar) => { let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); let (val1, val2) = from.load_scalar_pair(fx); diff --git a/src/vtable.rs b/src/vtable.rs index 14c607ccad7d7..82b6178be9dcd 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -47,7 +47,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( idx: usize, ) -> (Pointer, Value) { let (ptr, vtable) = 'block: { - if let Abi::Scalar(_) = arg.layout().abi { + if let BackendRepr::Scalar(_) = arg.layout().backend_repr { while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() { let (idx, _) = arg .layout() @@ -68,7 +68,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( } } - if let Abi::ScalarPair(_, _) = arg.layout().abi { + if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr { let (ptr, vtable) = arg.load_scalar_pair(fx); (Pointer::new(ptr), vtable) } else { From 05126cdc1015757c3d039fd7150ccb1f299c3ffb Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:28:49 +0000 Subject: [PATCH 41/59] Rustup to rustc 1.84.0-nightly (759e07f06 2024-10-30) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 4eb104ed51173..87426f7b8d554 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-24" +channel = "nightly-2024-10-31" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From 297e933bf8ffc740c56f11e5299243a5a0623275 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:51:09 +0000 Subject: [PATCH 42/59] Fix rustc test suite --- scripts/test_rustc_tests.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 035034e0fab85..a820da286f5c6 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -178,6 +178,18 @@ index 9607ff02f96..b7d97caf9a2 100644 Self { cmd } } +diff --git a/src/tools/compiletest/src/runtest/run_make.rs b/src/tools/compiletest/src/runtest/run_make.rs +index e7ae773ffa1d3..04bc2d7787da7 100644 +--- a/src/tools/compiletest/src/runtest/run_make.rs ++++ b/src/tools/compiletest/src/runtest/run_make.rs +@@ -329,7 +329,6 @@ impl TestCx<'_> { + .arg(format!("run_make_support={}", &support_lib_path.to_string_lossy())) + .arg("--edition=2021") + .arg(&self.testpaths.file.join("rmake.rs")) +- .arg("-Cprefer-dynamic") + // Provide necessary library search paths for rustc. + .env(dylib_env_var(), &env::join_paths(host_dylib_search_paths).unwrap()); + EOF echo "[TEST] rustc test suite" From 66351a61844aaabe76173c7c790c1a9adbc3d4a8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Nov 2024 09:59:55 +0100 Subject: [PATCH 43/59] get rid of a whole bunch of unnecessary rustc_const_unstable attributes --- library/core/src/array/iter.rs | 2 -- library/core/src/char/methods.rs | 1 - library/core/src/lib.rs | 5 ----- library/core/src/mem/maybe_uninit.rs | 6 ------ library/core/src/net/ip_addr.rs | 1 - library/core/src/num/f32.rs | 2 -- library/core/src/num/f64.rs | 2 -- library/core/src/num/int_macros.rs | 18 ------------------ library/core/src/num/mod.rs | 8 -------- library/core/src/num/nonzero.rs | 1 - library/core/src/num/uint_macros.rs | 16 ---------------- library/core/src/ptr/const_ptr.rs | 5 ----- library/core/src/ptr/mut_ptr.rs | 6 ------ library/core/src/ptr/non_null.rs | 9 --------- library/core/src/str/converts.rs | 2 -- library/core/src/sync/exclusive.rs | 2 -- library/core/src/task/wake.rs | 7 ------- library/core/src/time.rs | 2 -- library/core/src/unicode/unicode_data.rs | 3 --- library/core/tests/lib.rs | 2 -- .../src/range_search.rs | 1 - .../unicode-table-generator/src/raw_emitter.rs | 5 ----- 22 files changed, 106 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 2d19e4876f680..9ce0eb61e0814 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -136,7 +136,6 @@ impl IntoIter { /// assert_eq!(r.collect::>(), vec![10, 11, 12, 13, 14, 15]); /// ``` #[unstable(feature = "array_into_iter_constructors", issue = "91583")] - #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const unsafe fn new_unchecked( buffer: [MaybeUninit; N], initialized: Range, @@ -199,7 +198,6 @@ impl IntoIter { /// assert_eq!(get_bytes(false).collect::>(), vec![]); /// ``` #[unstable(feature = "array_into_iter_constructors", issue = "91583")] - #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const fn empty() -> Self { let buffer = [const { MaybeUninit::uninit() }; N]; let initialized = 0..0; diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 206bbf5690ef1..c37b9aa2aae3b 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1515,7 +1515,6 @@ impl char { /// ``` #[must_use] #[unstable(feature = "is_ascii_octdigit", issue = "101288")] - #[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")] #[inline] pub const fn is_ascii_octdigit(&self) -> bool { matches!(*self, '0'..='7') diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 115fdd7a14024..bbfe32027e8eb 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -115,8 +115,6 @@ #![feature(const_align_offset)] #![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] -#![feature(const_array_into_iter_constructors)] -#![feature(const_bigint_helper_methods)] #![feature(const_black_box)] #![feature(const_char_encode_utf16)] #![feature(const_eval_select)] @@ -125,7 +123,6 @@ #![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] -#![feature(const_num_midpoint)] #![feature(const_option_ext)] #![feature(const_pin_2)] #![feature(const_pointer_is_aligned)] @@ -135,7 +132,6 @@ #![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] #![feature(const_sockaddr_setters)] -#![feature(const_strict_overflow_ops)] #![feature(const_swap)] #![feature(const_try)] #![feature(const_type_id)] @@ -167,7 +163,6 @@ #![feature(unchecked_neg)] #![feature(unchecked_shifts)] #![feature(utf16_extra)] -#![feature(utf16_extra_const)] #![feature(variant_count)] // tidy-alphabetical-end // diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index a57e265c7cc00..8c6cdf57c5845 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -338,7 +338,6 @@ impl MaybeUninit { /// let data = read(&mut buf); /// ``` #[unstable(feature = "maybe_uninit_uninit_array", issue = "96097")] - #[rustc_const_unstable(feature = "const_maybe_uninit_uninit_array", issue = "96097")] #[must_use] #[inline(always)] pub const fn uninit_array() -> [Self; N] { @@ -946,7 +945,6 @@ impl MaybeUninit { /// assert_eq!(array, [0, 1, 2]); /// ``` #[unstable(feature = "maybe_uninit_array_assume_init", issue = "96097")] - #[rustc_const_unstable(feature = "const_maybe_uninit_array_assume_init", issue = "96097")] #[inline(always)] #[track_caller] pub const unsafe fn array_assume_init(array: [Self; N]) -> [T; N] { @@ -973,7 +971,6 @@ impl MaybeUninit { /// /// [`assume_init_ref`]: MaybeUninit::assume_init_ref #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] { // SAFETY: casting `slice` to a `*const [T]` is safe since the caller guarantees that @@ -995,7 +992,6 @@ impl MaybeUninit { /// /// [`assume_init_mut`]: MaybeUninit::assume_init_mut #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] { // SAFETY: similar to safety notes for `slice_get_ref`, but we have a @@ -1005,7 +1001,6 @@ impl MaybeUninit { /// Gets a pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const fn slice_as_ptr(this: &[MaybeUninit]) -> *const T { this.as_ptr() as *const T @@ -1013,7 +1008,6 @@ impl MaybeUninit { /// Gets a mutable pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit]) -> *mut T { this.as_mut_ptr() as *mut T diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 0d1f4a9ea3eed..d3360c1820719 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -373,7 +373,6 @@ impl IpAddr { /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true); /// ``` #[unstable(feature = "ip", issue = "27709")] - #[rustc_const_unstable(feature = "const_ipv4", issue = "76205")] #[must_use] #[inline] pub const fn is_benchmarking(&self) -> bool { diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index a01761ee5d4a3..2672fe773c224 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -748,7 +748,6 @@ impl f32 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -797,7 +796,6 @@ impl f32 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 2995e41cd6ea0..86082650e5593 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -765,7 +765,6 @@ impl f64 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -814,7 +813,6 @@ impl f64 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 72adb1bf19019..440e75c2113c7 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -477,7 +477,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -573,7 +572,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_unsigned(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -629,7 +627,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -725,7 +722,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub_unsigned(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -781,7 +777,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -895,7 +890,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -969,7 +963,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1042,7 +1035,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem(-1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1115,7 +1107,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem_euclid(-1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1203,7 +1194,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_neg();")] /// #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1266,7 +1256,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = 0x1", stringify!($SelfT), ".strict_shl(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1325,7 +1314,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1391,7 +1379,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(128);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1452,7 +1439,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.unbounded_shr(129), -1);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1519,7 +1505,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_abs();")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1594,7 +1579,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2368,7 +2352,6 @@ macro_rules! int_impl { /// assert_eq!((sum1, sum0), (6, 8)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2476,7 +2459,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((diff1, diff0), (10, ", stringify!($UnsignedT), "::MAX));")] /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 6a0b40ff51771..9e0af8b2ace8c 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -114,7 +114,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -142,7 +141,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -170,7 +168,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -196,7 +193,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -229,7 +225,6 @@ macro_rules! widening_impl { /// assert_eq!(1_000_000_000u32.widening_mul(10), (1410065408, 2)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -320,7 +315,6 @@ macro_rules! widening_impl { /// ); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -915,7 +909,6 @@ impl u8 { /// ``` #[must_use] #[unstable(feature = "is_ascii_octdigit", issue = "101288")] - #[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")] #[inline] pub const fn is_ascii_octdigit(&self) -> bool { matches!(*self, b'0'..=b'7') @@ -1195,7 +1188,6 @@ impl u16 { /// ``` #[must_use] #[unstable(feature = "utf16_extra", issue = "94919")] - #[rustc_const_unstable(feature = "utf16_extra_const", issue = "94919")] #[inline] pub const fn is_utf16_surrogate(self) -> bool { matches!(self, 0xD800..=0xDFFF) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index f04c83693ef63..e2560f48e5998 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -1474,7 +1474,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods { /// # } /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ded8997c634ed..550b6a087f923 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -524,7 +524,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -626,7 +625,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_signed(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -691,7 +689,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0", stringify!($SelfT), ".strict_sub(1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -873,7 +870,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -975,7 +971,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1035,7 +1030,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1097,7 +1091,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1159,7 +1152,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1392,7 +1384,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 1", stringify!($SelfT), ".strict_neg();")] /// #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1455,7 +1446,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shl(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1514,7 +1504,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1580,7 +1569,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1639,7 +1627,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1714,7 +1701,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2290,7 +2276,6 @@ macro_rules! uint_impl { /// assert_eq!((sum1, sum0), (9, 6)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2382,7 +2367,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!((diff1, diff0), (3, ", stringify!($SelfT), "::MAX));")] /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 57a7c0fc0925c..f00984da5270a 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -240,7 +240,6 @@ impl *const T { /// /// The pointer can be later reconstructed with [`from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn to_raw_parts(self) -> (*const (), ::Metadata) { (self.cast(), metadata(self)) @@ -316,7 +315,6 @@ impl *const T { /// ``` // FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T { @@ -1714,7 +1712,6 @@ impl *const [T] { /// ``` #[inline] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] pub const fn as_ptr(self) -> *const T { self as *const T } @@ -1814,7 +1811,6 @@ impl *const [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_ptr(self) -> *const T { self as *const T } @@ -1832,7 +1828,6 @@ impl *const [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_slice(self) -> *const [T] { self } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 7aa6a309a06b5..60a2dcd1ee72a 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -225,7 +225,6 @@ impl *mut T { /// /// The pointer can be later reconstructed with [`from_raw_parts_mut`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn to_raw_parts(self) -> (*mut (), ::Metadata) { (self.cast(), super::metadata(self)) @@ -306,7 +305,6 @@ impl *mut T { /// ``` // FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T { @@ -659,7 +657,6 @@ impl *mut T { /// ``` // FIXME: mention it in the docs for `as_mut` and `as_uninit_mut` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_mut_unchecked<'a>(self) -> &'a mut T { @@ -2059,7 +2056,6 @@ impl *mut [T] { /// ``` #[inline(always)] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] pub const fn as_mut_ptr(self) -> *mut T { self as *mut T } @@ -2215,7 +2211,6 @@ impl *mut [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_mut_ptr(self) -> *mut T { self as *mut T } @@ -2236,7 +2231,6 @@ impl *mut [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_mut_slice(self) -> *mut [T] { self } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index afc0c0123fa92..44eeb052661b2 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -131,7 +131,6 @@ impl NonNull { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_ref<'a>(self) -> &'a MaybeUninit { // SAFETY: the caller must guarantee that `self` meets all the // requirements for a reference. @@ -155,7 +154,6 @@ impl NonNull { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_mut<'a>(self) -> &'a mut MaybeUninit { // SAFETY: the caller must guarantee that `self` meets all the // requirements for a reference. @@ -230,7 +228,6 @@ impl NonNull { /// Converts a reference to a `NonNull` pointer. #[unstable(feature = "non_null_from_ref", issue = "130823")] - #[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")] #[inline] pub const fn from_ref(r: &T) -> Self { // SAFETY: A reference cannot be null. @@ -239,7 +236,6 @@ impl NonNull { /// Converts a mutable reference to a `NonNull` pointer. #[unstable(feature = "non_null_from_ref", issue = "130823")] - #[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")] #[inline] pub const fn from_mut(r: &mut T) -> Self { // SAFETY: A mutable reference cannot be null. @@ -253,7 +249,6 @@ impl NonNull { /// /// [`std::ptr::from_raw_parts`]: crate::ptr::from_raw_parts #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn from_raw_parts( data_pointer: NonNull<()>, @@ -269,7 +264,6 @@ impl NonNull { /// /// The pointer can be later reconstructed with [`NonNull::from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1545,7 +1539,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] #[rustc_never_returns_null_ptr] pub const fn as_mut_ptr(self) -> *mut T { self.as_non_null_ptr().as_ptr() @@ -1591,7 +1584,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_slice<'a>(self) -> &'a [MaybeUninit] { // SAFETY: the caller must uphold the safety contract for `as_uninit_slice`. unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) } @@ -1656,7 +1648,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_slice_mut<'a>(self) -> &'a mut [MaybeUninit] { // SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`. unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) } diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index c997e5e443dac..2bc1f1e49733f 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -218,7 +218,6 @@ pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str { #[inline] #[must_use] #[unstable(feature = "str_from_raw_parts", issue = "119206")] -#[rustc_const_unstable(feature = "str_from_raw_parts", issue = "119206")] pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str { // SAFETY: the caller must uphold the safety contract for `from_raw_parts`. unsafe { &*ptr::from_raw_parts(ptr, len) } @@ -237,7 +236,6 @@ pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str { #[inline] #[must_use] #[unstable(feature = "str_from_raw_parts", issue = "119206")] -#[rustc_const_unstable(feature = "const_str_from_raw_parts_mut", issue = "119206")] pub const unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut str { // SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`. unsafe { &mut *ptr::from_raw_parts_mut(ptr, len) } diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index af25f13973918..340b0b79e40a3 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -130,7 +130,6 @@ impl Exclusive { /// access to the underlying value, but _pinned_ `Exclusive`s only /// produce _pinned_ access to the underlying value. #[unstable(feature = "exclusive_wrapper", issue = "98407")] - #[rustc_const_unstable(feature = "exclusive_wrapper", issue = "98407")] #[must_use] #[inline] pub const fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { @@ -154,7 +153,6 @@ impl Exclusive { /// a _pinned mutable_ reference to a `T`. This allows you to skip /// building an `Exclusive` with [`Exclusive::new`]. #[unstable(feature = "exclusive_wrapper", issue = "98407")] - #[rustc_const_unstable(feature = "exclusive_wrapper", issue = "98407")] #[must_use] #[inline] pub const fn from_pin_mut(r: Pin<&'_ mut T>) -> Pin<&'_ mut Exclusive> { diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index fb7af8234ddb1..34673707f010a 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -253,7 +253,6 @@ impl<'a> Context<'a> { /// Returns a reference to the [`LocalWaker`] for the current task. #[inline] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const fn local_waker(&self) -> &'a LocalWaker { &self.local_waker } @@ -261,7 +260,6 @@ impl<'a> Context<'a> { /// Returns a reference to the extension data for the current task. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn ext(&mut self) -> &mut dyn Any { // FIXME: this field makes Context extra-weird about unwind safety // can we justify AssertUnwindSafe if we stabilize this? do we care? @@ -337,7 +335,6 @@ impl<'a> ContextBuilder<'a> { /// Creates a ContextBuilder from an existing Context. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn from(cx: &'a mut Context<'_>) -> Self { let ext = match &mut cx.ext.0 { ExtData::Some(ext) => ExtData::Some(*ext), @@ -355,7 +352,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the waker on `Context`. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn waker(self, waker: &'a Waker) -> Self { Self { waker, ..self } } @@ -363,7 +359,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the local waker on `Context`. #[inline] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self { Self { local_waker, ..self } } @@ -371,7 +366,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the extension data on `Context`. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn ext(self, data: &'a mut dyn Any) -> Self { Self { ext: ExtData::Some(data), ..self } } @@ -834,7 +828,6 @@ impl LocalWaker { #[inline] #[must_use] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker { Self { waker } } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 5081e777af464..2d93148bac09f 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -883,7 +883,6 @@ impl Duration { #[unstable(feature = "duration_millis_float", issue = "122451")] #[must_use] #[inline] - #[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")] pub const fn as_millis_f64(&self) -> f64 { (self.secs as f64) * (MILLIS_PER_SEC as f64) + (self.nanos.0 as f64) / (NANOS_PER_MILLI as f64) @@ -904,7 +903,6 @@ impl Duration { #[unstable(feature = "duration_millis_float", issue = "122451")] #[must_use] #[inline] - #[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")] pub const fn as_millis_f32(&self) -> f32 { (self.secs as f32) * (MILLIS_PER_SEC as f32) + (self.nanos.0 as f32) / (NANOS_PER_MILLI as f32) diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index cba53bf5054e6..4101aa5292e8e 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -1,6 +1,5 @@ ///! This file is generated by src/tools/unicode-table-generator; do not edit manually! -#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] #[inline(always)] const fn bitset_search< const N: usize, @@ -424,7 +423,6 @@ pub mod lowercase { (5, 187), (6, 78), (7, 132), ]; - #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32, @@ -549,7 +547,6 @@ pub mod uppercase { (2, 146), (2, 20), (3, 146), (3, 140), (3, 134), (4, 178), (4, 171), ]; - #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32, diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 2a9f1660a629e..7346d9f231939 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -17,13 +17,11 @@ #![feature(clone_to_uninit)] #![feature(const_align_of_val_raw)] #![feature(const_align_offset)] -#![feature(const_bigint_helper_methods)] #![feature(const_black_box)] #![feature(const_eval_select)] #![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] -#![feature(const_num_midpoint)] #![feature(const_option_ext)] #![feature(const_pin_2)] #![feature(const_pointer_is_aligned)] diff --git a/src/tools/unicode-table-generator/src/range_search.rs b/src/tools/unicode-table-generator/src/range_search.rs index 221e5d75ef568..9a51979a2f0d9 100644 --- a/src/tools/unicode-table-generator/src/range_search.rs +++ b/src/tools/unicode-table-generator/src/range_search.rs @@ -1,4 +1,3 @@ -#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] #[inline(always)] const fn bitset_search< const N: usize, diff --git a/src/tools/unicode-table-generator/src/raw_emitter.rs b/src/tools/unicode-table-generator/src/raw_emitter.rs index 8097d6a8caf35..46010692fe561 100644 --- a/src/tools/unicode-table-generator/src/raw_emitter.rs +++ b/src/tools/unicode-table-generator/src/raw_emitter.rs @@ -97,11 +97,6 @@ impl RawEmitter { self.blank_line(); - writeln!( - &mut self.file, - r#"#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")]"# - ) - .unwrap(); writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap(); if first_code_point > 0x7f { writeln!(&mut self.file, " (c as u32) >= {first_code_point:#04x} &&").unwrap(); From 720d618b5fe92efded36178bcc0f5796646d73c1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Nov 2024 10:06:52 +0100 Subject: [PATCH 44/59] unicode_data.rs: show command for generating file --- library/core/src/unicode/unicode_data.rs | 2 +- src/tools/unicode-table-generator/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index cba53bf5054e6..5465fff5f887d 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -1,4 +1,4 @@ -///! This file is generated by src/tools/unicode-table-generator; do not edit manually! +///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually! #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] #[inline(always)] diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index e1832091d7029..415db2c4dbc05 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -268,7 +268,7 @@ fn main() { let mut table_file = String::new(); table_file.push_str( - "///! This file is generated by src/tools/unicode-table-generator; do not edit manually!\n", + "///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually!\n", ); // Include the range search function From 34432f749463983e140e5047fb33b212e695f36a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Nov 2024 11:22:22 +0100 Subject: [PATCH 45/59] const_with_hasher test: actually construct a usable HashMap --- library/std/src/collections/hash/map/tests.rs | 26 ++++++++++++++++--- library/std/src/lib.rs | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index b79ad1c3119ff..a275488a55602 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -5,7 +5,7 @@ use super::Entry::{Occupied, Vacant}; use super::HashMap; use crate::assert_matches::assert_matches; use crate::cell::RefCell; -use crate::hash::RandomState; +use crate::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, RandomState}; use crate::test_helpers::test_rng; // https://github.com/rust-lang/rust/issues/62301 @@ -1124,6 +1124,26 @@ fn from_array() { #[test] fn const_with_hasher() { - const X: HashMap<(), (), ()> = HashMap::with_hasher(()); - assert_eq!(X.len(), 0); + const X: HashMap<(), (), BuildHasherDefault> = + HashMap::with_hasher(BuildHasherDefault::new()); + let mut x = X; + assert_eq!(x.len(), 0); + x.insert((), ()); + assert_eq!(x.len(), 1); + + // It *is* possible to do this without using the `BuildHasherDefault` type. + struct MyBuildDefaultHasher; + impl BuildHasher for MyBuildDefaultHasher { + type Hasher = DefaultHasher; + + fn build_hasher(&self) -> Self::Hasher { + DefaultHasher::new() + } + } + + const Y: HashMap<(), (), MyBuildDefaultHasher> = HashMap::with_hasher(MyBuildDefaultHasher); + let mut y = Y; + assert_eq!(y.len(), 0); + y.insert((), ()); + assert_eq!(y.len(), 1); } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 1de52eb7b21b2..887d845e03c31 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -328,6 +328,7 @@ // Library features (core): // tidy-alphabetical-start #![feature(array_chunks)] +#![feature(build_hasher_default_const_new)] #![feature(c_str_module)] #![feature(char_internals)] #![feature(clone_to_uninit)] From 52666238cfadb8b5780ffa337ad3128c2c7726af Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Nov 2024 11:24:28 +0100 Subject: [PATCH 46/59] remove const_hash feature leftovers --- library/core/src/hash/sip.rs | 12 ++++-------- library/core/src/lib.rs | 1 - library/core/tests/lib.rs | 1 - library/std/src/hash/random.rs | 3 +-- library/std/src/lib.rs | 1 - 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/library/core/src/hash/sip.rs b/library/core/src/hash/sip.rs index 17f2caaa0c083..6ea3241c59354 100644 --- a/library/core/src/hash/sip.rs +++ b/library/core/src/hash/sip.rs @@ -147,9 +147,8 @@ impl SipHasher { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")] - #[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[must_use] - pub const fn new() -> SipHasher { + pub fn new() -> SipHasher { SipHasher::new_with_keys(0, 0) } @@ -157,9 +156,8 @@ impl SipHasher { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")] - #[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[must_use] - pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher { + pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher { SipHasher(SipHasher24 { hasher: Hasher::new_with_keys(key0, key1) }) } } @@ -169,8 +167,7 @@ impl SipHasher13 { #[inline] #[unstable(feature = "hashmap_internals", issue = "none")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")] - #[rustc_const_unstable(feature = "const_hash", issue = "104061")] - pub const fn new() -> SipHasher13 { + pub fn new() -> SipHasher13 { SipHasher13::new_with_keys(0, 0) } @@ -178,8 +175,7 @@ impl SipHasher13 { #[inline] #[unstable(feature = "hashmap_internals", issue = "none")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")] - #[rustc_const_unstable(feature = "const_hash", issue = "104061")] - pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 { + pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 { SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) } } } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 115fdd7a14024..8110983e37dfe 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -122,7 +122,6 @@ #![feature(const_eval_select)] #![feature(const_exact_div)] #![feature(const_float_methods)] -#![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] #![feature(const_num_midpoint)] diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 2a9f1660a629e..2115e04a15eb0 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -20,7 +20,6 @@ #![feature(const_bigint_helper_methods)] #![feature(const_black_box)] #![feature(const_eval_select)] -#![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] #![feature(const_num_midpoint)] diff --git a/library/std/src/hash/random.rs b/library/std/src/hash/random.rs index 40f3a90f60c8a..236803b24a2ec 100644 --- a/library/std/src/hash/random.rs +++ b/library/std/src/hash/random.rs @@ -105,9 +105,8 @@ impl DefaultHasher { #[stable(feature = "hashmap_default_hasher", since = "1.13.0")] #[inline] #[allow(deprecated)] - #[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[must_use] - pub const fn new() -> DefaultHasher { + pub fn new() -> DefaultHasher { DefaultHasher(SipHasher13::new_with_keys(0, 0)) } } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 887d845e03c31..0fdfcef3081f0 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -416,7 +416,6 @@ // Only for const-ness: // tidy-alphabetical-start #![feature(const_collections_with_hasher)] -#![feature(const_hash)] #![feature(thread_local_internals)] // tidy-alphabetical-end // From 8837fc75426831d3f895d460bf86d5634f4458ce Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Sat, 2 Nov 2024 12:10:37 +0100 Subject: [PATCH 47/59] make codegen help output more consistent The output of `rustc -C help` generally has one option per line. There was one exception because of a (presumably) forgotten line continuation escape. --- compiler/rustc_session/src/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2b158627751bc..6ce737d4d4583 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1585,7 +1585,7 @@ options! { link_dead_code: Option = (None, parse_opt_bool, [TRACKED], "keep dead code at link time (useful for code coverage) (default: no)"), link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED], - "control whether to link Rust provided C objects/libraries or rely + "control whether to link Rust provided C objects/libraries or rely \ on a C toolchain or linker installed in the system"), linker: Option = (None, parse_opt_pathbuf, [UNTRACKED], "system linker to link outputs with"), From afe190204b0cdb37a2e09dd0899421cdad98e262 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 1 Nov 2024 12:47:53 +1100 Subject: [PATCH 48/59] coverage: Regression test for inlining into an uninstrumented crate --- .../coverage/auxiliary/inline_mixed_helper.rs | 13 +++++++++++++ tests/coverage/inline_mixed.rs | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/coverage/auxiliary/inline_mixed_helper.rs create mode 100644 tests/coverage/inline_mixed.rs diff --git a/tests/coverage/auxiliary/inline_mixed_helper.rs b/tests/coverage/auxiliary/inline_mixed_helper.rs new file mode 100644 index 0000000000000..1e91ab8ce7c03 --- /dev/null +++ b/tests/coverage/auxiliary/inline_mixed_helper.rs @@ -0,0 +1,13 @@ +//@ edition: 2021 +//@ compile-flags: -Cinstrument-coverage=on + +#[inline] +pub fn inline_me() {} + +#[inline(never)] +pub fn no_inlining_please() {} + +pub fn generic() {} + +// FIXME(#132436): Even though this doesn't ICE, it still produces coverage +// reports that undercount the affected code. diff --git a/tests/coverage/inline_mixed.rs b/tests/coverage/inline_mixed.rs new file mode 100644 index 0000000000000..163cc7d7d6c5b --- /dev/null +++ b/tests/coverage/inline_mixed.rs @@ -0,0 +1,19 @@ +//@ edition: 2021 +//@ compile-flags: -Cinstrument-coverage=off +//@ ignore-coverage-run +//@ aux-crate: inline_mixed_helper=inline_mixed_helper.rs + +// Regression test for . +// Various forms of cross-crate inlining can cause coverage statements to be +// inlined into crates that are being built without coverage instrumentation. +// At the very least, we need to not ICE when that happens. + +fn main() { + inline_mixed_helper::inline_me(); + inline_mixed_helper::no_inlining_please(); + inline_mixed_helper::generic::(); +} + +// FIXME(#132437): We currently don't test this in coverage-run mode, because +// whether or not it produces a `.profraw` file appears to differ between +// platforms. From f341a193666b836e5f2197e1c674b473b43939a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 2 Nov 2024 13:33:39 +0100 Subject: [PATCH 49/59] NFC add known bug nr to test --- .../source-impl-requires-constraining-predicates-ambig.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/specialization/source-impl-requires-constraining-predicates-ambig.rs b/tests/ui/specialization/source-impl-requires-constraining-predicates-ambig.rs index 977493c885b29..2296cd8a93756 100644 --- a/tests/ui/specialization/source-impl-requires-constraining-predicates-ambig.rs +++ b/tests/ui/specialization/source-impl-requires-constraining-predicates-ambig.rs @@ -2,7 +2,7 @@ //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver //@[next] check-pass -//@[current] known-bug: unknown +//@[current] known-bug: #132519 //@[current] failure-status: 101 //@[current] dont-check-compiler-stderr From 36040aacc225c922388a98e74b53222d606b4c9f Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sat, 2 Nov 2024 14:31:41 +1100 Subject: [PATCH 50/59] Add a run-make test for same-arch `--print=target-cpus` --- .../print-target-cpus-native/rmake.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/run-make/print-target-cpus-native/rmake.rs diff --git a/tests/run-make/print-target-cpus-native/rmake.rs b/tests/run-make/print-target-cpus-native/rmake.rs new file mode 100644 index 0000000000000..3bd210654db7f --- /dev/null +++ b/tests/run-make/print-target-cpus-native/rmake.rs @@ -0,0 +1,39 @@ +//@ ignore-cross-compile +//@ needs-llvm-components: aarch64 x86 +// FIXME(#132514): Is needs-llvm-components actually necessary for this test? + +use run_make_support::{assert_contains_regex, rfs, rustc, target}; + +// Test that when querying `--print=target-cpus` for a target with the same +// architecture as the host, the first CPU is "native" with a suitable remark. + +fn main() { + let expected = r"^Available CPUs for this target: + native +- Select the CPU of the current host \(currently [^ )]+\)\. +"; + + // Without an explicit target. + rustc().print("target-cpus").run().assert_stdout_contains_regex(expected); + + // With an explicit target that happens to be the host. + let host = target(); // Because of ignore-cross-compile, assume host == target. + rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected); + + // With an explicit output path. + rustc().print("target-cpus=./xyzzy.txt").run().assert_stdout_equals(""); + assert_contains_regex(rfs::read_to_string("./xyzzy.txt"), expected); + + // Now try some cross-target queries with the same arch as the host. + // (Specify multiple targets so that at least one of them is not the host.) + let cross_targets: &[&str] = if cfg!(target_arch = "aarch64") { + &["aarch64-unknown-linux-gnu", "aarch64-apple-darwin"] + } else if cfg!(target_arch = "x86_64") { + &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"] + } else { + &[] + }; + for target in cross_targets { + println!("Trying target: {target}"); + rustc().print("target-cpus").target(target).run().assert_stdout_contains_regex(expected); + } +} From 0fa86f966062a66f46b6471310d07e00b701e398 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sat, 2 Nov 2024 11:44:15 +1100 Subject: [PATCH 51/59] Use a dedicated safe wrapper for `LLVMRustGetHostCPUName` --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 +- compiler/rustc_codegen_llvm/src/llvm_util.rs | 32 ++++++++++++------- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 4 +-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 5fad7583e1aee..0c0e3b92e5991 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2204,7 +2204,7 @@ unsafe extern "C" { Desc: &mut *const c_char, ); - pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char; + pub fn LLVMRustGetHostCPUName(LenOut: &mut size_t) -> *const u8; // This function makes copies of pointed to data, so the data's lifetime may end after this // function returns. diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 9adb1299b3d31..20144824d88c7 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -476,23 +476,31 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) { } } -fn handle_native(name: &str) -> &str { - if name != "native" { - return name; - } - - unsafe { - let mut len = 0; +/// Returns the host CPU name, according to LLVM. +fn get_host_cpu_name() -> &'static str { + let mut len = 0; + // SAFETY: The underlying C++ global function returns a `StringRef` that + // isn't tied to any particular backing buffer, so it must be 'static. + let slice: &'static [u8] = unsafe { let ptr = llvm::LLVMRustGetHostCPUName(&mut len); - str::from_utf8(slice::from_raw_parts(ptr as *const u8, len)).unwrap() + assert!(!ptr.is_null()); + slice::from_raw_parts(ptr, len) + }; + str::from_utf8(slice).expect("host CPU name should be UTF-8") +} + +/// If the given string is `"native"`, returns the host CPU name according to +/// LLVM. Otherwise, the string is returned as-is. +fn handle_native(cpu_name: &str) -> &str { + match cpu_name { + "native" => get_host_cpu_name(), + _ => cpu_name, } } pub(crate) fn target_cpu(sess: &Session) -> &str { - match sess.opts.cg.target_cpu { - Some(ref name) => handle_native(name), - None => handle_native(sess.target.cpu.as_ref()), - } + let cpu_name = sess.opts.cg.target_cpu.as_deref().unwrap_or_else(|| &sess.target.cpu); + handle_native(cpu_name) } /// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3b7dc6de82553..245edde2768b3 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -382,9 +382,9 @@ extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index, *Desc = Feat.Desc; } -extern "C" const char *LLVMRustGetHostCPUName(size_t *len) { +extern "C" const char *LLVMRustGetHostCPUName(size_t *OutLen) { StringRef Name = sys::getHostCPUName(); - *len = Name.size(); + *OutLen = Name.size(); return Name.data(); } From 90f2075b66c778f8270be86ec34c54ae43831dad Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sat, 2 Nov 2024 12:40:28 +1100 Subject: [PATCH 52/59] Port most of `LLVMRustPrintTargetCPUs` to Rust --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 8 +- compiler/rustc_codegen_llvm/src/llvm_util.rs | 92 ++++++++++++------- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 46 ++-------- 3 files changed, 70 insertions(+), 76 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 0c0e3b92e5991..d84ae8d8836b9 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2190,12 +2190,8 @@ unsafe extern "C" { pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool; - pub fn LLVMRustPrintTargetCPUs( - T: &TargetMachine, - cpu: *const c_char, - print: unsafe extern "C" fn(out: *mut c_void, string: *const c_char, len: usize), - out: *mut c_void, - ); + #[allow(improper_ctypes)] + pub(crate) fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString); pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t; pub fn LLVMRustGetTargetFeature( T: &TargetMachine, diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 20144824d88c7..5b0a42d4532d2 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -1,4 +1,5 @@ -use std::ffi::{CStr, CString, c_char, c_void}; +use std::collections::VecDeque; +use std::ffi::{CStr, CString}; use std::fmt::Write; use std::path::Path; use std::sync::Once; @@ -387,7 +388,65 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> { ret } -fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMachine) { +pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) { + require_inited(); + let tm = create_informational_target_machine(sess, false); + match req.kind { + PrintKind::TargetCPUs => print_target_cpus(sess, &tm, out), + PrintKind::TargetFeatures => print_target_features(sess, &tm, out), + _ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req), + } +} + +fn print_target_cpus(sess: &Session, tm: &llvm::TargetMachine, out: &mut String) { + let cpu_names = llvm::build_string(|s| unsafe { + llvm::LLVMRustPrintTargetCPUs(&tm, s); + }) + .unwrap(); + + struct Cpu<'a> { + cpu_name: &'a str, + remark: String, + } + // Compare CPU against current target to label the default. + let target_cpu = handle_native(&sess.target.cpu); + let make_remark = |cpu_name| { + if cpu_name == target_cpu { + // FIXME(#132514): This prints the LLVM target string, which can be + // different from the Rust target string. Is that intended? + let target = &sess.target.llvm_target; + format!( + " - This is the default target CPU for the current build target (currently {target})." + ) + } else { + "".to_owned() + } + }; + let mut cpus = cpu_names + .lines() + .map(|cpu_name| Cpu { cpu_name, remark: make_remark(cpu_name) }) + .collect::>(); + + // Only print the "native" entry when host and target are the same arch, + // since otherwise it could be wrong or misleading. + if sess.host.arch == sess.target.arch { + let host = get_host_cpu_name(); + cpus.push_front(Cpu { + cpu_name: "native", + remark: format!(" - Select the CPU of the current host (currently {host})."), + }); + } + + let max_name_width = cpus.iter().map(|cpu| cpu.cpu_name.len()).max().unwrap_or(0); + writeln!(out, "Available CPUs for this target:").unwrap(); + for Cpu { cpu_name, remark } in cpus { + // Only pad the CPU name if there's a remark to print after it. + let width = if remark.is_empty() { 0 } else { max_name_width }; + writeln!(out, " {cpu_name:::default(); let mut rustc_target_features = sess @@ -447,35 +506,6 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n").unwrap(); } -pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) { - require_inited(); - let tm = create_informational_target_machine(sess, false); - match req.kind { - PrintKind::TargetCPUs => { - // SAFETY generate a C compatible string from a byte slice to pass - // the target CPU name into LLVM, the lifetime of the reference is - // at least as long as the C function - let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref())) - .unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e)); - unsafe extern "C" fn callback(out: *mut c_void, string: *const c_char, len: usize) { - let out = unsafe { &mut *(out as *mut &mut String) }; - let bytes = unsafe { slice::from_raw_parts(string as *const u8, len) }; - write!(out, "{}", String::from_utf8_lossy(bytes)).unwrap(); - } - unsafe { - llvm::LLVMRustPrintTargetCPUs( - &tm, - cpu_cstring.as_ptr(), - callback, - (&raw mut out) as *mut c_void, - ); - } - } - PrintKind::TargetFeatures => print_target_features(out, sess, &tm), - _ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req), - } -} - /// Returns the host CPU name, according to LLVM. fn get_host_cpu_name() -> &'static str { let mut len = 0; diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 245edde2768b3..e571e1900ca12 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -317,49 +317,17 @@ template static size_t getLongestEntryLength(ArrayRef Table) { return MaxLen; } -using PrintBackendInfo = void(void *, const char *Data, size_t Len); - extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, - const char *TargetCPU, - PrintBackendInfo Print, void *Out) { - const TargetMachine *Target = unwrap(TM); - const Triple::ArchType HostArch = - Triple(sys::getDefaultTargetTriple()).getArch(); - const Triple::ArchType TargetArch = Target->getTargetTriple().getArch(); + RustStringRef OutStr) { + ArrayRef CPUTable = + unwrap(TM)->getMCSubtargetInfo()->getAllProcessorDescriptions(); + auto OS = RawRustStringOstream(OutStr); - std::ostringstream Buf; - - const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); - const ArrayRef CPUTable = - MCInfo->getAllProcessorDescriptions(); - unsigned MaxCPULen = getLongestEntryLength(CPUTable); - - Buf << "Available CPUs for this target:\n"; - // Don't print the "native" entry when the user specifies --target with a - // different arch since that could be wrong or misleading. - if (HostArch == TargetArch) { - MaxCPULen = std::max(MaxCPULen, (unsigned)std::strlen("native")); - const StringRef HostCPU = sys::getHostCPUName(); - Buf << " " << std::left << std::setw(MaxCPULen) << "native" - << " - Select the CPU of the current host " - "(currently " - << HostCPU.str() << ").\n"; - } + // Just print a bare list of target CPU names, and let Rust-side code handle + // the full formatting of `--print=target-cpus`. for (auto &CPU : CPUTable) { - // Compare cpu against current target to label the default - if (strcmp(CPU.Key, TargetCPU) == 0) { - Buf << " " << std::left << std::setw(MaxCPULen) << CPU.Key - << " - This is the default target CPU for the current build target " - "(currently " - << Target->getTargetTriple().str() << ")."; - } else { - Buf << " " << CPU.Key; - } - Buf << "\n"; + OS << CPU.Key << "\n"; } - - const auto &BufString = Buf.str(); - Print(Out, BufString.data(), BufString.size()); } extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) { From b9196757a0c2c9ddbbca4372ca272b0e1fec077f Mon Sep 17 00:00:00 2001 From: ranger-ross Date: Sat, 2 Nov 2024 17:17:53 +0900 Subject: [PATCH 53/59] Added regression test for 117446 --- .../ice-index-out-of-bounds-issue-117446.rs | 24 ++++++++++++++ ...ce-index-out-of-bounds-issue-117446.stderr | 33 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/ui/traits/ice-index-out-of-bounds-issue-117446.rs create mode 100644 tests/ui/traits/ice-index-out-of-bounds-issue-117446.stderr diff --git a/tests/ui/traits/ice-index-out-of-bounds-issue-117446.rs b/tests/ui/traits/ice-index-out-of-bounds-issue-117446.rs new file mode 100644 index 0000000000000..fa31d8b820c81 --- /dev/null +++ b/tests/ui/traits/ice-index-out-of-bounds-issue-117446.rs @@ -0,0 +1,24 @@ +//@ check-fail +// +// Regression for https://github.com/rust-lang/rust/issues/117446 + +pub struct Repeated(Vec); + +trait Foo<'a> { + fn outer() -> Option<()>; +} + +impl<'a, T> Foo<'a> for Repeated { + fn outer() -> Option<()> { + //~^ ERROR associated function `outer` has 0 type parameters but its trait declaration has 1 type parameter [E0049] + //~^^ ERROR mismatched types [E0308] + fn inner(value: Option<()>) -> Repeated { + match value { + _ => Self(unimplemented!()), + //~^ ERROR can't reference `Self` constructor from outer item [E0401] + } + } + } +} + +fn main() {} diff --git a/tests/ui/traits/ice-index-out-of-bounds-issue-117446.stderr b/tests/ui/traits/ice-index-out-of-bounds-issue-117446.stderr new file mode 100644 index 0000000000000..ad33a70ed3bb6 --- /dev/null +++ b/tests/ui/traits/ice-index-out-of-bounds-issue-117446.stderr @@ -0,0 +1,33 @@ +error[E0049]: associated function `outer` has 0 type parameters but its trait declaration has 1 type parameter + --> $DIR/ice-index-out-of-bounds-issue-117446.rs:12:13 + | +LL | fn outer() -> Option<()>; + | - expected 1 type parameter +... +LL | fn outer() -> Option<()> { + | ^ found 0 type parameters + +error[E0308]: mismatched types + --> $DIR/ice-index-out-of-bounds-issue-117446.rs:12:19 + | +LL | fn outer() -> Option<()> { + | ----- ^^^^^^^^^^ expected `Option<()>`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected enum `Option<()>` + found unit type `()` + +error[E0401]: can't reference `Self` constructor from outer item + --> $DIR/ice-index-out-of-bounds-issue-117446.rs:17:22 + | +LL | impl<'a, T> Foo<'a> for Repeated { + | ----------------------------------- the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference +... +LL | _ => Self(unimplemented!()), + | ^^^^ help: replace `Self` with the actual type: `Repeated` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0049, E0308, E0401. +For more information about an error, try `rustc --explain E0049`. From 5b1246bb4bed72fd0bb8fa497d8e5ed2c7f3515c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:16:06 +0000 Subject: [PATCH 54/59] Rustup to rustc 1.84.0-nightly (705cfe0e9 2024-11-01) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 87426f7b8d554..2558b2b9f5dde 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-31" +channel = "nightly-2024-11-02" components = ["rust-src", "rustc-dev", "llvm-tools"] profile = "minimal" From c959f6e5fd13fc8312d96aeb0fa0ae7e70f0ad98 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:21:38 +0000 Subject: [PATCH 55/59] Update tidy license exceptions and allowed dependencies --- src/tools/tidy/src/deps.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index f3bd72fe64776..bad7b5783bc9a 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -203,7 +203,7 @@ const EXCEPTIONS_CRANELIFT: ExceptionList = &[ ("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"), + ("mach2", "BSD-2-Clause OR MIT OR Apache-2.0"), ("regalloc2", "Apache-2.0 WITH LLVM-exception"), ("target-lexicon", "Apache-2.0 WITH LLVM-exception"), ("wasmtime-jit-icache-coherence", "Apache-2.0 WITH LLVM-exception"), @@ -537,7 +537,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "libc", "libloading", "log", - "mach", + "mach2", "memchr", "object", "once_cell", @@ -554,9 +554,6 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "unicode-ident", "version_check", "wasmtime-jit-icache-coherence", - "winapi", - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", "windows-sys", "windows-targets", "windows_aarch64_gnullvm", From 82f8b8f0e3f44c7280f21364b54840f59890610a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 2 Nov 2024 15:24:57 +0000 Subject: [PATCH 56/59] Use opt functions to not ICE in fallback suggestion --- compiler/rustc_hir_typeck/src/fallback.rs | 7 ++++--- tests/ui/never_type/suggestion-ice-132517.rs | 4 ++++ tests/ui/never_type/suggestion-ice-132517.stderr | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/ui/never_type/suggestion-ice-132517.rs create mode 100644 tests/ui/never_type/suggestion-ice-132517.stderr diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 8d8573c65c5b8..97f3807c2521e 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result { // Try to replace `_` with `()`. if let hir::TyKind::Infer = hir_ty.kind - && let ty = self.fcx.typeck_results.borrow().node_type(hir_ty.hir_id) + && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(hir_ty.hir_id) && let Some(vid) = self.fcx.root_vid(ty) && self.reachable_vids.contains(&vid) { @@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind && let Res::Def(DefKind::AssocFn, def_id) = path.res && self.fcx.tcx.trait_of_item(def_id).is_some() - && let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0) + && let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id) + && let self_ty = args.type_at(0) && let Some(vid) = self.fcx.root_vid(self_ty) && self.reachable_vids.contains(&vid) && let [.., trait_segment, _method_segment] = path.segments @@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result { // For a local, try suggest annotating the type if it's missing. if let None = local.ty - && let ty = self.fcx.typeck_results.borrow().node_type(local.hir_id) + && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id) && let Some(vid) = self.fcx.root_vid(ty) && self.reachable_vids.contains(&vid) { diff --git a/tests/ui/never_type/suggestion-ice-132517.rs b/tests/ui/never_type/suggestion-ice-132517.rs new file mode 100644 index 0000000000000..c1730d06f6b1d --- /dev/null +++ b/tests/ui/never_type/suggestion-ice-132517.rs @@ -0,0 +1,4 @@ +fn main() { + x::<_>(|_| panic!()) + //~^ ERROR cannot find function `x` in this scope +} diff --git a/tests/ui/never_type/suggestion-ice-132517.stderr b/tests/ui/never_type/suggestion-ice-132517.stderr new file mode 100644 index 0000000000000..4f280a0e4f152 --- /dev/null +++ b/tests/ui/never_type/suggestion-ice-132517.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `x` in this scope + --> $DIR/suggestion-ice-132517.rs:2:5 + | +LL | x::<_>(|_| panic!()) + | ^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0425`. From ab5583ed1e75869b765a90386dac9119992f8ed7 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Thu, 31 Oct 2024 14:41:35 -0400 Subject: [PATCH 57/59] PassWrapper: adapt for llvm/llvm-project@b01e2a8b5620466c3b80cc6f049efbc90b9d103a We don't see a reason to explicitly pass the default here, so just use the default instead of explicitly passing it and needing an ifdef. @rustbot label: +llvm-main --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3e906f89c15c3..6dfda10b38bd2 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -827,9 +827,9 @@ extern "C" LLVMRustResult LLVMRustOptimize( !NoPrepopulatePasses) { PipelineStartEPCallbacks.push_back( [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr, - /*ImportSummary=*/nullptr, - /*DropTypeTests=*/false)); + MPM.addPass(LowerTypeTestsPass( + /*ExportSummary=*/nullptr, + /*ImportSummary=*/nullptr)); }); } From c7b07d58c32d015e8f26da0bd3defd6898aac2b7 Mon Sep 17 00:00:00 2001 From: tuturuu Date: Thu, 31 Oct 2024 08:23:50 +0100 Subject: [PATCH 58/59] Rustdoc: added brief colon explanation --- library/alloc/src/fmt.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/alloc/src/fmt.rs b/library/alloc/src/fmt.rs index 3da71038a5e76..695dddb25eeb4 100644 --- a/library/alloc/src/fmt.rs +++ b/library/alloc/src/fmt.rs @@ -109,6 +109,16 @@ //! parameters (corresponding to `format_spec` in [the syntax](#syntax)). These //! parameters affect the string representation of what's being formatted. //! +//! The colon `:` in format syntax divides indentifier of the input data and +//! the formatting options, the colon itself does not change anything, only +//! introduces the options. +//! +//! ``` +//! let a = 5; +//! let b = &a; +//! println!("{a:e} {b:p}"); // => 5e0 0x7ffe37b7273c +//! ``` +//! //! ## Width //! //! ``` From 16394e9776e1be1abc61a9b26baf73070aa7c37b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 2 Nov 2024 20:25:02 +0000 Subject: [PATCH 59/59] Do not format generic consts --- compiler/rustc_ast/src/ast.rs | 6 +++++ src/tools/rustfmt/src/items.rs | 27 ++++++++++++++----- .../rustfmt/tests/target/const-generics.rs | 25 +++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/tools/rustfmt/tests/target/const-generics.rs diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ec6ca70ae0a4b..997c44cffff03 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -414,6 +414,12 @@ pub struct WhereClause { pub span: Span, } +impl WhereClause { + pub fn is_empty(&self) -> bool { + !self.has_where_token && self.predicates.is_empty() + } +} + impl Default for WhereClause { fn default() -> WhereClause { WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP } diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index fc043a697e039..327a547b2959c 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -2009,6 +2009,7 @@ pub(crate) struct StaticParts<'a> { safety: ast::Safety, vis: &'a ast::Visibility, ident: symbol::Ident, + generics: Option<&'a ast::Generics>, ty: &'a ast::Ty, mutability: ast::Mutability, expr_opt: Option<&'a ptr::P>, @@ -2018,8 +2019,10 @@ pub(crate) struct StaticParts<'a> { impl<'a> StaticParts<'a> { pub(crate) fn from_item(item: &'a ast::Item) -> Self { - let (defaultness, prefix, safety, ty, mutability, expr) = match &item.kind { - ast::ItemKind::Static(s) => (None, "static", s.safety, &s.ty, s.mutability, &s.expr), + let (defaultness, prefix, safety, ty, mutability, expr, generics) = match &item.kind { + ast::ItemKind::Static(s) => { + (None, "static", s.safety, &s.ty, s.mutability, &s.expr, None) + } ast::ItemKind::Const(c) => ( Some(c.defaultness), "const", @@ -2027,6 +2030,7 @@ impl<'a> StaticParts<'a> { &c.ty, ast::Mutability::Not, &c.expr, + Some(&c.generics), ), _ => unreachable!(), }; @@ -2035,6 +2039,7 @@ impl<'a> StaticParts<'a> { safety, vis: &item.vis, ident: item.ident, + generics, ty, mutability, expr_opt: expr.as_ref(), @@ -2044,8 +2049,8 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self { - let (defaultness, ty, expr_opt) = match &ti.kind { - ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr), + let (defaultness, ty, expr_opt, generics) = match &ti.kind { + ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)), _ => unreachable!(), }; StaticParts { @@ -2053,6 +2058,7 @@ impl<'a> StaticParts<'a> { safety: ast::Safety::Default, vis: &ti.vis, ident: ti.ident, + generics, ty, mutability: ast::Mutability::Not, expr_opt: expr_opt.as_ref(), @@ -2062,8 +2068,8 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self { - let (defaultness, ty, expr) = match &ii.kind { - ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr), + let (defaultness, ty, expr, generics) = match &ii.kind { + ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)), _ => unreachable!(), }; StaticParts { @@ -2071,6 +2077,7 @@ impl<'a> StaticParts<'a> { safety: ast::Safety::Default, vis: &ii.vis, ident: ii.ident, + generics, ty, mutability: ast::Mutability::Not, expr_opt: expr.as_ref(), @@ -2085,6 +2092,14 @@ fn rewrite_static( static_parts: &StaticParts<'_>, offset: Indent, ) -> Option { + // For now, if this static (or const) has generics, then bail. + if static_parts + .generics + .is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty()) + { + return None; + } + let colon = colon_spaces(context.config); let mut prefix = format!( "{}{}{}{} {}{}{}", diff --git a/src/tools/rustfmt/tests/target/const-generics.rs b/src/tools/rustfmt/tests/target/const-generics.rs new file mode 100644 index 0000000000000..94f76643664dc --- /dev/null +++ b/src/tools/rustfmt/tests/target/const-generics.rs @@ -0,0 +1,25 @@ +// Make sure we don't mess up the formatting of generic consts + +#![feature(generic_const_items)] + +const GENERIC: i32 = 0; + +const WHERECLAUSE: i32 = 0 +where + i32:; + +trait Foo { + const GENERIC: i32; + + const WHERECLAUSE: i32 + where + i32:; +} + +impl Foo for () { + const GENERIC: i32 = 0; + + const WHERECLAUSE: i32 = 0 + where + i32:; +}