about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-10-02 08:34:10 +0200
committerRalf Jung <post@ralfj.de>2023-10-02 08:34:10 +0200
commitec2e00c4045f49f8efc5b1490b6276ecb364b2dd (patch)
treec092c79cab65a23872127783ac7f9eb261778699
parent15783292e5e26336f76ddc2123d66025ec6d84b7 (diff)
downloadrust-ec2e00c4045f49f8efc5b1490b6276ecb364b2dd.tar.gz
rust-ec2e00c4045f49f8efc5b1490b6276ecb364b2dd.zip
update some comments around swap()
-rw-r--r--library/core/src/mem/mod.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 5244e478018..4ec49a6d0b9 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -728,10 +728,6 @@ pub const fn swap<T>(x: &mut T, y: &mut T) {
     // reinterpretation of values as (chunkable) byte arrays, and the loop in the
     // block optimization in `swap_slice` is hard to rewrite back
     // into the (unoptimized) direct swapping implementation, so we disable it.
-    // FIXME(eddyb) the block optimization also prevents MIR optimizations from
-    // understanding `mem::replace`, `Option::take`, etc. - a better overall
-    // solution might be to make `ptr::swap_nonoverlapping` into an intrinsic, which
-    // a backend can choose to implement using the block optimization, or not.
     #[cfg(not(any(target_arch = "spirv")))]
     {
         // For types that are larger multiples of their alignment, the simple way
@@ -768,11 +764,14 @@ pub(crate) const fn swap_simple<T>(x: &mut T, y: &mut T) {
     // And LLVM actually optimizes it to 3Ă—memcpy if called with
     // a type larger than it's willing to keep in a register.
     // Having typed reads and writes in MIR here is also good as
-    // it lets MIRI and CTFE understand them better, including things
+    // it lets Miri and CTFE understand them better, including things
     // like enforcing type validity for them.
     // Importantly, read+copy_nonoverlapping+write introduces confusing
     // asymmetry to the behaviour where one value went through read+write
     // whereas the other was copied over by the intrinsic (see #94371).
+    // Furthermore, using only read+write here benefits limited backends
+    // such as SPIR-V that work on an underlying *typed* view of memory,
+    // and thus have trouble with Rust's untyped memory operations.
 
     // SAFETY: exclusive references are always valid to read/write,
     // including being aligned, and nothing here panics so it's drop-safe.