Skip to content

Commit fd1f479

Browse files
authored
Rollup merge of #142489 - tgross35:update-builtins, r=tgross35
Update the `compiler-builtins` subtree Update the Josh subtree to rust-lang/compiler-builtins@7c46e921c117. r? `@ghost`
2 parents 22f91ae + 7222fa6 commit fd1f479

File tree

24 files changed

+554
-157
lines changed

24 files changed

+554
-157
lines changed

library/compiler-builtins/.release-plz.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

library/compiler-builtins/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[workspace]
22
resolver = "2"
33
members = [
4+
"builtins-shim",
45
"builtins-test",
5-
"compiler-builtins",
66
"crates/josh-sync",
77
"crates/libm-macros",
88
"crates/musl-math-sys",
@@ -14,8 +14,8 @@ members = [
1414
]
1515

1616
default-members = [
17+
"builtins-shim",
1718
"builtins-test",
18-
"compiler-builtins",
1919
"crates/libm-macros",
2020
"libm",
2121
"libm-test",
@@ -26,6 +26,10 @@ exclude = [
2626
# and `mangled-names` disabled, which is the opposite of what is needed for
2727
# other tests, so it makes sense to keep it out of the workspace.
2828
"builtins-test-intrinsics",
29+
# We test via the `builtins-shim` crate, so exclude the `compiler-builtins`
30+
# that has a dependency on `core`. See `builtins-shim/Cargo.toml` for more
31+
# details.
32+
"compiler-builtins",
2933
]
3034

3135
[profile.release]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# NOTE: Must be kept in sync with `../compiler-builtins/Cargo.toml`.
2+
#
3+
# The manifest at `../compiler-builtins` is what actually gets used in the
4+
# rust-lang/rust tree; however, we can't build it out of tree because it
5+
# depends on `core` by path, and even optional Cargo dependencies need to be
6+
# available at build time. So, we work around this by having this "shim"
7+
# manifest that is identical except for the `core` dependency and forwards
8+
# to the same sources, which acts as the `compiler-builtins` Cargo entrypoint
9+
# for out of tree testing
10+
11+
[package]
12+
name = "compiler_builtins"
13+
version = "0.1.160"
14+
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
15+
description = "Compiler intrinsics used by the Rust compiler."
16+
repository = "https://github.com/rust-lang/compiler-builtins"
17+
license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
18+
edition = "2024"
19+
publish = false
20+
links = "compiler-rt"
21+
22+
build = "../compiler-builtins/build.rs"
23+
24+
[lib]
25+
path = "../compiler-builtins/src/lib.rs"
26+
bench = false
27+
doctest = false
28+
test = false
29+
30+
[build-dependencies]
31+
cc = { optional = true, version = "1.2" }
32+
33+
[features]
34+
default = ["compiler-builtins"]
35+
36+
# Enable compilation of C code in compiler-rt, filling in some more optimized
37+
# implementations and also filling in unimplemented intrinsics
38+
c = ["dep:cc"]
39+
40+
# Workaround for the Cranelift codegen backend. Disables any implementations
41+
# which use inline assembly and fall back to pure Rust versions (if available).
42+
no-asm = []
43+
44+
# Workaround for codegen backends which haven't yet implemented `f16` and
45+
# `f128` support. Disabled any intrinsics which use those types.
46+
no-f16-f128 = []
47+
48+
# Flag this library as the unstable compiler-builtins lib
49+
compiler-builtins = []
50+
51+
# Generate memory-related intrinsics like memcpy
52+
mem = []
53+
54+
# Mangle all names so this can be linked in with other versions or other
55+
# compiler-rt implementations. Also used for testing
56+
mangled-names = []
57+
58+
# Only used in the compiler's build system
59+
rustc-dep-of-std = ["compiler-builtins"]
60+
61+
# This makes certain traits and function specializations public that
62+
# are not normally public but are required by the `builtins-test`
63+
unstable-public-internals = []

library/compiler-builtins/builtins-test-intrinsics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66
license = "MIT OR Apache-2.0"
77

88
[dependencies]
9-
compiler_builtins = { path = "../compiler-builtins", features = ["compiler-builtins"] }
9+
compiler_builtins = { path = "../builtins-shim", features = ["compiler-builtins"] }
1010
panic-handler = { path = "../crates/panic-handler" }
1111

1212
[features]

library/compiler-builtins/builtins-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustc_apfloat = "0.2.2"
1717
iai-callgrind = { version = "0.14.1", optional = true }
1818

1919
[dependencies.compiler_builtins]
20-
path = "../compiler-builtins"
20+
path = "../builtins-shim"
2121
default-features = false
2222
features = ["unstable-public-internals"]
2323

library/compiler-builtins/builtins-test/tests/lse.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(decl_macro)] // so we can use pub(super)
2+
#![feature(macro_metavar_expr_concat)]
23
#![cfg(all(target_arch = "aarch64", target_os = "linux", not(feature = "no-asm")))]
34

45
/// Translate a byte size to a Rust type.
@@ -87,7 +88,7 @@ test_op!(add, |left, right| left.wrapping_add(right));
8788
test_op!(clr, |left, right| left & !right);
8889
test_op!(xor, std::ops::BitXor::bitxor);
8990
test_op!(or, std::ops::BitOr::bitor);
90-
91+
use compiler_builtins::{foreach_bytes, foreach_ordering};
9192
compiler_builtins::foreach_cas!(cas::test);
9293
compiler_builtins::foreach_cas16!(test_cas16);
9394
compiler_builtins::foreach_swp!(swap::test);

library/compiler-builtins/ci/bench-icount.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function run_icount_benchmarks() {
5757
# Disregard regressions after merge
5858
echo "Benchmarks completed with regressions; ignoring (not in a PR)"
5959
else
60-
./ci/ci-util.py handle-banch-regressions "$PR_NUMBER"
60+
./ci/ci-util.py handle-bench-regressions "$PR_NUMBER"
6161
fi
6262
}
6363

library/compiler-builtins/compiler-builtins/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
# NOTE: Must be kept in sync with `../builtins-shim/Cargo.toml`.
2+
#
3+
# This manifest is actually used in-tree by rust-lang/rust,
4+
# `../builtins-shim/Cargo.toml` is used by out-of-tree testing. See the other
5+
# manifest for further details.
6+
17
[package]
2-
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
38
name = "compiler_builtins"
49
version = "0.1.160"
5-
license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
6-
readme = "README.md"
10+
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
11+
description = "Compiler intrinsics used by the Rust compiler."
712
repository = "https://github.com/rust-lang/compiler-builtins"
8-
homepage = "https://github.com/rust-lang/compiler-builtins"
9-
documentation = "https://docs.rs/compiler_builtins"
13+
license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
1014
edition = "2024"
11-
description = "Compiler intrinsics used by the Rust compiler."
15+
publish = false
1216
links = "compiler-rt"
1317

1418
[lib]
@@ -53,7 +57,3 @@ rustc-dep-of-std = ["compiler-builtins", "dep:core"]
5357
# This makes certain traits and function specializations public that
5458
# are not normally public but are required by the `builtins-test`
5559
unstable-public-internals = []
56-
57-
[lints.rust]
58-
# The cygwin config can be dropped after our benchmark toolchain is bumped
59-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)', 'cfg(target_os, values("cygwin"))'] }

