-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move str
to libcore.
#70911
Move str
to libcore.
#70911
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 137c171 with merge f95a789e60e4d3fbb4e0c82de224af9d890e5b75... |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☀️ Try build successful - checks-azure |
Queued f95a789e60e4d3fbb4e0c82de224af9d890e5b75 with parent 42abbd8, future comparison URL. |
Simplifying the language by pushing more of it into the standard library sounds nice from a theoretical point of view, but what is the practical benefit that we would gain by having someone spend the bandwidth to finish this? |
@@ -715,7 +714,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |||
fields: impl Iterator<Item = InterpResult<'tcx, Self::V>>, | |||
) -> InterpResult<'tcx> { | |||
match op.layout.ty.kind { | |||
ty::Str => { | |||
// FIXME(eddyb) does this belong here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well you could remove that branch and then str would not be special any more in terms of validity. ;)
Finished benchmarking try commit f95a789e60e4d3fbb4e0c82de224af9d890e5b75, comparison URL. |
Not sure there is much to finish, it's more about keeping this working and adjusting it due to review comments, throughout the approval process, whichever teams would decide on it. But also, wow, this is a slowdown. It really shouldn't, I think every single place in the compiler this PR makes slower also has been slowing down user-defined types w/o parameters this entire time, so it might be worth digging into some of these and trying to fix them. |
The previous attempt: #19612. I wanted to get this done in 2014 and I still want to get it done. |
|
@@ -548,7 +548,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
Ok(Some(self.read_size_and_align_from_vtable(vtable)?)) | |||
} | |||
|
|||
ty::Slice(_) | ty::Str => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential site for the perf regression, easy to test by doing the old logic if ty.is_str()
@@ -314,8 +314,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
|
|||
// Turn the wide MPlace into a string (must already be dereferenced!) | |||
pub fn read_str(&self, mplace: MPlaceTy<'tcx, M::PointerTag>) -> InterpResult<'tcx, &str> { | |||
let len = mplace.len(self)?; | |||
let bytes = self.memory.read_bytes(mplace.ptr, Size::from_bytes(len))?; | |||
let bytes_mplace = self.mplace_field(mplace, 0)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential site for the perf regression. We should probably check whether we can make mplace_field
a no-op in case of repr(Rust)
with one field or repr(transparent)
types.
I think the main problem here is that we compute the field's layout even for cases like this one where we don't actually need the layout. We've seen major regressions in miri due to a single additional call to tcx.layout_of
before.
Note: the diff is actually negative if you ignore the newly added tests. |
Reviewed. It feels like most of the special treatment in diagnostics can be removed if we officially recognize that The special case in mangling can be removed as well, except that it would needs a version bump. |
👍 |
I haven't done any testing on this but I wonder if:
We sort of had plans for that, along the lines of representing paths like However, I realize now that we could encode it as We shouldn't need a bump to make the |
To expand on this a bit: one of the unshadowed_prelude_items: FxHashMap<DefId, Symbol>, that we use in |
Yes,
It would, but that's not a big deal? EDIT: Unless you were talking about error messages here, |
Neat! Presumably scanning for locally defined items with the same names would be more effort, but maybe there's some map (oh, there's the
Sorry, yeah, my concerns are:
|
Thoughts from the language team meeting yesterday:
So in conclusion, I think we can green-light this from a lang team POV (regressions in perf etc. are for the compiler team to assess, and fix), but let's also be careful not to lock us into a world where this cannot be reverted. |
Closing due to inactivity. |
It's possible #73996 unblocked the "diagnostics should still say |
I was reminded we tried to do this before and didn't go through with it for some reason, after seeing rust-lang/unsafe-code-guidelines#78 (the impact on this PR on that question isn't significant, FWIW).
One thing I didn't do is change how
str
is resolved: it's still a builtin type forrustc_resolve
, which only after name resolution is turned into the right type, using the"str"
lang item.(Presumably if
core::str
hadcrate mod sealed { pub struct Str([u8]); }
thencore::prelude
could dopub use crate::str::sealed::Str as str;
, but I haven't tried it - IMO a requirement is that users can't observecore::str::str
orcore::str::Str
. cc @petrochenkov)While this does seem to work with enough tweaks, I don't have the bandwidth to push this through.
So I suppose this could be considered insta-abandonware ♻️.
r? @ghost cc @rust-lang/libs @rust-lang/compiler