rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <benno.lossin@proton.me>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
	netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
	andrew@lunn.ch, miguel.ojeda.sandonis@gmail.com,
	tmgross@umich.edu, wedsonaf@gmail.com, greg@kroah.com
Subject: Re: [PATCH net-next v4 1/4] rust: core abstractions for network PHY drivers
Date: Sat, 14 Oct 2023 08:53:13 -0700	[thread overview]
Message-ID: <ZSq5aY9R66vwcd6k@Boquns-Mac-mini.home> (raw)
In-Reply-To: <3469de1c-0e6f-4fe5-9d93-2542f87ffd0d@proton.me>

On Sat, Oct 14, 2023 at 02:54:30PM +0000, Benno Lossin wrote:
[...]
> >>>
> >>> Boqun asked me to drop mut on v3 review and then you ask why on v4?
> >>> Trying to find a way to discourage developpers to write Rust
> >>> abstractions? :)
> >>>
> >>> I would recommend the Rust reviewers to make sure that such would
> >>> not happen. I really appreciate comments but inconsistent reviewing is
> >>> painful.
> >>
> >> I agree with Boqun. Before Boqun's suggestion all functions were
> >> `&mut self`. Now all functions are `&self`. Both are incorrect. A
> >> function that takes `&mut self` can modify the state of `Self`,
> >> but it is weird for it to not modify anything at all. Such a
> >> function also can only be called by a single thread (per instance
> >> of `Self`) at a time. Functions with `&self` cannot modify the
> >> state of `Self`, except of course with interior mutability. If
> >> they do modify state with interior mutability, then they should
> >> have a good reason to do that.
> >>
> >> What I want you to do here is think about which functions should
> >> be `&mut self` and which should be `&self`, since clearly just
> >> one or the other is wrong here.
> > 
> > https://lore.kernel.org/netdev/20231011.231607.1747074555988728415.fujita.tomonori@gmail.com/T/#mb7d219b2e17d3f3e31a0d05697d91eb8205c5c6e
> > 
> > Hmm, I undertood that he suggested all mut.
> 

To be clear, I was only talking about phy_id() at the email thread,

My original reply:

> >>> >> +    pub fn phy_id(&mut self) -> u32 {
> >>> > 
> >>> > This function doesn't modify the `self`, why does this need to be a
> >>> > `&mut self` function? Ditto for a few functions in this impl block.

so Tomo, I wasn't suggesting dropping `mut` for all functions (I used
the words "a few" not "all"), just dropping them accordingly.

Actually this is an excellent example for the fragile of relying on
implicit requirements ;-) The original intent got lost track in a few
email exchanges. 

API soundness is not the sliver bullet, but it at least tries to bring
a common base for handling such problems. Again maybe you now can
understand why we push so hard on "tiny" things again and again.

Also of course Rust is still somehow immature, so if you have an idea
but cannot express in Rust, feel free to call it out, we can work
together to 1) find a temp solution and 2) push Rust to improve. That's
one of the points of the experiment.

Regards,
Boqun

> That remark seems to me to only apply to the return type of
> `assume_locked` in that thread.
> 

  reply	other threads:[~2023-10-14 15:53 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 12:53 [PATCH net-next v4 0/4] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-10-12 12:53 ` [PATCH net-next v4 1/4] rust: core " FUJITA Tomonori
2023-10-13 21:31   ` Benno Lossin
2023-10-14  2:12     ` Andrew Lunn
2023-10-14  4:50       ` FUJITA Tomonori
2023-10-14 17:00       ` Miguel Ojeda
2023-10-14 23:18         ` FUJITA Tomonori
2023-10-15 15:47           ` Andrew Lunn
2023-10-14  7:22     ` FUJITA Tomonori
2023-10-14  8:07       ` Benno Lossin
2023-10-14 10:32         ` FUJITA Tomonori
2023-10-14 14:54           ` Benno Lossin
2023-10-14 15:53             ` Boqun Feng [this message]
2023-10-14 16:15             ` FUJITA Tomonori
2023-10-14 17:07               ` Benno Lossin
2023-10-14 21:18                 ` Andrew Lunn
2023-10-14 22:39                 ` FUJITA Tomonori
2023-10-17  7:06                   ` Benno Lossin
2023-10-17  7:32                     ` FUJITA Tomonori
2023-10-17  7:41                       ` Benno Lossin
2023-10-17 11:32                         ` FUJITA Tomonori
2023-10-17 12:38                     ` Andrew Lunn
2023-10-17 14:04                       ` Benno Lossin
2023-10-17 14:21                         ` Greg KH
2023-10-17 14:32                           ` Benno Lossin
2023-10-17 15:17                             ` Miguel Ojeda
2023-10-17 16:15                               ` Greg KH
2023-10-17 16:13                             ` Boqun Feng
2023-10-17 15:03                           ` Miguel Ojeda
2023-10-14 12:00       ` Miguel Ojeda
2023-10-12 12:53 ` [PATCH net-next v4 2/4] rust: net::phy add module_phy_driver macro FUJITA Tomonori
2023-10-12 12:53 ` [PATCH net-next v4 3/4] MAINTAINERS: add Rust PHY abstractions to the ETHERNET PHY LIBRARY FUJITA Tomonori
2023-10-13 14:34   ` Boqun Feng
2023-10-13 15:24     ` FUJITA Tomonori
2023-10-13 16:10       ` Boqun Feng
2023-10-13 16:17     ` Trevor Gross
2023-10-13 18:43       ` Miguel Ojeda
2023-10-13 18:49         ` Andrew Lunn
2023-10-14  5:15           ` FUJITA Tomonori
2023-10-14 18:18             ` Miguel Ojeda
2023-10-12 12:53 ` [PATCH net-next v4 4/4] net: phy: add Rust Asix PHY driver FUJITA Tomonori
2023-10-14  6:01   ` 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=ZSq5aY9R66vwcd6k@Boquns-Mac-mini.home \
    --to=boqun.feng@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=benno.lossin@proton.me \
    --cc=fujita.tomonori@gmail.com \
    --cc=greg@kroah.com \
    --cc=miguel.ojeda.sandonis@gmail.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).