Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[proof of concept] give String support for CoW wrapping of literals #46993
Conversation
Gankro
added some commits
Dec 25, 2017
rust-highfive
assigned
sfackler
Dec 25, 2017
This comment has been minimized.
This comment has been minimized.
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
How to test this: replace instances of:
with |
kennytm
added
the
S-waiting-on-author
label
Dec 25, 2017
ghost
reviewed
Dec 25, 2017
| Ok(ptr) => (new_cap, ptr), | ||
| Err(e) => self.a.oom(e), | ||
| if used_cap == 0 { | ||
| // skip to 4 because tiny Vec's are dumb; but not if that |
This comment has been minimized.
This comment has been minimized.
ghost
Dec 25, 2017
Isn't it "Vecs", not "Vec's"?
You only need the apostrophe if the "Vec" is possessing something.
This comment has been minimized.
This comment has been minimized.
ghost
reviewed
Dec 25, 2017
| @@ -384,6 +384,38 @@ impl String { | |||
| String { vec: Vec::new() } | |||
| } | |||
|
|
|||
| #[inline] | |||
| #[unstable(feature = "lit_strings", reason = "its TOO lit", issue = "42069")] | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Gankro
Dec 25, 2017
Author
Contributor
This isn't intended to be landed any time soon, so I opted for a joke :)
This comment has been minimized.
This comment has been minimized.
BurntSushi
Jan 6, 2018
Member
This isn't intended to be landed any time soon
Do you say this because there is more implementation work to be done, or because it hasn't been decided that this is a good thing? (I'm pretty out of the loop.) If the former, cool. If the latter, has it been discussed somewhere?
This comment has been minimized.
This comment has been minimized.
withoutboats
Jan 6, 2018
Contributor
There's a thread on internals about landing this feature as a coercion (rather than a method): https://internals.rust-lang.org/t/pre-rfc-allowing-string-literals-to-be-either-static-str-or-string-similar-to-numeric-literals/5029
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
https://github.com/manishearth/rust/tree/literally-sed has it all sed-ed. The sed commands are in each commit ( There's a |
This comment has been minimized.
This comment has been minimized.
|
I don't really know how to triage this. You uh... hmm. Uh, what do you think we should do? |
This comment has been minimized.
This comment has been minimized.
|
@shepmaster I'm gonna mark as waiting on (libs) team. cc @rust-lang/libs |
aturon
added
S-waiting-on-team
T-libs
and removed
S-waiting-on-author
labels
Jan 6, 2018
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this PR some today, and the following points came up:
Modulo these concerns, no one saw a blocking objection, and we'd love to see this proceed to an RFC. |
This comment has been minimized.
This comment has been minimized.
|
We only found examples of people assuming vec's capacity. We halted progress because it was possible to use String in the same way. It still is. That's one of the reasons this PR exists: so we can test this change out on other crates. Sadly it's hard to cargo-bomb this since nothing in the ecosystem uses it, so nothing would trip it! I am vaguely considered about stable address assumptions, but also we could reasonably just phase it out of the ecosystem, like we've done for other implementation-defined assumptions that we've broken (heap::EMPTY). |
This comment has been minimized.
This comment has been minimized.
Unless I misunderstood something, the assumption in question is This PR breaks the assumption, but I believe it's easy to avoid breaking it. The trick is to implement fn capacity(&self) -> usize {
cmp::max(self.vec.capacity(), self.vec.len())
}This way the assumption is still valid, and we can still internally disambiguate owned and literal strings by checking |
This comment has been minimized.
This comment has been minimized.
|
No, this will break anyone using the _raw apis. |
This comment has been minimized.
This comment has been minimized.
Rental assumes that string's derefmut derefs to a stable address. I spoke briefly with the author once; rental has a I'm really eager to see this change, but I think it needs to be epoch gated. |
This comment has been minimized.
This comment has been minimized.
|
I thought library changes can't be epoch-specific, because crates of all epochs share the same standard library (and other libraries, for that matter)? |
This comment has been minimized.
This comment has been minimized.
We can introduce new APIs only in a new epoch; in this case |
This comment has been minimized.
This comment has been minimized.
|
Can't such a String get moved into a library that is written against the 2015 epoch though? |
This comment has been minimized.
This comment has been minimized.
Absolutely. To be clearer, I don't think we need an epoch to change this (from a legalistic perspective). Rental is currently making an assumption that Often, we will say our hands are tied by the unsafe code that exists and is relying on this thing, so we now guarantee this thing we didn't originally say we would. I don't think that needs to be the case here, since the guarantee failing can only be observed in very particular edge cases - assuming that calling However, I'd like to very clearly and loudly message to users about the fact that these assumptions about String are now invalidated. One way to do that is have it be one of the changes we're making in the epoch transition. So I'd like to use the epoch as a social force in amplifying information about this potential incorrect assumption that as far as we know no one is actually relying on. |
This comment has been minimized.
This comment has been minimized.
|
|
carols10cents
added
S-waiting-on-author
and removed
S-waiting-on-team
labels
Jan 22, 2018
shepmaster
added
the
S-waiting-on-team
label
Jan 26, 2018
shepmaster
added
I-nominated
and removed
S-waiting-on-author
labels
Jan 26, 2018
This comment has been minimized.
This comment has been minimized.
|
I'm going to unilaterally move this to be nominated for discussion by the team, otherwise it seems like this will just languish forever. (or you know, what @aturon said in response to me earlier that I forgot about...) |
This comment has been minimized.
This comment has been minimized.
|
@shepmaster I'm going to go a step further and close this PR -- not because we don't want it, but because the next step is an RFC. I don't have the bandwidth to write such an RFC myself, but I'd really like to see this at least attempted. Is there anyone who would like to take on an RFC with me mentoring/serving as backup? |
aturon
closed this
Jan 27, 2018
This comment has been minimized.
This comment has been minimized.
|
I can do an RFC, if Gankro doesn't want to.
But if someone else wants to be mentored it's better if they do it (I can
help mentor).
On Jan 27, 2018 10:47 PM, "Aaron Turon" <notifications@github.com> wrote:
@shepmaster <https://github.com/shepmaster> I'm going to go a step further
and *close* this PR -- not because we don't want it, but because the next
step is an RFC.
I don't have the bandwidth to write such an RFC myself, but I'd really like
to see this at least attempted. Is there anyone who would like to take on
an RFC with me mentoring/serving as backup?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#46993 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABivSC4dRuAXJLARGdZrb8f-0I0JImLfks5tO1o1gaJpZM4RMFN5>
.
|
This comment has been minimized.
This comment has been minimized.
|
I don't have any interest in working on an RFC. I made this PoC so ergonomics people couldn't complain to me about implementation issues anymore. Yer problem now! |
This comment has been minimized.
This comment has been minimized.
|
I'm interested in shepherding (but not writing) an RFC that adds this as a coercion (rather than the |
This comment has been minimized.
This comment has been minimized.
|
Why not both a coercion and an explicit contructor? Coercion sounds like it’d work from any |
This comment has been minimized.
This comment has been minimized.
|
I don't really have an objection to having a constructor. I laid out an argument in favor of epoch gating a few posts up. More generally these seem like good questions for an RFC thread |
Gankro commentedDec 25, 2017
This is a proof of concept implementation for people who want to test this out. It isn't fully tested, and the RawVec changes probably need more work. In addition the implementation isn't as optimized as it could be (see FIXME's).
This adds a
String::literallyconstructor that wraps up a literal without allocating. It in turn makes Vec partially support this (with more robust capacity checking) and RawVec partially support this (by copying the source if len > cap). String also gains some make_unique guards for methods which don't naturally do this themselves (ones which make mutable views or mutate the middle of the buffer).