-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Get rid of EscapeDebugInner
.
#138237
base: master
Are you sure you want to change the base?
Get rid of EscapeDebugInner
.
#138237
Conversation
57c0a80
to
0854482
Compare
// Note: It’s possible to manually encode the EscapeDebugInner inside of | ||
// EscapeIterInner (e.g. with alive=254..255 indicating that data[0..4] holds | ||
// a char) which would likely result in a more optimised code. For now we use | ||
// the option easier to implement. |
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.
I think this is the comment you reference, so perfrun seems to be in order.
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.
Yeah. Should definitely be optimized in terms of size, speed remains to be seen.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm sure you know this, but if you highlight these lines, you can see that the trailing space is the problem. |
This comment has been minimized.
This comment has been minimized.
c9e5395
to
724d171
Compare
This comment has been minimized.
This comment has been minimized.
724d171
to
46da058
Compare
This comment has been minimized.
This comment has been minimized.
46da058
to
033fdc6
Compare
033fdc6
to
8b1d999
Compare
r? @hkBst |
self.alive.advance_by(n) | ||
impl<const N: usize> EscapeIterInner<N, MaybeEscaped> { | ||
// This is the only way to create any `EscapeIterInner` with `self.data.literal`, meaning | ||
// the `AlwaysEscaped` marker guarantees that `self.data.escape_seq` is valid. |
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.
I still think this comment is logically wrong. If there was another way to create an EscapeIterInner
with self.data.literal
besides this function, would that impact the things that AlwaysEscaped guarantees? I think it does not, which would mean that this comment gives the wrong reason for the guarantees that AlwaysEscaped provides and thus this comment is wrong.
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.
@rustbot author
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.
I still think this comment is logically wrong.
I don't think so. You can argue both ways:
EscapeIterInner::<N, MaybeEscaped>::printable
is the only way to create anyEscapeIterInner<N, T>
withself.data.literal
, so it followsEscapeIterInner::<AlwaysEscaped>
(or anyEscapeIterInner<N, T>
whereT != MaybeEscaped
, for that matter) always containsself.data_escape_seq
, givenMaybeEscapedCharacter
only has two variants.EscapeIterInner<N, AlwaysEscaped>
always containsself.data_escape_seq
since there is no constructor for creating anEscapeIterInner<N, AlwaysEscaped>
containingself.data.literal
.
However, I'm not sure where I would place the second one, given that the constructors for EscapeIterInner<N, AlwaysEscaped>
are a subset of those for EscapeIterInner<N, MaybeEscaped>
.
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.
@rustbot ready
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.
* `EscapeIterInner::<N, MaybeEscaped>::printable` is the only way to create any `EscapeIterInner<N, T>` with `self.data.literal`, so it follows `EscapeIterInner::<AlwaysEscaped>` (or any `EscapeIterInner<N, T>` where `T != MaybeEscaped`, for that matter) always contains `self.data_escape_seq`, given `MaybeEscapedCharacter` only has two variants.
I strongly prefer a formulation similar to this which talks about what the union contains or which variant it is, over the formulation "self.data.escape_seq
is valid", because validity requirements are in my mind requirements beyond just being initialized. Also I think it is good to remind readers of the union nature of this member.
* `EscapeIterInner<N, AlwaysEscaped>` always contains `self.data_escape_seq` since there is no constructor for creating an `EscapeIterInner<N, AlwaysEscaped>` containing `self.data.literal`.
Instead of talking about the absence of constructor functions that create other union variants, you could just as easily and more clearly say that all constructor functions create the one union variant, and it remains true irrespective of the number of union variants that exist.
However, I'm not sure where I would place the second one, given that the constructors for
EscapeIterInner<N, AlwaysEscaped>
are a subset of those forEscapeIterInner<N, MaybeEscaped>
.
Maybe it makes sense to place this entire rationale with the generic definition where the union member is defined to explain how the code manages to not access it invalidly.
I don't have the power to approve, so it's probably best to keep someone around who does. r? @thomcc |
Reminder, once the PR becomes ready for a review, use |
@thomcc I think it would make sense to see the perf impact of this change, since it is supposed to be an optimization (and increases the use of unsafe). Otherwise it seems hard to determine if this is a worthy trade-off. |
I read the note on
EscapeDebugInner
and thought I'd give it a try.