From: Benno Lossin <benno.lossin@proton.me>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.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>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Marco Elver" <elver@google.com>,
"Kees Cook" <keescook@chromium.org>, "Coly Li" <colyli@suse.de>,
"Paolo Abeni" <pabeni@redhat.com>,
"Pierre Gondois" <pierre.gondois@arm.com>,
"Ingo Molnar" <mingo@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Wei Yang" <richard.weiyang@gmail.com>,
"Matthew Wilcox" <willy@infradead.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 5/9] rust: list: add List
Date: Mon, 08 Apr 2024 08:51:04 +0000 [thread overview]
Message-ID: <f51231b2-46a4-4fea-af9d-d16b0ea59bf5@proton.me> (raw)
In-Reply-To: <CAH5fLggF=dBYzySEt-TgNT+Tr-SNYvQxp3A26NktXNb2SNhDDg@mail.gmail.com>
On 08.04.24 10:04, Alice Ryhl wrote:
> On Thu, Apr 4, 2024 at 4:51 PM Benno Lossin <benno.lossin@proton.me> wrote:
>>
>> On 04.04.24 16:12, Alice Ryhl wrote:
>>> On Thu, Apr 4, 2024 at 4:03 PM Benno Lossin <benno.lossin@proton.me> wrote:
>>>> On 02.04.24 14:17, Alice Ryhl wrote:
>>>>> + // never null for items in a list.
>>>>> + //
>>>>> + // INVARIANT: There are three cases:
>>>>> + // * If the list has at least three items, then after removing the item, `prev` and `next`
>>>>> + // will be next to each other.
>>>>> + // * If the list has two items, then the remaining item will point at itself.
>>>>> + // * If the list has one item, then `next == prev == item`, so these writes have no effect
>>>>> + // due to the writes to `item` below.
>>>>
>>>> I think the writes do not have an effect. (no need to reference the
>>>> writes to `item` below)
>>>
>>> ?
>>
>> The first write is
>>
>> (*next).prev = prev;
>>
>> Using the fact that `next == prev == item` we have
>>
>> (*item).prev = prev;
>>
>> But that is already true, since the function requirement is that
>> `(*item).prev == prev`. So the write has no effect.
>> The same should hold for `(*prev).next = next`.
>
> Oh, you are arguing that we aren't changing the value? I hadn't
> actually realized that this was the case. But the reason that they end
> up with the correct values according to the invariants is the writes
> below that set them to null - not the fact that we don't change them
> here. After all, setting them to a non-null value is wrong according
> to the invariants.
I just was confused by the "due to the writes to `item` below".
In the single element case, I also think that the INVARIANT comment of
the next `unsafe` block (still visible in this mail) is a bit weird,
since the element still is in the list.
For a single item, removing it is setting the prev, next and first
pointers to null. So I think you might be able to use this for the last
bullet point:
* If the list has one item, then `next == prev == item`, so these
writes have no effect, since also `(*item).prev == prev` and
`(*item).next == next` by function requirement.
For the INVARIANT comment below, I think you also need the case
distinction:
* If the list had more than one item, `item` is no longer in the
list, so the pointers should be null.
* If the list had one item, then `item` points to itself, to remove
it, we set `prev` and `next` to null and later also `self.first`.
What do you think?
--
Cheers,
Benno
>
> Alice
>
>>>>> + unsafe {
>>>>> + (*next).prev = prev;
>>>>> + (*prev).next = next;
>>>>> + }
>>>>> + // SAFETY: We have exclusive access to items in the list.
>>>>> + // INVARIANT: The item is no longer in a list, so the pointers should be null.
>>>>> + unsafe {
>>>>> + (*item).prev = ptr::null_mut();
>>>>> + (*item).next = ptr::null_mut();
>>>>> + }
next prev parent reply other threads:[~2024-04-08 8:51 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 12:16 [PATCH 0/9] Add Rust linked list for reference counted values Alice Ryhl
2024-04-02 12:16 ` [PATCH 1/9] rust: list: add ListArc Alice Ryhl
2024-04-03 15:51 ` Benno Lossin
2024-04-04 14:00 ` Alice Ryhl
2024-05-03 14:36 ` Alice Ryhl
2024-05-04 15:50 ` Benno Lossin
2024-04-03 17:18 ` Kane York
2024-04-02 12:16 ` [PATCH 2/9] rust: list: add tracking for ListArc Alice Ryhl
2024-04-03 15:52 ` Benno Lossin
2024-04-04 14:14 ` Alice Ryhl
2024-04-04 14:41 ` Benno Lossin
2024-04-02 12:17 ` [PATCH 3/9] rust: list: add struct with prev/next pointers Alice Ryhl
2024-04-03 15:57 ` Benno Lossin
2024-04-04 14:03 ` Alice Ryhl
2024-04-04 14:05 ` Benno Lossin
2024-04-05 9:47 ` Benno Lossin
2024-04-08 7:57 ` Alice Ryhl
2024-04-02 12:17 ` [PATCH 4/9] rust: list: add macro for implementing ListItem Alice Ryhl
2024-04-03 10:42 ` Benno Lossin
2024-04-02 12:17 ` [PATCH 5/9] rust: list: add List Alice Ryhl
2024-04-04 14:03 ` Benno Lossin
2024-04-04 14:12 ` Alice Ryhl
2024-04-04 14:51 ` Benno Lossin
2024-04-08 8:04 ` Alice Ryhl
2024-04-08 8:51 ` Benno Lossin [this message]
2024-04-02 12:17 ` [PATCH 6/9] rust: list: add iterators Alice Ryhl
2024-04-04 14:36 ` Benno Lossin
2024-04-04 14:41 ` Alice Ryhl
2024-04-04 14:52 ` Benno Lossin
2024-04-08 8:00 ` Alice Ryhl
2024-04-02 12:17 ` [PATCH 7/9] rust: list: add cursor Alice Ryhl
2024-04-03 12:19 ` Benno Lossin
2024-04-03 12:49 ` Alice Ryhl
2024-04-04 13:28 ` Benno Lossin
2024-04-04 13:40 ` Alice Ryhl
2024-04-02 12:17 ` [PATCH 8/9] rust: list: support heterogeneous lists Alice Ryhl
2024-04-04 15:35 ` Benno Lossin
2024-04-08 7:59 ` Alice Ryhl
2024-04-02 12:17 ` [PATCH 9/9] rust: list: add ListArcField Alice Ryhl
2024-04-04 15:47 ` Benno Lossin
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=f51231b2-46a4-4fea-af9d-d16b0ea59bf5@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=colyli@suse.de \
--cc=elver@google.com \
--cc=gary@garyguo.net \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=ojeda@kernel.org \
--cc=pabeni@redhat.com \
--cc=pierre.gondois@arm.com \
--cc=richard.weiyang@gmail.com \
--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).