Re: [PATCH v3 2/4] rust: convert `Arc` to use `Refcount`

Alice Ryhl
2025-02-21T12:05:43Z

On Wed, Feb 19, 2025 at 8:17 PM Gary Guo <gary@garyguo.net> wrote:
>
> With `Refcount` type created, `Arc` can use `Refcount` instead of
> calling into FFI directly.
>
> Signed-off-by: Gary Guo <gary@garyguo.net>

Overall LGTM. Other than Tamir's questions, I have one:

> + if refcount.dec_and_test() {
> + refcount.set(1);
>
> - // INVARIANT: We own the only refcount to this arc, so we may create a `UniqueArc`. We
> - // must pin the `UniqueArc` because the values was previously in an `Arc`, and they pin
> - // their values.
> + // INVARIANT: If the refcount failed to decrement because it is 1, then we have the
> + // exclusive ownership, so we may create a `UniqueArc`. We must pin the `UniqueArc`
> + // because the values was previously in an `Arc`, and they pin their values.

"If the refcount failed to decrement" seems to be leftover from a
previous version. This should say "If the refcount was decremented to
zero" or similar.

Alice