library/compiler-builtins/compiler-builtins/build.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
mod configure;
22

3-
use std::collections::BTreeMap;
43
use std::env;
5-
use std::path::PathBuf;
6-
use std::sync::atomic::Ordering;
74

85
use configure::{Target, configure_aliases, configure_f16_f128};
96

@@ -86,10 +83,6 @@ fn main() {
8683
{
8784
println!("cargo:rustc-cfg=kernel_user_helpers")
8885
}
89-
90-
if llvm_target[0].starts_with("aarch64") {
91-
generate_aarch64_outlined_atomics();
92-
}
9386
}
9487

9588
/// Run configuration for `libm` since it is included directly.
@@ -132,61 +125,6 @@ fn configure_libm(target: &Target) {
132125
println!("cargo:rustc-cfg=feature=\"unstable-intrinsics\"");
133126
}
134127

135-
fn aarch64_symbol(ordering: Ordering) -> &'static str {
136-
match ordering {
137-
Ordering::Relaxed => "relax",
138-
Ordering::Acquire => "acq",
139-
Ordering::Release => "rel",
140-
Ordering::AcqRel => "acq_rel",
141-
_ => panic!("unknown symbol for {ordering:?}"),
142-
}
143-
}
144-
145-
/// The `concat_idents` macro is extremely annoying and doesn't allow us to define new items.
146-
/// Define them from the build script instead.
147-
/// Note that the majority of the code is still defined in `aarch64.rs` through inline macros.
148-
fn generate_aarch64_outlined_atomics() {
149-
use std::fmt::Write;
150-
// #[macro_export] so that we can use this in tests
151-
let gen_macro =
152-
|name| format!("#[macro_export] macro_rules! foreach_{name} {{ ($macro:path) => {{\n");
153-
154-
// Generate different macros for add/clr/eor/set so that we can test them separately.
155-
let sym_names = ["cas", "ldadd", "ldclr", "ldeor", "ldset", "swp"];
156-
let mut macros = BTreeMap::new();
157-
for sym in sym_names {
158-
macros.insert(sym, gen_macro(sym));
159-
}
160-
161-
// Only CAS supports 16 bytes, and it has a different implementation that uses a different macro.
162-
let mut cas16 = gen_macro("cas16");
163-
164-
for ordering in [
165-
Ordering::Relaxed,
166-
Ordering::Acquire,
167-
Ordering::Release,
168-
Ordering::AcqRel,
169-
] {
170-
let sym_ordering = aarch64_symbol(ordering);
171-
for size in [1, 2, 4, 8] {
172-
for (sym, macro_) in &mut macros {
173-
let name = format!("__aarch64_{sym}{size}_{sym_ordering}");
174-
writeln!(macro_, "$macro!( {ordering:?}, {size}, {name} );").unwrap();
175-
}
176-
}
177-
let name = format!("__aarch64_cas16_{sym_ordering}");
178-
writeln!(cas16, "$macro!( {ordering:?}, {name} );").unwrap();
179-
}
180-
181-
let mut buf = String::new();
182-
for macro_def in macros.values().chain(std::iter::once(&cas16)) {
183-
buf += macro_def;
184-
buf += "}; }\n";
185-
}
186-
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
187-
std::fs::write(out_dir.join("outlined_atomics.rs"), buf).unwrap();
188-
}
189-
190128
/// Emit directives for features we expect to support that aren't in `Cargo.toml`.
191129
///
192130
/// These are mostly cfg elements emitted by this `build.rs`.

