rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: andrew@lunn.ch, benno.lossin@proton.me, netdev@vger.kernel.org,
	 rust-for-linux@vger.kernel.org, tmgross@umich.edu,
	boqun.feng@gmail.com,  wedsonaf@gmail.com, greg@kroah.com
Subject: Re: [PATCH net-next v5 1/5] rust: core abstractions for network PHY drivers
Date: Sun, 22 Oct 2023 13:37:33 +0200	[thread overview]
Message-ID: <CANiq72mDWJDb9Fhd4CHt8YKapdWaOrqhJMOrQZ9CDRtvNdrGqA@mail.gmail.com> (raw)
In-Reply-To: <20231022.184702.1777825182430453165.fujita.tomonori@gmail.com>

On Sun, Oct 22, 2023 at 11:47 AM FUJITA Tomonori
<fujita.tomonori@gmail.com> wrote:
>
> Agreed that the first three paragraphs at the top of the file are
> implementation comments. Are there any other comments in the file,
> which look implementation comments to you? To me, the rest look the
> docs for Rust API users.

I think some should be improved with that in mind, yeah. For instance,
this one seems good to me:

    /// An instance of a PHY driver.

But this one is not:

    /// Creates the kernel's `phy_driver` instance.

It is especially bad because the first line of the docs is the "short
description" used for lists by `rustdoc`.

For similar reasons, this one is bad (and in this case it is the only line!):

    /// Corresponds to the kernel's `enum phy_state`.

That line could be part of the documentation if you think it is
helpful for a reader as a practical note explaining what it is
supposed to map in the C side. But it should really not be the very
first line / short description.

Instead, the documentation should answer the question "What is this?".
And the answer should be something like "The state of the PHY ......"
as the short description. Then ideally a longer explanation of why it
is needed, how it is intended to be used, what this maps to in the C
side (if relevant), anything else that the user may need to know about
it, particular subtleties if any, examples if relevant, etc.

> I'm not sure that a comment on the relationship between C and Rust
> structures like "Wraps the kernel's `struct phy_driver`" is API docs
> but the in-tree files like mutex.rs have the similar so I assume it's
> fine.

Yes, documenting that something wraps/relies on/maps a particular C
functionality is something we do for clarity and practicality (we also
link the related C headers). This is, I assume, the kind of clarity
Andrew was asking for, i.e. to be practical and let the user know what
they are dealing with on the C side, especially early on.

But if some detail is not needed to use the API, then we should avoid
writing it in the documentation. And if it is needed, but it can be
written in a way that does not depend/reference the C side, then it
should be.

For instance, as you can see from the `mutex.rs` you mention, the
short description does not mention the C side -- it does so
afterwards, and then it goes onto explaining why it is needed, how it
is used (with examples), and so on. The fact that it exposes the C
`struct mutex` is there, because it adds value ("oh, ok, so this is
what I would use if I wanted the C mutex"), but that bit (and the
rest) is not really about explaining how `Mutex` is implemented:

    /// A mutual exclusion primitive.
    ///
    /// Exposes the kernel's [`struct mutex`]. When multiple threads
attempt to lock the same mutex,
    /// only one at a time is allowed to progress, the others will
block (sleep) until the mutex is
    /// unlocked, at which point another thread will be allowed to
wake up and make progress.
    ///
    /// Since it may block, [`Mutex`] needs to be used with care in
atomic contexts.
    ///
    /// Instances of [`Mutex`] need a lock class and to be pinned. The
recommended way to create such
    /// instances is with the [`pin_init`](crate::pin_init) and
[`new_mutex`] macros.
    ///
    /// # Examples
    ///
    /// The following example shows how to declare, allocate and
initialise a struct (`Example`) that
    /// contains an inner struct (`Inner`) that is protected by a mutex.

    ...

    /// The following example shows how to use interior mutability to
modify the contents of a struct
    /// protected by a mutex despite only having a shared reference:

    ...

`Mutex`'s docs are, in fact, a good a good example of how to write docs!

> Where the implementation comments are supposed to be placed?
> Documentation/networking?

No, they would be normal `//` comments and they should be as close to
the relevant code as possible -- please see
https://docs.kernel.org/rust/coding-guidelines.html#comments. They can
still be read in the generated docs via the "source" buttons, so they
will be there for those reading the actual implementation in the
browser.

Instead, `Documentation/` is detached from the actual code. For Rust
code, we hope to use only those for out-of-line information that is
not related to any particular API.

For instance, the "coding guidelines" document I just linked. Or
end-user / distributor documentation. Or, as another example, Wedson
at some point considered adding some high-level design documents, and
if those would not fit any particular API or if they are not intended
for users of the API, they could perhaps go into `Doc/`. Or perhaps
Boqun's idea of having a reviewers guide, etc.

