From a60e71c765d64a5f94303d0a4b142297b598db31 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Wed, 22 Oct 2025 16:37:55 -0700 Subject: [PATCH] Clarify comment about Arc::as_ptr --- wgpu-core/src/id.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 76b83e5fa..79cddeb9a 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -161,12 +161,13 @@ impl Hash for PointerId { impl From<&Arc> for PointerId { fn from(arc: &Arc) -> Self { - // Since the memory representation of `Arc` is just a pointer, it - // would be nice to use that pointer as the trace ID, since many - // `into_trace` implementations would then be no-ops at runtime. - // Unfortunately, because `Arc::as_ptr` returns a pointer to the - // contained data, and `Arc` stores reference counts before the data, - // we are adding an offset to the pointer here. + // Since the memory representation of `Arc` is just a pointer to + // `ArcInner`, it would be nice to use that pointer as the trace ID, + // since many `into_trace` implementations would then be no-ops at + // runtime. However, `Arc::as_ptr` returns a pointer to the contained + // data, not to the `ArcInner`. The `ArcInner` stores the reference + // counts before the data, so the machine code for this conversion has + // to add an offset to the pointer. PointerId::PointerId(Arc::as_ptr(arc) as usize, PhantomData) } }