library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,78 @@ macro_rules! or {
262262
};
263263
}
264264

265-
// See `generate_aarch64_outlined_atomics` in build.rs.
266-
include!(concat!(env!("OUT_DIR"), "/outlined_atomics.rs"));
265+
#[macro_export]
266+
macro_rules! foreach_ordering {
267+
($macro:path, $bytes:tt, $name:ident) => {
268+
$macro!( Relaxed, $bytes, ${concat($name, _relax)} );
269+
$macro!( Acquire, $bytes, ${concat($name, _acq)} );
270+
$macro!( Release, $bytes, ${concat($name, _rel)} );
271+
$macro!( AcqRel, $bytes, ${concat($name, _acq_rel)} );
272+
};
273+
($macro:path, $name:ident) => {
274+
$macro!( Relaxed, ${concat($name, _relax)} );
275+
$macro!( Acquire, ${concat($name, _acq)} );
276+
$macro!( Release, ${concat($name, _rel)} );
277+
$macro!( AcqRel, ${concat($name, _acq_rel)} );
278+
};
279+
}
280+
281+
#[macro_export]
282+
macro_rules! foreach_bytes {
283+
($macro:path, $name:ident) => {
284+
foreach_ordering!( $macro, 1, ${concat(__aarch64_, $name, "1")} );
285+
foreach_ordering!( $macro, 2, ${concat(__aarch64_, $name, "2")} );
286+
foreach_ordering!( $macro, 4, ${concat(__aarch64_, $name, "4")} );
287+
foreach_ordering!( $macro, 8, ${concat(__aarch64_, $name, "8")} );
288+
};
289+
}
290+
291+
/// Generate different macros for cas/swp/add/clr/eor/set so that we can test them separately.
292+
#[macro_export]
293+
macro_rules! foreach_cas {
294+
($macro:path) => {
295+
foreach_bytes!($macro, cas);
296+
};
297+
}
298+
299+
/// Only CAS supports 16 bytes, and it has a different implementation that uses a different macro.
300+
#[macro_export]
301+
macro_rules! foreach_cas16 {
302+
($macro:path) => {
303+
foreach_ordering!($macro, __aarch64_cas16);
304+
};
305+
}
306+
#[macro_export]
307+
macro_rules! foreach_swp {
308+
($macro:path) => {
309+
foreach_bytes!($macro, swp);
310+
};
311+
}
312+
#[macro_export]
313+
macro_rules! foreach_ldadd {
314+
($macro:path) => {
315+
foreach_bytes!($macro, ldadd);
316+
};
317+
}
318+
#[macro_export]
319+
macro_rules! foreach_ldclr {
320+
($macro:path) => {
321+
foreach_bytes!($macro, ldclr);
322+
};
323+
}
324+
#[macro_export]
325+
macro_rules! foreach_ldeor {
326+
($macro:path) => {
327+
foreach_bytes!($macro, ldeor);
328+
};
329+
}
330+
#[macro_export]
331+
macro_rules! foreach_ldset {
332+
($macro:path) => {
333+
foreach_bytes!($macro, ldset);
334+
};
335+
}
336+
267337
foreach_cas!(compare_and_swap);
268338
foreach_cas16!(compare_and_swap_i128);
269339
foreach_swp!(swap);

library/compiler-builtins/compiler-builtins/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(linkage)]
99
#![feature(naked_functions)]
1010
#![feature(repr_simd)]
11+
#![feature(macro_metavar_expr_concat)]
1112
#![feature(rustc_attrs)]
1213
#![cfg_attr(f16_enabled, feature(f16))]
1314
#![cfg_attr(f128_enabled, feature(f128))]

library/compiler-builtins/libm/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
[package]
2+
name = "libm"
3+
version = "0.2.15"
24
authors = ["Jorge Aparicio <jorge@japaric.io>"]
3-
categories = ["no-std"]
45
description = "libm in pure Rust"
5-
documentation = "https://docs.rs/libm"
6+
categories = ["no-std"]
67
keywords = ["libm", "math"]
7-
license = "MIT"
8-
name = "libm"
9-
readme = "README.md"
108
repository = "https://github.com/rust-lang/compiler-builtins"
11-
version = "0.2.15"
9+
license = "MIT"
1210
edition = "2021"
1311
rust-version = "1.63"
1412

0 commit comments

Comments
 (0)