Skip to content

[do not merge] core::mem::replace using core::mem::swap#154575

Open
GrigorenkoPV wants to merge 1 commit intorust-lang:mainfrom
GrigorenkoPV:replace-swap
Open

[do not merge] core::mem::replace using core::mem::swap#154575
GrigorenkoPV wants to merge 1 commit intorust-lang:mainfrom
GrigorenkoPV:replace-swap

Conversation

@GrigorenkoPV
Copy link
Copy Markdown
Contributor

@GrigorenkoPV GrigorenkoPV commented Mar 30, 2026

Brought up in and closes #154546.
Reverts #83022.
Needs a perf run.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, scottmcm

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Mar 30, 2026

Have you checked codegen for larger types?

@rust-log-analyzer

This comment has been minimized.

// CHECK-NEXT: call void @llvm.memcpy
// CHECK-NEXT: ret
core::mem::take(&mut x)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing this subtest, maybe fix the test expectation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this is somewhat of a regression. If I understand correctly, the test checks that we just do a memcpy the pointers/sizes from x into the return value, because we no longer care about x after the function returns. But this is no longer the case after the change to mem::replace. This sounds like it might be a good place to stop right there and say "this is a regression, we're not doing it", but a maybe a perf run is still worth it?

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

The Miri subtree was changed

cc @rust-lang/miri

@GrigorenkoPV GrigorenkoPV changed the title core::mem::replace using core::mem::swap [do not merge] core::mem::replace using core::mem::swap Mar 30, 2026
@GrigorenkoPV
Copy link
Copy Markdown
Contributor Author

GrigorenkoPV commented Mar 30, 2026

Have you checked codegen for larger types?

Haven't. Will.


@rustbot author

I also ran into a very strange failure in miri, let's see if CI gets it too.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 30, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
+         _3 = copy _2;
+         StorageLive(_4);
+         _4 = &raw mut (*_1);
+         StorageLive(_5);
+         _5 = &raw mut _3;
+         _6 = typed_swap_nonoverlapping::<u32>(move _4, move _5) -> [return: bb1, unwind unreachable];
+     }
+ 
+     bb1: {
+         StorageDead(_5);
+         StorageDead(_4);
+         _0 = move _3;
+         StorageDead(_3);
15         return;
16     }
17 }


thread '[mir-opt] tests/mir-opt/pre-codegen/mem_replace.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:84:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-unwind.mir
stack backtrace:
   5: __rustc::rust_begin_unwind
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:689:5
   6: core::panicking::panic_fmt
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/panicking.rs:80:14

For more information how to resolve CI failures of this job, visit this link.

@RalfJung
Copy link
Copy Markdown
Member

Cc @m-ou-se @scottmcm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suboptimal code generation with unnecessary stack spills around std::mem::take / alternative implementation suggested

6 participants