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

From: Alice Ryhl
Date: Fri Feb 21 2025 - 07:10:54 EST


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

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