Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

reitermarkus
Copy link
Contributor

I read the note on EscapeDebugInner and thought I'd give it a try.

@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 8, 2025
@reitermarkus reitermarkus force-pushed the remove-escape-debug-inner branch 3 times, most recently from 57c0a80 to 0854482 Compare March 8, 2025 20:52
Comment on lines -309 to -312
// 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.
Copy link
Member

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.

Copy link
Contributor Author

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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@reitermarkus reitermarkus requested a review from hkBst March 10, 2025 17:43
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@hkBst
Copy link
Member

hkBst commented Mar 11, 2025

-        // SAFETY: `self.data.escape_seq` contains an escape sequence, as is 
-        // guaranteed by the caller, and in that case `self.alive` is guaranteed 
+        // SAFETY: `self.data.escape_seq` contains an escape sequence, as is
+        // guaranteed by the caller, and in that case `self.alive` is guaranteed

I'm sure you know this, but if you highlight these lines, you can see that the trailing space is the problem.

@rust-log-analyzer

This comment has been minimized.

@reitermarkus reitermarkus force-pushed the remove-escape-debug-inner branch 2 times, most recently from c9e5395 to 724d171 Compare March 31, 2025 17:02
@rust-log-analyzer

This comment has been minimized.

@reitermarkus reitermarkus force-pushed the remove-escape-debug-inner branch from 724d171 to 46da058 Compare March 31, 2025 17:34
@rust-log-analyzer

This comment has been minimized.

@reitermarkus reitermarkus force-pushed the remove-escape-debug-inner branch from 46da058 to 033fdc6 Compare March 31, 2025 18:01

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@reitermarkus reitermarkus force-pushed the remove-escape-debug-inner branch from 033fdc6 to 8b1d999 Compare March 31, 2025 18:09
@reitermarkus
Copy link
Contributor Author

r? @hkBst

@rustbot rustbot assigned hkBst and unassigned thomcc Mar 31, 2025
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.
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot author

Copy link
Contributor Author

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 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.
  • EscapeIterInner<N, AlwaysEscaped> always contains self.data_escape_seq since there is no constructor for creating an EscapeIterInner<N, AlwaysEscaped> containing self.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>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot ready

Copy link
Member

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 for EscapeIterInner<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.

@hkBst
Copy link
Member

hkBst commented Apr 1, 2025

I don't have the power to approve, so it's probably best to keep someone around who does.

r? @thomcc

@rustbot rustbot assigned thomcc and unassigned hkBst Apr 1, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 1, 2025
@hkBst
Copy link
Member

hkBst commented Apr 2, 2025

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants