mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Merge commit '63734fcdd718cca089f84c42f3a42c0096cfd431' into sync_cg_clif-2022-05-15
This commit is contained in:
parent
bb7b844d7c
commit
d9025cebac
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
timeout-minutes: 10
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install rustfmt
|
||||
run: |
|
||||
@ -39,7 +39,7 @@ jobs:
|
||||
TARGET_TRIPLE: aarch64-unknown-linux-gnu
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache cargo installed crates
|
||||
uses: actions/cache@v2
|
||||
@ -127,7 +127,7 @@ jobs:
|
||||
timeout-minutes: 60
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
#- name: Cache cargo installed crates
|
||||
# uses: actions/cache@v2
|
||||
|
4
.github/workflows/nightly-cranelift.yml
vendored
4
.github/workflows/nightly-cranelift.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
||||
timeout-minutes: 60
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache cargo installed crates
|
||||
uses: actions/cache@v2
|
||||
@ -34,7 +34,7 @@ jobs:
|
||||
sed -i 's/cranelift-jit = { version = "\w*.\w*.\w*", optional = true }/cranelift-jit = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git", optional = true }/' Cargo.toml
|
||||
sed -i 's/cranelift-object = "\w*.\w*.\w*"/cranelift-object = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml
|
||||
|
||||
sed -i 's/gimli = { version = "0.25.0", default-features = false, features = \["write"\]}/gimli = { version = "0.26.1", default-features = false, features = ["write"] }/' Cargo.toml
|
||||
sed -i 's/object = { version = "0.27.0"/object = { version = "0.28.0"/' Cargo.toml
|
||||
|
||||
cat Cargo.toml
|
||||
|
||||
|
4
.github/workflows/rustc.yml
vendored
4
.github/workflows/rustc.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache cargo installed crates
|
||||
uses: actions/cache@v2
|
||||
@ -46,7 +46,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache cargo installed crates
|
||||
uses: actions/cache@v2
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -5,7 +5,7 @@
|
||||
"rust-analyzer.assist.importEnforceGranularity": true,
|
||||
"rust-analyzer.assist.importPrefix": "crate",
|
||||
"rust-analyzer.cargo.runBuildScripts": true,
|
||||
"rust-analyzer.cargo.features": ["unstable-features"]
|
||||
"rust-analyzer.cargo.features": ["unstable-features"],
|
||||
"rust-analyzer.linkedProjects": [
|
||||
"./Cargo.toml",
|
||||
//"./build_sysroot/sysroot_src/src/libstd/Cargo.toml",
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -41,15 +41,5 @@ unstable-features = ["jit", "inline_asm"]
|
||||
jit = ["cranelift-jit", "libloading"]
|
||||
inline_asm = []
|
||||
|
||||
# Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the
|
||||
# execution time of build scripts is so fast that optimizing them slows down the total build time.
|
||||
[profile.release.build-override]
|
||||
opt-level = 0
|
||||
debug = false
|
||||
|
||||
[profile.release.package.cranelift-codegen-meta]
|
||||
opt-level = 0
|
||||
debug = false
|
||||
|
||||
[package.metadata.rust-analyzer]
|
||||
rustc_private = true
|
||||
|
12
build_sysroot/Cargo.lock
generated
12
build_sysroot/Cargo.lock
generated
@ -112,9 +112,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.0"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
|
||||
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"rustc-std-workspace-alloc",
|
||||
@ -134,18 +134,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.124"
|
||||
version = "0.2.125"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
|
||||
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
|
||||
dependencies = [
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"rustc-std-workspace-core",
|
||||
|
@ -34,18 +34,6 @@ pub(crate) fn build_backend(
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
// Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
|
||||
// LD_LIBRARY_PATH
|
||||
if cfg!(unix) {
|
||||
if cfg!(target_os = "macos") {
|
||||
rustflags += " -Csplit-debuginfo=unpacked \
|
||||
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
|
||||
-Zosx-rpath-install-name";
|
||||
} else {
|
||||
rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
|
||||
}
|
||||
}
|
||||
|
||||
cmd.env("RUSTFLAGS", rustflags);
|
||||
|
||||
eprintln!("[BUILD] rustc_codegen_cranelift");
|
||||
|
@ -1,4 +1,3 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Command};
|
||||
@ -22,35 +21,28 @@ pub(crate) fn build_sysroot(
|
||||
fs::create_dir_all(target_dir.join("lib")).unwrap();
|
||||
|
||||
// Copy the backend
|
||||
for file in ["cg_clif", "cg_clif_build_sysroot"] {
|
||||
try_hard_link(
|
||||
cg_clif_build_dir.join(get_file_name(file, "bin")),
|
||||
target_dir.join("bin").join(get_file_name(file, "bin")),
|
||||
);
|
||||
}
|
||||
|
||||
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
|
||||
try_hard_link(
|
||||
cg_clif_build_dir.join(&cg_clif_dylib),
|
||||
target_dir
|
||||
.join(if cfg!(windows) {
|
||||
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
|
||||
// binaries.
|
||||
"bin"
|
||||
} else {
|
||||
"lib"
|
||||
})
|
||||
.join(cg_clif_dylib),
|
||||
);
|
||||
let cg_clif_dylib_path = target_dir
|
||||
.join(if cfg!(windows) {
|
||||
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
|
||||
// binaries.
|
||||
"bin"
|
||||
} else {
|
||||
"lib"
|
||||
})
|
||||
.join(&cg_clif_dylib);
|
||||
try_hard_link(cg_clif_build_dir.join(cg_clif_dylib), &cg_clif_dylib_path);
|
||||
|
||||
// Build and copy cargo wrapper
|
||||
let mut build_cargo_wrapper_cmd = Command::new("rustc");
|
||||
build_cargo_wrapper_cmd
|
||||
.arg("scripts/cargo-clif.rs")
|
||||
.arg("-o")
|
||||
.arg(target_dir.join("cargo-clif"))
|
||||
.arg("-g");
|
||||
spawn_and_wait(build_cargo_wrapper_cmd);
|
||||
// Build and copy rustc and cargo wrappers
|
||||
for wrapper in ["rustc-clif", "cargo-clif"] {
|
||||
let mut build_cargo_wrapper_cmd = Command::new("rustc");
|
||||
build_cargo_wrapper_cmd
|
||||
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
|
||||
.arg("-o")
|
||||
.arg(target_dir.join(wrapper))
|
||||
.arg("-g");
|
||||
spawn_and_wait(build_cargo_wrapper_cmd);
|
||||
}
|
||||
|
||||
let default_sysroot = super::rustc_info::get_default_sysroot();
|
||||
|
||||
@ -117,7 +109,13 @@ pub(crate) fn build_sysroot(
|
||||
}
|
||||
}
|
||||
SysrootKind::Clif => {
|
||||
build_clif_sysroot_for_triple(channel, target_dir, host_triple, None);
|
||||
build_clif_sysroot_for_triple(
|
||||
channel,
|
||||
target_dir,
|
||||
host_triple,
|
||||
&cg_clif_dylib_path,
|
||||
None,
|
||||
);
|
||||
|
||||
if host_triple != target_triple {
|
||||
// When cross-compiling it is often necessary to manually pick the right linker
|
||||
@ -126,14 +124,21 @@ pub(crate) fn build_sysroot(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
build_clif_sysroot_for_triple(channel, target_dir, target_triple, linker);
|
||||
build_clif_sysroot_for_triple(
|
||||
channel,
|
||||
target_dir,
|
||||
target_triple,
|
||||
&cg_clif_dylib_path,
|
||||
linker,
|
||||
);
|
||||
}
|
||||
|
||||
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
|
||||
// libstd.
|
||||
for file in fs::read_dir(host_rustlib_lib).unwrap() {
|
||||
let file = file.unwrap().path();
|
||||
if file.file_name().unwrap().to_str().unwrap().contains("std-") {
|
||||
let filename = file.file_name().unwrap().to_str().unwrap();
|
||||
if filename.contains("std-") && !filename.contains(".rlib") {
|
||||
try_hard_link(&file, target_dir.join("lib").join(file.file_name().unwrap()));
|
||||
}
|
||||
}
|
||||
@ -145,6 +150,7 @@ fn build_clif_sysroot_for_triple(
|
||||
channel: &str,
|
||||
target_dir: &Path,
|
||||
triple: &str,
|
||||
cg_clif_dylib_path: &Path,
|
||||
linker: Option<&str>,
|
||||
) {
|
||||
match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) {
|
||||
@ -168,18 +174,18 @@ fn build_clif_sysroot_for_triple(
|
||||
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
|
||||
|
||||
if !super::config::get_bool("keep_sysroot") {
|
||||
// Cleanup the target dir with the exception of build scripts and the incremental cache
|
||||
for dir in ["build", "deps", "examples", "native"] {
|
||||
if build_dir.join(dir).exists() {
|
||||
fs::remove_dir_all(build_dir.join(dir)).unwrap();
|
||||
}
|
||||
// Cleanup the deps dir, but keep build scripts and the incremental cache for faster
|
||||
// recompilation as they are not affected by changes in cg_clif.
|
||||
if build_dir.join("deps").exists() {
|
||||
fs::remove_dir_all(build_dir.join("deps")).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Build sysroot
|
||||
let mut build_cmd = Command::new("cargo");
|
||||
build_cmd.arg("build").arg("--target").arg(triple).current_dir("build_sysroot");
|
||||
let mut rustflags = "--clif -Zforce-unstable-if-unmarked".to_string();
|
||||
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
|
||||
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
|
||||
if channel == "release" {
|
||||
build_cmd.arg("--release");
|
||||
rustflags.push_str(" -Zmir-opt-level=3");
|
||||
@ -189,10 +195,6 @@ fn build_clif_sysroot_for_triple(
|
||||
write!(rustflags, " -Clinker={}", linker).unwrap();
|
||||
}
|
||||
build_cmd.env("RUSTFLAGS", rustflags);
|
||||
build_cmd.env(
|
||||
"RUSTC",
|
||||
env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"),
|
||||
);
|
||||
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
|
||||
spawn_and_wait(build_cmd);
|
||||
|
||||
|
@ -86,6 +86,7 @@ pub fn main() {
|
||||
arg => arg_error!("Unexpected argument {}", arg),
|
||||
}
|
||||
}
|
||||
target_dir = std::env::current_dir().unwrap().join(target_dir);
|
||||
|
||||
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
||||
host_triple
|
||||
|
@ -19,7 +19,7 @@ This will build your project with rustc_codegen_cranelift instead of the usual L
|
||||
> You should prefer using the Cargo method.
|
||||
|
||||
```bash
|
||||
$ $cg_clif_dir/build/bin/cg_clif my_crate.rs
|
||||
$ $cg_clif_dir/build/rustc-clif my_crate.rs
|
||||
```
|
||||
|
||||
## Jit mode
|
||||
@ -38,7 +38,7 @@ $ $cg_clif_dir/build/cargo-clif jit
|
||||
or
|
||||
|
||||
```bash
|
||||
$ $cg_clif_dir/build/bin/cg_clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
|
||||
$ $cg_clif_dir/build/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
|
||||
```
|
||||
|
||||
There is also an experimental lazy jit mode. In this mode functions are only compiled once they are
|
||||
@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell
|
||||
|
||||
```bash
|
||||
function jit_naked() {
|
||||
echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
|
||||
echo "$@" | $cg_clif_dir/build/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
|
||||
}
|
||||
|
||||
function jit() {
|
||||
|
@ -21,7 +21,7 @@ index 092b7cf..158cf71 100644
|
||||
-#[cfg(target_has_atomic_load_store = "128")]
|
||||
-#[unstable(feature = "integer_atomics", issue = "32976")]
|
||||
-impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {}
|
||||
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "ptr")]
|
||||
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
|
||||
@@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {}
|
||||
@ -31,14 +31,14 @@ index 092b7cf..158cf71 100644
|
||||
-#[cfg(target_has_atomic_load_store = "128")]
|
||||
-#[unstable(feature = "integer_atomics", issue = "32976")]
|
||||
-impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {}
|
||||
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "8")]
|
||||
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
|
||||
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
|
||||
index d9de37e..8293fce 100644
|
||||
--- a/library/core/src/sync/atomic.rs
|
||||
+++ b/library/core/src/sync/atomic.rs
|
||||
@@ -2234,44 +2234,6 @@ atomic_int! {
|
||||
@@ -2234,46 +2234,6 @@ atomic_int! {
|
||||
"AtomicU64::new(0)",
|
||||
u64 AtomicU64 ATOMIC_U64_INIT
|
||||
}
|
||||
@ -54,6 +54,7 @@ index d9de37e..8293fce 100644
|
||||
- unstable(feature = "integer_atomics", issue = "32976"),
|
||||
- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
|
||||
- unstable(feature = "integer_atomics", issue = "32976"),
|
||||
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"),
|
||||
- "i128",
|
||||
- "#![feature(integer_atomics)]\n\n",
|
||||
- atomic_min, atomic_max,
|
||||
@ -73,6 +74,7 @@ index d9de37e..8293fce 100644
|
||||
- unstable(feature = "integer_atomics", issue = "32976"),
|
||||
- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
|
||||
- unstable(feature = "integer_atomics", issue = "32976"),
|
||||
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"),
|
||||
- "u128",
|
||||
- "#![feature(integer_atomics)]\n\n",
|
||||
- atomic_umin, atomic_umax,
|
||||
@ -98,6 +100,6 @@ index b735957..ea728b6 100644
|
||||
#[cfg(target_has_atomic = "ptr")]
|
||||
assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>());
|
||||
#[cfg(target_has_atomic = "ptr")]
|
||||
--
|
||||
--
|
||||
2.26.2.7.g19db9cfb68
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2022-04-21"
|
||||
channel = "nightly-2022-05-15"
|
||||
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
|
||||
|
@ -5,20 +5,11 @@ use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
if env::var("RUSTC_WRAPPER").map_or(false, |wrapper| wrapper.contains("sccache")) {
|
||||
eprintln!(
|
||||
"\x1b[1;93m=== Warning: Unsetting RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m"
|
||||
);
|
||||
env::remove_var("RUSTC_WRAPPER");
|
||||
}
|
||||
|
||||
let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
|
||||
|
||||
env::set_var("RUSTC", sysroot.join("bin/cg_clif".to_string() + env::consts::EXE_SUFFIX));
|
||||
|
||||
let mut rustdoc_flags = env::var("RUSTDOCFLAGS").unwrap_or(String::new());
|
||||
rustdoc_flags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
|
||||
rustdoc_flags.push_str(
|
||||
let mut rustflags = String::new();
|
||||
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
|
||||
rustflags.push_str(
|
||||
sysroot
|
||||
.join(if cfg!(windows) { "bin" } else { "lib" })
|
||||
.join(
|
||||
@ -29,9 +20,10 @@ fn main() {
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
);
|
||||
rustdoc_flags.push_str(" --sysroot ");
|
||||
rustdoc_flags.push_str(sysroot.to_str().unwrap());
|
||||
env::set_var("RUSTDOCFLAGS", rustdoc_flags);
|
||||
rustflags.push_str(" --sysroot ");
|
||||
rustflags.push_str(sysroot.to_str().unwrap());
|
||||
env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
|
||||
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
|
||||
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
|
||||
@ -46,7 +38,7 @@ fn main() {
|
||||
.chain(env::args().skip(2))
|
||||
.chain([
|
||||
"--".to_string(),
|
||||
"-Zunstable-features".to_string(),
|
||||
"-Zunstable-options".to_string(),
|
||||
"-Cllvm-args=mode=jit".to_string(),
|
||||
])
|
||||
.collect()
|
||||
@ -60,7 +52,7 @@ fn main() {
|
||||
.chain(env::args().skip(2))
|
||||
.chain([
|
||||
"--".to_string(),
|
||||
"-Zunstable-features".to_string(),
|
||||
"-Zunstable-options".to_string(),
|
||||
"-Cllvm-args=mode=jit-lazy".to_string(),
|
||||
])
|
||||
.collect()
|
||||
|
@ -1,6 +0,0 @@
|
||||
# Note to people running shellcheck: this file should only be sourced, not executed directly.
|
||||
|
||||
set -e
|
||||
|
||||
export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH"
|
||||
export DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH"
|
@ -1,32 +0,0 @@
|
||||
# Note to people running shellcheck: this file should only be sourced, not executed directly.
|
||||
|
||||
# Various env vars that should only be set for the build system
|
||||
|
||||
set -e
|
||||
|
||||
export CG_CLIF_DISPLAY_CG_TIME=1
|
||||
export CG_CLIF_DISABLE_INCR_CACHE=1
|
||||
|
||||
export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
|
||||
export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE}
|
||||
|
||||
export RUN_WRAPPER=''
|
||||
export JIT_SUPPORTED=1
|
||||
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
|
||||
export JIT_SUPPORTED=0
|
||||
if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
|
||||
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
||||
export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS
|
||||
export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
|
||||
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
|
||||
# We are cross-compiling for Windows. Run tests in wine.
|
||||
export RUN_WRAPPER='wine'
|
||||
else
|
||||
echo "Unknown non-native platform"
|
||||
fi
|
||||
fi
|
||||
|
||||
# FIXME fix `#[linkage = "extern_weak"]` without this
|
||||
if [[ "$(uname)" == 'Darwin' ]]; then
|
||||
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
|
||||
fi
|
@ -2,8 +2,7 @@
|
||||
#![forbid(unsafe_code)]/* This line is ignored by bash
|
||||
# This block is ignored by rustc
|
||||
pushd $(dirname "$0")/../
|
||||
source scripts/config.sh
|
||||
RUSTC="$(pwd)/build/bin/cg_clif"
|
||||
RUSTC="$(pwd)/build/rustc-clif"
|
||||
popd
|
||||
PROFILE=$1 OUTPUT=$2 exec $RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic $0
|
||||
#*/
|
||||
|
36
scripts/rustc-clif.rs
Normal file
36
scripts/rustc-clif.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
|
||||
|
||||
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
|
||||
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
||||
);
|
||||
|
||||
let mut args = std::env::args_os().skip(1).collect::<Vec<_>>();
|
||||
args.push(OsString::from("-Cpanic=abort"));
|
||||
args.push(OsString::from("-Zpanic-abort-tests"));
|
||||
let mut codegen_backend_arg = OsString::from("-Zcodegen-backend=");
|
||||
codegen_backend_arg.push(cg_clif_dylib_path);
|
||||
args.push(codegen_backend_arg);
|
||||
if !args.contains(&OsString::from("--sysroot")) {
|
||||
args.push(OsString::from("--sysroot"));
|
||||
args.push(OsString::from(sysroot.to_str().unwrap()));
|
||||
}
|
||||
|
||||
// Ensure that the right toolchain is used
|
||||
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
|
||||
|
||||
#[cfg(unix)]
|
||||
Command::new("rustc").args(args).exec();
|
||||
|
||||
#[cfg(not(unix))]
|
||||
std::process::exit(
|
||||
Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
||||
);
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
set -e
|
||||
|
||||
./y.rs build --no-unstable-features
|
||||
source scripts/config.sh
|
||||
|
||||
echo "[SETUP] Rust fork"
|
||||
git clone https://github.com/rust-lang/rust.git || true
|
||||
@ -26,21 +25,6 @@ index d95b5b7f17f..00b6f0e3635 100644
|
||||
[dev-dependencies]
|
||||
rand = "0.7"
|
||||
rand_xorshift = "0.2"
|
||||
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
|
||||
index 887d27fd6dca4..2c2239f2b83d1 100644
|
||||
--- a/src/tools/compiletest/src/header.rs
|
||||
+++ b/src/tools/compiletest/src/header.rs
|
||||
@@ -806,8 +806,8 @@ pub fn make_test_description<R: Read>(
|
||||
cfg: Option<&str>,
|
||||
) -> test::TestDesc {
|
||||
let mut ignore = false;
|
||||
#[cfg(not(bootstrap))]
|
||||
- let ignore_message: Option<String> = None;
|
||||
+ let ignore_message: Option<&str> = None;
|
||||
let mut should_fail = false;
|
||||
|
||||
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
|
||||
|
||||
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
|
||||
index 8431aa7b818..a3ff7e68ce5 100644
|
||||
--- a/src/tools/compiletest/src/runtest.rs
|
||||
@ -67,7 +51,7 @@ changelog-seen = 2
|
||||
ninja = false
|
||||
|
||||
[build]
|
||||
rustc = "$(pwd)/../build/bin/cg_clif"
|
||||
rustc = "$(pwd)/../build/rustc-clif"
|
||||
cargo = "$(rustup which cargo)"
|
||||
full-bootstrap = true
|
||||
local-rebuild = true
|
||||
|
@ -101,11 +101,10 @@ rm src/test/incremental/spike-neg1.rs # errors out for some reason
|
||||
rm src/test/incremental/spike-neg2.rs # same
|
||||
rm src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs # gives a stackoverflow before the backend runs
|
||||
rm src/test/ui/mir/ssa-analysis-regression-50041.rs # produces ICE
|
||||
rm src/test/ui/type-alias-impl-trait/assoc-projection-ice.rs # produces ICE
|
||||
|
||||
rm src/test/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered doesn't accept an accumulator for integer vectors
|
||||
|
||||
rm src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs # wrong result from `Location::caller()`
|
||||
|
||||
# bugs in the test suite
|
||||
# ======================
|
||||
rm src/test/ui/backtrace.rs # TODO warning
|
||||
|
@ -2,10 +2,43 @@
|
||||
|
||||
set -e
|
||||
|
||||
source scripts/config.sh
|
||||
source scripts/ext_config.sh
|
||||
export RUSTC=false # ensure that cg_llvm isn't accidentally used
|
||||
MY_RUSTC="$(pwd)/build/bin/cg_clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
|
||||
export CG_CLIF_DISPLAY_CG_TIME=1
|
||||
export CG_CLIF_DISABLE_INCR_CACHE=1
|
||||
|
||||
export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
|
||||
export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE}
|
||||
|
||||
export RUN_WRAPPER=''
|
||||
|
||||
case "$TARGET_TRIPLE" in
|
||||
x86_64*)
|
||||
export JIT_SUPPORTED=1
|
||||
;;
|
||||
*)
|
||||
export JIT_SUPPORTED=0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
|
||||
export JIT_SUPPORTED=0
|
||||
if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
|
||||
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
||||
export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS
|
||||
export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
|
||||
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
|
||||
# We are cross-compiling for Windows. Run tests in wine.
|
||||
export RUN_WRAPPER='wine'
|
||||
else
|
||||
echo "Unknown non-native platform"
|
||||
fi
|
||||
fi
|
||||
|
||||
# FIXME fix `#[linkage = "extern_weak"]` without this
|
||||
if [[ "$(uname)" == 'Darwin' ]]; then
|
||||
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
|
||||
fi
|
||||
|
||||
MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
|
||||
|
||||
function no_sysroot_tests() {
|
||||
echo "[BUILD] mini_core"
|
||||
@ -39,7 +72,7 @@ function base_sysroot_tests() {
|
||||
$MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/issue_91827_extern_types
|
||||
|
||||
echo "[AOT] alloc_system"
|
||||
echo "[BUILD] alloc_system"
|
||||
$MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
|
||||
|
||||
echo "[AOT] alloc_example"
|
||||
@ -56,14 +89,14 @@ function base_sysroot_tests() {
|
||||
echo "[JIT] std_example (skipped)"
|
||||
fi
|
||||
|
||||
echo "[AOT] dst_field_align"
|
||||
$MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
|
||||
|
||||
echo "[AOT] std_example"
|
||||
$MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/std_example arg
|
||||
|
||||
echo "[AOT] dst_field_align"
|
||||
$MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/dst_field_align
|
||||
|
||||
echo "[AOT] subslice-patterns-const-eval"
|
||||
$MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
|
||||
@ -97,7 +130,7 @@ function extended_sysroot_tests() {
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
echo "[BENCH COMPILE] ebobby/simple-raytracer"
|
||||
hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
|
||||
"RUSTC=rustc RUSTFLAGS='' cargo build" \
|
||||
"RUSTFLAGS='' cargo build" \
|
||||
"../build/cargo-clif build"
|
||||
|
||||
echo "[BENCH RUN] ebobby/simple-raytracer"
|
||||
|
@ -309,7 +309,7 @@ fn codegen_call_argument_operand<'tcx>(
|
||||
|
||||
pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
span: Span,
|
||||
source_info: mir::SourceInfo,
|
||||
func: &Operand<'tcx>,
|
||||
args: &[Operand<'tcx>],
|
||||
mir_dest: Option<(Place<'tcx>, BasicBlock)>,
|
||||
@ -340,7 +340,13 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
match instance.def {
|
||||
InstanceDef::Intrinsic(_) => {
|
||||
crate::intrinsics::codegen_intrinsic_call(fx, instance, args, destination, span);
|
||||
crate::intrinsics::codegen_intrinsic_call(
|
||||
fx,
|
||||
instance,
|
||||
args,
|
||||
destination,
|
||||
source_info,
|
||||
);
|
||||
return;
|
||||
}
|
||||
InstanceDef::DropGlue(_, None) => {
|
||||
@ -402,7 +408,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
// Pass the caller location for `#[track_caller]`.
|
||||
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
|
||||
let caller_location = fx.get_caller_location(span);
|
||||
let caller_location = fx.get_caller_location(source_info);
|
||||
args.push(CallArgument { value: caller_location, is_owned: false });
|
||||
}
|
||||
|
||||
@ -479,9 +485,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
// FIXME find a cleaner way to support varargs
|
||||
if fn_sig.c_variadic {
|
||||
if !matches!(fn_sig.abi, Abi::C { .. }) {
|
||||
fx.tcx
|
||||
.sess
|
||||
.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
|
||||
fx.tcx.sess.span_fatal(
|
||||
source_info.span,
|
||||
&format!("Variadic call for non-C abi {:?}", fn_sig.abi),
|
||||
);
|
||||
}
|
||||
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
|
||||
let abi_params = call_args
|
||||
@ -490,9 +497,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
let ty = fx.bcx.func.dfg.value_type(arg);
|
||||
if !ty.is_int() {
|
||||
// FIXME set %al to upperbound on float args once floats are supported
|
||||
fx.tcx
|
||||
.sess
|
||||
.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
|
||||
fx.tcx.sess.span_fatal(
|
||||
source_info.span,
|
||||
&format!("Non int ty {:?} for variadic call", ty),
|
||||
);
|
||||
}
|
||||
AbiParam::new(ty)
|
||||
})
|
||||
@ -513,7 +521,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
pub(crate) fn codegen_drop<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
span: Span,
|
||||
source_info: mir::SourceInfo,
|
||||
drop_place: CPlace<'tcx>,
|
||||
) {
|
||||
let ty = drop_place.layout().ty;
|
||||
@ -560,7 +568,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
|
||||
if drop_instance.def.requires_caller_location(fx.tcx) {
|
||||
// Pass the caller location for `#[track_caller]`.
|
||||
let caller_location = fx.get_caller_location(span);
|
||||
let caller_location = fx.get_caller_location(source_info);
|
||||
call_args.extend(
|
||||
adjust_arg_for_abi(fx, caller_location, &fn_abi.args[1], false).into_iter(),
|
||||
);
|
||||
|
26
src/base.rs
26
src/base.rs
@ -325,7 +325,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
|
||||
AssertKind::BoundsCheck { ref len, ref index } => {
|
||||
let len = codegen_operand(fx, len).load_scalar(fx);
|
||||
let index = codegen_operand(fx, index).load_scalar(fx);
|
||||
let location = fx.get_caller_location(source_info.span).load_scalar(fx);
|
||||
let location = fx.get_caller_location(source_info).load_scalar(fx);
|
||||
|
||||
codegen_panic_inner(
|
||||
fx,
|
||||
@ -336,7 +336,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
|
||||
}
|
||||
_ => {
|
||||
let msg_str = msg.description();
|
||||
codegen_panic(fx, msg_str, source_info.span);
|
||||
codegen_panic(fx, msg_str, source_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -398,7 +398,13 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
|
||||
from_hir_call: _,
|
||||
} => {
|
||||
fx.tcx.sess.time("codegen call", || {
|
||||
crate::abi::codegen_terminator_call(fx, *fn_span, func, args, *destination)
|
||||
crate::abi::codegen_terminator_call(
|
||||
fx,
|
||||
mir::SourceInfo { span: *fn_span, ..source_info },
|
||||
func,
|
||||
args,
|
||||
*destination,
|
||||
)
|
||||
});
|
||||
}
|
||||
TerminatorKind::InlineAsm {
|
||||
@ -450,7 +456,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
|
||||
}
|
||||
TerminatorKind::Drop { place, target, unwind: _ } => {
|
||||
let drop_place = codegen_place(fx, *place);
|
||||
crate::abi::codegen_drop(fx, source_info.span, drop_place);
|
||||
crate::abi::codegen_drop(fx, source_info, drop_place);
|
||||
|
||||
let target_block = fx.get_block(*target);
|
||||
fx.bcx.ins().jump(target_block, &[]);
|
||||
@ -471,7 +477,7 @@ fn codegen_stmt<'tcx>(
|
||||
|
||||
fx.set_debug_loc(stmt.source_info);
|
||||
|
||||
#[cfg(disabled)]
|
||||
#[cfg(any())] // This is never true
|
||||
match &stmt.kind {
|
||||
StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful
|
||||
_ => {
|
||||
@ -898,14 +904,18 @@ pub(crate) fn codegen_operand<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) {
|
||||
let location = fx.get_caller_location(span).load_scalar(fx);
|
||||
pub(crate) fn codegen_panic<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
msg_str: &str,
|
||||
source_info: mir::SourceInfo,
|
||||
) {
|
||||
let location = fx.get_caller_location(source_info).load_scalar(fx);
|
||||
|
||||
let msg_ptr = fx.anonymous_str(msg_str);
|
||||
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
|
||||
let args = [msg_ptr, msg_len, location];
|
||||
|
||||
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, span);
|
||||
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, source_info.span);
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_panic_inner<'tcx>(
|
||||
|
@ -1,94 +0,0 @@
|
||||
#![feature(rustc_private)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![warn(unused_lifetimes)]
|
||||
#![warn(unreachable_pub)]
|
||||
|
||||
extern crate rustc_data_structures;
|
||||
extern crate rustc_driver;
|
||||
extern crate rustc_interface;
|
||||
extern crate rustc_session;
|
||||
extern crate rustc_target;
|
||||
|
||||
use std::panic;
|
||||
|
||||
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
||||
use rustc_interface::interface;
|
||||
use rustc_session::config::{ErrorOutputType, TrimmedDefPaths};
|
||||
use rustc_session::early_error;
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
|
||||
// FIXME use std::lazy::SyncLazy once it stabilizes
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new";
|
||||
|
||||
static DEFAULT_HOOK: Lazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
|
||||
Lazy::new(|| {
|
||||
let hook = panic::take_hook();
|
||||
panic::set_hook(Box::new(|info| {
|
||||
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
|
||||
(*DEFAULT_HOOK)(info);
|
||||
|
||||
// Separate the output with an empty line
|
||||
eprintln!();
|
||||
|
||||
// Print the ICE message
|
||||
rustc_driver::report_ice(info, BUG_REPORT_URL);
|
||||
}));
|
||||
hook
|
||||
});
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CraneliftPassesCallbacks {
|
||||
time_passes: bool,
|
||||
}
|
||||
|
||||
impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
|
||||
fn config(&mut self, config: &mut interface::Config) {
|
||||
// If a --prints=... option has been given, we don't print the "total"
|
||||
// time because it will mess up the --prints output. See #64339.
|
||||
self.time_passes = config.opts.prints.is_empty()
|
||||
&& (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
|
||||
|
||||
config.opts.cg.panic = Some(PanicStrategy::Abort);
|
||||
config.opts.debugging_opts.panic_abort_tests = true;
|
||||
config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
|
||||
std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned()
|
||||
}));
|
||||
|
||||
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let start_time = std::time::Instant::now();
|
||||
let start_rss = get_resident_set_size();
|
||||
rustc_driver::init_rustc_env_logger();
|
||||
let mut callbacks = CraneliftPassesCallbacks::default();
|
||||
Lazy::force(&DEFAULT_HOOK); // Install ice hook
|
||||
let exit_code = rustc_driver::catch_with_exit_code(|| {
|
||||
let args = std::env::args_os()
|
||||
.enumerate()
|
||||
.map(|(i, arg)| {
|
||||
arg.into_string().unwrap_or_else(|arg| {
|
||||
early_error(
|
||||
ErrorOutputType::default(),
|
||||
&format!("Argument {} is not valid Unicode: {:?}", i, arg),
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
|
||||
run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
|
||||
Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
|
||||
})));
|
||||
run_compiler.run()
|
||||
});
|
||||
|
||||
if callbacks.time_passes {
|
||||
let end_rss = get_resident_set_size();
|
||||
print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss);
|
||||
}
|
||||
|
||||
std::process::exit(exit_code)
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
//! The only difference between this and cg_clif.rs is that this binary defaults to using cg_llvm
|
||||
//! instead of cg_clif and requires `--clif` to use cg_clif and that this binary doesn't have JIT
|
||||
//! support.
|
||||
//! This is necessary as with Cargo `RUSTC` applies to both target crates and host crates. The host
|
||||
//! crates must be built with cg_llvm as we are currently building a sysroot for cg_clif.
|
||||
//! `RUSTFLAGS` however is only applied to target crates, so `--clif` would only be passed to the
|
||||
//! target crates.
|
||||
|
||||
#![feature(rustc_private)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![warn(unused_lifetimes)]
|
||||
#![warn(unreachable_pub)]
|
||||
|
||||
extern crate rustc_driver;
|
||||
extern crate rustc_interface;
|
||||
extern crate rustc_session;
|
||||
extern crate rustc_target;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_interface::interface;
|
||||
use rustc_session::config::ErrorOutputType;
|
||||
use rustc_session::early_error;
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
|
||||
fn find_sysroot() -> String {
|
||||
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
|
||||
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
||||
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
||||
match (home, toolchain) {
|
||||
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
|
||||
_ => option_env!("RUST_SYSROOT")
|
||||
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
|
||||
.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CraneliftPassesCallbacks {
|
||||
use_clif: bool,
|
||||
}
|
||||
|
||||
impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
|
||||
fn config(&mut self, config: &mut interface::Config) {
|
||||
if !self.use_clif {
|
||||
config.opts.maybe_sysroot = Some(PathBuf::from(find_sysroot()));
|
||||
return;
|
||||
}
|
||||
|
||||
config.opts.cg.panic = Some(PanicStrategy::Abort);
|
||||
config.opts.debugging_opts.panic_abort_tests = true;
|
||||
config.opts.maybe_sysroot =
|
||||
Some(std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rustc_driver::init_rustc_env_logger();
|
||||
rustc_driver::install_ice_hook();
|
||||
let exit_code = rustc_driver::catch_with_exit_code(|| {
|
||||
let mut use_clif = false;
|
||||
|
||||
let args = std::env::args_os()
|
||||
.enumerate()
|
||||
.map(|(i, arg)| {
|
||||
arg.into_string().unwrap_or_else(|arg| {
|
||||
early_error(
|
||||
ErrorOutputType::default(),
|
||||
&format!("Argument {} is not valid Unicode: {:?}", i, arg),
|
||||
)
|
||||
})
|
||||
})
|
||||
.filter(|arg| {
|
||||
if arg == "--clif" {
|
||||
use_clif = true;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut callbacks = CraneliftPassesCallbacks { use_clif };
|
||||
|
||||
let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
|
||||
if use_clif {
|
||||
run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
|
||||
Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
|
||||
})));
|
||||
}
|
||||
run_compiler.run()
|
||||
});
|
||||
std::process::exit(exit_code)
|
||||
}
|
@ -340,22 +340,46 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
|
||||
self.bcx.set_srcloc(SourceLoc::new(index as u32));
|
||||
}
|
||||
|
||||
pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> {
|
||||
if let Some(loc) = self.caller_location {
|
||||
// `#[track_caller]` is used; return caller location instead of current location.
|
||||
return loc;
|
||||
// Note: must be kept in sync with get_caller_location from cg_ssa
|
||||
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
|
||||
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
|
||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
let const_loc = fx.tcx.const_caller_location((
|
||||
rustc_span::symbol::Symbol::intern(
|
||||
&caller.file.name.prefer_remapped().to_string_lossy(),
|
||||
),
|
||||
caller.line as u32,
|
||||
caller.col_display as u32 + 1,
|
||||
));
|
||||
crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty())
|
||||
};
|
||||
|
||||
// Walk up the `SourceScope`s, in case some of them are from MIR inlining.
|
||||
// If so, the starting `source_info.span` is in the innermost inlined
|
||||
// function, and will be replaced with outer callsite spans as long
|
||||
// as the inlined functions were `#[track_caller]`.
|
||||
loop {
|
||||
let scope_data = &self.mir.source_scopes[source_info.scope];
|
||||
|
||||
if let Some((callee, callsite_span)) = scope_data.inlined {
|
||||
// Stop inside the most nested non-`#[track_caller]` function,
|
||||
// before ever reaching its caller (which is irrelevant).
|
||||
if !callee.def.requires_caller_location(self.tcx) {
|
||||
return span_to_caller_location(self, source_info.span);
|
||||
}
|
||||
source_info.span = callsite_span;
|
||||
}
|
||||
|
||||
// Skip past all of the parents with `inlined: None`.
|
||||
match scope_data.inlined_parent_scope {
|
||||
Some(parent) => source_info.scope = parent,
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
let const_loc = self.tcx.const_caller_location((
|
||||
rustc_span::symbol::Symbol::intern(
|
||||
&caller.file.name.prefer_remapped().to_string_lossy(),
|
||||
),
|
||||
caller.line as u32,
|
||||
caller.col_display as u32 + 1,
|
||||
));
|
||||
crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())
|
||||
// No inlined `SourceScope`s, or all of them were `#[track_caller]`.
|
||||
self.caller_location.unwrap_or_else(|| span_to_caller_location(self, source_info.span))
|
||||
}
|
||||
|
||||
pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {
|
||||
|
@ -74,6 +74,7 @@ fn create_jit_module<'tcx>(
|
||||
jit_builder.hotswap(hotswap);
|
||||
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
||||
jit_builder.symbols(imported_symbols);
|
||||
jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8);
|
||||
let mut jit_module = JITModule::new(jit_builder);
|
||||
|
||||
let mut cx = crate::CodegenCx::new(
|
||||
@ -210,8 +211,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn __clif_jit_fn(
|
||||
extern "C" fn clif_jit_fn(
|
||||
instance_ptr: *const Instance<'static>,
|
||||
trampoline_ptr: *const u8,
|
||||
) -> *const u8 {
|
||||
|
@ -218,7 +218,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
instance: Instance<'tcx>,
|
||||
args: &[mir::Operand<'tcx>],
|
||||
destination: Option<(CPlace<'tcx>, BasicBlock)>,
|
||||
span: Span,
|
||||
source_info: mir::SourceInfo,
|
||||
) {
|
||||
let intrinsic = fx.tcx.item_name(instance.def_id());
|
||||
let substs = instance.substs;
|
||||
@ -232,7 +232,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
fx.bcx.ins().trap(TrapCode::User(0));
|
||||
}
|
||||
sym::transmute => {
|
||||
crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", span);
|
||||
crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", source_info);
|
||||
}
|
||||
_ => unimplemented!("unsupported instrinsic {}", intrinsic),
|
||||
}
|
||||
@ -241,7 +241,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
};
|
||||
|
||||
if intrinsic.as_str().starts_with("simd_") {
|
||||
self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, span);
|
||||
self::simd::codegen_simd_intrinsic_call(fx, intrinsic, substs, args, ret, source_info.span);
|
||||
let ret_block = fx.get_block(destination.expect("SIMD intrinsics don't diverge").1);
|
||||
fx.bcx.ins().jump(ret_block, &[]);
|
||||
} else if codegen_float_intrinsic_call(fx, intrinsic, args, ret) {
|
||||
@ -255,7 +255,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
substs,
|
||||
args,
|
||||
ret,
|
||||
span,
|
||||
source_info,
|
||||
destination,
|
||||
);
|
||||
}
|
||||
@ -339,7 +339,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: &[mir::Operand<'tcx>],
|
||||
ret: CPlace<'tcx>,
|
||||
span: Span,
|
||||
source_info: mir::SourceInfo,
|
||||
destination: Option<(CPlace<'tcx>, BasicBlock)>,
|
||||
) {
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
@ -347,7 +347,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
intrinsic_match! {
|
||||
fx, intrinsic, args,
|
||||
_ => {
|
||||
fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
|
||||
fx.tcx.sess.span_fatal(source_info.span, &format!("unsupported intrinsic {}", intrinsic));
|
||||
};
|
||||
|
||||
assume, (c _a) {};
|
||||
@ -658,7 +658,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
crate::base::codegen_panic(
|
||||
fx,
|
||||
&format!("attempted to instantiate uninhabited type `{}`", layout.ty),
|
||||
span,
|
||||
source_info,
|
||||
)
|
||||
});
|
||||
return;
|
||||
@ -669,7 +669,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
crate::base::codegen_panic(
|
||||
fx,
|
||||
&format!("attempted to zero-initialize type `{}`, which is invalid", layout.ty),
|
||||
span,
|
||||
source_info,
|
||||
);
|
||||
});
|
||||
return;
|
||||
@ -680,7 +680,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
crate::base::codegen_panic(
|
||||
fx,
|
||||
&format!("attempted to leave type `{}` uninitialized, which is invalid", layout.ty),
|
||||
span,
|
||||
source_info,
|
||||
)
|
||||
});
|
||||
return;
|
||||
@ -715,19 +715,19 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
|
||||
ptr_offset_from | ptr_offset_from_unsigned, (v ptr, v base) {
|
||||
let ty = substs.type_at(0);
|
||||
let isize_layout = fx.layout_of(fx.tcx.types.isize);
|
||||
|
||||
let pointee_size: u64 = fx.layout_of(ty).size.bytes();
|
||||
let diff_bytes = fx.bcx.ins().isub(ptr, base);
|
||||
// FIXME this can be an exact division.
|
||||
let diff = if intrinsic == sym::ptr_offset_from_unsigned {
|
||||
let val = if intrinsic == sym::ptr_offset_from_unsigned {
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
// Because diff_bytes ULE isize::MAX, this would be fine as signed,
|
||||
// but unsigned is slightly easier to codegen, so might as well.
|
||||
fx.bcx.ins().udiv_imm(diff_bytes, pointee_size as i64)
|
||||
CValue::by_val(fx.bcx.ins().udiv_imm(diff_bytes, pointee_size as i64), usize_layout)
|
||||
} else {
|
||||
fx.bcx.ins().sdiv_imm(diff_bytes, pointee_size as i64)
|
||||
let isize_layout = fx.layout_of(fx.tcx.types.isize);
|
||||
CValue::by_val(fx.bcx.ins().sdiv_imm(diff_bytes, pointee_size as i64), isize_layout)
|
||||
};
|
||||
let val = CValue::by_val(diff, isize_layout);
|
||||
ret.write_cvalue(fx, val);
|
||||
};
|
||||
|
||||
@ -742,7 +742,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
};
|
||||
|
||||
caller_location, () {
|
||||
let caller_location = fx.get_caller_location(span);
|
||||
let caller_location = fx.get_caller_location(source_info);
|
||||
ret.write_cvalue(fx, caller_location);
|
||||
};
|
||||
|
||||
@ -765,12 +765,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
fx.bcx.ins().jump(ret_block, &[]);
|
||||
return;
|
||||
} else {
|
||||
fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported");
|
||||
fx.tcx.sess.span_fatal(source_info.span, "128bit atomics not yet supported");
|
||||
}
|
||||
}
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -793,12 +793,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
fx.bcx.ins().jump(ret_block, &[]);
|
||||
return;
|
||||
} else {
|
||||
fx.tcx.sess.span_fatal(span, "128bit atomics not yet supported");
|
||||
fx.tcx.sess.span_fatal(source_info.span, "128bit atomics not yet supported");
|
||||
}
|
||||
}
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -812,7 +812,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -830,7 +830,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -850,7 +850,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -868,7 +868,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -886,7 +886,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -904,7 +904,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -922,7 +922,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -940,7 +940,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -958,7 +958,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -976,7 +976,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -994,7 +994,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1012,7 +1012,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
match layout.ty.kind() {
|
||||
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
||||
_ => {
|
||||
report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
|
||||
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -828,6 +828,7 @@ pub(crate) fn assert_assignable<'tcx>(
|
||||
}
|
||||
}
|
||||
}
|
||||
(ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, *a, *b),
|
||||
_ => {
|
||||
assert_eq!(
|
||||
from_ty, to_ty,
|
||||
|
Loading…
Reference in New Issue
Block a user