Skip to content

Commit ef4cff2

Browse files
Rollup merge of #153015 - joboet:atomic_alias_generic, r=jhpratt
core: make atomic primitives type aliases of `Atomic<T>` Tracking issue: #130539 This makes `AtomicI32` and friends type aliases of `Atomic<T>` by encoding their alignment requirements via the use of an internal `Storage` associated type. This is also used to encode that `AtomicBool` store a `u8` internally. Modulo the `Send`/`Sync` implementations, this PR does not move any trait implementations, methods or associated functions – I'll leave that for another PR.
2 parents 4a3d3cb + e9ca34f commit ef4cff2

27 files changed

+315
-330
lines changed

compiler/rustc_data_structures/src/marker.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ macro_rules! already_send {
5959

6060
// These structures are already `Send`.
6161
already_send!(
62-
[std::backtrace::Backtrace][std::io::Stdout][std::io::Stderr][std::io::Error][std::fs::File][std::panic::Location<'_>]
63-
[rustc_arena::DroplessArena][jobserver_crate::Client][jobserver_crate::HelperThread]
64-
[crate::memmap::Mmap][crate::profiling::SelfProfiler][crate::owned_slice::OwnedSlice]
62+
[std::sync::atomic::AtomicBool][std::sync::atomic::AtomicUsize][std::sync::atomic::AtomicU8]
63+
[std::sync::atomic::AtomicU32][std::backtrace::Backtrace][std::io::Stdout][std::io::Stderr]
64+
[std::io::Error][std::fs::File][std::panic::Location<'_>][rustc_arena::DroplessArena]
65+
[jobserver_crate::Client][jobserver_crate::HelperThread][crate::memmap::Mmap]
66+
[crate::profiling::SelfProfiler][crate::owned_slice::OwnedSlice]
6567
);
6668

69+
#[cfg(target_has_atomic = "64")]
70+
already_send!([std::sync::atomic::AtomicU64]);
71+
6772
macro_rules! impl_dyn_send {
6873
($($($attr: meta)* [$ty: ty where $($generics2: tt)*])*) => {
6974
$(unsafe impl<$($generics2)*> DynSend for $ty {})*

compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,31 +1036,13 @@ impl InvalidAtomicOrdering {
10361036
expr: &Expr<'hir>,
10371037
recognized_names: &[Symbol], // used for fast path calculation
10381038
) -> Option<(Symbol, &'hir [Expr<'hir>])> {
1039-
const ATOMIC_TYPES: &[Symbol] = &[
1040-
sym::AtomicBool,
1041-
sym::AtomicPtr,
1042-
sym::AtomicUsize,
1043-
sym::AtomicU8,
1044-
sym::AtomicU16,
1045-
sym::AtomicU32,
1046-
sym::AtomicU64,
1047-
sym::AtomicU128,
1048-
sym::AtomicIsize,
1049-
sym::AtomicI8,
1050-
sym::AtomicI16,
1051-
sym::AtomicI32,
1052-
sym::AtomicI64,
1053-
sym::AtomicI128,
1054-
];
10551039
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind
10561040
&& recognized_names.contains(&method_path.ident.name)
10571041
&& let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
10581042
// skip extension traits, only lint functions from the standard library
10591043
&& let Some(impl_did) = cx.tcx.inherent_impl_of_assoc(m_def_id)
10601044
&& let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def()
1061-
&& let parent = cx.tcx.parent(adt.did())
1062-
&& cx.tcx.is_diagnostic_item(sym::atomic_mod, parent)
1063-
&& ATOMIC_TYPES.contains(&cx.tcx.item_name(adt.did()))
1045+
&& cx.tcx.is_diagnostic_item(sym::Atomic, adt.did())
10641046
{
10651047
return Some((method_path.ident.name, args));
10661048
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,7 @@ symbols! {
171171
AsyncGenFinished,
172172
AsyncGenPending,
173173
AsyncGenReady,
174-
AtomicBool,
175-
AtomicI8,
176-
AtomicI16,
177-
AtomicI32,
178-
AtomicI64,
179-
AtomicI128,
180-
AtomicIsize,
181-
AtomicPtr,
182-
AtomicU8,
183-
AtomicU16,
184-
AtomicU32,
185-
AtomicU64,
186-
AtomicU128,
187-
AtomicUsize,
174+
Atomic,
188175
BTreeMap,
189176
Bool,
190177
Borrow,
@@ -485,7 +472,6 @@ symbols! {
485472
atomic_load,
486473
atomic_max,
487474
atomic_min,
488-
atomic_mod,
489475
atomic_nand,
490476
atomic_or,
491477
atomic_singlethreadfence,

0 commit comments

Comments
 (0)