From eaa952b536c48658a5a2e3f128e3afdef03a01b6 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 16 Dec 2025 13:33:47 -0500 Subject: [PATCH] YJIT: Print `Rc` strong and weak count on assert failure For , the panic is looking like some sort of third party memory corruption, with YJIT taking the fall. At the point of this assert, the assembler has dropped, so there's nothing in YJIT's code other than JITState that could be holding on to these transient `PendingBranchRef`. The strong count being more than a handful or the weak count is non-zero shows that someone in the process (likely some native extension) corrupted the Rc's counts. --- yjit/src/core.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yjit/src/core.rs b/yjit/src/core.rs index 0a14c44ae4..0590135392 100644 --- a/yjit/src/core.rs +++ b/yjit/src/core.rs @@ -2419,7 +2419,9 @@ impl<'a> JITState<'a> { // Pending branches => actual branches outgoing: MutableBranchList(Cell::new(self.pending_outgoing.into_iter().map(|pending_out| { let pending_out = Rc::try_unwrap(pending_out) - .ok().expect("all PendingBranchRefs should be unique when ready to construct a Block"); + .unwrap_or_else(|rc| panic!( + "PendingBranchRef should be unique when ready to construct a Block. \ + strong={} weak={}", Rc::strong_count(&rc), Rc::weak_count(&rc))); pending_out.into_branch(NonNull::new(blockref as *mut Block).expect("no null from Box")) }).collect())) });