Cheers,
Miguel

  reply	other threads:[~2023-10-22 11:37 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 11:30 [PATCH net-next v5 0/5] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 1/5] rust: core " FUJITA Tomonori
2023-10-18 15:07   ` Benno Lossin
2023-10-19  0:24     ` FUJITA Tomonori
2023-10-19 13:45       ` Benno Lossin
2023-10-19 14:42         ` FUJITA Tomonori
2023-10-19 15:20           ` Benno Lossin
2023-10-19 15:32             ` FUJITA Tomonori
2023-10-19 16:37               ` Benno Lossin
2023-10-19 21:51                 ` FUJITA Tomonori
2023-10-21  7:21                   ` Benno Lossin
2023-10-20  0:34             ` FUJITA Tomonori
2023-10-20 12:54               ` FUJITA Tomonori
2023-10-21  7:25                 ` Benno Lossin
2023-10-21  7:30                   ` FUJITA Tomonori
2023-10-21  8:37                     ` Benno Lossin
2023-10-21 10:27                       ` FUJITA Tomonori
2023-10-21 11:21                         ` Benno Lossin
2023-10-21 11:36                           ` FUJITA Tomonori
2023-10-21 12:13                             ` Benno Lossin
2023-10-21 12:38                               ` FUJITA Tomonori
2023-10-21 12:50                                 ` Benno Lossin
2023-10-21 13:00                                   ` FUJITA Tomonori
2023-10-21 13:05                                     ` Benno Lossin
2023-10-21 13:31                                       ` FUJITA Tomonori
2023-10-21 13:35                                         ` Benno Lossin
2023-10-21 21:45                                           ` FUJITA Tomonori
2023-10-23  6:35                                             ` Benno Lossin
2023-10-23  6:37                                               ` Benno Lossin
2023-10-21 15:57                                       ` Andrew Lunn
2023-10-21 16:31                                         ` Benno Lossin
2023-10-21 15:41                             ` Andrew Lunn
2023-10-20 18:42     ` Andrew Lunn
2023-10-21  4:44       ` FUJITA Tomonori
2023-10-21  7:36       ` Benno Lossin
2023-10-21 12:47       ` Miguel Ojeda
2023-10-22  9:47         ` FUJITA Tomonori
2023-10-22 11:37           ` Miguel Ojeda [this message]
2023-10-22 15:34             ` Andrew Lunn
2023-10-24  1:37               ` FUJITA Tomonori
2023-10-24  8:48               ` Miguel Ojeda
2023-10-18 20:27   ` Andrew Lunn
2023-10-19  0:41     ` FUJITA Tomonori
2023-10-19 13:57       ` Benno Lossin
2023-10-20 19:50         ` Andrew Lunn
2023-10-21  8:01           ` Benno Lossin
2023-10-21 15:35             ` Andrew Lunn
2023-10-20 17:26   ` Andreas Hindborg (Samsung)
2023-10-20 17:56     ` Benno Lossin
2023-10-20 19:59     ` Andrew Lunn
2023-10-20 20:30       ` Andreas Hindborg (Samsung)
2023-10-21  3:49         ` FUJITA Tomonori
2023-10-21  4:01     ` FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 2/5] rust: net::phy add module_phy_driver macro FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 3/5] WIP rust: add second `bindgen` pass for enum exhaustiveness checking FUJITA Tomonori
2023-10-20 11:37   ` Andreas Hindborg (Samsung)
2023-10-20 12:34     ` Miguel Ojeda
2023-10-20 12:35       ` Miguel Ojeda
2023-10-23  8:57       ` Andreas Hindborg (Samsung)
2023-10-21  3:51     ` FUJITA Tomonori
2023-10-21 12:05       ` Miguel Ojeda
2023-10-22  6:30         ` FUJITA Tomonori
2023-10-23  8:58         ` Andreas Hindborg (Samsung)
2023-10-17 11:30 ` [PATCH net-next v5 4/5] MAINTAINERS: add Rust PHY abstractions for ETHERNET PHY LIBRARY FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 5/5] net: phy: add Rust Asix PHY driver FUJITA Tomonori

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=CANiq72mDWJDb9Fhd4CHt8YKapdWaOrqhJMOrQZ9CDRtvNdrGqA@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=benno.lossin@proton.me \
    --cc=boqun.feng@gmail.com \
    --cc=fujita.tomonori@gmail.com \
    --cc=greg@kroah.com \
    --cc=netdev@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=wedsonaf@gmail.com \
    /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).