-
Notifications
You must be signed in to change notification settings - Fork 59
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
Is String allowed to switch to a small-string optimization? #499
Comments
I think this is primarily a t-libs / t-libs-api question; in this repo we're mostly talking about language-level questions. |
We can't do this for
|
@RalfJung fair, though I think specifically the "can miri check this" is relevant here too cc @rust-lang/libs-api I would like this discussion to focus on whether we want to allow for the possibility, not whether we want to make such a change. |
There's a general question of whether and how Miri can and should detect library UB. For some cases that's trivial, e.g. all |
In discussion around the storages proposal, we've discussed the possibility of a "fixed size storage" which could allow However, such tricks add further complexity into an already complex API surface and thus don't seem particularly helpful. Furthermore, a general storage can't niche data into the As |
|
bjorn3 mentioned that. The method could theoretically allocate a small-optimized string before returning the vec reference. |
|
FWIW, the String docs currently say:
|
I don't think That means that things like There are a few other places where |
In theory, String could implement a small-string optimization where in certain cases the string is stored inline and
Deref
returns a pointer to the flat in-memory representation.The only thing that really changes here would be the behavior of
into_raw_parts()
, it would be forced to perform a last minute allocation.And that would potentially break Rust code that was calling this function with an older pointer.
It also of course breaks
StableDeref
, though there are already open questions about that.Concretely, I have the following questions:
Deref
are not valid forfrom_raw_parts
, only ones frominto_raw_parts()
?even if we decide that StableDeref is an important property to maintain here, it might be worth getting unsafe code to not rely on
into_raw_parts()
' behavior, so that people tweaking the stdlib can still have some hope of having this work (e.g. "as long as we patch outimpl StableDeref for String
, we are fine")Anyway, curious about thoughts.
cc @gribozavr
The text was updated successfully, but these errors were encountered: