Conversation
text/3918-maybe-dropped.md
Outdated
|
|
||
| > - What parts of the design do you expect to resolve through the implementation of this feature before stabilization? | ||
|
|
||
| - How will we expose the public API? |
There was a problem hiding this comment.
Did I really just read an RFC for a new unsafe standard library API that left the questions of what that new API should actually look like, and under what conditions it's going to be safe to use or UB, entirely as an unresolved question??
text/3918-maybe-dropped.md
Outdated
| Take this example, from the standard library (simplified) | ||
|
|
||
| ```rust | ||
| pub struct Fuse<I> { | ||
| iter: I | ||
| } | ||
| ``` | ||
|
|
||
| The actual iterator is not needed after it yields `None` once, so in this case (not in the standard library, | ||
| however, due to a possible breaking change), We can replace the `I` with a `MaybeDropped`, which can optimize code by dropping the value early | ||
| (eg. by freeing allocator space, releasing a lock, etc.) | ||
|
|
||
| But you may realize this is exactly the same as using an `Option` (Which `Fuse` does). However, the following point contradicts this. |
There was a problem hiding this comment.
Ignoring the confusing wording and weirdly modified version of Fuse in the code snipped, I fail to see how a type which is all about cases where dropped-ness is tracked elsewhere (as the subsequent paragraph already notes1) in the case of Fuse where there is no “elsewhere”, for lack of any additional fields
Footnotes
-
the relevant sentence:
↩types/systems which would need
MaybeDroppedlikely already have a means of tracking whetherTis still needed or not elsewhere
|
I have to ask, genuinely, did you write this? And, similarly, did you fully understand what you're writing about? This gives me LLM vibes all over and unlike something that was machine-translated or written by a non-native English speaker, it just doesn't strike me as being written by someone who actually understands the purpose of the related APIs being mentioned ( I always feel bad making these types of assertions because it's almost impossible to tell the difference sometimes between someone who has genuinely tried their best, and someone who has not tried at all and is just wasting everyone's time. In the former case, I think that people should be given the support they need to write good proposals and help contribute to the language, but I just can't drop the suspicion that it's the latter case. For example:
This is incorrect. In fact, this is explicitly the reason why, for example, transmuting
Early drop is required, in cases where… a value is dropped? This is definitely an example of something that might have just been lost in translation, so, I'm not going to put too much weight on it, but regardless, this is definitely a common case of something LLMs love to do, which is list examples that definitely apply, just trust me without any additional reasoning.
What do you even mean? FFI-safe transfer of data that has possibly been dropped? We don't even have a concept of ownership for FFI so this argument just makes no sense.
Again, this just fundamentally misunderstands how Rust's data model works at the most basic level. Yes, it would make sense to not keep a very complicated loader after you've loaded something, so, you just drop it. You drop the loader. It's gone. You don't need to store its corpse anywhere, because you've dropped it. This is how a large number of APIs work: you have a loader which is called by-value because doing so consumes the loader: the loader is dropped, and the loaded value is returned in its place. This is coming up with a solution to a problem that doesn't even make sense to ask.
This fundamentally misunderstands Rust's unsafe guidelines, which already have not been fully defined:
I really, really want to give the benefit of the doubt, but after reading your ABI descriptors RFC where you similarly tried to come up with a solution you openly admitted to not understand, I really do not want to read your RFC in good faith because it really does feel like a case of someone who didn't read any reference material to understand the problem, and didn't actually write the RFC to solve the problem. And I don't think we should be encouraging that kind of behaviour. Again, I want to reiterate that it's okay to not understand English or to use machine translation tools to interact with the community. And it's okay to not be an expert at Rust. But if you want to propose a targeted change to Rust, you need to understand why that change is good, and I don't think that's the case. |
There was a problem hiding this comment.
I believe you can simply implement this whole type, assuming the implementation as you describe it here, as a simple wrapper around MaybeUninit<T>. And with the changes to ManuallyDrop from RFC 3336 becoming available soon (AFAICT), eventually that can become a wrapper around ManuallyDrop<T>. Types like ManuallyDrop<T> and MaybeUninit<T> are in the standard library because the former needs some compiler magic to be implemented, and the latter is used a lot and appears in argument or return types in a number of other standard library APIs. The standard library is deliberately kept somewhat minimalistic – I don’t see why the MaybeDropped<T> type here shouldn’t first onl[y be part of some downstream crate, where it can prove itself useful.
Unless there is any fundamentally “magic” property that this MaybeDropped type is supposed to have why it can not simply be implemented downstream, but I don’t see any mention of such a thing in this RFC.
There was a problem hiding this comment.
Definitely, parsing out the most I could get from the RFC, it feels like the proposal is just a misunderstanding of how ManuallyDrop works, and ManuallyDrop would work for the cases mentioned.
And the actual proposed definition in the reference-level description is literally just MaybeUninit<ManuallyDrop<T>>, so 🤷🏻
There was a problem hiding this comment.
I do realize now I wrote this RFC in confusing wording (and i wrote like an LLM for some reason, i don't know why). Im also not a native english speaker, I will try to rewrite better and update it now.
Adds a type for representing values whose destructor may have ran already.
Important
When responding to RFCs, try to use inline review comments (it is possible to leave an inline review comment for the entire file at the top) instead of direct comments for normal comments and keep normal comments for procedural matters like starting FCPs.
This keeps the discussion more organized.
Rendered