Skip to content

Commit 6cf6fd3

Browse files
committedApr 5, 2024
Merge commit 'fbda869b4e230c788b6bce426038ba8419956f2d' into sync_cg_clif-2024-04-05
2 parents 5958f5e + fbda869 commit 6cf6fd3

File tree

16 files changed

+85
-121
lines changed

16 files changed

+85
-121
lines changed
 

‎compiler/rustc_codegen_cranelift/.cirrus.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ task:
1313
- ./y.sh prepare
1414
test_script:
1515
- . $HOME/.cargo/env
16+
# Disabling incr comp reduces cache size and incr comp doesn't save as much
17+
# on CI anyway.
18+
- export CARGO_BUILD_INCREMENTAL=false
1619
- ./y.sh test

‎compiler/rustc_codegen_cranelift/.github/workflows/abi-cafe.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Abi-cafe
33
on:
44
- push
55

6+
permissions: {}
7+
68
jobs:
79
abi_cafe:
810
runs-on: ${{ matrix.os }}

‎compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+28-40
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ on:
44
- push
55
- pull_request
66

7+
defaults:
8+
run:
9+
shell: bash
10+
11+
permissions: {}
12+
13+
env:
14+
# Disabling incr comp reduces cache size and incr comp doesn't save as much
15+
# on CI anyway.
16+
CARGO_BUILD_INCREMENTAL: false
17+
# Rust's CI denies warnings. Deny them here too to ensure subtree syncs don't
18+
# fail because of warnings.
19+
RUSTFLAGS: "-Dwarnings"
20+
721
jobs:
822
rustfmt:
923
runs-on: ubuntu-latest
@@ -23,15 +37,15 @@ jobs:
2337
cargo fmt --check
2438
rustfmt --check build_system/main.rs
2539
rustfmt --check example/*
40+
rustfmt --check scripts/*.rs
2641
2742
2843
test:
2944
runs-on: ${{ matrix.os }}
3045
timeout-minutes: 60
3146

32-
defaults:
33-
run:
34-
shell: bash
47+
env:
48+
CG_CLIF_EXPENSIVE_CHECKS: 1
3549

3650
strategy:
3751
fail-fast: false
@@ -47,15 +61,19 @@ jobs:
4761
- os: ubuntu-latest
4862
env:
4963
TARGET_TRIPLE: x86_64-pc-windows-gnu
64+
apt_deps: gcc-mingw-w64-x86-64 wine-stable
5065
- os: ubuntu-latest
5166
env:
5267
TARGET_TRIPLE: aarch64-unknown-linux-gnu
68+
apt_deps: gcc-aarch64-linux-gnu qemu-user
5369
- os: ubuntu-latest
5470
env:
5571
TARGET_TRIPLE: s390x-unknown-linux-gnu
72+
apt_deps: gcc-s390x-linux-gnu qemu-user
5673
- os: ubuntu-latest
5774
env:
5875
TARGET_TRIPLE: riscv64gc-unknown-linux-gnu
76+
apt_deps: gcc-riscv64-linux-gnu qemu-user
5977
- os: windows-latest
6078
env:
6179
TARGET_TRIPLE: x86_64-pc-windows-msvc
@@ -80,29 +98,11 @@ jobs:
8098
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
8199
run: rustup set default-host x86_64-pc-windows-gnu
82100

83-
- name: Install MinGW toolchain and wine
84-
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
85-
run: |
86-
sudo apt-get update
87-
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
88-
89-
- name: Install AArch64 toolchain and qemu
90-
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
91-
run: |
92-
sudo apt-get update
93-
sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user
94-
95-
- name: Install s390x toolchain and qemu
96-
if: matrix.env.TARGET_TRIPLE == 's390x-unknown-linux-gnu'
101+
- name: Install toolchain and emulator
102+
if: matrix.apt_deps != null
97103
run: |
98104
sudo apt-get update
99-
sudo apt-get install -y gcc-s390x-linux-gnu qemu-user
100-
101-
- name: Install riscv64gc toolchain and qemu
102-
if: matrix.env.TARGET_TRIPLE == 'riscv64gc-unknown-linux-gnu'
103-
run: |
104-
sudo apt-get update
105-
sudo apt-get install -y gcc-riscv64-linux-gnu qemu-user
105+
sudo apt-get install -y ${{ matrix.apt_deps }}
106106
107107
- name: Prepare dependencies
108108
run: ./y.sh prepare
@@ -142,10 +142,6 @@ jobs:
142142
runs-on: ubuntu-latest
143143
timeout-minutes: 60
144144

145-
defaults:
146-
run:
147-
shell: bash
148-
149145
steps:
150146
- uses: actions/checkout@v4
151147

@@ -168,10 +164,6 @@ jobs:
168164
runs-on: ubuntu-latest
169165
timeout-minutes: 60
170166

171-
defaults:
172-
run:
173-
shell: bash
174-
175167
steps:
176168
- uses: actions/checkout@v4
177169

@@ -193,20 +185,16 @@ jobs:
193185
run: ./y.sh prepare
194186

195187
- name: Build
196-
run: CI_OPT=1 ./y.sh build --sysroot none
188+
run: ./y.sh build --sysroot none
197189

198190
- name: Benchmark
199-
run: CI_OPT=1 ./y.sh bench
191+
run: ./y.sh bench
200192

201193

202194
dist:
203195
runs-on: ${{ matrix.os }}
204196
timeout-minutes: 60
205197

206-
defaults:
207-
run:
208-
shell: bash
209-
210198
strategy:
211199
fail-fast: false
212200
matrix:
@@ -252,10 +240,10 @@ jobs:
252240
run: ./y.sh prepare
253241

254242
- name: Build backend
255-
run: CI_OPT=1 ./y.sh build --sysroot none
243+
run: ./y.sh build --sysroot none
256244

257245
- name: Build sysroot
258-
run: CI_OPT=1 ./y.sh build
246+
run: ./y.sh build
259247

260248
- name: Package prebuilt cg_clif
261249
run: tar cvfJ cg_clif.tar.xz dist

‎compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Various rustc tests
33
on:
44
- push
55

6+
permissions: {}
7+
68
jobs:
79
bootstrap_rustc:
810
runs-on: ubuntu-latest

‎compiler/rustc_codegen_cranelift/Readme.md

+1-21
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,7 @@ For additional ways to use rustc_codegen_cranelift like the JIT mode see [usage.
101101

102102
## Building and testing with changes in rustc code
103103

104-
This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/).
105-
This can happen, for example, when you are implementing a new compiler intrinsic.
106-
107-
Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository.
108-
109-
You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code:
110-
111-
1. `cd $RustCheckoutDir`
112-
2. Run `python x.py setup` and choose option for compiler (`b`).
113-
3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt`
114-
* (Optional) You can also build cargo by adding `src/tools/cargo` to previous command.
115-
4. Copy cargo from a nightly toolchain: `cp $(rustup +nightly which cargo) ./build/host/stage2/bin/cargo`. Note that you would need to do this every time you rebuilt `rust` repository.
116-
5. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`.
117-
6. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`.
118-
7. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.
119-
* `rustup run stage2 ./y.sh prepare`
120-
* `rustup run stage2 ./y.sh build`
121-
* (Optional) run tests: `rustup run stage2 ./y.sh test`
122-
8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.
123-
124-
You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes.
104+
See [rustc_testing.md](docs/rustc_testing.md).
125105

126106
## Not yet supported
127107

‎compiler/rustc_codegen_cranelift/build_system/build_backend.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use std::env;
12
use std::path::PathBuf;
23

34
use crate::path::{Dirs, RelPath};
45
use crate::rustc_info::get_file_name;
56
use crate::shared_utils::{rustflags_from_env, rustflags_to_cmd_env};
6-
use crate::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
7+
use crate::utils::{CargoProject, Compiler, LogGroup};
78

89
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
910

@@ -16,20 +17,15 @@ pub(crate) fn build_backend(
1617
let _group = LogGroup::guard("Build backend");
1718

1819
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
19-
maybe_incremental(&mut cmd);
2020

2121
let mut rustflags = rustflags_from_env("RUSTFLAGS");
2222

2323
rustflags.push("-Zallow-features=rustc_private".to_owned());
2424

25-
if is_ci() {
26-
// Deny warnings on CI
27-
rustflags.push("-Dwarnings".to_owned());
28-
29-
if !is_ci_opt() {
30-
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
31-
cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true");
32-
}
25+
if env::var("CG_CLIF_EXPENSIVE_CHECKS").is_ok() {
26+
// Enabling debug assertions implicitly enables the clif ir verifier
27+
cmd.env("CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS", "true");
28+
cmd.env("CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS", "true");
3329
}
3430

3531
if use_unstable_features {

‎compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::process::Command;
66
use crate::path::{Dirs, RelPath};
77
use crate::rustc_info::get_file_name;
88
use crate::utils::{
9-
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
10-
LogGroup,
9+
remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler, LogGroup,
1110
};
1211
use crate::{config, CodegenBackend, SysrootKind};
1312

@@ -270,7 +269,6 @@ fn build_clif_sysroot_for_triple(
270269
}
271270
compiler.rustflags.extend(rustflags);
272271
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
273-
maybe_incremental(&mut build_cmd);
274272
if channel == "release" {
275273
build_cmd.arg("--release");
276274
}

‎compiler/rustc_codegen_cranelift/build_system/main.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
use std::path::PathBuf;
77
use std::process;
88

9-
use self::utils::{is_ci, is_ci_opt, Compiler};
9+
use self::utils::Compiler;
1010

1111
mod abi_cafe;
1212
mod bench;
@@ -60,14 +60,9 @@ fn main() {
6060
}
6161
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
6262

63-
if is_ci() {
64-
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
65-
env::set_var("CARGO_BUILD_INCREMENTAL", "false");
66-
67-
if !is_ci_opt() {
68-
// Enable the Cranelift verifier
69-
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
70-
}
63+
// Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled
64+
if env::var_os("CARGO_BUILD_INCREMENTAL").is_none() {
65+
env::set_var("CARGO_BUILD_INCREMENTAL", "true");
7166
}
7267

7368
let mut args = env::args().skip(1);

‎compiler/rustc_codegen_cranelift/build_system/prepare.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub(crate) fn prepare(dirs: &Dirs) {
1515
RelPath::DOWNLOAD.ensure_exists(dirs);
1616
crate::tests::RAND_REPO.fetch(dirs);
1717
crate::tests::REGEX_REPO.fetch(dirs);
18-
crate::tests::PORTABLE_SIMD_REPO.fetch(dirs);
1918
}
2019

2120
pub(crate) fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {

‎compiler/rustc_codegen_cranelift/build_system/tests.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,10 @@ pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
130130

131131
pub(crate) static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir(), "regex_target");
132132

133-
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
134-
"rust-lang",
135-
"portable-simd",
136-
"5794c837bc605c4cd9dbb884285976dfdb293cce",
137-
"a64d8fdd0ed0d9c4",
138-
"portable-simd",
139-
);
133+
pub(crate) static PORTABLE_SIMD_SRC: RelPath = RelPath::BUILD.join("coretests");
140134

141135
pub(crate) static PORTABLE_SIMD: CargoProject =
142-
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable-simd_target");
136+
CargoProject::new(&PORTABLE_SIMD_SRC, "portable-simd_target");
143137

144138
static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests");
145139

@@ -221,7 +215,12 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
221215
}
222216
}),
223217
TestCase::custom("test.portable-simd", &|runner| {
224-
PORTABLE_SIMD_REPO.patch(&runner.dirs);
218+
apply_patches(
219+
&runner.dirs,
220+
"portable-simd",
221+
&runner.stdlib_source.join("library/portable-simd"),
222+
&PORTABLE_SIMD_SRC.to_path(&runner.dirs),
223+
);
225224

226225
PORTABLE_SIMD.clean(&runner.dirs);
227226

‎compiler/rustc_codegen_cranelift/build_system/utils.rs

-18
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,6 @@ pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) {
254254
}
255255
}
256256

257-
pub(crate) fn is_ci() -> bool {
258-
env::var("CI").is_ok()
259-
}
260-
261-
pub(crate) fn is_ci_opt() -> bool {
262-
env::var("CI_OPT").is_ok()
263-
}
264-
265257
static IN_GROUP: AtomicBool = AtomicBool::new(false);
266258
pub(crate) struct LogGroup {
267259
is_gha: bool,
@@ -288,13 +280,3 @@ impl Drop for LogGroup {
288280
IN_GROUP.store(false, Ordering::SeqCst);
289281
}
290282
}
291-
292-
pub(crate) fn maybe_incremental(cmd: &mut Command) {
293-
if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
294-
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
295-
cmd.env("CARGO_BUILD_INCREMENTAL", "false");
296-
} else {
297-
// Force incr comp even in release mode unless in CI or incremental builds are explicitly disabled
298-
cmd.env("CARGO_BUILD_INCREMENTAL", "true");
299-
}
300-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Building and testing with changes in rustc code
2+
3+
This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/).
4+
This can happen, for example, when you are implementing a new compiler intrinsic.
5+
6+
Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository.
7+
8+
You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code:
9+
10+
1. `cd $RustCheckoutDir`
11+
2. Run `python x.py setup` and choose option for compiler (`b`).
12+
3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt`
13+
* (Optional) You can also build cargo by adding `src/tools/cargo` to previous command.
14+
4. Copy cargo from a nightly toolchain: `cp $(rustup +nightly which cargo) ./build/host/stage2/bin/cargo`. Note that you would need to do this every time you rebuilt `rust` repository.
15+
5. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`.
16+
6. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`.
17+
7. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.
18+
* `rustup run stage2 ./y.sh prepare`
19+
* `rustup run stage2 ./y.sh build`
20+
* (Optional) run tests: `rustup run stage2 ./y.sh test`
21+
8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.
22+
23+
You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes.

‎compiler/rustc_codegen_cranelift/example/mini_core.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ unsafe impl Sync for i16 {}
9090
unsafe impl Sync for i32 {}
9191
unsafe impl Sync for isize {}
9292
unsafe impl Sync for char {}
93+
unsafe impl Sync for f32 {}
9394
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
94-
unsafe impl Sync for [u8; 16] {}
95+
unsafe impl<T: Sync, const N: usize> Sync for [T; N] {}
9596

9697
#[lang = "freeze"]
9798
unsafe auto trait Freeze {}
@@ -467,7 +468,6 @@ pub fn panic(_msg: &'static str) -> ! {
467468

468469
macro_rules! panic_const {
469470
($($lang:ident = $message:expr,)+) => {
470-
#[cfg(not(bootstrap))]
471471
pub mod panic_const {
472472
use super::*;
473473

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-03-28"
2+
channel = "nightly-2024-04-05"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

‎compiler/rustc_codegen_cranelift/scripts/filter_profile.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
#![forbid(unsafe_code)]/* This line is ignored by bash
2+
#![rustfmt::skip]/* This line is ignored by bash
33
# This block is ignored by rustc
44
pushd $(dirname "$0")/../
55
RUSTC="$(pwd)/dist/rustc-clif"
@@ -26,11 +26,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2626
}
2727
let profile = std::fs::read_to_string(profile_name)
2828
.map_err(|err| format!("Failed to read profile {}", err))?;
29-
let mut output = std::fs::OpenOptions::new()
30-
.create(true)
31-
.write(true)
32-
.truncate(true)
33-
.open(output_name)?;
29+
let mut output =
30+
std::fs::OpenOptions::new().create(true).write(true).truncate(true).open(output_name)?;
3431

3532
for line in profile.lines() {
3633
let mut stack = &line[..line.rfind(" ").unwrap()];

‎compiler/rustc_codegen_cranelift/src/num.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub(crate) fn codegen_int_binop<'tcx>(
130130
in_lhs: CValue<'tcx>,
131131
in_rhs: CValue<'tcx>,
132132
) -> CValue<'tcx> {
133-
if bin_op != BinOp::Shl && bin_op != BinOp::Shr {
133+
if !matches!(bin_op, BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked) {
134134
assert_eq!(
135135
in_lhs.layout().ty,
136136
in_rhs.layout().ty,

0 commit comments

Comments
 (0)
Please sign in to comment.