archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <>
To: "Maíra Canal" <>
Cc: "Asahi Lina" <>,
	"Miguel Ojeda" <>,
	"Alex Gaynor" <>,
	"Wedson Almeida Filho" <>,
	"Boqun Feng" <>,
	"Gary Guo" <>,
	"Björn Roy Baron" <>,
	"Benno Lossin" <>,
	"Andreas Hindborg" <>,
	"Alice Ryhl" <>,
	"Matthew Wilcox" <>,,,
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: <> (raw)
In-Reply-To: <>

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 <> 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. ``):

    /// # 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 ``).


      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:

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

  git send-email \
    --in-reply-to='' \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

* 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).