-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add back BorrowedBuf::filled_mut #103754
Add back BorrowedBuf::filled_mut #103754
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
b5a019b
to
e195931
Compare
Signed-off-by: Alex Saveau <[email protected]>
e195931
to
050d5f6
Compare
I don't think I have any particular expertise here, so I'll leave it to highfive's original choice. r? joshtriplett Also, has this been discussed at all in #78485? Given that this type had an RFC (https://rust-lang.github.io/rfcs/2930-read-buf.html), it seems odd that this didn't come up back then if it's needed? |
Sounds good. The original RFC has filled_mut and I can't find any explanation for its disappearance, so yeah just seems like an oversight. |
r? @thomcc |
@nrc can you confirm that this change wasn't intentional? |
Needs an ACP? |
Going to mark as blocked on ACP, but really it's just that while the impl seems fine, I'm not an API reviewer so I don't really feel qualified to say. |
Dang, yeah that's fair. And no, this shouldn't need an ACP since the API was removed without explanation and is already part of the RFC. I'll keep doing the rounds—I've got a crate that needs this feature and my past experience has suggested it'll take 1-3 months before anyone from the libs team looks at this which is a bummer. r? @the8472 PS: you can probably make another contributor happy by taking a look at this easy PR #103901 |
Sweet, thanks for replying! The use-case is that I'm continuously filling and clearing the same buffer and doing in-place processing of the data. Currently I have to copy it over to a Vec which is really sad. It'd be a huge pain to use the original buffer since a) its a bunch of MaybeUninits and I'd have to manually assume_init them, but the whole point of this API is to avoid that and b) I would need to create and drop the borrowedbuf in the state machine of my loop and dealing with the lifetimes of passing stuff across some but not all iterations of the loop will be a huge pain.
Not super true since you have
I don't think this read-only split is the right approach. I think of BorrowedBuf as having full access to the filled part of the buffer and BorrowedCursor having full access to the unfilled part.
But then you have to deal with MaybeUninits. Or am I missing something? |
Note that I'm on the libs team, not libs-api, so approving this is not in my purview. r? libs-api |
Oops, you're listed in the first group of people on the libs team website so I got confused. Thanks for the heads up. |
Yeah, not only
That's fine. If you regard the filled part as immutable once writing is complete, then these two points of view are equivalent.
You do if the undlerlying buffer uses MaybeUninits. I expect the common case to be something like a Vec where the filled part is always initialised and the unfilled part if MaybeUninit, in which case you don't have to deal with this.
Creating and destroying a BorrowedBuf is cheap, so I would expect you to do this on every iteration. As a strawman solution, I suggest you have a Vec initialised with a capacity outside the loop, and create a BorrowedBuf on each iteration, using the underlying Vec for accessing the data. I'd be curious if that works out as a good solution or if it is not ergonomic in some way. |
Sure, but again I then have to keep track of which bytes were initialized myself.
This doesn't make sense given that the whole point of the API is to use a borrowed buf: it should be able to come from anywhere including people passing me arbitrary buffers that I can't control. The way I see it, the API is forcing its users to bend over backwards for theoretical purity that doesn't offer material benefits. Anyway, since this is an intentional change, I'll create an ACP later today to fix this. |
I'm trying to understand your use case here. It sounded like you were providing the underlying buffer and then operating on it, but here it sounds like you want to take a buffer and both read into it and operate on it? That is not a situation I imagined, so I'm keen to understand what you need.
The point of the API is to have an abstraction over a buffer to read into. It sounds like you want to do more than that, so we need to understand what exactly.
One person's useless theoretical purity is another person's clean API design. It would be more useful to fully explain your requirements rather than name calling. |
Yup, it's read + preprocessing.
But don't you need to actually use the buffer after reading it in? I don't why the API is being constrained to only allow reading. For example, I'm pretty sure the lifetimes would allow a neat API like
I'm missing something then. BorrowedBuf takes in a mut reference so you could always combine a Going back to this:
Not true since you can do the above I mentioned. The "useless theoretical purity" is not a dis — I legitimately don't see any benefit to preventing buffer modification. What bug would it be preventing? And if such a bug exists, how is it more scary than forcing people to use unsafe to modify the buffer? Sidenote: I haven't actually seen the discussion that led to this change so maybe there's more context I'm missing? |
Actually, setting aside the preprocessing stuff, the |
Alrighty, created the ACP: rust-lang/libs-team#139 |
Reassigning yaahc's reviews as she has stepped down from the review rotation. r? rust-lang/libs-api |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (48a814d): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 657.118s -> 656.572s (-0.08%) |
This is useful if you want to do some processing on the bytes while still using the BorrowedBuf.
The API was removed in #97015 with no explanation. The RFC also has it as part of its API, so this just seems like a mistake: RFC
ACP: rust-lang/libs-team#139