rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: "Maíra Canal" <mcanal@igalia.com>
Cc: "Asahi Lina" <lina@asahilina.net>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@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>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	kernel-dev@igalia.com
Subject: Re: [PATCH v7 2/2] rust: xarray: Add an abstraction for XArray
Date: Wed, 28 Feb 2024 11:44:19 +0100	[thread overview]
Message-ID: <CANiq72nNAYERpeOx5Q4bMGizQfx=RCpR8NukiYCbRHx3-93Vpg@mail.gmail.com> (raw)
In-Reply-To: <20240209223201.2145570-4-mcanal@igalia.com>

Hi Maíra,

Thanks for keeping up the work on this! A quick "nit review" on docs/comments.

On Fri, Feb 9, 2024 at 11:32 PM Maíra Canal <mcanal@igalia.com> wrote:
>
> +//! C header: [`include/linux/xarray.h`](../../include/linux/xarray.h)

This can be migrated to the new `srctree/` notation:

    +//! C header: [`include/linux/xarray.h`](srctree/include/linux/xarray.h)

> +/// Flags passed to `XArray::new` to configure the `XArray`.

Please use intra-doc links where possible, e.g. this could be:

    /// Flags passed to [`XArray::new`] to configure the [`XArray`].

Sometimes you may need to help `rustdoc` a bit -- you can check how it
is done in other places for those that may not work. Of course, if a
particular instance gets too involved/hard to read for plain text
reading, then you can ignore it.

(Same for other instances, e.g. I see `None`, `Vec<Option<T>>`,
`Arc<T>`, `ForeignOwnable`, `Deref`..., also methods like
`into_foreign` etc.).

> +/// This is similar to a `Vec<Option<T>>`, but more efficient when there are holes in the
> +/// index space, and can be efficiently grown.

This line seems wrapped differently than the others nearby -- in
general, please try to keep comments at 100 columns if possible (or at
least try to be consistent within the same file).

> +/// INVARIANT: All pointers stored in the array are pointers obtained by
> +/// calling `T::into_foreign` or are NULL pointers. By using the pin-init
> +/// initialization, `self.xa` is always an initialized and valid XArray.

Shouldn't this be in an `# Invariants` section instead?

> +/// `Guard` holds a reference (`self.0`) to the underlying value owned by the
> +/// `XArray` (`self.1`) with its lock held.

Should we use "pointer" here?

> +        // SAFETY: By the type invariant, we own the XArray lock, so we must
> +        // unlock it here.

Please also use Markdown in normal comments too (like you do elsewhere).

(Same for other instances).

> +            // Consider it a success anyway, not much we can do

Period at the end.

> +///
> +/// # Examples
> +///

Is something missing here at the top of these docs? Or what is the intention?

> +/// use kernel::prelude::*;

This line can be removed -- it is implicitly added in examples.

> +/// let foo = Arc::try_new(Foo { a : 1, b: 2 }).expect("Unable to allocate Foo");

Please consider using `?` instead to simplify the example, you will
need to add a line at the end for that (see e.g. `arc.rs`):

    /// # Ok::<(), Error>(())

> +    /// The type is `unsigned long`, which is always the same as `usize` in
> +    /// the kernel. Therefore, we can use this method to convert between those.

This comment sounds like an implementation detail, rather than the
documentation of the function.

> +        let mut index: core::ffi::c_ulong = 0;

This is `use`d above, but here the full path is given.

(Same for other instances).

> +// SAFETY: XArray is thread-safe and all mutation operations are internally locked.

Ideally we use different comments for each `unsafe impl` and we
explain the rationale for the bounds on each case (e.g. see `arc.rs`).

Cheers,
Miguel

      parent reply	other threads:[~2024-02-28 10:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 22:31 [PATCH v7 0/2] rust: xarray: Add an abstraction for XArray Maíra Canal
2024-02-09 22:31 ` [PATCH v7 1/2] rust: types: add FOREIGN_ALIGN to ForeignOwnable Maíra Canal
2024-02-27  7:53   ` Andreas Hindborg
2024-02-28 10:09   ` Alice Ryhl
2024-02-09 22:31 ` [PATCH v7 2/2] rust: xarray: Add an abstraction for XArray Maíra Canal
2024-02-27  7:54   ` Andreas Hindborg
2024-02-28  9:56     ` Andreas Hindborg
2024-02-28 10:32   ` Alice Ryhl
2024-02-28 10:44   ` Miguel Ojeda [this message]

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='CANiq72nNAYERpeOx5Q4bMGizQfx=RCpR8NukiYCbRHx3-93Vpg@mail.gmail.com' \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=a.hindborg@samsung.com \
    --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=kernel-dev@igalia.com \
    --cc=lina@asahilina.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mcanal@igalia.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=willy@infradead.org \
    /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).