rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Oliver Mangold" <oliver.mangold@pm.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3] rust: adding UniqueRefCounted and UniqueRef types
Date: Mon, 03 Mar 2025 15:22:43 +0100	[thread overview]
Message-ID: <87o6yijirw.fsf@kernel.org> (raw)
In-Reply-To: <Z8Wuud2UQX6Yukyr@mango> (Oliver Mangold's message of "Mon, 03 Mar 2025 13:29:36 +0000")

"Oliver Mangold" <oliver.mangold@pm.me> writes:

> From: Oliver Mangold <oliver.mangold@pm.me>
> Date: Fri, 21 Feb 2025 08:36:46 +0100
> Subject: [PATCH] rust: adding UniqueRefCounted and UniqueRef types
>
> Add `UniqueRef` as a variant of `ARef` that is guaranteed to be unique.
> This is useful when mutable access to the underlying type is required
> and we can guarantee uniqueness, and when APIs that would normally take
> an `ARef` require uniqueness.
>
> Signed-off-by: Oliver Mangold <oliver.mangold@pm.me>


This part:


    This should address all issues that have been raised with v2:

    - Added a default implementation for unique_to_shared() which does a simple
      rewrap of the underlying object.
    - Added a SimpleUniqueRefCounted trait which requires only to implement
      is_unique() as Benoît asked for. Maybe the feature is not worth
      the extra code, though. For me keeping it or removing would be both fine.
    - Removed the unsound conversion from &T to UniqueRef, as spotted by Benoît.
    - Relaxed the requirements for Send and Sync, to be identical to the ones
      for Box. See comment below.
    - Added Examples for both UniqueRefCounted and SimpleUniqueRefCounted
      as asked for by Boqun Feng.
      For me they compile and run without errors as KUnits.
    - Changed the commit message like suggested by Andreas.

    @Benoît: I think you are right about Send and Sync.
    What gave me a bit of a headache is if Send really does not require
    the underlying object to be Sync, as the refcount itself -
    which is part of the object - might be touched concurrently in a case
    like with tag_to_req(), but I think one would not implement
    something like that without having a synchronized refcount.

    Best regards,

    Oliver


Goes immedieatly after the cut like so:


    From: Oliver Mangold <oliver.mangold@pm.me>
    Date: Fri, 21 Feb 2025 08:36:46 +0100
    Subject: [PATCH] rust: adding UniqueRefCounted and UniqueRef types

    Add `UniqueRef` as a variant of `ARef` that is guaranteed to be unique.
    This is useful when mutable access to the underlying type is required
    and we can guarantee uniqueness, and when APIs that would normally take
    an `ARef` require uniqueness.

    Signed-off-by: Oliver Mangold <oliver.mangold@pm.me>
    ---


    This should address all issues that have been raised with v2:

    - Added a default implementation for unique_to_shared() which does a simple
      rewrap of the underlying object.
    - Added a SimpleUniqueRefCounted trait which requires only to implement
      is_unique() as Benoît asked for. Maybe the feature is not worth
      the extra code, though. For me keeping it or removing would be both fine.
    - Removed the unsound conversion from &T to UniqueRef, as spotted by Benoît.
    - Relaxed the requirements for Send and Sync, to be identical to the ones
      for Box. See comment below.
    - Added Examples for both UniqueRefCounted and SimpleUniqueRefCounted
      as asked for by Boqun Feng.
      For me they compile and run without errors as KUnits.
    - Changed the commit message like suggested by Andreas.

    @Benoît: I think you are right about Send and Sync.
    What gave me a bit of a headache is if Send really does not require
    the underlying object to be Sync, as the refcount itself -
    which is part of the object - might be touched concurrently in a case
    like with tag_to_req(), but I think one would not implement
    something like that without having a synchronized refcount.

    Best regards,

    Oliver

    ---

    rust/kernel/types.rs | 315 +++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 315 insertions(+)


Again, I'll recommend the use of b4 [1].

Best regards,
Andreas Hindborg


[1] https://b4.docs.kernel.org/en/latest/contributor/prep.html


  reply	other threads:[~2025-03-03 14:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 14:43 [PATCH] rust: adding UniqueRefCounted and UniqueRef types Oliver Mangold
2025-02-28 15:21 ` Miguel Ojeda
2025-02-28 15:54 ` Boqun Feng
2025-02-28 18:01 ` [PATCH v2] " Oliver Mangold
2025-02-28 18:09   ` Boqun Feng
2025-02-28 18:16     ` Boqun Feng
2025-02-28 18:29   ` Andreas Hindborg
2025-03-03 13:29     ` [PATCH v3] " Oliver Mangold
2025-03-03 14:22       ` Andreas Hindborg [this message]
2025-03-03 16:33         ` Oliver Mangold
2025-03-03 14:09   ` [PATCH v2] " Andreas Hindborg
2025-02-28 23:41 ` [PATCH] " Benoît du Garreau
2025-03-01  8:06   ` Oliver Mangold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o6yijirw.fsf@kernel.org \
    --to=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=oliver.mangold@pm.me \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).