提交 263d8682 编写于 作者: B bors

Auto merge of #97887 - matthiaskrgr:rollup-ym5k7kb, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #97507 (Move rustfmt downloads from bootstrap.py to rustbuild)
 - #97813 (Sync rustc_codegen_gcc)
 - #97878 (Add regression test for anonymous lifetimes)
 - #97879 (remove unneeded code)
 - #97880 (Fix typo: fo->for)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
......@@ -216,6 +216,7 @@ dependencies = [
"cmake",
"filetime",
"getopts",
"hex 0.4.2",
"ignore",
"libc",
"once_cell",
......@@ -223,6 +224,7 @@ dependencies = [
"pretty_assertions 0.7.2",
"serde",
"serde_json",
"sha2",
"sysinfo",
"tar",
"toml",
......
......@@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so", "libgccjit12.so"]
steps:
- uses: actions/checkout@v2
......@@ -78,12 +78,21 @@ jobs:
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
- name: Build
if: matrix.libgccjit_version != 'libgccjit12.so'
run: |
./prepare_build.sh
./build.sh
cargo test
./clean_all.sh
- name: Build
if: matrix.libgccjit_version == 'libgccjit12.so'
run: |
./prepare_build.sh
./build.sh --no-default-features
cargo test --no-default-features
./clean_all.sh
- name: Prepare dependencies
run: |
git config --global user.email "user@example.com"
......@@ -98,6 +107,7 @@ jobs:
args: --release
- name: Test
if: matrix.libgccjit_version != 'libgccjit12.so'
run: |
# Enable backtraces for easier debugging
export RUST_BACKTRACE=1
......@@ -107,3 +117,15 @@ jobs:
export RUN_RUNS=2
./test.sh --release
- name: Test
if: matrix.libgccjit_version == 'libgccjit12.so'
run: |
# Enable backtraces for easier debugging
export RUST_BACKTRACE=1
# Reduce amount of benchmark runs as they are slow
export COMPILE_RUNS=2
export RUN_RUNS=2
./test.sh --release --no-default-features
......@@ -13,9 +13,13 @@ perf.data.old
/rust
/simple-raytracer
/regex
/rand
gimple*
*asm
res
test-backend
gcc_path
benchmarks
tools/llvm-project
tools/llvmint
tools/llvmint-2
......@@ -41,7 +41,7 @@ dependencies = [
[[package]]
name = "gccjit"
version = "1.0.0"
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
source = "git+https://github.com/antoyo/gccjit.rs#bdb86fb5092895ff5589726b33250010c64d93f6"
dependencies = [
"gccjit_sys",
]
......@@ -49,7 +49,7 @@ dependencies = [
[[package]]
name = "gccjit_sys"
version = "0.0.1"
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
source = "git+https://github.com/antoyo/gccjit.rs#bdb86fb5092895ff5589726b33250010c64d93f6"
dependencies = [
"libc 0.1.12",
]
......
......@@ -9,9 +9,17 @@ license = "MIT OR Apache-2.0"
crate-type = ["dylib"]
[[test]]
name = "lang_tests"
path = "tests/lib.rs"
name = "lang_tests_debug"
path = "tests/lang_tests_debug.rs"
harness = false
[[test]]
name = "lang_tests_release"
path = "tests/lang_tests_release.rs"
harness = false
[features]
default = ["master"]
master = ["gccjit/master"]
[dependencies]
gccjit = { git = "https://github.com/antoyo/gccjit.rs" }
......
#!/bin/bash
#!/usr/bin/env bash
#set -x
set -e
......@@ -6,6 +6,8 @@ set -e
codegen_channel=debug
sysroot_channel=debug
flags=
while [[ $# -gt 0 ]]; do
case $1 in
--release)
......@@ -16,6 +18,15 @@ while [[ $# -gt 0 ]]; do
sysroot_channel=release
shift
;;
--no-default-features)
flags="$flags --no-default-features"
shift
;;
--features)
shift
flags="$flags --features $1"
shift
;;
*)
echo "Unknown option $1"
exit 1
......@@ -33,21 +44,13 @@ fi
export LD_LIBRARY_PATH="$GCC_PATH"
export LIBRARY_PATH="$GCC_PATH"
features=
if [[ "$1" == "--features" ]]; then
shift
features="--features $1"
shift
fi
if [[ "$codegen_channel" == "release" ]]; then
export CHANNEL='release'
CARGO_INCREMENTAL=1 cargo rustc --release $features
CARGO_INCREMENTAL=1 cargo rustc --release $flags
else
echo $LD_LIBRARY_PATH
export CHANNEL='debug'
cargo rustc $features
cargo rustc $flags
fi
source config.sh
......
#!/bin/bash
#!/usr/bin/env bash
# Requires the CHANNEL env var to be set to `debug` or `release.`
......
#!/bin/bash
#!/usr/bin/env bash
set -e
cd $(dirname "$0")
......
#!/bin/bash
#!/usr/bin/env bash
if [ -z $CHANNEL ]; then
export CHANNEL='debug'
......@@ -20,4 +20,4 @@ fi
cmd=$1
shift
RUSTDOCFLAGS="$RUSTFLAGS" cargo +${TOOLCHAIN} $cmd --target $TARGET_TRIPLE $@
RUSTDOCFLAGS="$RUSTFLAGS" cargo +${TOOLCHAIN} $cmd $@
#!/bin/bash --verbose
#!/usr/bin/env bash
set -e
set -v
rm -rf target/ build_sysroot/{sysroot/,sysroot_src/,target/,Cargo.lock} perf.data{,.old}
rm -rf regex/ simple-raytracer/
......@@ -2,7 +2,7 @@ set -e
export CARGO_INCREMENTAL=0
if [ -f ./gcc_path ]; then
if [ -f ./gcc_path ]; then
export GCC_PATH=$(cat gcc_path)
else
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
......@@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
fi
fi
export RUSTFLAGS="$linker -Cpanic=abort -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
export RUSTFLAGS="$CG_RUSTFLAGS $linker -Cpanic=abort -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
# FIXME(antoyo): remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then
......
From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001
From: bjorn3 <bjorn3@users.noreply.github.com>
Date: Sat, 15 Aug 2020 20:04:38 +0200
Subject: [PATCH] [rand] Disable failing test
---
src/distributions/uniform.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs
index 480b859..c80bb6f 100644
--- a/src/distributions/uniform.rs
+++ b/src/distributions/uniform.rs
@@ -1085,7 +1085,7 @@ mod tests {
_ => panic!("`UniformDurationMode` was not serialized/deserialized correctly")
}
}
-
+
#[test]
#[cfg(feature = "serde1")]
fn test_uniform_serialization() {
@@ -1314,6 +1314,7 @@ mod tests {
not(target_arch = "wasm32"),
not(target_arch = "asmjs")
))]
+ #[ignore] // FIXME
fn test_float_assertions() {
use super::SampleUniform;
use std::panic::catch_unwind;
--
2.20.1
......@@ -93,9 +93,10 @@ fn main() {
println!("{:?}", std::intrinsics::caller_location());
/*unsafe {
#[cfg(feature="master")]
unsafe {
test_simd();
}*/
}
Box::pin(move |mut _task_context| {
yield ();
......@@ -104,7 +105,8 @@ fn main() {
println!("End");
}
/*#[target_feature(enable = "sse2")]
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_simd() {
let x = _mm_setzero_si128();
let y = _mm_set1_epi16(7);
......@@ -112,7 +114,7 @@ unsafe fn test_simd() {
let cmp_eq = _mm_cmpeq_epi8(y, y);
let cmp_lt = _mm_cmplt_epi8(y, y);
/*assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]);
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]);
......@@ -124,14 +126,15 @@ unsafe fn test_simd() {
test_mm_cvtepi8_epi16();
test_mm_cvtsi128_si64();
// FIXME(#666) implement `#[rustc_arg_required_const(..)]` support
//test_mm_extract_epi8();
test_mm_extract_epi8();
test_mm_insert_epi16();
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
assert_eq!(mask1, 1);*/
}*/
assert_eq!(mask1, 1);
}
/*#[target_feature(enable = "sse2")]
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_slli_si128() {
#[rustfmt::skip]
let a = _mm_setr_epi8(
......@@ -155,22 +158,10 @@ unsafe fn test_mm_slli_si128() {
);
let r = _mm_slli_si128(a, 16);
assert_eq_m128i(r, _mm_set1_epi8(0));
#[rustfmt::skip]
let a = _mm_setr_epi8(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
);
let r = _mm_slli_si128(a, -1);
assert_eq_m128i(_mm_set1_epi8(0), r);
#[rustfmt::skip]
let a = _mm_setr_epi8(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
);
let r = _mm_slli_si128(a, -0x80000000);
assert_eq_m128i(r, _mm_set1_epi8(0));
}
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_movemask_epi8() {
#[rustfmt::skip]
......@@ -184,6 +175,7 @@ unsafe fn test_mm_movemask_epi8() {
assert_eq!(r, 0b10100100_00100101);
}
#[cfg(feature="master")]
#[target_feature(enable = "avx2")]
unsafe fn test_mm256_movemask_epi8() {
let a = _mm256_set1_epi8(-1);
......@@ -192,6 +184,7 @@ unsafe fn test_mm256_movemask_epi8() {
assert_eq!(r, e);
}
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_add_epi8() {
let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
......@@ -207,6 +200,7 @@ unsafe fn test_mm_add_epi8() {
assert_eq_m128i(r, e);
}
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_add_pd() {
let a = _mm_setr_pd(1.0, 2.0);
......@@ -215,12 +209,14 @@ unsafe fn test_mm_add_pd() {
assert_eq_m128d(r, _mm_setr_pd(6.0, 12.0));
}
#[cfg(feature="master")]
fn assert_eq_m128i(x: std::arch::x86_64::__m128i, y: std::arch::x86_64::__m128i) {
unsafe {
assert_eq!(std::mem::transmute::<_, [u8; 16]>(x), std::mem::transmute::<_, [u8; 16]>(y));
}
}
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
if _mm_movemask_pd(_mm_cmpeq_pd(a, b)) != 0b11 {
......@@ -228,12 +224,14 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
}
}
#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_cvtsi128_si64() {
let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0]));
assert_eq!(r, 5);
}
#[cfg(feature="master")]
#[target_feature(enable = "sse4.1")]
unsafe fn test_mm_cvtepi8_epi16() {
let a = _mm_set1_epi8(10);
......@@ -246,6 +244,7 @@ unsafe fn test_mm_cvtepi8_epi16() {
assert_eq_m128i(r, e);
}
#[cfg(feature="master")]
#[target_feature(enable = "sse4.1")]
unsafe fn test_mm_extract_epi8() {
#[rustfmt::skip]
......@@ -254,10 +253,19 @@ unsafe fn test_mm_extract_epi8() {
8, 9, 10, 11, 12, 13, 14, 15
);
let r1 = _mm_extract_epi8(a, 0);
let r2 = _mm_extract_epi8(a, 19);
let r2 = _mm_extract_epi8(a, 3);
assert_eq!(r1, 0xFF);
assert_eq!(r2, 3);
}*/
}
#[cfg(all(feature="master", target_arch = "x86_64"))]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_insert_epi16() {
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
let r = _mm_insert_epi16(a, 9, 0);
let e = _mm_setr_epi16(9, 1, 2, 3, 4, 5, 6, 7);
assert_eq_m128i(r, e);
}
#[derive(PartialEq)]
enum LoopState {
......
......@@ -7,167 +7,6 @@ Subject: [PATCH] [core] Disable portable-simd test
library/core/tests/lib.rs | 1 -
1 file changed, 1 deletion(-)
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index aa1ad93..95fbf55 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -398,23 +398,4 @@ pub mod arch {
}
}
-// Pull in the `core_simd` crate directly into libcore. The contents of
-// `core_simd` are in a different repository: rust-lang/portable-simd.
-//
-// `core_simd` depends on libcore, but the contents of this module are
-// set up in such a way that directly pulling it here works such that the
-// crate uses this crate as its libcore.
-#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
-#[allow(rustdoc::bare_urls)]
-#[unstable(feature = "portable_simd", issue = "86656")]
-mod core_simd;
-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
-#[unstable(feature = "portable_simd", issue = "86656")]
-pub mod simd {
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub use crate::core_simd::simd::*;
-}
-
include!("primitive_docs.rs");
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index cd38c3a..ad632dc 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -17,6 +17,5 @@ use crate::ptr;
use crate::result::Result;
use crate::result::Result::{Err, Ok};
-use crate::simd::{self, Simd};
use crate::slice;
#[unstable(
@@ -3475,121 +3474,6 @@ impl<T> [T] {
}
}
- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
- ///
- /// This is a safe wrapper around [`slice::align_to`], so has the same weak
- /// postconditions as that method. You're only assured that
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
- ///
- /// Notably, all of the following are possible:
- /// - `prefix.len() >= LANES`.
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
- /// - `suffix.len() >= LANES`.
- ///
- /// That said, this is a safe method, so if you're only writing safe code,
- /// then this can at most cause incorrect logic, not unsoundness.
- ///
- /// # Panics
- ///
- /// This will panic if the size of the SIMD type is different from
- /// `LANES` times that of the scalar.
- ///
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
- /// that from ever happening, as only power-of-two numbers of lanes are
- /// supported. It's possible that, in the future, those restrictions might
- /// be lifted in a way that would make it possible to see panics from this
- /// method for something like `LANES == 3`.
- ///
- /// # Examples
- ///
- /// ```
- /// #![feature(portable_simd)]
- ///
- /// let short = &[1, 2, 3];
- /// let (prefix, middle, suffix) = short.as_simd::<4>();
- /// assert_eq!(middle, []); // Not enough elements for anything in the middle
- ///
- /// // They might be split in any possible way between prefix and suffix
- /// let it = prefix.iter().chain(suffix).copied();
- /// assert_eq!(it.collect::<Vec<_>>(), vec![1, 2, 3]);
- ///
- /// fn basic_simd_sum(x: &[f32]) -> f32 {
- /// use std::ops::Add;
- /// use std::simd::f32x4;
- /// let (prefix, middle, suffix) = x.as_simd();
- /// let sums = f32x4::from_array([
- /// prefix.iter().copied().sum(),
- /// 0.0,
- /// 0.0,
- /// suffix.iter().copied().sum(),
- /// ]);
- /// let sums = middle.iter().copied().fold(sums, f32x4::add);
- /// sums.reduce_sum()
- /// }
- ///
- /// let numbers: Vec<f32> = (1..101).map(|x| x as _).collect();
- /// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
- /// ```
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
- where
- Simd<T, LANES>: AsRef<[T; LANES]>,
- T: simd::SimdElement,
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
- {
- // These are expected to always match, as vector types are laid out like
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
- // might as well double-check since it'll optimize away anyhow.
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
-
- // SAFETY: The simd types have the same layout as arrays, just with
- // potentially-higher alignment, so the de-facto transmutes are sound.
- unsafe { self.align_to() }
- }
-
- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
- ///
- /// This is a safe wrapper around [`slice::align_to_mut`], so has the same weak
- /// postconditions as that method. You're only assured that
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
- ///
- /// Notably, all of the following are possible:
- /// - `prefix.len() >= LANES`.
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
- /// - `suffix.len() >= LANES`.
- ///
- /// That said, this is a safe method, so if you're only writing safe code,
- /// then this can at most cause incorrect logic, not unsoundness.
- ///
- /// This is the mutable version of [`slice::as_simd`]; see that for examples.
- ///
- /// # Panics
- ///
- /// This will panic if the size of the SIMD type is different from
- /// `LANES` times that of the scalar.
- ///
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
- /// that from ever happening, as only power-of-two numbers of lanes are
- /// supported. It's possible that, in the future, those restrictions might
- /// be lifted in a way that would make it possible to see panics from this
- /// method for something like `LANES == 3`.
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
- where
- Simd<T, LANES>: AsMut<[T; LANES]>,
- T: simd::SimdElement,
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
- {
- // These are expected to always match, as vector types are laid out like
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
- // might as well double-check since it'll optimize away anyhow.
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
-
- // SAFETY: The simd types have the same layout as arrays, just with
- // potentially-higher alignment, so the de-facto transmutes are sound.
- unsafe { self.align_to_mut() }
- }
-
/// Checks if the elements of this slice are sorted.
///
/// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 06c7be0..359e2e7 100644
--- a/library/core/tests/lib.rs
......@@ -188,41 +27,3 @@ index 06c7be0..359e2e7 100644
mod slice;
mod str;
mod str_lossy;
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 5dc586d..b6fc48f 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -312,6 +312,5 @@
#![feature(panic_can_unwind)]
#![feature(panic_unwind)]
#![feature(platform_intrinsics)]
-#![feature(portable_simd)]
#![feature(prelude_import)]
#![feature(ptr_as_uninit)]
@@ -508,23 +508,6 @@ pub mod time;
#[unstable(feature = "once_cell", issue = "74465")]
pub mod lazy;
-// Pull in `std_float` crate into libstd. The contents of
-// `std_float` are in a different repository: rust-lang/portable-simd.
-#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
-#[allow(rustdoc::bare_urls)]
-#[unstable(feature = "portable_simd", issue = "86656")]
-mod std_float;
-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
-#[unstable(feature = "portable_simd", issue = "86656")]
-pub mod simd {
- #[doc(inline)]
- pub use crate::std_float::StdFloat;
- #[doc(inline)]
- pub use core::simd::*;
-}
-
#[stable(feature = "futures_api", since = "1.36.0")]
pub mod task {
//! Types and Traits for working with asynchronous tasks.
--
2.26.2.7.g19db9cfb68
#!/bin/bash --verbose
#!/usr/bin/env bash
set -e
set -v
source prepare_build.sh
cargo install hyperfine || echo "Skipping hyperfine install"
git clone https://github.com/rust-random/rand.git || echo "rust-random/rand has already been cloned"
pushd rand
git checkout -- .
git checkout 0f933f9c7176e53b2a3c7952ded484e1783f0bf1
git am ../crate_patches/*-rand-*.patch
popd
git clone https://github.com/rust-lang/regex.git || echo "rust-lang/regex has already been cloned"
pushd regex
git checkout -- .
......
#!/bin/bash --verbose
#!/usr/bin/env bash
set -e
set -v
./build_sysroot/prepare_sysroot_src.sh
[toolchain]
channel = "nightly-2022-03-26"
channel = "nightly-2022-06-06"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
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();
#!/bin/bash
#!/usr/bin/env bash
set -e
......
......@@ -13,6 +13,7 @@
use crate::builder::Builder;
use crate::context::CodegenCx;
use crate::type_of::LayoutGccExt;
use crate::callee::get_fn;
// Rust asm! and GCC Extended Asm semantics differ substantially.
......@@ -116,7 +117,6 @@ fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_opera
let asm_arch = self.tcx.sess.asm_arch.unwrap();
let is_x86 = matches!(asm_arch, InlineAsmArch::X86 | InlineAsmArch::X86_64);
let att_dialect = is_x86 && options.contains(InlineAsmOptions::ATT_SYNTAX);
let intel_dialect = is_x86 && !options.contains(InlineAsmOptions::ATT_SYNTAX);
// GCC index of an output operand equals its position in the array
let mut outputs = vec![];
......@@ -348,9 +348,24 @@ fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_opera
// processed in the previous pass
}
InlineAsmOperandRef::Const { .. }
| InlineAsmOperandRef::SymFn { .. }
| InlineAsmOperandRef::SymStatic { .. } => {
InlineAsmOperandRef::SymFn { instance } => {
inputs.push(AsmInOperand {
constraint: "X".into(),
rust_idx,
val: self.cx.rvalue_as_function(get_fn(self.cx, instance))
.get_address(None),
});
}
InlineAsmOperandRef::SymStatic { def_id } => {
inputs.push(AsmInOperand {
constraint: "X".into(),
rust_idx,
val: self.cx.get_static(def_id).get_address(None),
});
}
InlineAsmOperandRef::Const { .. } => {
// processed in the previous pass
}
}
......@@ -359,7 +374,7 @@ fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_opera
// 3. Build the template string
let mut template_str = String::with_capacity(estimate_template_length(template, constants_len, att_dialect));
if !intel_dialect {
if att_dialect {
template_str.push_str(ATT_SYNTAX_INS);
}
......@@ -444,7 +459,7 @@ fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_opera
}
}
if !intel_dialect {
if att_dialect {
template_str.push_str(INTEL_SYNTAX_INS);
}
......@@ -588,7 +603,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
| InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg) => "x",
InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => "v",
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => unimplemented!(),
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => "Yk",
InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg0) => unimplemented!(),
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => unimplemented!(),
InlineAsmRegClass::X86(
......@@ -672,8 +687,8 @@ fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[Gl
let asm_arch = self.tcx.sess.asm_arch.unwrap();
// Default to Intel syntax on x86
let intel_syntax = matches!(asm_arch, InlineAsmArch::X86 | InlineAsmArch::X86_64)
&& !options.contains(InlineAsmOptions::ATT_SYNTAX);
let att_dialect = matches!(asm_arch, InlineAsmArch::X86 | InlineAsmArch::X86_64)
&& options.contains(InlineAsmOptions::ATT_SYNTAX);
// Build the template string
let mut template_str = String::new();
......@@ -723,11 +738,11 @@ fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[Gl
}
let template_str =
if intel_syntax {
format!("{}\n\t.intel_syntax noprefix", template_str)
if att_dialect {
format!(".att_syntax\n\t{}\n\t.intel_syntax noprefix", template_str)
}
else {
format!(".att_syntax\n\t{}\n\t.intel_syntax noprefix", template_str)
template_str
};
// NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually.
let template_str = format!(".pushsection .text\n{}\n.popsection", template_str);
......
......@@ -78,9 +78,19 @@ fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, supports_128bit_integers): (Symbol
let context = Context::default();
// TODO(antoyo): only set on x86 platforms.
context.add_command_line_option("-masm=intel");
// TODO(antoyo): only add the following cli argument if the feature is supported.
context.add_command_line_option("-msse2");
context.add_command_line_option("-mavx2");
context.add_command_line_option("-msha");
context.add_command_line_option("-mpclmul");
// FIXME(antoyo): the following causes an illegal instruction on vmovdqu64 in std_example on my CPU.
// Only add if the CPU supports it.
//context.add_command_line_option("-mavx512f");
for arg in &tcx.sess.opts.cg.llvm_args {
context.add_command_line_option(arg);
}
// NOTE: This is needed to compile the file src/intrinsic/archs.rs during a bootstrap of rustc.
context.add_command_line_option("-fno-var-tracking-assignments");
// NOTE: an optimization (https://github.com/rust-lang/rustc_codegen_gcc/issues/53).
context.add_command_line_option("-fno-semantic-interposition");
// NOTE: Rust relies on LLVM not doing TBAA (https://github.com/rust-lang/unsafe-code-guidelines/issues/292).
......
......@@ -3,11 +3,11 @@
use std::convert::TryFrom;
use std::ops::Deref;
use gccjit::FunctionType;
use gccjit::{
BinaryOp,
Block,
ComparisonOp,
Context,
Function,
LValue,
RValue,
......@@ -48,6 +48,7 @@
use crate::common::{SignType, TypeReflection, type_is_pointer};
use crate::context::CodegenCx;
use crate::intrinsic::llvm;
use crate::type_of::LayoutGccExt;
// TODO(antoyo)
......@@ -199,17 +200,28 @@ fn check_ptr_call<'b>(&mut self, _typ: &str, func_ptr: RValue<'gcc>, args: &'b [
return Cow::Borrowed(args);
}
let func_name = format!("{:?}", func_ptr);
let casted_args: Vec<_> = param_types
.into_iter()
.zip(args.iter())
.enumerate()
.map(|(index, (expected_ty, &actual_val))| {
if llvm::ignore_arg_cast(&func_name, index, args.len()) {
return actual_val;
}
let actual_ty = actual_val.get_type();
if expected_ty != actual_ty {
if on_stack_param_indices.contains(&index) {
if !actual_ty.is_vector() && !expected_ty.is_vector() && actual_ty.is_integral() && expected_ty.is_integral() && actual_ty.get_size() != expected_ty.get_size() {
self.context.new_cast(None, actual_val, expected_ty)
}
else if on_stack_param_indices.contains(&index) {
actual_val.dereference(None).to_rvalue()
}
else {
assert!(!((actual_ty.is_vector() && !expected_ty.is_vector()) || (!actual_ty.is_vector() && expected_ty.is_vector())), "{:?} ({}) -> {:?} ({}), index: {:?}[{}]", actual_ty, actual_ty.is_vector(), expected_ty, expected_ty.is_vector(), func_ptr, index);
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
self.bitcast(actual_val, expected_ty)
}
}
......@@ -268,22 +280,20 @@ fn function_ptr_call(&mut self, func_ptr: RValue<'gcc>, args: &[RValue<'gcc>], _
// gccjit requires to use the result of functions, even when it's not used.
// That's why we assign the result to a local or call add_eval().
let gcc_func = func_ptr.get_type().dyncast_function_ptr_type().expect("function ptr");
let mut return_type = gcc_func.get_return_type();
let return_type = gcc_func.get_return_type();
let void_type = self.context.new_type::<()>();
let current_func = self.block.get_function();
// FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
if gcc_func.get_param_count() == 0 && format!("{:?}", func_ptr) == "__builtin_ia32_pmovmskb128" {
return_type = self.int_type;
}
if return_type != void_type {
unsafe { RETURN_VALUE_COUNT += 1 };
let result = current_func.new_local(None, return_type, &format!("ptrReturnValue{}", unsafe { RETURN_VALUE_COUNT }));
let func_name = format!("{:?}", func_ptr);
let args = llvm::adjust_intrinsic_arguments(&self, gcc_func, args, &func_name);
self.block.add_assignment(None, result, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
result.to_rvalue()
}
else {
#[cfg(not(feature="master"))]
if gcc_func.get_param_count() == 0 {
// FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &[]));
......@@ -291,6 +301,8 @@ fn function_ptr_call(&mut self, func_ptr: RValue<'gcc>, args: &[RValue<'gcc>], _
else {
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
}
#[cfg(feature="master")]
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
// Return dummy value when not having return value.
let result = current_func.new_local(None, self.isize_type, "dummyValueThatShouldNeverBeUsed");
self.block.add_assignment(None, result, self.context.new_rvalue_from_long(self.isize_type, 0));
......@@ -480,8 +492,11 @@ fn udiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
}
fn exactudiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
// TODO(antoyo): convert the arguments to unsigned?
// TODO(antoyo): poison if not exact.
let a_type = a.get_type().to_unsigned(self);
let a = self.gcc_int_cast(a, a_type);
let b_type = b.get_type().to_unsigned(self);
let b = self.gcc_int_cast(b, b_type);
a / b
}
......@@ -511,12 +526,12 @@ fn srem(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
}
fn frem(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
if a.get_type() == self.cx.float_type {
if a.get_type().is_compatible_with(self.cx.float_type) {
let fmodf = self.context.get_builtin_function("fmodf");
// FIXME(antoyo): this seems to produce the wrong result.
return self.context.new_call(None, fmodf, &[a, b]);
}
assert_eq!(a.get_type(), self.cx.double_type);
assert_eq!(a.get_type().unqualified(), self.cx.double_type);
let fmod = self.context.get_builtin_function("fmod");
return self.context.new_call(None, fmod, &[a, b]);
......@@ -632,18 +647,17 @@ fn array_alloca(&mut self, _ty: Type<'gcc>, _len: RValue<'gcc>, _align: Align) -
unimplemented!();
}
fn load(&mut self, _ty: Type<'gcc>, ptr: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
// TODO(antoyo): use ty.
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
let block = self.llbb();
let function = block.get_function();
// NOTE: instead of returning the dereference here, we have to assign it to a variable in
// the current basic block. Otherwise, it could be used in another basic block, causing a
// dereference after a drop, for instance.
// TODO(antoyo): handle align.
// TODO(antoyo): handle align of the load instruction.
let ptr = self.context.new_cast(None, ptr, pointee_ty.make_pointer());
let deref = ptr.dereference(None).to_rvalue();
let value_type = deref.get_type();
unsafe { RETURN_VALUE_COUNT += 1 };
let loaded_value = function.new_local(None, value_type, &format!("loadedValue{}", unsafe { RETURN_VALUE_COUNT }));
let loaded_value = function.new_local(None, pointee_ty, &format!("loadedValue{}", unsafe { RETURN_VALUE_COUNT }));
block.add_assignment(None, loaded_value, deref);
loaded_value.to_rvalue()
}
......@@ -695,7 +709,11 @@ fn scalar_load_metadata<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>, load:
OperandValue::Ref(place.llval, Some(llextra), place.align)
}
else if place.layout.is_gcc_immediate() {
let load = self.load(place.llval.get_type(), place.llval, place.align);
let load = self.load(
place.layout.gcc_type(self, false),
place.llval,
place.align,
);
if let abi::Abi::Scalar(ref scalar) = place.layout.abi {
scalar_load_metadata(self, load, scalar);
}
......@@ -707,7 +725,8 @@ fn scalar_load_metadata<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>, load:
let mut load = |i, scalar: &abi::Scalar, align| {
let llptr = self.struct_gep(pair_type, place.llval, i as u64);
let load = self.load(llptr.get_type(), llptr, align);
let llty = place.layout.scalar_pair_element_gcc_type(self, i, false);
let load = self.load(llty, llptr, align);
scalar_load_metadata(self, load, scalar);
if scalar.is_bool() { self.trunc(load, self.type_i1()) } else { load }
};
......@@ -779,9 +798,16 @@ fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValu
self.store_with_flags(val, ptr, align, MemFlags::empty())
}
fn store_with_flags(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, _align: Align, _flags: MemFlags) -> RValue<'gcc> {
fn store_with_flags(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align, _flags: MemFlags) -> RValue<'gcc> {
let ptr = self.check_store(val, ptr);
self.llbb().add_assignment(None, ptr.dereference(None), val);
let destination = ptr.dereference(None);
// NOTE: libgccjit does not support specifying the alignment on the assignment, so we cast
// to type so it gets the proper alignment.
let destination_type = destination.to_rvalue().get_type().unqualified();
let aligned_type = destination_type.get_aligned(align.bytes()).make_pointer();
let aligned_destination = self.cx.context.new_bitcast(None, ptr, aligned_type);
let aligned_destination = aligned_destination.dereference(None);
self.llbb().add_assignment(None, aligned_destination, val);
// TODO(antoyo): handle align and flags.
// NOTE: dummy value here since it's never used. FIXME(antoyo): API should not return a value here?
self.cx.context.new_rvalue_zero(self.type_i32())
......@@ -953,7 +979,7 @@ fn memcpy(&mut self, dst: RValue<'gcc>, _dst_align: Align, src: RValue<'gcc>, _s
fn memmove(&mut self, dst: RValue<'gcc>, dst_align: Align, src: RValue<'gcc>, src_align: Align, size: RValue<'gcc>, flags: MemFlags) {
if flags.contains(MemFlags::NONTEMPORAL) {
// HACK(nox): This is inefficient but there is no nontemporal memmove.
let val = self.load(src.get_type(), src, src_align);
let val = self.load(src.get_type().get_pointee().expect("get_pointee"), src, src_align);
let ptr = self.pointercast(dst, self.type_ptr_to(self.val_ty(val)));
self.store_with_flags(val, ptr, dst_align, flags);
return;
......@@ -1269,16 +1295,183 @@ fn instrprof_increment(&mut self, _fn_name: RValue<'gcc>, _hash: RValue<'gcc>, _
}
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
#[cfg(feature="master")]
pub fn shuffle_vector(&mut self, v1: RValue<'gcc>, v2: RValue<'gcc>, mask: RValue<'gcc>) -> RValue<'gcc> {
let return_type = v1.get_type();
let params = [
self.context.new_parameter(None, return_type, "v1"),
self.context.new_parameter(None, return_type, "v2"),
self.context.new_parameter(None, mask.get_type(), "mask"),
];
let shuffle = self.context.new_function(None, FunctionType::Extern, return_type, &params, "_mm_shuffle_epi8", false);
self.context.new_call(None, shuffle, &[v1, v2, mask])
let struct_type = mask.get_type().is_struct().expect("mask of struct type");
// TODO(antoyo): use a recursive unqualified() here.
let vector_type = v1.get_type().unqualified().dyncast_vector().expect("vector type");
let element_type = vector_type.get_element_type();
let vec_num_units = vector_type.get_num_units();
let mask_num_units = struct_type.get_field_count();
let mut vector_elements = vec![];
let mask_element_type =
if element_type.is_integral() {
element_type
}
else {
#[cfg(feature="master")]
{
self.cx.type_ix(element_type.get_size() as u64 * 8)
}
#[cfg(not(feature="master"))]
self.int_type
};
for i in 0..mask_num_units {
let field = struct_type.get_field(i as i32);
vector_elements.push(self.context.new_cast(None, mask.access_field(None, field).to_rvalue(), mask_element_type));
}
// NOTE: the mask needs to be the same length as the input vectors, so add the missing
// elements in the mask if needed.
for _ in mask_num_units..vec_num_units {
vector_elements.push(self.context.new_rvalue_zero(mask_element_type));
}
let array_type = self.context.new_array_type(None, element_type, vec_num_units as i32);
let result_type = self.context.new_vector_type(element_type, mask_num_units as u64);
let (v1, v2) =
if vec_num_units < mask_num_units {
// NOTE: the mask needs to be the same length as the input vectors, so join the 2
// vectors and create a dummy second vector.
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, v1, array_type);
let mut elements = vec![];
for i in 0..vec_num_units {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());
}
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, v2, array_type);
for i in 0..(mask_num_units - vec_num_units) {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());
}
let v1 = self.context.new_rvalue_from_vector(None, result_type, &elements);
let zero = self.context.new_rvalue_zero(element_type);
let v2 = self.context.new_rvalue_from_vector(None, result_type, &vec![zero; mask_num_units]);
(v1, v2)
}
else {
(v1, v2)
};
let new_mask_num_units = std::cmp::max(mask_num_units, vec_num_units);
let mask_type = self.context.new_vector_type(mask_element_type, new_mask_num_units as u64);
let mask = self.context.new_rvalue_from_vector(None, mask_type, &vector_elements);
let result = self.context.new_rvalue_vector_perm(None, v1, v2, mask);
if vec_num_units != mask_num_units {
// NOTE: if padding was added, only select the number of elements of the masks to
// remove that padding in the result.
let mut elements = vec![];
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, result, array_type);
for i in 0..mask_num_units {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());
}
self.context.new_rvalue_from_vector(None, result_type, &elements)
}
else {
result
}
}
#[cfg(not(feature="master"))]
pub fn shuffle_vector(&mut self, _v1: RValue<'gcc>, _v2: RValue<'gcc>, _mask: RValue<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
#[cfg(feature="master")]
pub fn vector_reduce<F>(&mut self, src: RValue<'gcc>, op: F) -> RValue<'gcc>
where F: Fn(RValue<'gcc>, RValue<'gcc>, &'gcc Context<'gcc>) -> RValue<'gcc>
{
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
let element_count = vector_type.get_num_units();
let mut vector_elements = vec![];
for i in 0..element_count {
vector_elements.push(i);
}
let mask_type = self.context.new_vector_type(self.int_type, element_count as u64);
let mut shift = 1;
let mut res = src;
while shift < element_count {
let vector_elements: Vec<_> =
vector_elements.iter()
.map(|i| self.context.new_rvalue_from_int(self.int_type, ((i + shift) % element_count) as i32))
.collect();
let mask = self.context.new_rvalue_from_vector(None, mask_type, &vector_elements);
let shifted = self.context.new_rvalue_vector_perm(None, res, res, mask);
shift *= 2;
res = op(res, shifted, &self.context);
}
self.context.new_vector_access(None, res, self.context.new_rvalue_zero(self.int_type))
.to_rvalue()
}
#[cfg(not(feature="master"))]
pub fn vector_reduce<F>(&mut self, src: RValue<'gcc>, op: F) -> RValue<'gcc>
where F: Fn(RValue<'gcc>, RValue<'gcc>, &'gcc Context<'gcc>) -> RValue<'gcc>
{
unimplemented!();
}
pub fn vector_reduce_op(&mut self, src: RValue<'gcc>, op: BinaryOp) -> RValue<'gcc> {
self.vector_reduce(src, |a, b, context| context.new_binary_op(None, op, a.get_type(), a, b))
}
pub fn vector_reduce_fadd_fast(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
pub fn vector_reduce_fmul_fast(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
// Inspired by Hacker's Delight min implementation.
pub fn vector_reduce_min(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
self.vector_reduce(src, |a, b, context| {
let differences_or_zeros = difference_or_zero(a, b, context);
context.new_binary_op(None, BinaryOp::Minus, a.get_type(), a, differences_or_zeros)
})
}
// Inspired by Hacker's Delight max implementation.
pub fn vector_reduce_max(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
self.vector_reduce(src, |a, b, context| {
let differences_or_zeros = difference_or_zero(a, b, context);
context.new_binary_op(None, BinaryOp::Plus, b.get_type(), b, differences_or_zeros)
})
}
pub fn vector_select(&mut self, cond: RValue<'gcc>, then_val: RValue<'gcc>, else_val: RValue<'gcc>) -> RValue<'gcc> {
// cond is a vector of integers, not of bools.
let cond_type = cond.get_type();
let vector_type = cond_type.unqualified().dyncast_vector().expect("vector type");
let num_units = vector_type.get_num_units();
let element_type = vector_type.get_element_type();
let zeros = vec![self.context.new_rvalue_zero(element_type); num_units];
let zeros = self.context.new_rvalue_from_vector(None, cond_type, &zeros);
let masks = self.context.new_comparison(None, ComparisonOp::NotEquals, cond, zeros);
let then_vals = masks & then_val;
let ones = vec![self.context.new_rvalue_one(element_type); num_units];
let ones = self.context.new_rvalue_from_vector(None, cond_type, &ones);
let inverted_masks = masks + ones;
// NOTE: sometimes, the type of else_val can be different than the type of then_val in
// libgccjit (vector of int vs vector of int32_t), but they should be the same for the AND
// operation to work.
let else_val = self.context.new_bitcast(None, else_val, then_val.get_type());
let else_vals = inverted_masks & else_val;
then_vals | else_vals
}
}
fn difference_or_zero<'gcc>(a: RValue<'gcc>, b: RValue<'gcc>, context: &'gcc Context<'gcc>) -> RValue<'gcc> {
let difference = a - b;
let masks = context.new_comparison(None, ComparisonOp::GreaterThanEquals, b, a);
difference & masks
}
impl<'a, 'gcc, 'tcx> StaticBuilderMethods for Builder<'a, 'gcc, 'tcx> {
......
......@@ -121,8 +121,8 @@ fn const_u8(&self, _i: u8) -> RValue<'gcc> {
unimplemented!();
}
fn const_real(&self, _t: Type<'gcc>, _val: f64) -> RValue<'gcc> {
unimplemented!();
fn const_real(&self, typ: Type<'gcc>, val: f64) -> RValue<'gcc> {
self.context.new_rvalue_from_double(typ, val)
}
fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) {
......@@ -279,6 +279,21 @@ fn to_signed(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
else if self.is_u128(cx) {
cx.i128_type
}
else if self.is_uchar(cx) {
cx.char_type
}
else if self.is_ushort(cx) {
cx.short_type
}
else if self.is_uint(cx) {
cx.int_type
}
else if self.is_ulong(cx) {
cx.long_type
}
else if self.is_ulonglong(cx) {
cx.longlong_type
}
else {
self.clone()
}
......@@ -300,6 +315,21 @@ fn to_unsigned(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
else if self.is_i128(cx) {
cx.u128_type
}
else if self.is_char(cx) {
cx.uchar_type
}
else if self.is_short(cx) {
cx.ushort_type
}
else if self.is_int(cx) {
cx.uint_type
}
else if self.is_long(cx) {
cx.ulong_type
}
else if self.is_longlong(cx) {
cx.ulonglong_type
}
else {
self.clone()
}
......@@ -312,6 +342,11 @@ pub trait TypeReflection<'gcc, 'tcx> {
fn is_uint(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_ulong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_ulonglong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_char(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_short(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_int(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_long(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_longlong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_u8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
......@@ -326,15 +361,17 @@ pub trait TypeReflection<'gcc, 'tcx> {
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_vector(&self) -> bool;
}
impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
fn is_uchar(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.u8_type
self.unqualified() == cx.uchar_type
}
fn is_ushort(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.u16_type
self.unqualified() == cx.ushort_type
}
fn is_uint(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
......@@ -349,6 +386,26 @@ fn is_ulonglong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.ulonglong_type
}
fn is_char(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.char_type
}
fn is_short(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.short_type
}
fn is_int(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.int_type
}
fn is_long(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.long_type
}
fn is_longlong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.longlong_type
}
fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.i8_type
}
......@@ -396,4 +453,21 @@ fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.context.new_type::<f64>()
}
fn is_vector(&self) -> bool {
let mut typ = self.clone();
loop {
if typ.dyncast_vector().is_some() {
return true;
}
let old_type = typ;
typ = typ.unqualified();
if old_type == typ {
break;
}
}
false
}
}
......@@ -25,7 +25,9 @@ pub fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc
}
}
}
self.context.new_bitcast(None, value, typ)
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
// SIMD builtins require a constant value.
self.bitcast_if_needed(value, typ)
}
}
......@@ -45,7 +47,10 @@ fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) ->
}
}
let global_value = self.static_addr_of_mut(cv, align, kind);
// TODO(antoyo): set global constant.
#[cfg(feature = "master")]
self.global_lvalues.borrow().get(&global_value)
.expect("`static_addr_of_mut` did not add the global to `self.global_lvalues`")
.global_set_readonly();
self.const_globals.borrow_mut().insert(cv, global_value);
global_value
}
......@@ -79,20 +84,15 @@ fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
// TODO(antoyo): set alignment.
let value =
if value.get_type() != gcc_type {
self.context.new_bitcast(None, value, gcc_type)
}
else {
value
};
let value = self.bitcast_if_needed(value, gcc_type);
global.global_set_initializer_rvalue(value);
// As an optimization, all shared statics which do not have interior
// mutability are placed into read-only memory.
if !is_mutable {
if self.type_is_freeze(ty) {
// TODO(antoyo): set global constant.
#[cfg(feature = "master")]
global.global_set_readonly();
}
}
......@@ -171,8 +171,9 @@ pub fn static_addr_of_mut(&self, cv: RValue<'gcc>, align: Align, kind: Option<&s
Some(kind) if !self.tcx.sess.fewer_names() => {
let name = self.generate_local_symbol_name(kind);
// TODO(antoyo): check if it's okay that no link_section is set.
// TODO(antoyo): set alignment here as well.
let global = self.declare_private_global(&name[..], self.val_ty(cv));
let typ = self.val_ty(cv).get_aligned(align.bytes());
let global = self.declare_private_global(&name[..], typ);
global
}
_ => {
......
......@@ -35,6 +35,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
pub normal_function_addresses: RefCell<FxHashSet<RValue<'gcc>>>,
pub functions: RefCell<FxHashMap<String, Function<'gcc>>>,
pub intrinsics: RefCell<FxHashMap<String, Function<'gcc>>>,
pub tls_model: gccjit::TlsModel,
......@@ -53,10 +54,15 @@ pub struct CodegenCx<'gcc, 'tcx> {
pub u128_type: Type<'gcc>,
pub usize_type: Type<'gcc>,
pub char_type: Type<'gcc>,
pub uchar_type: Type<'gcc>,
pub short_type: Type<'gcc>,
pub ushort_type: Type<'gcc>,
pub int_type: Type<'gcc>,
pub uint_type: Type<'gcc>,
pub long_type: Type<'gcc>,
pub ulong_type: Type<'gcc>,
pub longlong_type: Type<'gcc>,
pub ulonglong_type: Type<'gcc>,
pub sizet_type: Type<'gcc>,
......@@ -145,10 +151,15 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
let float_type = context.new_type::<f32>();
let double_type = context.new_type::<f64>();
let char_type = context.new_c_type(CType::Char);
let uchar_type = context.new_c_type(CType::UChar);
let short_type = context.new_c_type(CType::Short);
let ushort_type = context.new_c_type(CType::UShort);
let int_type = context.new_c_type(CType::Int);
let uint_type = context.new_c_type(CType::UInt);
let long_type = context.new_c_type(CType::Long);
let ulong_type = context.new_c_type(CType::ULong);
let longlong_type = context.new_c_type(CType::LongLong);
let ulonglong_type = context.new_c_type(CType::ULongLong);
let sizet_type = context.new_c_type(CType::SizeT);
......@@ -184,6 +195,7 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
current_func: RefCell::new(None),
normal_function_addresses: Default::default(),
functions: RefCell::new(functions),
intrinsics: RefCell::new(FxHashMap::default()),
tls_model,
......@@ -200,10 +212,15 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
u32_type,
u64_type,
u128_type,
char_type,
uchar_type,
short_type,
ushort_type,
int_type,
uint_type,
long_type,
ulong_type,
longlong_type,
ulonglong_type,
sizet_type,
......@@ -269,16 +286,25 @@ pub fn is_non_native_int_type(&self, typ: Type<'gcc>) -> bool {
}
pub fn is_native_int_type_or_bool(&self, typ: Type<'gcc>) -> bool {
self.is_native_int_type(typ) || typ == self.bool_type
self.is_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
}
pub fn is_int_type_or_bool(&self, typ: Type<'gcc>) -> bool {
self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ == self.bool_type
self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
}
pub fn sess(&self) -> &Session {
&self.tcx.sess
}
pub fn bitcast_if_needed(&self, value: RValue<'gcc>, expected_type: Type<'gcc>) -> RValue<'gcc> {
if value.get_type() != expected_type {
self.context.new_bitcast(None, value, expected_type)
}
else {
value
}
}
}
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
......@@ -306,8 +332,16 @@ fn get_fn(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
}
fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
let func = get_fn(self, instance);
let func = self.rvalue_as_function(func);
let func_name = self.tcx.symbol_name(instance).name;
let func =
if self.intrinsics.borrow().contains_key(func_name) {
self.intrinsics.borrow()[func_name].clone()
}
else {
let func = get_fn(self, instance);
self.rvalue_as_function(func)
};
let ptr = func.get_address(None);
// TODO(antoyo): don't do this twice: i.e. in declare_fn and here.
......
......@@ -11,7 +11,7 @@
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
pub fn get_or_insert_global(&self, name: &str, ty: Type<'gcc>, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
if self.globals.borrow().contains_key(name) {
let typ = self.globals.borrow().get(name).expect("global").get_type();
let typ = self.globals.borrow()[name].get_type();
let global = self.context.new_global(None, GlobalKind::Imported, typ, name);
if is_tls {
global.set_tls_model(self.tls_model);
......@@ -103,11 +103,13 @@ pub fn get_declared_value(&self, name: &str) -> Option<RValue<'gcc>> {
/// update the declaration and return existing Value instead.
fn declare_raw_fn<'gcc>(cx: &CodegenCx<'gcc, '_>, name: &str, _callconv: () /*llvm::CallConv*/, return_type: Type<'gcc>, param_types: &[Type<'gcc>], variadic: bool) -> Function<'gcc> {
if name.starts_with("llvm.") {
return llvm::intrinsic(name, cx);
let intrinsic = llvm::intrinsic(name, cx);
cx.intrinsics.borrow_mut().insert(name.to_string(), intrinsic);
return intrinsic;
}
let func =
if cx.functions.borrow().contains_key(name) {
*cx.functions.borrow().get(name).expect("function")
cx.functions.borrow()[name]
}
else {
let params: Vec<_> = param_types.into_iter().enumerate()
......
......@@ -153,8 +153,15 @@ fn additive_operation(&self, operation: BinaryOp, a: RValue<'gcc>, mut b: RValue
let a_type = a.get_type();
let b_type = b.get_type();
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
if a.get_type() != b.get_type() {
b = self.context.new_cast(None, b, a.get_type());
if a_type != b_type {
if a_type.is_vector() {
// Vector types need to be bitcast.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
b = self.context.new_bitcast(None, b, a.get_type());
}
else {
b = self.context.new_cast(None, b, a.get_type());
}
}
self.context.new_binary_op(None, operation, a_type, a, b)
}
......@@ -593,7 +600,10 @@ fn bitwise_operation(&self, operation: BinaryOp, a: RValue<'gcc>, mut b: RValue<
let b_type = b.get_type();
let a_native = self.is_native_int_type_or_bool(a_type);
let b_native = self.is_native_int_type_or_bool(b_type);
if a_native && b_native {
if a_type.is_vector() && b_type.is_vector() {
self.context.new_binary_op(None, operation, a_type, a, b)
}
else if a_native && b_native {
if a_type != b_type {
b = self.context.new_cast(None, b, a_type);
}
......@@ -639,6 +649,8 @@ pub fn gcc_int_cast(&self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<
else {
// Since u128 and i128 are the only types that can be unsupported, we know the type of
// value and the destination type have the same size, so a bitcast is fine.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
self.context.new_bitcast(None, value, dest_typ)
}
}
......
此差异已折叠。
use gccjit::Function;
use std::borrow::Cow;
use crate::context::CodegenCx;
use gccjit::{Function, FunctionPtrType, RValue, ToRValue};
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
let _gcc_name =
match name {
"llvm.x86.xgetbv" => {
let gcc_name = "__builtin_trap";
let func = cx.context.get_builtin_function(gcc_name);
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
return func;
use crate::{context::CodegenCx, builder::Builder};
pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(builder: &Builder<'a, 'gcc, 'tcx>, gcc_func: FunctionPtrType<'gcc>, mut args: Cow<'b, [RValue<'gcc>]>, func_name: &str) -> Cow<'b, [RValue<'gcc>]> {
// Some LLVM intrinsics do not map 1-to-1 to GCC intrinsics, so we add the missing
// arguments here.
if gcc_func.get_param_count() != args.len() {
match &*func_name {
"__builtin_ia32_pmuldq512_mask" | "__builtin_ia32_pmuludq512_mask"
// FIXME(antoyo): the following intrinsics has 4 (or 5) arguments according to the doc, but is defined with 2 (or 3) arguments in library/stdarch/crates/core_arch/src/x86/avx512f.rs.
| "__builtin_ia32_pmaxsd512_mask" | "__builtin_ia32_pmaxsq512_mask" | "__builtin_ia32_pmaxsq256_mask"
| "__builtin_ia32_pmaxsq128_mask" | "__builtin_ia32_maxps512_mask" | "__builtin_ia32_maxpd512_mask"
| "__builtin_ia32_pmaxud512_mask" | "__builtin_ia32_pmaxuq512_mask" | "__builtin_ia32_pmaxuq256_mask"
| "__builtin_ia32_pmaxuq128_mask"
| "__builtin_ia32_pminsd512_mask" | "__builtin_ia32_pminsq512_mask" | "__builtin_ia32_pminsq256_mask"
| "__builtin_ia32_pminsq128_mask" | "__builtin_ia32_minps512_mask" | "__builtin_ia32_minpd512_mask"
| "__builtin_ia32_pminud512_mask" | "__builtin_ia32_pminuq512_mask" | "__builtin_ia32_pminuq256_mask"
| "__builtin_ia32_pminuq128_mask" | "__builtin_ia32_sqrtps512_mask" | "__builtin_ia32_sqrtpd512_mask"
=> {
// TODO: refactor by separating those intrinsics outside of this branch.
let add_before_last_arg =
match &*func_name {
"__builtin_ia32_maxps512_mask" | "__builtin_ia32_maxpd512_mask"
| "__builtin_ia32_minps512_mask" | "__builtin_ia32_minpd512_mask"
| "__builtin_ia32_sqrtps512_mask" | "__builtin_ia32_sqrtpd512_mask" => true,
_ => false,
};
let new_first_arg_is_zero =
match &*func_name {
"__builtin_ia32_pmaxuq256_mask" | "__builtin_ia32_pmaxuq128_mask"
| "__builtin_ia32_pminuq256_mask" | "__builtin_ia32_pminuq128_mask" => true,
_ => false
};
let arg3_index =
match &*func_name {
"__builtin_ia32_sqrtps512_mask" | "__builtin_ia32_sqrtpd512_mask" => 1,
_ => 2,
};
let mut new_args = args.to_vec();
let arg3_type = gcc_func.get_param_type(arg3_index);
let first_arg =
if new_first_arg_is_zero {
let vector_type = arg3_type.dyncast_vector().expect("vector type");
let zero = builder.context.new_rvalue_zero(vector_type.get_element_type());
let num_units = vector_type.get_num_units();
builder.context.new_rvalue_from_vector(None, arg3_type, &vec![zero; num_units])
}
else {
builder.current_func().new_local(None, arg3_type, "undefined_for_intrinsic").to_rvalue()
};
if add_before_last_arg {
new_args.insert(new_args.len() - 1, first_arg);
}
else {
new_args.push(first_arg);
}
let arg4_index =
match &*func_name {
"__builtin_ia32_sqrtps512_mask" | "__builtin_ia32_sqrtpd512_mask" => 2,
_ => 3,
};
let arg4_type = gcc_func.get_param_type(arg4_index);
let minus_one = builder.context.new_rvalue_from_int(arg4_type, -1);
if add_before_last_arg {
new_args.insert(new_args.len() - 1, minus_one);
}
else {
new_args.push(minus_one);
}
args = new_args.into();
},
"__builtin_ia32_pternlogd512_mask" | "__builtin_ia32_pternlogd256_mask"
| "__builtin_ia32_pternlogd128_mask" | "__builtin_ia32_pternlogq512_mask"
| "__builtin_ia32_pternlogq256_mask" | "__builtin_ia32_pternlogq128_mask" => {
let mut new_args = args.to_vec();
let arg5_type = gcc_func.get_param_type(4);
let minus_one = builder.context.new_rvalue_from_int(arg5_type, -1);
new_args.push(minus_one);
args = new_args.into();
},
"__builtin_ia32_vfmaddps512_mask" | "__builtin_ia32_vfmaddpd512_mask" => {
let mut new_args = args.to_vec();
let mut last_arg = None;
if args.len() == 4 {
last_arg = new_args.pop();
}
let arg4_type = gcc_func.get_param_type(3);
let minus_one = builder.context.new_rvalue_from_int(arg4_type, -1);
new_args.push(minus_one);
if args.len() == 3 {
// Both llvm.fma.v16f32 and llvm.x86.avx512.vfmadd.ps.512 maps to
// the same GCC intrinsic, but the former has 3 parameters and the
// latter has 4 so it doesn't require this additional argument.
let arg5_type = gcc_func.get_param_type(4);
new_args.push(builder.context.new_rvalue_from_int(arg5_type, 4));
}
if let Some(last_arg) = last_arg {
new_args.push(last_arg);
}
args = new_args.into();
},
"__builtin_ia32_addps512_mask" | "__builtin_ia32_addpd512_mask"
| "__builtin_ia32_subps512_mask" | "__builtin_ia32_subpd512_mask"
| "__builtin_ia32_mulps512_mask" | "__builtin_ia32_mulpd512_mask"
| "__builtin_ia32_divps512_mask" | "__builtin_ia32_divpd512_mask" => {
let mut new_args = args.to_vec();
let last_arg = new_args.pop().expect("last arg");
let arg3_type = gcc_func.get_param_type(2);
let undefined = builder.current_func().new_local(None, arg3_type, "undefined_for_intrinsic").to_rvalue();
new_args.push(undefined);
let arg4_type = gcc_func.get_param_type(3);
let minus_one = builder.context.new_rvalue_from_int(arg4_type, -1);
new_args.push(minus_one);
new_args.push(last_arg);
args = new_args.into();
},
"__builtin_ia32_vfmaddsubps512_mask" | "__builtin_ia32_vfmaddsubpd512_mask" => {
let mut new_args = args.to_vec();
let last_arg = new_args.pop().expect("last arg");
let arg4_type = gcc_func.get_param_type(3);
let minus_one = builder.context.new_rvalue_from_int(arg4_type, -1);
new_args.push(minus_one);
new_args.push(last_arg);
args = new_args.into();
},
_ => (),
}
}
args
}
pub fn ignore_arg_cast(func_name: &str, index: usize, args_len: usize) -> bool {
// NOTE: these intrinsics have missing parameters before the last one, so ignore the
// last argument type check.
// FIXME(antoyo): find a way to refactor in order to avoid this hack.
match func_name {
"__builtin_ia32_maxps512_mask" | "__builtin_ia32_maxpd512_mask"
| "__builtin_ia32_minps512_mask" | "__builtin_ia32_minpd512_mask" | "__builtin_ia32_sqrtps512_mask"
| "__builtin_ia32_sqrtpd512_mask" | "__builtin_ia32_addps512_mask" | "__builtin_ia32_addpd512_mask"
| "__builtin_ia32_subps512_mask" | "__builtin_ia32_subpd512_mask"
| "__builtin_ia32_mulps512_mask" | "__builtin_ia32_mulpd512_mask"
| "__builtin_ia32_divps512_mask" | "__builtin_ia32_divpd512_mask"
| "__builtin_ia32_vfmaddsubps512_mask" | "__builtin_ia32_vfmaddsubpd512_mask" => {
if index == args_len - 1 {
return true;
}
},
// NOTE: this doc specifies the equivalent GCC builtins: http://huonw.github.io/llvmint/llvmint/x86/index.html
"llvm.x86.sse2.cmp.pd" => "__builtin_ia32_cmppd",
"llvm.x86.sse2.movmsk.pd" => "__builtin_ia32_movmskpd",
"llvm.x86.sse2.pmovmskb.128" => "__builtin_ia32_pmovmskb128",
_ => unimplemented!("unsupported LLVM intrinsic {}", name)
};
unimplemented!();
"__builtin_ia32_vfmaddps512_mask" | "__builtin_ia32_vfmaddpd512_mask" => {
// Since there are two LLVM intrinsics that map to each of these GCC builtins and only
// one of them has a missing parameter before the last one, we check the number of
// arguments to distinguish those cases.
if args_len == 4 && index == args_len - 1 {
return true;
}
},
_ => (),
}
false
}
#[cfg(not(feature="master"))]
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
match name {
"llvm.x86.xgetbv" => {
let gcc_name = "__builtin_trap";
let func = cx.context.get_builtin_function(gcc_name);
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
return func;
},
_ => unimplemented!("unsupported LLVM intrinsic {}", name),
}
}
#[cfg(feature="master")]
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
let gcc_name = match name {
"llvm.x86.xgetbv" => "__builtin_ia32_xgetbv",
// NOTE: this doc specifies the equivalent GCC builtins: http://huonw.github.io/llvmint/llvmint/x86/index.html
"llvm.sqrt.v2f64" => "__builtin_ia32_sqrtpd",
"llvm.x86.avx512.pmul.dq.512" => "__builtin_ia32_pmuldq512_mask",
"llvm.x86.avx512.pmulu.dq.512" => "__builtin_ia32_pmuludq512_mask",
"llvm.x86.avx512.mask.pmaxs.q.256" => "__builtin_ia32_pmaxsq256_mask",
"llvm.x86.avx512.mask.pmaxs.q.128" => "__builtin_ia32_pmaxsq128_mask",
"llvm.x86.avx512.max.ps.512" => "__builtin_ia32_maxps512_mask",
"llvm.x86.avx512.max.pd.512" => "__builtin_ia32_maxpd512_mask",
"llvm.x86.avx512.mask.pmaxu.q.256" => "__builtin_ia32_pmaxuq256_mask",
"llvm.x86.avx512.mask.pmaxu.q.128" => "__builtin_ia32_pmaxuq128_mask",
"llvm.x86.avx512.mask.pmins.q.256" => "__builtin_ia32_pminsq256_mask",
"llvm.x86.avx512.mask.pmins.q.128" => "__builtin_ia32_pminsq128_mask",
"llvm.x86.avx512.min.ps.512" => "__builtin_ia32_minps512_mask",
"llvm.x86.avx512.min.pd.512" => "__builtin_ia32_minpd512_mask",
"llvm.x86.avx512.mask.pminu.q.256" => "__builtin_ia32_pminuq256_mask",
"llvm.x86.avx512.mask.pminu.q.128" => "__builtin_ia32_pminuq128_mask",
"llvm.fma.v16f32" => "__builtin_ia32_vfmaddps512_mask",
"llvm.fma.v8f64" => "__builtin_ia32_vfmaddpd512_mask",
"llvm.x86.avx512.vfmaddsub.ps.512" => "__builtin_ia32_vfmaddsubps512_mask",
"llvm.x86.avx512.vfmaddsub.pd.512" => "__builtin_ia32_vfmaddsubpd512_mask",
"llvm.x86.avx512.pternlog.d.512" => "__builtin_ia32_pternlogd512_mask",
"llvm.x86.avx512.pternlog.d.256" => "__builtin_ia32_pternlogd256_mask",
"llvm.x86.avx512.pternlog.d.128" => "__builtin_ia32_pternlogd128_mask",
"llvm.x86.avx512.pternlog.q.512" => "__builtin_ia32_pternlogq512_mask",
"llvm.x86.avx512.pternlog.q.256" => "__builtin_ia32_pternlogq256_mask",
"llvm.x86.avx512.pternlog.q.128" => "__builtin_ia32_pternlogq128_mask",
"llvm.x86.avx512.add.ps.512" => "__builtin_ia32_addps512_mask",
"llvm.x86.avx512.add.pd.512" => "__builtin_ia32_addpd512_mask",
"llvm.x86.avx512.sub.ps.512" => "__builtin_ia32_subps512_mask",
"llvm.x86.avx512.sub.pd.512" => "__builtin_ia32_subpd512_mask",
"llvm.x86.avx512.mul.ps.512" => "__builtin_ia32_mulps512_mask",
"llvm.x86.avx512.mul.pd.512" => "__builtin_ia32_mulpd512_mask",
"llvm.x86.avx512.div.ps.512" => "__builtin_ia32_divps512_mask",
"llvm.x86.avx512.div.pd.512" => "__builtin_ia32_divpd512_mask",
"llvm.x86.avx512.vfmadd.ps.512" => "__builtin_ia32_vfmaddps512_mask",
"llvm.x86.avx512.vfmadd.pd.512" => "__builtin_ia32_vfmaddpd512_mask",
// The above doc points to unknown builtins for the following, so override them:
"llvm.x86.avx2.gather.d.d" => "__builtin_ia32_gathersiv4si",
"llvm.x86.avx2.gather.d.d.256" => "__builtin_ia32_gathersiv8si",
"llvm.x86.avx2.gather.d.ps" => "__builtin_ia32_gathersiv4sf",
"llvm.x86.avx2.gather.d.ps.256" => "__builtin_ia32_gathersiv8sf",
"llvm.x86.avx2.gather.d.q" => "__builtin_ia32_gathersiv2di",
"llvm.x86.avx2.gather.d.q.256" => "__builtin_ia32_gathersiv4di",
"llvm.x86.avx2.gather.d.pd" => "__builtin_ia32_gathersiv2df",
"llvm.x86.avx2.gather.d.pd.256" => "__builtin_ia32_gathersiv4df",
"llvm.x86.avx2.gather.q.d" => "__builtin_ia32_gatherdiv4si",
"llvm.x86.avx2.gather.q.d.256" => "__builtin_ia32_gatherdiv4si256",
"llvm.x86.avx2.gather.q.ps" => "__builtin_ia32_gatherdiv4sf",
"llvm.x86.avx2.gather.q.ps.256" => "__builtin_ia32_gatherdiv4sf256",
"llvm.x86.avx2.gather.q.q" => "__builtin_ia32_gatherdiv2di",
"llvm.x86.avx2.gather.q.q.256" => "__builtin_ia32_gatherdiv4di",
"llvm.x86.avx2.gather.q.pd" => "__builtin_ia32_gatherdiv2df",
"llvm.x86.avx2.gather.q.pd.256" => "__builtin_ia32_gatherdiv4df",
"" => "",
// NOTE: this file is generated by https://github.com/GuillaumeGomez/llvmint/blob/master/generate_list.py
_ => include!("archs.rs"),
};
let func = cx.context.get_target_builtin_function(gcc_name);
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
func
}
......@@ -967,34 +967,55 @@ fn rotate_right(&mut self, value: RValue<'gcc>, shift: RValue<'gcc>, width: u64)
}
fn saturating_add(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>, signed: bool, width: u64) -> RValue<'gcc> {
let func = self.current_func.borrow().expect("func");
let result_type = lhs.get_type();
if signed {
// Algorithm from: https://stackoverflow.com/a/56531252/389119
let after_block = func.new_block("after");
let func_name =
match width {
8 => "__builtin_add_overflow",
16 => "__builtin_add_overflow",
32 => "__builtin_sadd_overflow",
64 => "__builtin_saddll_overflow",
128 => "__builtin_add_overflow",
_ => unreachable!(),
};
let overflow_func = self.context.get_builtin_function(func_name);
let result_type = lhs.get_type();
// Based on algorithm from: https://stackoverflow.com/a/56531252/389119
let func = self.current_func.borrow().expect("func");
let res = func.new_local(None, result_type, "saturating_sum");
let overflow = self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(None)], None);
let supports_native_type = self.is_native_int_type(result_type);
let overflow =
if supports_native_type {
let func_name =
match width {
8 => "__builtin_add_overflow",
16 => "__builtin_add_overflow",
32 => "__builtin_sadd_overflow",
64 => "__builtin_saddll_overflow",
128 => "__builtin_add_overflow",
_ => unreachable!(),
};
let overflow_func = self.context.get_builtin_function(func_name);
self.overflow_call(overflow_func, &[lhs, rhs, res.get_address(None)], None)
}
else {
let func_name =
match width {
128 => "__rust_i128_addo",
_ => unreachable!(),
};
let param_a = self.context.new_parameter(None, result_type, "a");
let param_b = self.context.new_parameter(None, result_type, "b");
let result_field = self.context.new_field(None, result_type, "result");
let overflow_field = self.context.new_field(None, self.bool_type, "overflow");
let return_type = self.context.new_struct_type(None, "result_overflow", &[result_field, overflow_field]);
let func = self.context.new_function(None, FunctionType::Extern, return_type.as_type(), &[param_a, param_b], func_name, false);
let result = self.context.new_call(None, func, &[lhs, rhs]);
let overflow = result.access_field(None, overflow_field);
let int_result = result.access_field(None, result_field);
self.llbb().add_assignment(None, res, int_result);
overflow
};
let then_block = func.new_block("then");
let after_block = func.new_block("after");
let unsigned_type = self.context.new_int_type(width as i32 / 8, false);
let shifted = self.context.new_cast(None, lhs, unsigned_type) >> self.context.new_rvalue_from_int(unsigned_type, width as i32 - 1);
let uint_max = self.context.new_unary_op(None, UnaryOp::BitwiseNegate, unsigned_type,
self.context.new_rvalue_from_int(unsigned_type, 0)
);
let int_max = uint_max >> self.context.new_rvalue_one(unsigned_type);
then_block.add_assignment(None, res, self.context.new_cast(None, shifted + int_max, result_type));
// Return `result_type`'s maximum or minimum value on overflow
// NOTE: convert the type to unsigned to have an unsigned shift.
let unsigned_type = result_type.to_unsigned(&self.cx);
let shifted = self.gcc_lshr(self.gcc_int_cast(lhs, unsigned_type), self.gcc_int(unsigned_type, width as i64 - 1));
let uint_max = self.gcc_not(self.gcc_int(unsigned_type, 0));
let int_max = self.gcc_lshr(uint_max, self.gcc_int(unsigned_type, 1));
then_block.add_assignment(None, res, self.gcc_int_cast(self.gcc_add(shifted, int_max), result_type));
then_block.end_with_jump(None, after_block);
self.llbb().end_with_conditional(None, overflow, then_block, after_block);
......@@ -1007,19 +1028,18 @@ fn saturating_add(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>, signed: bool,
}
else {
// Algorithm from: http://locklessinc.com/articles/sat_arithmetic/
let res = lhs + rhs;
let res_type = res.get_type();
let cond = self.context.new_comparison(None, ComparisonOp::LessThan, res, lhs);
let value = self.context.new_unary_op(None, UnaryOp::Minus, res_type, self.context.new_cast(None, cond, res_type));
res | value
let res = self.gcc_add(lhs, rhs);
let cond = self.gcc_icmp(IntPredicate::IntULT, res, lhs);
let value = self.gcc_neg(self.gcc_int_cast(cond, result_type));
self.gcc_or(res, value)
}
}
// Algorithm from: https://locklessinc.com/articles/sat_arithmetic/
fn saturating_sub(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>, signed: bool, width: u64) -> RValue<'gcc> {
let result_type = lhs.get_type();
if signed {
// Also based on algorithm from: https://stackoverflow.com/a/56531252/389119
let result_type = lhs.get_type();
// Based on algorithm from: https://stackoverflow.com/a/56531252/389119
let func = self.current_func.borrow().expect("func");
let res = func.new_local(None, result_type, "saturating_diff");
let supports_native_type = self.is_native_int_type(result_type);
......@@ -1059,6 +1079,7 @@ fn saturating_sub(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>, signed: bool,
let then_block = func.new_block("then");
let after_block = func.new_block("after");
// Return `result_type`'s maximum or minimum value on overflow
// NOTE: convert the type to unsigned to have an unsigned shift.
let unsigned_type = result_type.to_unsigned(&self.cx);
let shifted = self.gcc_lshr(self.gcc_int_cast(lhs, unsigned_type), self.gcc_int(unsigned_type, width as i64 - 1));
......@@ -1076,11 +1097,10 @@ fn saturating_sub(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>, signed: bool,
res.to_rvalue()
}
else {
let res = lhs - rhs;
let comparison = self.context.new_comparison(None, ComparisonOp::LessThanEquals, res, lhs);
let comparison = self.context.new_cast(None, comparison, lhs.get_type());
let unary_op = self.context.new_unary_op(None, UnaryOp::Minus, comparison.get_type(), comparison);
self.and(res, unary_op)
let res = self.gcc_sub(lhs, rhs);
let comparison = self.gcc_icmp(IntPredicate::IntULE, res, lhs);
let value = self.gcc_neg(self.gcc_int_cast(comparison, result_type));
self.gcc_and(res, value)
}
}
}
......
......@@ -203,7 +203,7 @@ impl WriteBackendMethods for GccCodegenBackend {
fn run_fat_lto(_cgcx: &CodegenContext<Self>, mut modules: Vec<FatLTOInput<Self>>, _cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>) -> Result<LtoModuleCodegen<Self>, FatalError> {
// TODO(antoyo): implement LTO by sending -flto to libgccjit and adding the appropriate gcc linker plugins.
// NOTE: implemented elsewhere.
// TODO: what is implemented elsewhere ^ ?
// TODO(antoyo): what is implemented elsewhere ^ ?
let module =
match modules.remove(0) {
FatLTOInput::InMemory(module) => module,
......@@ -301,7 +301,22 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
)
.filter(|_feature| {
// TODO(antoyo): implement a way to get enabled feature in libgccjit.
false
// Probably using the equivalent of __builtin_cpu_supports.
#[cfg(feature="master")]
{
_feature.contains("sse") || _feature.contains("avx")
}
#[cfg(not(feature="master"))]
{
false
}
/*
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512gfni,
avx512ifma, avx512pf, avx512vaes, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpclmulqdq,
avx512vpopcntdq, bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm,
sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, xsave, xsavec, xsaveopt, xsaves
*/
//false
})
.map(|feature| Symbol::intern(feature))
.collect()
......
......@@ -3,10 +3,11 @@
use gccjit::{RValue, Struct, Type};
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods};
use rustc_codegen_ssa::common::TypeKind;
use rustc_middle::bug;
use rustc_middle::{bug, ty};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_target::abi::{AddressSpace, Align, Integer, Size};
use crate::common::TypeReflection;
use crate::context::CodegenCx;
use crate::type_of::LayoutGccExt;
......@@ -60,6 +61,17 @@ pub fn type_pointee_for_align(&self, align: Align) -> Type<'gcc> {
let ity = Integer::approximate_align(self, align);
self.type_from_integer(ity)
}
pub fn type_vector(&self, ty: Type<'gcc>, len: u64) -> Type<'gcc> {
self.context.new_vector_type(ty, len)
}
pub fn type_float_from_ty(&self, t: ty::FloatTy) -> Type<'gcc> {
match t {
ty::FloatTy::F32 => self.type_f32(),
ty::FloatTy::F64 => self.type_f64(),
}
}
}
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
......@@ -103,7 +115,7 @@ fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc
self.context.new_function_pointer_type(None, return_type, params, false)
}
fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
let types = fields.to_vec();
if let Some(typ) = self.struct_types.borrow().get(fields) {
return typ.clone();
......@@ -111,8 +123,11 @@ fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
let fields: Vec<_> = fields.iter().enumerate()
.map(|(index, field)| self.context.new_field(None, *field, &format!("field{}_TODO", index)))
.collect();
// TODO(antoyo): use packed.
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
if packed {
#[cfg(feature="master")]
typ.set_packed();
}
self.struct_types.borrow_mut().insert(types, typ);
typ
}
......@@ -127,7 +142,7 @@ fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
else if typ.is_compatible_with(self.double_type) {
TypeKind::Double
}
else if typ.dyncast_vector().is_some() {
else if typ.is_vector() {
TypeKind::Vector
}
else {
......@@ -141,7 +156,7 @@ fn type_ptr_to(&self, ty: Type<'gcc>) -> Type<'gcc> {
}
fn type_ptr_to_ext(&self, ty: Type<'gcc>, _address_space: AddressSpace) -> Type<'gcc> {
// TODO(antoyo): use address_space
// TODO(antoyo): use address_space, perhaps with TYPE_ADDR_SPACE?
ty.make_pointer()
}
......@@ -167,10 +182,10 @@ fn vector_length(&self, _ty: Type<'gcc>) -> usize {
fn float_width(&self, typ: Type<'gcc>) -> usize {
let f32 = self.context.new_type::<f32>();
let f64 = self.context.new_type::<f64>();
if typ == f32 {
if typ.is_compatible_with(f32) {
32
}
else if typ == f64 {
else if typ.is_compatible_with(f64) {
64
}
else {
......@@ -197,12 +212,15 @@ pub fn type_padding_filler(&self, size: Size, align: Align) -> Type<'gcc> {
self.type_array(self.type_from_integer(unit), size / unit_size)
}
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], _packed: bool) {
// TODO(antoyo): use packed.
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed: bool) {
let fields: Vec<_> = fields.iter().enumerate()
.map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index)))
.collect();
typ.set_fields(None, &fields);
if packed {
#[cfg(feature="master")]
typ.as_type().set_packed();
}
}
pub fn type_named_struct(&self, name: &str) -> Struct<'gcc> {
......@@ -229,6 +247,10 @@ pub fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
self.context.new_array_type(None, ty, len)
}
pub fn type_bool(&self) -> Type<'gcc> {
self.context.new_type::<bool>()
}
}
pub fn struct_fields<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout<'tcx>) -> (Vec<Type<'gcc>>, bool) {
......
......@@ -24,6 +24,30 @@ fn type_from_unsigned_integer(&self, i: Integer) -> Type<'gcc> {
I128 => self.type_u128(),
}
}
#[cfg(feature="master")]
pub fn type_int_from_ty(&self, t: ty::IntTy) -> Type<'gcc> {
match t {
ty::IntTy::Isize => self.type_isize(),
ty::IntTy::I8 => self.type_i8(),
ty::IntTy::I16 => self.type_i16(),
ty::IntTy::I32 => self.type_i32(),
ty::IntTy::I64 => self.type_i64(),
ty::IntTy::I128 => self.type_i128(),
}
}
#[cfg(feature="master")]
pub fn type_uint_from_ty(&self, t: ty::UintTy) -> Type<'gcc> {
match t {
ty::UintTy::Usize => self.type_isize(),
ty::UintTy::U8 => self.type_i8(),
ty::UintTy::U16 => self.type_i16(),
ty::UintTy::U32 => self.type_i32(),
ty::UintTy::U64 => self.type_i64(),
ty::UintTy::U128 => self.type_i128(),
}
}
}
pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout<'tcx>, defer: &mut Option<(Struct<'gcc>, TyAndLayout<'tcx>)>) -> Type<'gcc> {
......
#!/bin/bash
#!/usr/bin/env bash
# TODO(antoyo): rewrite to cargo-make (or just) or something like that to only rebuild the sysroot when needed?
......@@ -14,25 +14,87 @@ fi
export LD_LIBRARY_PATH="$GCC_PATH"
export LIBRARY_PATH="$GCC_PATH"
features=
if [[ "$1" == "--features" ]]; then
shift
features="--features $1"
shift
fi
if [[ "$1" == "--release" ]]; then
flags=
gcc_master_branch=1
channel="debug"
func=all
build_only=0
while [[ $# -gt 0 ]]; do
case $1 in
--release)
codegen_channel=release
shift
;;
--release-sysroot)
sysroot_channel=release
shift
;;
--no-default-features)
gcc_master_branch=0
flags="$flags --no-default-features"
shift
;;
--features)
shift
flags="$flags --features $1"
shift
;;
--release)
channel="release"
shift
;;
"--test-rustc")
func=test_rustc
shift
;;
"--test-libcore")
func=test_libcore
shift
;;
"--clean-ui-tests")
func=clean_ui_tests
shift
;;
"--std-tests")
func=std_tests
shift
;;
"--extended-tests")
func=extended_sysroot_tests
shift
;;
"--build-sysroot")
func=build_sysroot
shift
;;
"--build")
build_only=1
shift
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done
if [[ $channel == "release" ]]; then
export CHANNEL='release'
CARGO_INCREMENTAL=1 cargo rustc --release $features
CARGO_INCREMENTAL=1 cargo rustc --release $flags
shift
else
echo $LD_LIBRARY_PATH
export CHANNEL='debug'
cargo rustc $features
cargo rustc $flags
fi
if [[ "$1" == "--build" ]]; then
if (( $build_only == 1 )); then
exit
fi
......@@ -78,7 +140,11 @@ function std_tests() {
$RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
echo "[AOT] std_example"
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE
std_flags="--cfg feature=\"master\""
if (( $gcc_master_branch == 0 )); then
std_flags=""
fi
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE $std_flags
$RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE
echo "[AOT] subslice-patterns-const-eval"
......@@ -97,25 +163,6 @@ function std_tests() {
#echo "[BUILD] sysroot in release mode"
#./build_sysroot/build_sysroot.sh --release
# TODO(antoyo): uncomment when it works.
#pushd simple-raytracer
#if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
#echo "[BENCH COMPILE] ebobby/simple-raytracer"
#hyperfine --runs ${RUN_RUNS:-10} --warmup 1 --prepare "rm -r target/*/debug || true" \
#"RUSTFLAGS='' cargo build --target $TARGET_TRIPLE" \
#"../cargo.sh build"
#echo "[BENCH RUN] ebobby/simple-raytracer"
#cp ./target/*/debug/main ./raytracer_cg_gccjit
#hyperfine --runs ${RUN_RUNS:-10} ./raytracer_cg_llvm ./raytracer_cg_gccjit
#else
#echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
#echo "[COMPILE] ebobby/simple-raytracer"
#../cargo.sh build
#echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
#fi
#popd
function test_libcore() {
pushd build_sysroot/sysroot_src/library/core/tests
echo "[TEST] libcore"
......@@ -124,19 +171,6 @@ function test_libcore() {
popd
}
# TODO(antoyo): uncomment when it works.
#pushd regex
#echo "[TEST] rust-lang/regex example shootout-regex-dna"
#../cargo.sh clean
## Make sure `[codegen mono items] start` doesn't poison the diff
#../cargo.sh build --example shootout-regex-dna
#cat examples/regexdna-input.txt | ../cargo.sh run --example shootout-regex-dna | grep -v "Spawned thread" > res.txt
#diff -u res.txt examples/regexdna-output.txt
#echo "[TEST] rust-lang/regex tests"
#../cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options
#popd
#echo
#echo "[BENCH COMPILE] mod_bench"
......@@ -153,6 +187,44 @@ function test_libcore() {
#echo "[BENCH RUN] mod_bench"
#hyperfine --runs ${RUN_RUNS:-10} ./target/out/mod_bench{,_inline} ./target/out/mod_bench_llvm_*
function extended_sysroot_tests() {
if (( $gcc_master_branch == 0 )); then
return
fi
pushd rand
cargo clean
echo "[TEST] rust-random/rand"
../cargo.sh test --workspace
popd
#pushd simple-raytracer
#echo "[BENCH COMPILE] ebobby/simple-raytracer"
#hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "cargo clean" \
#"RUSTC=rustc RUSTFLAGS='' cargo build" \
#"../cargo.sh build"
#echo "[BENCH RUN] ebobby/simple-raytracer"
#cp ./target/debug/main ./raytracer_cg_gcc
#hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_gcc
#popd
pushd regex
echo "[TEST] rust-lang/regex example shootout-regex-dna"
cargo clean
export CG_RUSTFLAGS="--cap-lints warn" # newer aho_corasick versions throw a deprecation warning
# Make sure `[codegen mono items] start` doesn't poison the diff
../cargo.sh build --example shootout-regex-dna
cat examples/regexdna-input.txt \
| ../cargo.sh run --example shootout-regex-dna \
| grep -v "Spawned thread" > res.txt
diff -u res.txt examples/regexdna-output.txt
echo "[TEST] rust-lang/regex tests"
../cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
popd
}
function test_rustc() {
echo
echo "[TEST] rust-lang/rust"
......@@ -165,23 +237,7 @@ function test_rustc() {
git checkout $(rustc -V | cut -d' ' -f3 | tr -d '(')
export RUSTFLAGS=
git apply - <<EOF
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();
EOF
git apply ../rustc_patches/compile_test.patch || true
rm config.toml || true
......@@ -205,7 +261,7 @@ EOF
git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed
rm -r src/test/ui/{abi*,extern/,panic-runtime/,panics/,unsized-locals/,proc-macro/,threads-sendsync/,thinlto/,simd*,borrowck/,test*,*lto*.rs} || true
rm -r src/test/ui/{abi*,extern/,panic-runtime/,panics/,unsized-locals/,proc-macro/,threads-sendsync/,thinlto/,borrowck/,test*,*lto*.rs} || true
for test in $(rg --files-with-matches "catch_unwind|should_panic|thread|lto" src/test/ui); do
rm $test
done
......@@ -222,33 +278,14 @@ function clean_ui_tests() {
find rust/build/x86_64-unknown-linux-gnu/test/ui/ -name stamp -exec rm -rf {} \;
}
case $1 in
"--test-rustc")
test_rustc
;;
"--test-libcore")
test_libcore
;;
"--clean-ui-tests")
clean_ui_tests
;;
"--std-tests")
std_tests
;;
"--build-sysroot")
build_sysroot
;;
*)
clean
mini_tests
build_sysroot
std_tests
test_libcore
test_rustc
;;
esac
function all() {
clean
mini_tests
build_sysroot
std_tests
test_libcore
extended_sysroot_tests
test_rustc
}
$func
//! The common code for `tests/lang_tests_*.rs`
use std::{
env::{self, current_dir},
path::PathBuf,
......@@ -7,7 +8,15 @@
use lang_tester::LangTester;
use tempfile::TempDir;
fn main() {
/// Controls the compile options (e.g., optimization level) used to compile
/// test code.
#[allow(dead_code)] // Each test crate picks one variant
pub enum Profile {
Debug,
Release,
}
pub fn main_inner(profile: Profile) {
let tempdir = TempDir::new().expect("temp dir");
let current_dir = current_dir().expect("current dir");
let current_dir = current_dir.to_str().expect("current dir").to_string();
......@@ -42,6 +51,15 @@ fn main() {
"-o", exe.to_str().expect("to_str"),
path.to_str().expect("to_str"),
]);
match profile {
Profile::Debug => {}
Profile::Release => {
compiler.args(&[
"-C", "opt-level=3",
"-C", "lto=no",
]);
}
}
// Test command 2: run `tempdir/x`.
let runtime = Command::new(exe);
vec![("Compiler", compiler), ("Run-time", runtime)]
......
mod lang_tests_common;
fn main() {
lang_tests_common::main_inner(lang_tests_common::Profile::Debug);
}
mod lang_tests_common;
fn main() {
lang_tests_common::main_inner(lang_tests_common::Profile::Release);
}
......@@ -3,151 +3,338 @@
// Run-time:
// status: 0
#![feature(arbitrary_self_types, auto_traits, core_intrinsics, lang_items, start, intrinsics)]
#![feature(bench_black_box, const_black_box, core_intrinsics, start)]
#![no_std]
mod intrinsics {
extern "rust-intrinsic" {
pub fn abort() -> !;
}
#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
core::intrinsics::abort();
}
/*
* Core
* Code
*/
mod libc {
#[link(name = "c")]
extern "C" {
pub fn puts(s: *const u8) -> i32;
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
use core::hint::black_box;
macro_rules! check {
($ty:ty, $expr:expr) => {
{
const EXPECTED: $ty = $expr;
assert_eq!($expr, EXPECTED);
}
};
}
}
#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
unsafe {
core::intrinsics::abort();
check!(u32, (2220326408_u32 + black_box(1)) >> (32 - 6));
/// Generate `check!` tests for integer types at least as wide as 128 bits.
macro_rules! check_ops128 {
() => {
check_ops64!();
// Shifts.
check!(T, VAL1 << black_box(64));
check!(T, VAL1 << black_box(81));
check!(T, VAL3 << black_box(63));
check!(T, VAL3 << black_box(64));
check!(T, VAL1 >> black_box(64));
check!(T, VAL2 >> black_box(64));
check!(T, VAL3 >> black_box(64));
check!(T, VAL3 >> black_box(81));
};
}
}
/*
* Code
*/
/// Generate `check!` tests for integer types at least as wide as 64 bits.
macro_rules! check_ops64 {
() => {
check_ops32!();
// Shifts.
check!(T, VAL2 << black_box(33));
check!(T, VAL2 << black_box(49));
check!(T, VAL2 << black_box(61));
check!(T, VAL2 << black_box(63));
check!(T, VAL3 << black_box(33));
check!(T, VAL3 << black_box(49));
check!(T, VAL3 << black_box(61));
check!(T, VAL1 >> black_box(33));
check!(T, VAL1 >> black_box(49));
check!(T, VAL1 >> black_box(61));
check!(T, VAL1 >> black_box(63));
check!(T, VAL2 >> black_box(33));
check!(T, VAL2 >> black_box(49));
check!(T, VAL2 >> black_box(61));
check!(T, VAL2 >> black_box(63));
check!(T, VAL3 >> black_box(33));
check!(T, VAL3 >> black_box(49));
check!(T, VAL3 >> black_box(61));
check!(T, VAL3 >> black_box(63));
};
}
#[start]
fn main(argc: isize, _argv: *const *const u8) -> isize {
let var = 134217856_u128;
let var2 = 10475372733397991552_u128;
let var3 = 193236519889708027473620326106273939584_u128;
let var4 = 123236519889708027473620326106273939584_u128;
let var5 = 153236519889708027473620326106273939584_u128;
let var6 = 18446744073709551616_i128;
let var7 = 170141183460469231731687303715884105728_u128;
// Shifts.
assert_eq!(var << (argc as u128 - 1), var);
assert_eq!(var << argc as u128, 268435712);
assert_eq!(var << (argc + 32) as u128, 1152922604118474752);
assert_eq!(var << (argc + 48) as u128, 75557935783508361347072);
assert_eq!(var << (argc + 60) as u128, 309485304969250248077606912);
assert_eq!(var << (argc + 62) as u128, 1237941219877000992310427648);
assert_eq!(var << (argc + 63) as u128, 2475882439754001984620855296);
assert_eq!(var << (argc + 80) as u128, 324518863143436548128224745357312);
assert_eq!(var2 << argc as u128, 20950745466795983104);
assert_eq!(var2 << (argc as u128 - 1), var2);
assert_eq!(var2 << (argc + 32) as u128, 89982766606709001335848566784);
assert_eq!(var2 << (argc + 48) as u128, 5897110592337281111546171672756224);
assert_eq!(var2 << (argc + 60) as u128, 24154564986213503432893119171609493504);
assert_eq!(var2 << (argc + 62) as u128, 96618259944854013731572476686437974016);
assert_eq!(var2 << (argc + 63) as u128, 193236519889708027463144953372875948032);
assert_eq!(var3 << argc as u128, 46190672858477591483866044780779667712);
assert_eq!(var3 << (argc as u128 - 1), var3);
assert_eq!(var3 << (argc + 32) as u128, 21267668304951024224840338247585366016);
assert_eq!(var3 << (argc + 48) as u128, 1335125106377253154015353231953100800);
assert_eq!(var3 << (argc + 60) as u128, 24154564986213503432893119171609493504);
assert_eq!(var3 << (argc + 62) as u128, 96618259944854013731572476686437974016);
assert_eq!(var3 << (argc + 63) as u128, 193236519889708027463144953372875948032);
assert_eq!((2220326408_u32 + argc as u32) >> (32 - 6), 33);
assert_eq!(var >> (argc as u128 - 1), var);
assert_eq!(var >> argc as u128, 67108928);
assert_eq!(var >> (argc + 32) as u128, 0);
assert_eq!(var >> (argc + 48) as u128, 0);
assert_eq!(var >> (argc + 60) as u128, 0);
assert_eq!(var >> (argc + 62) as u128, 0);
assert_eq!(var >> (argc + 63) as u128, 0);
assert_eq!(var2 >> argc as u128, 5237686366698995776);
assert_eq!(var2 >> (argc as u128 - 1), var2);
assert_eq!(var2 >> (argc + 32) as u128, 1219493888);
assert_eq!(var2 >> (argc + 48) as u128, 18608);
assert_eq!(var2 >> (argc + 60) as u128, 4);
assert_eq!(var2 >> (argc + 62) as u128, 1);
assert_eq!(var2 >> (argc + 63) as u128, 0);
assert_eq!(var3 >> (argc as u128 - 1), var3);
assert_eq!(var3 >> argc as u128, 96618259944854013736810163053136969792);
assert_eq!(var3 >> (argc + 32) as u128, 22495691651677250335181635584);
assert_eq!(var3 >> (argc + 48) as u128, 343257013727985387194544);
assert_eq!(var3 >> (argc + 60) as u128, 83802981867183932420);
assert_eq!(var3 >> (argc + 62) as u128, 20950745466795983105);
assert_eq!(var3 >> (argc + 63) as u128, 10475372733397991552);
assert_eq!(var3 >> (argc + 80) as u128, 79920751444992);
assert_eq!(var6 >> argc as u128, 9223372036854775808);
assert_eq!((var6 - 1) >> argc as u128, 9223372036854775807);
assert_eq!(var7 >> argc as u128, 85070591730234615865843651857942052864);
// Casts
assert_eq!((var >> (argc + 32) as u128) as u64, 0);
assert_eq!((var >> argc as u128) as u64, 67108928);
// Addition.
assert_eq!(var + argc as u128, 134217857);
assert_eq!(var2 + argc as u128, 10475372733397991553);
assert_eq!(var2 + (var2 + argc as u128) as u128, 20950745466795983105);
assert_eq!(var3 + argc as u128, 193236519889708027473620326106273939585);
// Subtraction
assert_eq!(var - argc as u128, 134217855);
assert_eq!(var2 - argc as u128, 10475372733397991551);
assert_eq!(var3 - argc as u128, 193236519889708027473620326106273939583);
// Multiplication
assert_eq!(var * (argc + 1) as u128, 268435712);
assert_eq!(var * (argc as u128 + var2), 1405982069077538020949770368);
assert_eq!(var2 * (argc + 1) as u128, 20950745466795983104);
assert_eq!(var2 * (argc as u128 + var2), 109733433903618109003204073240861360256);
assert_eq!(var3 * argc as u128, 193236519889708027473620326106273939584);
assert_eq!(var4 * (argc + 1) as u128, 246473039779416054947240652212547879168);
assert_eq!(var5 * (argc + 1) as u128, 306473039779416054947240652212547879168);
// Division.
assert_eq!(var / (argc + 1) as u128, 67108928);
assert_eq!(var / (argc + 2) as u128, 44739285);
assert_eq!(var2 / (argc + 1) as u128, 5237686366698995776);
assert_eq!(var2 / (argc + 2) as u128, 3491790911132663850);
assert_eq!(var3 / (argc + 1) as u128, 96618259944854013736810163053136969792);
assert_eq!(var3 / (argc + 2) as u128, 64412173296569342491206775368757979861);
assert_eq!(var3 / (argc as u128 + var4), 1);
assert_eq!(var3 / (argc as u128 + var2), 18446744073709551615);
assert_eq!(var4 / (argc + 1) as u128, 61618259944854013736810163053136969792);
assert_eq!(var4 / (argc + 2) as u128, 41078839963236009157873442035424646528);
/// Generate `check!` tests for integer types at least as wide as 32 bits.
macro_rules! check_ops32 {
() => {
// Shifts.
check!(T, VAL2 << black_box(1));
check!(T, VAL2 << black_box(0));
check!(T, VAL3 << black_box(1));
check!(T, VAL3 << black_box(0));
check!(T, VAL1.wrapping_shl(black_box(0)));
check!(T, VAL1.wrapping_shl(black_box(1)));
check!(T, VAL1.wrapping_shl(black_box(33)));
check!(T, VAL1.wrapping_shl(black_box(49)));
check!(T, VAL1.wrapping_shl(black_box(61)));
check!(T, VAL1.wrapping_shl(black_box(63)));
check!(T, VAL1.wrapping_shl(black_box(64)));
check!(T, VAL1.wrapping_shl(black_box(81)));
check!(Option<T>, VAL1.checked_shl(black_box(0)));
check!(Option<T>, VAL1.checked_shl(black_box(1)));
check!(Option<T>, VAL1.checked_shl(black_box(33)));
check!(Option<T>, VAL1.checked_shl(black_box(49)));
check!(Option<T>, VAL1.checked_shl(black_box(61)));
check!(Option<T>, VAL1.checked_shl(black_box(63)));
check!(Option<T>, VAL1.checked_shl(black_box(64)));
check!(Option<T>, VAL1.checked_shl(black_box(81)));
check!(T, VAL1 >> black_box(0));
check!(T, VAL1 >> black_box(1));
check!(T, VAL2 >> black_box(1));
check!(T, VAL2 >> black_box(0));
check!(T, VAL3 >> black_box(0));
check!(T, VAL3 >> black_box(1));
check!(T, VAL1.wrapping_shr(black_box(0)));
check!(T, VAL1.wrapping_shr(black_box(1)));
check!(T, VAL1.wrapping_shr(black_box(33)));
check!(T, VAL1.wrapping_shr(black_box(49)));
check!(T, VAL1.wrapping_shr(black_box(61)));
check!(T, VAL1.wrapping_shr(black_box(63)));
check!(T, VAL1.wrapping_shr(black_box(64)));
check!(T, VAL1.wrapping_shr(black_box(81)));
check!(Option<T>, VAL1.checked_shr(black_box(0)));
check!(Option<T>, VAL1.checked_shr(black_box(1)));
check!(Option<T>, VAL1.checked_shr(black_box(33)));
check!(Option<T>, VAL1.checked_shr(black_box(49)));
check!(Option<T>, VAL1.checked_shr(black_box(61)));
check!(Option<T>, VAL1.checked_shr(black_box(63)));
check!(Option<T>, VAL1.checked_shr(black_box(64)));
check!(Option<T>, VAL1.checked_shr(black_box(81)));
// Casts
check!(u64, (VAL1 >> black_box(1)) as u64);
// Addition.
check!(T, VAL1 + black_box(1));
check!(T, VAL2 + black_box(1));
check!(T, VAL2 + (VAL2 + black_box(1)));
check!(T, VAL3 + black_box(1));
check!(Option<T>, VAL1.checked_add(black_box(1)));
check!(Option<T>, VAL2.checked_add(black_box(1)));
check!(Option<T>, VAL2.checked_add(VAL2 + black_box(1)));
check!(Option<T>, VAL3.checked_add(T::MAX));
check!(Option<T>, VAL3.checked_add(T::MIN));
check!(T, VAL1.wrapping_add(black_box(1)));
check!(T, VAL2.wrapping_add(black_box(1)));
check!(T, VAL2.wrapping_add(VAL2 + black_box(1)));
check!(T, VAL3.wrapping_add(T::MAX));
check!(T, VAL3.wrapping_add(T::MIN));
check!((T, bool), VAL1.overflowing_add(black_box(1)));
check!((T, bool), VAL2.overflowing_add(black_box(1)));
check!((T, bool), VAL2.overflowing_add(VAL2 + black_box(1)));
check!((T, bool), VAL3.overflowing_add(T::MAX));
check!((T, bool), VAL3.overflowing_add(T::MIN));
check!(T, VAL1.saturating_add(black_box(1)));
check!(T, VAL2.saturating_add(black_box(1)));
check!(T, VAL2.saturating_add(VAL2 + black_box(1)));
check!(T, VAL3.saturating_add(T::MAX));
check!(T, VAL3.saturating_add(T::MIN));
// Subtraction
check!(T, VAL1 - black_box(1));
check!(T, VAL2 - black_box(1));
check!(T, VAL3 - black_box(1));
check!(Option<T>, VAL1.checked_sub(black_box(1)));
check!(Option<T>, VAL2.checked_sub(black_box(1)));
check!(Option<T>, VAL2.checked_sub(VAL2 + black_box(1)));
check!(Option<T>, VAL3.checked_sub(T::MAX));
check!(Option<T>, VAL3.checked_sub(T::MIN));
check!(T, VAL1.wrapping_sub(black_box(1)));
check!(T, VAL2.wrapping_sub(black_box(1)));
check!(T, VAL2.wrapping_sub(VAL2 + black_box(1)));
check!(T, VAL3.wrapping_sub(T::MAX));
check!(T, VAL3.wrapping_sub(T::MIN));
check!((T, bool), VAL1.overflowing_sub(black_box(1)));
check!((T, bool), VAL2.overflowing_sub(black_box(1)));
check!((T, bool), VAL2.overflowing_sub(VAL2 + black_box(1)));
check!((T, bool), VAL3.overflowing_sub(T::MAX));
check!((T, bool), VAL3.overflowing_sub(T::MIN));
check!(T, VAL1.saturating_sub(black_box(1)));
check!(T, VAL2.saturating_sub(black_box(1)));
check!(T, VAL2.saturating_sub(VAL2 + black_box(1)));
check!(T, VAL3.saturating_sub(T::MAX));
check!(T, VAL3.saturating_sub(T::MIN));
// Multiplication
check!(T, VAL1 * black_box(2));
check!(T, VAL1 * (black_box(1) + VAL2));
check!(T, VAL2 * black_box(2));
check!(T, VAL2 * (black_box(1) + VAL2));
check!(T, VAL3 * black_box(1));
check!(T, VAL4 * black_box(2));
check!(T, VAL5 * black_box(2));
check!(Option<T>, VAL1.checked_mul(black_box(2)));
check!(Option<T>, VAL1.checked_mul(black_box(1) + VAL2));
check!(Option<T>, VAL3.checked_mul(VAL3));
check!(Option<T>, VAL4.checked_mul(black_box(2)));
check!(Option<T>, VAL5.checked_mul(black_box(2)));
check!(T, VAL1.wrapping_mul(black_box(2)));
check!(T, VAL1.wrapping_mul((black_box(1) + VAL2)));
check!(T, VAL3.wrapping_mul(VAL3));
check!(T, VAL4.wrapping_mul(black_box(2)));
check!(T, VAL5.wrapping_mul(black_box(2)));
check!((T, bool), VAL1.overflowing_mul(black_box(2)));
check!((T, bool), VAL1.overflowing_mul(black_box(1) + VAL2));
check!((T, bool), VAL3.overflowing_mul(VAL3));
check!((T, bool), VAL4.overflowing_mul(black_box(2)));
check!((T, bool), VAL5.overflowing_mul(black_box(2)));
check!(T, VAL1.saturating_mul(black_box(2)));
check!(T, VAL1.saturating_mul(black_box(1) + VAL2));
check!(T, VAL3.saturating_mul(VAL3));
check!(T, VAL4.saturating_mul(black_box(2)));
check!(T, VAL5.saturating_mul(black_box(2)));
// Division.
check!(T, VAL1 / black_box(2));
check!(T, VAL1 / black_box(3));
check!(T, VAL2 / black_box(2));
check!(T, VAL2 / black_box(3));
check!(T, VAL3 / black_box(2));
check!(T, VAL3 / black_box(3));
check!(T, VAL3 / (black_box(1) + VAL4));
check!(T, VAL3 / (black_box(1) + VAL2));
check!(T, VAL4 / black_box(2));
check!(T, VAL4 / black_box(3));
check!(Option<T>, VAL1.checked_div(black_box(2)));
check!(Option<T>, VAL1.checked_div(black_box(1) + VAL2));
check!(Option<T>, VAL3.checked_div(VAL3));
check!(Option<T>, VAL4.checked_div(black_box(2)));
check!(Option<T>, VAL5.checked_div(black_box(2)));
check!(Option<T>, (T::MIN).checked_div(black_box(0 as T).wrapping_sub(1)));
check!(Option<T>, VAL5.checked_div(black_box(0))); // var5 / 0
check!(T, VAL1.wrapping_div(black_box(2)));
check!(T, VAL1.wrapping_div(black_box(1) + VAL2));
check!(T, VAL3.wrapping_div(VAL3));
check!(T, VAL4.wrapping_div(black_box(2)));
check!(T, VAL5.wrapping_div(black_box(2)));
check!(T, (T::MIN).wrapping_div(black_box(0 as T).wrapping_sub(1)));
check!((T, bool), VAL1.overflowing_div(black_box(2)));
check!((T, bool), VAL1.overflowing_div(black_box(1) + VAL2));
check!((T, bool), VAL3.overflowing_div(VAL3));
check!((T, bool), VAL4.overflowing_div(black_box(2)));
check!((T, bool), VAL5.overflowing_div(black_box(2)));
check!((T, bool), (T::MIN).overflowing_div(black_box(0 as T).wrapping_sub(1)));
check!(T, VAL1.saturating_div(black_box(2)));
check!(T, VAL1.saturating_div((black_box(1) + VAL2)));
check!(T, VAL3.saturating_div(VAL3));
check!(T, VAL4.saturating_div(black_box(2)));
check!(T, VAL5.saturating_div(black_box(2)));
check!(T, (T::MIN).saturating_div((0 as T).wrapping_sub(black_box(1))));
};
}
{
type T = u32;
const VAL1: T = 14162_u32;
const VAL2: T = 14556_u32;
const VAL3: T = 323656954_u32;
const VAL4: T = 2023651954_u32;
const VAL5: T = 1323651954_u32;
check_ops32!();
}
{
type T = i32;
const VAL1: T = 13456_i32;
const VAL2: T = 10475_i32;
const VAL3: T = 923653954_i32;
const VAL4: T = 993198738_i32;
const VAL5: T = 1023653954_i32;
check_ops32!();
}
{
type T = u64;
const VAL1: T = 134217856_u64;
const VAL2: T = 104753732_u64;
const VAL3: T = 12323651988970863954_u64;
const VAL4: T = 7323651988970863954_u64;
const VAL5: T = 8323651988970863954_u64;
check_ops64!();
}
{
type T = i64;
const VAL1: T = 134217856_i64;
const VAL2: T = 104753732_i64;
const VAL3: T = 6323651988970863954_i64;
const VAL4: T = 2323651988970863954_i64;
const VAL5: T = 3323651988970863954_i64;
check_ops64!();
}
{
type T = u128;
const VAL1: T = 134217856_u128;
const VAL2: T = 10475372733397991552_u128;
const VAL3: T = 193236519889708027473620326106273939584_u128;
const VAL4: T = 123236519889708027473620326106273939584_u128;
const VAL5: T = 153236519889708027473620326106273939584_u128;
check_ops128!();
}
{
type T = i128;
const VAL1: T = 134217856_i128;
const VAL2: T = 10475372733397991552_i128;
const VAL3: T = 83236519889708027473620326106273939584_i128;
const VAL4: T = 63236519889708027473620326106273939584_i128;
const VAL5: T = 73236519889708027473620326106273939584_i128;
check_ops128!();
}
0
}
// Compiler:
//
// Run-time:
// stdout: Panicking
// stdout: Success
// status: signal
#![allow(unused_attributes)]
......@@ -64,7 +64,9 @@ mod intrinsics {
#[no_mangle]
pub fn panic(_msg: &str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
// Panicking is expected iff overflow checking is enabled.
#[cfg(debug_assertions)]
libc::puts("Success\0" as *const str as *const u8);
libc::fflush(libc::stdout);
intrinsics::abort();
}
......@@ -124,6 +126,15 @@ fn add(self, rhs: Self) -> Self {
#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
let int = 9223372036854775807isize;
let int = int + argc;
let int = int + argc; // overflow
// If overflow checking is disabled, we should reach here.
#[cfg(not(debug_assertions))]
unsafe {
libc::puts("Success\0" as *const str as *const u8);
libc::fflush(libc::stdout);
intrinsics::abort();
}
int
}
import json
import os
import re
import sys
import subprocess
from os import walk
def run_command(command, cwd=None):
p = subprocess.Popen(command, cwd=cwd)
if p.wait() != 0:
print("command `{}` failed...".format(" ".join(command)))
sys.exit(1)
def clone_repository(repo_name, path, repo_url, sub_path=None):
if os.path.exists(path):
while True:
choice = input("There is already a `{}` folder, do you want to update it? [y/N]".format(path))
if choice == "" or choice.lower() == "n":
print("Skipping repository update.")
return
elif choice.lower() == "y":
print("Updating repository...")
run_command(["git", "pull", "origin"], cwd=path)
return
else:
print("Didn't understand answer...")
print("Cloning {} repository...".format(repo_name))
if sub_path is None:
run_command(["git", "clone", repo_url, "--depth", "1", path])
else:
run_command(["git", "clone", repo_url, "--filter=tree:0", "--no-checkout", path])
run_command(["git", "sparse-checkout", "init"], cwd=path)
run_command(["git", "sparse-checkout", "set", "add", sub_path], cwd=path)
run_command(["git", "checkout"], cwd=path)
def append_intrinsic(array, intrinsic_name, translation):
array.append((intrinsic_name, translation))
def extract_instrinsics(intrinsics, file):
print("Extracting intrinsics from `{}`...".format(file))
with open(file, "r", encoding="utf8") as f:
content = f.read()
lines = content.splitlines()
pos = 0
current_arch = None
while pos < len(lines):
line = lines[pos].strip()
if line.startswith("let TargetPrefix ="):
current_arch = line.split('"')[1].strip()
if len(current_arch) == 0:
current_arch = None
elif current_arch is None:
pass
elif line == "}":
current_arch = None
elif line.startswith("def "):
content = ""
while not content.endswith(";") and not content.endswith("}") and pos < len(lines):
line = lines[pos].split(" // ")[0].strip()
content += line
pos += 1
entries = re.findall('GCCBuiltin<"(\\w+)">', content)
if len(entries) > 0:
intrinsic = content.split("def ")[1].strip().split(":")[0].strip()
intrinsic = intrinsic.split("_")
if len(intrinsic) < 2 or intrinsic[0] != "int":
continue
intrinsic[0] = "llvm"
intrinsic = ".".join(intrinsic)
if current_arch not in intrinsics:
intrinsics[current_arch] = []
for entry in entries:
append_intrinsic(intrinsics[current_arch], intrinsic, entry)
continue
pos += 1
continue
print("Done!")
def extract_instrinsics_from_llvm(llvm_path, intrinsics):
files = []
intrinsics_path = os.path.join(llvm_path, "llvm/include/llvm/IR")
for (dirpath, dirnames, filenames) in walk(intrinsics_path):
files.extend([os.path.join(intrinsics_path, f) for f in filenames if f.endswith(".td")])
for file in files:
extract_instrinsics(intrinsics, file)
def append_translation(json_data, p, array):
it = json_data["index"][p]
content = it["docs"].split('`')
if len(content) != 5:
return
append_intrinsic(array, content[1], content[3])
def extract_instrinsics_from_llvmint(llvmint, intrinsics):
archs = [
"AMDGPU",
"aarch64",
"arm",
"cuda",
"hexagon",
"mips",
"nvvm",
"ppc",
"ptx",
"x86",
"xcore",
]
json_file = os.path.join(llvmint, "target/doc/llvmint.json")
# We need to regenerate the documentation!
run_command(
["cargo", "rustdoc", "--", "-Zunstable-options", "--output-format", "json"],
cwd=llvmint,
)
with open(json_file, "r", encoding="utf8") as f:
json_data = json.loads(f.read())
for p in json_data["paths"]:
it = json_data["paths"][p]
if it["crate_id"] != 0:
# This is from an external crate.
continue
if it["kind"] != "function":
# We're only looking for functions.
continue
# if len(it["path"]) == 2:
# # This is a "general" intrinsic, not bound to a specific arch.
# append_translation(json_data, p, general)
# continue
if len(it["path"]) != 3 or it["path"][1] not in archs:
continue
arch = it["path"][1]
if arch not in intrinsics:
intrinsics[arch] = []
append_translation(json_data, p, intrinsics[arch])
def fill_intrinsics(intrinsics, from_intrinsics, all_intrinsics):
for arch in from_intrinsics:
if arch not in intrinsics:
intrinsics[arch] = []
for entry in from_intrinsics[arch]:
if entry[0] in all_intrinsics:
if all_intrinsics[entry[0]] == entry[1]:
# This is a "full" duplicate, both the LLVM instruction and the GCC
# translation are the same.
continue
intrinsics[arch].append((entry[0], entry[1], True))
else:
intrinsics[arch].append((entry[0], entry[1], False))
all_intrinsics[entry[0]] = entry[1]
def update_intrinsics(llvm_path, llvmint, llvmint2):
intrinsics_llvm = {}
intrinsics_llvmint = {}
all_intrinsics = {}
extract_instrinsics_from_llvm(llvm_path, intrinsics_llvm)
extract_instrinsics_from_llvmint(llvmint, intrinsics_llvmint)
extract_instrinsics_from_llvmint(llvmint2, intrinsics_llvmint)
intrinsics = {}
# We give priority to translations from LLVM over the ones from llvmint.
fill_intrinsics(intrinsics, intrinsics_llvm, all_intrinsics)
fill_intrinsics(intrinsics, intrinsics_llvmint, all_intrinsics)
archs = [arch for arch in intrinsics]
archs.sort()
output_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../src/intrinsic/archs.rs",
)
print("Updating content of `{}`...".format(output_file))
with open(output_file, "w", encoding="utf8") as out:
out.write("// File generated by `rustc_codegen_gcc/tools/generate_intrinsics.py`\n")
out.write("// DO NOT EDIT IT!\n")
out.write("match name {\n")
for arch in archs:
if len(intrinsics[arch]) == 0:
continue
intrinsics[arch].sort(key=lambda x: (x[0], x[2]))
out.write(' // {}\n'.format(arch))
for entry in intrinsics[arch]:
if entry[2] == True: # if it is a duplicate
out.write(' // [DUPLICATE]: "{}" => "{}",\n'.format(entry[0], entry[1]))
else:
out.write(' "{}" => "{}",\n'.format(entry[0], entry[1]))
out.write(' _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n')
out.write("}\n")
print("Done!")
def main():
llvm_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"llvm-project",
)
llvmint_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"llvmint",
)
llvmint2_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"llvmint-2",
)
# First, we clone the LLVM repository if it's not already here.
clone_repository(
"llvm-project",
llvm_path,
"https://github.com/llvm/llvm-project",
sub_path="llvm/include/llvm/IR",
)
clone_repository(
"llvmint",
llvmint_path,
"https://github.com/GuillaumeGomez/llvmint",
)
clone_repository(
"llvmint2",
llvmint2_path,
"https://github.com/antoyo/llvmint",
)
update_intrinsics(llvm_path, llvmint_path, llvmint2_path)
if __name__ == "__main__":
sys.exit(main())
......@@ -362,7 +362,7 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
}
// Note: the vectors could be created and dropped within `parse_tt`, but to avoid excess
// allocations we have a single vector fo each kind that is cleared and reused repeatedly.
// allocations we have a single vector for each kind that is cleared and reused repeatedly.
pub struct TtParser {
macro_name: Ident,
......
......@@ -24,11 +24,6 @@ pub const fn new() -> Condvar {
Condvar { counter: AtomicUsize::new(0), sem1: ptr::null(), sem2: ptr::null() }
}
pub unsafe fn init(&mut self) {
let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0);
let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0);
}
pub unsafe fn notify_one(&self) {
if self.counter.load(SeqCst) > 0 {
self.counter.fetch_sub(1, SeqCst);
......
......@@ -40,8 +40,10 @@ filetime = "0.2"
getopts = "0.2.19"
cc = "1.0.69"
libc = "0.2"
hex = "0.4"
serde = { version = "1.0.8", features = ["derive"] }
serde_json = "1.0.2"
sha2 = "0.10"
tar = "0.4"
toml = "0.5"
ignore = "0.4.10"
......
......@@ -63,31 +63,30 @@ def support_xz():
except tarfile.CompressionError:
return False
def get(base, url, path, checksums, verbose=False, do_verify=True):
def get(base, url, path, checksums, verbose=False):
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_path = temp_file.name
try:
if do_verify:
if url not in checksums:
raise RuntimeError(("src/stage0.json doesn't contain a checksum for {}. "
"Pre-built artifacts might not available for this "
"target at this time, see https://doc.rust-lang.org/nightly"
"/rustc/platform-support.html for more information.")
.format(url))
sha256 = checksums[url]
if os.path.exists(path):
if verify(path, sha256, False):
if verbose:
print("using already-download file", path)
return
else:
if verbose:
print("ignoring already-download file",
path, "due to failed verification")
os.unlink(path)
if url not in checksums:
raise RuntimeError(("src/stage0.json doesn't contain a checksum for {}. "
"Pre-built artifacts might not be available for this "
"target at this time, see https://doc.rust-lang.org/nightly"
"/rustc/platform-support.html for more information.")
.format(url))
sha256 = checksums[url]
if os.path.exists(path):
if verify(path, sha256, False):
if verbose:
print("using already-download file", path)
return
else:
if verbose:
print("ignoring already-download file",
path, "due to failed verification")
os.unlink(path)
download(temp_path, "{}/{}".format(base, url), True, verbose)
if do_verify and not verify(temp_path, sha256, verbose):
if not verify(temp_path, sha256, verbose):
raise RuntimeError("failed verification")
if verbose:
print("moving {} to {}".format(temp_path, path))
......@@ -430,7 +429,6 @@ class RustBuild(object):
def __init__(self):
self.checksums_sha256 = {}
self.stage0_compiler = None
self.stage0_rustfmt = None
self._download_url = ''
self.build = ''
self.build_dir = ''
......@@ -484,31 +482,10 @@ class RustBuild(object):
with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(key)
if self.rustfmt() and self.rustfmt().startswith(bin_root) and (
not os.path.exists(self.rustfmt())
or self.program_out_of_date(
self.rustfmt_stamp(),
"" if self.stage0_rustfmt is None else self.stage0_rustfmt.channel()
)
):
if self.stage0_rustfmt is not None:
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
filename = "rustfmt-{}-{}{}".format(
self.stage0_rustfmt.version, self.build, tarball_suffix,
)
self._download_component_helper(
filename, "rustfmt-preview", tarball_suffix, key=self.stage0_rustfmt.date
)
self.fix_bin_or_dylib("{}/bin/rustfmt".format(bin_root))
self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(bin_root))
with output(self.rustfmt_stamp()) as rustfmt_stamp:
rustfmt_stamp.write(self.stage0_rustfmt.channel())
def _download_component_helper(
self, filename, pattern, tarball_suffix, key=None
self, filename, pattern, tarball_suffix,
):
if key is None:
key = self.stage0_compiler.date
key = self.stage0_compiler.date
cache_dst = os.path.join(self.build_dir, "cache")
rustc_cache = os.path.join(cache_dst, key)
if not os.path.exists(rustc_cache):
......@@ -524,7 +501,6 @@ class RustBuild(object):
tarball,
self.checksums_sha256,
verbose=self.verbose,
do_verify=True,
)
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
......@@ -634,16 +610,6 @@ class RustBuild(object):
"""
return os.path.join(self.bin_root(), '.rustc-stamp')
def rustfmt_stamp(self):
"""Return the path for .rustfmt-stamp
>>> rb = RustBuild()
>>> rb.build_dir = "build"
>>> rb.rustfmt_stamp() == os.path.join("build", "stage0", ".rustfmt-stamp")
True
"""
return os.path.join(self.bin_root(), '.rustfmt-stamp')
def program_out_of_date(self, stamp_path, key):
"""Check if the given program stamp is out of date"""
if not os.path.exists(stamp_path) or self.clean:
......@@ -717,12 +683,6 @@ class RustBuild(object):
"""Return config path for rustc"""
return self.program_config('rustc')
def rustfmt(self):
"""Return config path for rustfmt"""
if self.stage0_rustfmt is None:
return None
return self.program_config('rustfmt')
def program_config(self, program):
"""Return config path for the given program at the given stage
......@@ -1082,8 +1042,6 @@ def bootstrap(help_triggered):
data = json.load(f)
build.checksums_sha256 = data["checksums_sha256"]
build.stage0_compiler = Stage0Toolchain(data["compiler"])
if data.get("rustfmt") is not None:
build.stage0_rustfmt = Stage0Toolchain(data["rustfmt"])
build.set_dist_environment(data["dist_server"])
......
......@@ -728,7 +728,8 @@ pub fn new(build: &Build) -> Builder<'_> {
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
Subcommand::Run { ref paths } => (Kind::Run, &paths[..]),
Subcommand::Format { .. } | Subcommand::Clean { .. } | Subcommand::Setup { .. } => {
Subcommand::Format { .. } => (Kind::Format, &[][..]),
Subcommand::Clean { .. } | Subcommand::Setup { .. } => {
panic!()
}
};
......@@ -878,7 +879,6 @@ pub(crate) fn download_component(
) {
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
// FIXME: support `do_verify` (only really needed for nightly rustfmt)
self.download_with_retries(&tempfile, &format!("{}/{}", base, url), help_on_error);
t!(std::fs::rename(&tempfile, dest_path));
}
......@@ -970,6 +970,28 @@ pub(crate) fn unpack(&self, tarball: &Path, dst: &Path, pattern: &str) {
t!(fs::remove_dir_all(dst.join(directory_prefix)));
}
/// Returns whether the SHA256 checksum of `path` matches `expected`.
pub(crate) fn verify(&self, path: &Path, expected: &str) -> bool {
use sha2::Digest;
self.verbose(&format!("verifying {}", path.display()));
let mut hasher = sha2::Sha256::new();
// FIXME: this is ok for rustfmt (4.1 MB large at time of writing), but it seems memory-intensive for rustc and larger components.
// Consider using streaming IO instead?
let contents = if self.config.dry_run { vec![] } else { t!(fs::read(path)) };
hasher.update(&contents);
let found = hex::encode(hasher.finalize().as_slice());
let verified = found == expected;
if !verified && !self.config.dry_run {
println!(
"invalid checksum: \n\
found: {found}\n\
expected: {expected}",
);
}
return verified;
}
/// Obtain a compiler at a given stage and for a given host. Explicitly does
/// not take `Compiler` since all `Compiler` instances are meant to be
/// obtained through this function, since it ensures that they are valid
......@@ -1192,6 +1214,10 @@ pub(crate) fn download_rustc(&self) -> bool {
Config::download_rustc(self)
}
pub(crate) fn initial_rustfmt(&self) -> Option<PathBuf> {
Config::initial_rustfmt(self)
}
/// Prepares an invocation of `cargo` to be run.
///
/// This will create a `Command` that represents a pending execution of
......
......@@ -3,7 +3,7 @@
//! This module implements parsing `config.toml` configuration files to tweak
//! how the build runs.
use std::cell::Cell;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::collections::{HashMap, HashSet};
use std::env;
......@@ -20,6 +20,7 @@
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags};
use crate::util::{exe, output, program_out_of_date, t};
use crate::RustfmtMetadata;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Deserializer};
......@@ -204,10 +205,27 @@ pub struct Config {
// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,
pub initial_rustfmt: Option<PathBuf>,
#[cfg(not(test))]
initial_rustfmt: RefCell<RustfmtState>,
#[cfg(test)]
pub initial_rustfmt: RefCell<RustfmtState>,
pub out: PathBuf,
}
#[derive(Clone, Debug)]
pub enum RustfmtState {
SystemToolchain(PathBuf),
Downloaded(PathBuf),
Unavailable,
LazyEvaluated,
}
impl Default for RustfmtState {
fn default() -> Self {
RustfmtState::LazyEvaluated
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LlvmLibunwind {
No,
......@@ -859,9 +877,6 @@ pub fn parse(args: &[String]) -> Config {
set(&mut config.full_bootstrap, build.full_bootstrap);
set(&mut config.extended, build.extended);
config.tools = build.tools;
if build.rustfmt.is_some() {
config.initial_rustfmt = build.rustfmt;
}
set(&mut config.verbose, build.verbose);
set(&mut config.sanitizers, build.sanitizers);
set(&mut config.profiler, build.profiler);
......@@ -1154,18 +1169,22 @@ pub fn parse(args: &[String]) -> Config {
set(&mut config.missing_tools, t.missing_tools);
}
config.initial_rustfmt = config.initial_rustfmt.or_else({
let build = config.build;
let initial_rustc = &config.initial_rustc;
move || {
// Cargo does not provide a RUSTFMT environment variable, so we
// synthesize it manually.
let rustfmt = initial_rustc.with_file_name(exe("rustfmt", build));
if rustfmt.exists() { Some(rustfmt) } else { None }
if let Some(r) = build.rustfmt {
*config.initial_rustfmt.borrow_mut() = if r.exists() {
RustfmtState::SystemToolchain(r)
} else {
RustfmtState::Unavailable
};
} else {
// If using a system toolchain for bootstrapping, see if that has rustfmt available.
let host = config.build;
let rustfmt_path = config.initial_rustc.with_file_name(exe("rustfmt", host));
let bin_root = config.out.join(host.triple).join("stage0");
if !rustfmt_path.starts_with(&bin_root) {
// Using a system-provided toolchain; we shouldn't download rustfmt.
*config.initial_rustfmt.borrow_mut() = RustfmtState::SystemToolchain(rustfmt_path);
}
});
}
// Now that we've reached the end of our configuration, infer the
// default values for all options that we haven't otherwise stored yet.
......@@ -1335,6 +1354,25 @@ pub(crate) fn download_rustc(builder: &Builder<'_>) -> bool {
})
}
pub(crate) fn initial_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
match &mut *builder.config.initial_rustfmt.borrow_mut() {
RustfmtState::SystemToolchain(p) | RustfmtState::Downloaded(p) => Some(p.clone()),
RustfmtState::Unavailable => None,
r @ RustfmtState::LazyEvaluated => {
if builder.config.dry_run {
return Some(PathBuf::new());
}
let path = maybe_download_rustfmt(builder);
*r = if let Some(p) = &path {
RustfmtState::Downloaded(p.clone())
} else {
RustfmtState::Unavailable
};
path
}
}
}
pub fn verbose(&self) -> bool {
self.verbose > 0
}
......@@ -1445,6 +1483,28 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
Some(commit.to_string())
}
fn maybe_download_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
let RustfmtMetadata { date, version } = builder.stage0_metadata.rustfmt.as_ref()?;
let channel = format!("{version}-{date}");
let host = builder.config.build;
let rustfmt_path = builder.config.initial_rustc.with_file_name(exe("rustfmt", host));
let bin_root = builder.config.out.join(host.triple).join("stage0");
let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
return Some(rustfmt_path);
}
let filename = format!("rustfmt-{version}-{build}.tar.xz", build = host.triple);
download_component(builder, DownloadSource::Dist, filename, "rustfmt-preview", &date, "stage0");
builder.fix_bin_or_dylib(&bin_root.join("bin").join("rustfmt"));
builder.fix_bin_or_dylib(&bin_root.join("bin").join("cargo-fmt"));
builder.create(&rustfmt_stamp, &channel);
Some(rustfmt_path)
}
fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
builder.verbose(&format!("using downloaded stage2 artifacts from CI (commit {commit})"));
// FIXME: support downloading artifacts from the beta channel
......@@ -1459,12 +1519,12 @@ fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
}
let filename = format!("rust-std-{CHANNEL}-{host}.tar.xz");
let pattern = format!("rust-std-{host}");
download_component(builder, filename, &pattern, commit);
download_ci_component(builder, filename, &pattern, commit);
let filename = format!("rustc-{CHANNEL}-{host}.tar.xz");
download_component(builder, filename, "rustc", commit);
download_ci_component(builder, filename, "rustc", commit);
// download-rustc doesn't need its own cargo, it can just use beta's.
let filename = format!("rustc-dev-{CHANNEL}-{host}.tar.xz");
download_component(builder, filename, "rustc-dev", commit);
download_ci_component(builder, filename, "rustc-dev", commit);
builder.fix_bin_or_dylib(&bin_root.join("bin").join("rustc"));
builder.fix_bin_or_dylib(&bin_root.join("bin").join("rustdoc"));
......@@ -1479,21 +1539,83 @@ fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
}
}
pub(crate) enum DownloadSource {
CI,
Dist,
}
/// Download a single component of a CI-built toolchain (not necessarily a published nightly).
// NOTE: intentionally takes an owned string to avoid downloading multiple times by accident
fn download_component(builder: &Builder<'_>, filename: String, prefix: &str, commit: &str) {
fn download_ci_component(builder: &Builder<'_>, filename: String, prefix: &str, commit: &str) {
download_component(builder, DownloadSource::CI, filename, prefix, commit, "ci-rustc")
}
fn download_component(
builder: &Builder<'_>,
mode: DownloadSource,
filename: String,
prefix: &str,
key: &str,
destination: &str,
) {
let cache_dst = builder.out.join("cache");
let rustc_cache = cache_dst.join(commit);
if !rustc_cache.exists() {
t!(fs::create_dir_all(&rustc_cache));
let cache_dir = cache_dst.join(key);
if !cache_dir.exists() {
t!(fs::create_dir_all(&cache_dir));
}
let base = "https://ci-artifacts.rust-lang.org";
let url = format!("rustc-builds/{commit}");
let tarball = rustc_cache.join(&filename);
if !tarball.exists() {
builder.download_component(base, &format!("{url}/{filename}"), &tarball, "");
let bin_root = builder.out.join(builder.config.build.triple).join(destination);
let tarball = cache_dir.join(&filename);
let (base_url, url, should_verify) = match mode {
DownloadSource::CI => (
"https://ci-artifacts.rust-lang.org/rustc-builds".to_string(),
format!("{key}/{filename}"),
false,
),
DownloadSource::Dist => {
let dist_server = env::var("RUSTUP_DIST_SERVER")
.unwrap_or(builder.stage0_metadata.dist_server.to_string());
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
(dist_server, format!("dist/{key}/{filename}"), true)
}
};
// For the beta compiler, put special effort into ensuring the checksums are valid.
// FIXME: maybe we should do this for download-rustc as well? but it would be a pain to update
// this on each and every nightly ...
let checksum = if should_verify {
let error = format!(
"src/stage0.json doesn't contain a checksum for {url}. \
Pre-built artifacts might not be available for this \
target at this time, see https://doc.rust-lang.org/nightly\
/rustc/platform-support.html for more information."
);
let sha256 = builder.stage0_metadata.checksums_sha256.get(&url).expect(&error);
if tarball.exists() {
if builder.verify(&tarball, sha256) {
builder.unpack(&tarball, &bin_root, prefix);
return;
} else {
builder.verbose(&format!(
"ignoring cached file {} due to failed verification",
tarball.display()
));
builder.remove(&tarball);
}
}
Some(sha256)
} else if tarball.exists() {
return;
} else {
None
};
builder.download_component(&base_url, &url, &tarball, "");
if let Some(sha256) = checksum {
if !builder.verify(&tarball, sha256) {
panic!("failed to verify {}", tarball.display());
}
}
let bin_root = builder.out.join(builder.config.build.triple).join("ci-rustc");
builder.unpack(&tarball, &bin_root, prefix)
builder.unpack(&tarball, &bin_root, prefix);
}
//! Runs rustfmt on the repository.
use crate::builder::Builder;
use crate::util::{output, t};
use crate::Build;
use ignore::WalkBuilder;
use std::collections::VecDeque;
use std::path::{Path, PathBuf};
......@@ -42,7 +42,7 @@ struct RustfmtConfig {
ignore: Vec<String>,
}
pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
if build.config.dry_run {
return;
}
......@@ -112,15 +112,11 @@ pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
}
let ignore_fmt = ignore_fmt.build().unwrap();
let rustfmt_path = build
.config
.initial_rustfmt
.as_ref()
.unwrap_or_else(|| {
eprintln!("./x.py fmt is not supported on this channel");
std::process::exit(1);
})
.to_path_buf();
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
eprintln!("./x.py fmt is not supported on this channel");
std::process::exit(1);
});
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
let src = build.src.clone();
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
let walker = match paths.get(0) {
......
......@@ -118,6 +118,7 @@
use filetime::FileTime;
use once_cell::sync::OnceCell;
use serde::Deserialize;
use crate::builder::Kind;
use crate::config::{LlvmLibunwind, TargetSelection};
......@@ -294,6 +295,7 @@ pub struct Build {
targets: Vec<TargetSelection>,
// Stage 0 (downloaded) compiler, lld and cargo or their local rust equivalents
stage0_metadata: Stage0Metadata,
initial_rustc: PathBuf,
initial_cargo: PathBuf,
initial_lld: PathBuf,
......@@ -320,6 +322,18 @@ pub struct Build {
metrics: metrics::BuildMetrics,
}
#[derive(Deserialize)]
struct Stage0Metadata {
dist_server: String,
checksums_sha256: HashMap<String, String>,
rustfmt: Option<RustfmtMetadata>,
}
#[derive(Deserialize)]
struct RustfmtMetadata {
date: String,
version: String,
}
#[derive(Debug)]
struct Crate {
name: Interned<String>,
......@@ -468,7 +482,11 @@ pub fn new(config: Config) -> Build {
bootstrap_out
};
let stage0_json = t!(std::fs::read_to_string(&src.join("src").join("stage0.json")));
let stage0_metadata = t!(serde_json::from_str::<Stage0Metadata>(&stage0_json));
let mut build = Build {
stage0_metadata,
initial_rustc: config.initial_rustc.clone(),
initial_cargo: config.initial_cargo.clone(),
initial_lld,
......@@ -661,7 +679,7 @@ pub fn build(&mut self) {
self.maybe_update_submodules();
if let Subcommand::Format { check, paths } = &self.config.cmd {
return format::format(self, *check, &paths);
return format::format(&builder::Builder::new(&self), *check, &paths);
}
if let Subcommand::Clean { all } = self.config.cmd {
......
......@@ -1010,7 +1010,7 @@ fn run(self, builder: &Builder<'_>) {
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
builder.info("fmt check");
if builder.config.initial_rustfmt.is_none() {
if builder.initial_rustfmt().is_none() {
let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
eprintln!(
"\
......@@ -1023,7 +1023,7 @@ fn run(self, builder: &Builder<'_>) {
);
std::process::exit(1);
}
crate::format::format(&builder.build, !builder.config.cmd.bless(), &[]);
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
}
}
......
// Regression test for https://github.com/rust-lang/rust/issues/84634
#![crate_name = "foo"]
use std::pin::Pin;
use std::task::Poll;
pub trait Stream {
type Item;
fn poll_next(mut self: Pin<&mut Self>) -> Poll<Option<Self::Item>>;
fn size_hint(&self) -> (usize, Option<usize>);
}
// @has 'foo/trait.Stream.html'
// @has - '//*[@class="code-header in-band"]' 'impl<S: ?Sized + Stream + Unpin> Stream for &mut S'
impl<S: ?Sized + Stream + Unpin> Stream for &mut S {
type Item = S::Item;
fn poll_next(
mut self: Pin<&mut Self>,
) -> Poll<Option<Self::Item>> {
S::poll_next(Pin::new(&mut **self), cx)
}
fn size_hint(&self) -> (usize, Option<usize>) {
(**self).size_hint()
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册