Re: [PATCH 2/2] rust: alloc: add `Vec::dec_len`

Tamir Duberstein
2025-03-18T18:54:26Z

On Tue, Mar 18, 2025 at 2:46 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Tue, Mar 18, 2025 at 02:28:02PM -0400, Tamir Duberstein wrote:
> > On Tue, Mar 18, 2025 at 10:44 AM Alice Ryhl <aliceryhl@google.com> wrote:
> > >
> > > On Tue, Mar 18, 2025 at 10:12:28AM -0400, Tamir Duberstein wrote:\
> > > >
> > > > The methods you're describing are all on Vec, right? In other words,
> > > > their usage calls for a private `dec_len` or `set_len`. As I've said
> > > > repeatedly in the course of this discussion: I would prefer not to
> > > > introduce `dec_len` at all here. It (or `set_len`) can be introduced
> > > > in the series that adds truncate or your patch that adds clear, where
> > > > its signature can be properly scrutinized in the context of an actual
> > > > caller.
> > >
> > > Oh I did not see that you said that. Dropping patch 2 is fine with me.
> > >
> > > Alice
> >
> > Benno, Danilo: are you both OK with this? I'll discard this patch on
> > the respin and prepend the patch adding the len <= cap invariant.
>
> I mean, the whole reason to switch set_len() to inc_len() and have a separate
> dec_len() was to properly cover things like [1] and Alice' patch by having
> dec_len() return the abandoned entries.
>
> If we now only switch set_len() to inc_len() and drop dec_len() then what should
> Andrew do?

I'd be completely fine with Andrew (or Alice) taking this patch into
the truncate/resize series[1] (or the series that introduces clear
[2]). It can be properly reviewed there in context.

> Maybe we should just revert to Tamir's first proposal, i.e. keep set_len() as it
> is, but make it return the abandoned entries, if any.

This wouldn't be my preference.

> [1] https://lore.kernel.org/rust-for-linux/20250316111644.154602-1-andrewjballance@gmail.com/

[2] https://lore.kernel.org/all/20250311-iov-iter-v1-4-f6c9134ea824@google.com/