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

Replace ASCII control chars with Unicode Control Pictures #127528

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jul 9, 2024

Replace ASCII control chars like CR with Unicode Control Pictures like :

error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '␍'
   |                                ^

Centralize the checking of unicode char width for the purposes of CLI display in one place. Account for the new replacements. Remove unneeded tracking of "zero-width" unicode chars, as we calculate these in the SourceMap as needed now.

@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
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 A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 9, 2024
@estebank
Copy link
Contributor Author

estebank commented Jul 9, 2024

If we're concerned by legibility or by replacing with characters that might not be well supported in all terminals, we can also replace these with something like [CR]:

error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '[CR]'
   |                                ^^^^

@rust-log-analyzer

This comment has been minimized.

@estebank estebank force-pushed the ascii-control-chars branch from 0089595 to 4db25f7 Compare July 9, 2024 17:21
@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2024

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@bors
Copy link
Contributor

bors commented Jul 15, 2024

☔ The latest upstream changes (presumably #127777) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank estebank force-pushed the ascii-control-chars branch from 4db25f7 to 42ed400 Compare July 16, 2024 00:07
@bors
Copy link
Contributor

bors commented Jul 16, 2024

☔ The latest upstream changes (presumably #127819) made this pull request unmergeable. Please resolve the merge conflicts.

```
error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '␍'
   |                                ^
```
@estebank estebank force-pushed the ascii-control-chars branch from 42ed400 to ac6eb65 Compare July 18, 2024 19:45
estebank added 2 commits July 18, 2024 20:08
No longer track "zero-width" chars in `SourceMap`, read directly from the line when calculating the `display_col` of a `BytePos`. Move `char_width` to `rustc_span` and use it from the emitter.

This change allows the following to properly align in terminals (depending on the font, the replaced control codepoints are rendered as 1 or 2 width, on my terminal they are rendered as 1, on VSCode text they are rendered as 2):

```
error: this file contains an unclosed delimiter
  --> $DIR/issue-68629.rs:5:17
   |
LL | ␜␟ts␀![{i
   |       -- unclosed delimiter
   |       |
   |       unclosed delimiter
LL | ␀␀  fn rݻoa>rݻm
   |                ^
```
We already point these out quite aggressively, telling people not to use them, but would normally be rendered as nothing. Having them visible will make it easier for people to actually deal with them.

```
error: unicode codepoint changing visible direction of text present in literal
  --> $DIR/unicode-control-codepoints.rs:26:22
   |
LL |     println!("{:?}", '�');
   |                      ^-^
   |                      ||
   |                      |'\u{202e}'
   |                      this literal contains an invisible unicode text flow control codepoint
   |
   = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
   = help: if their presence wasn't intentional, you can remove them
help: if you want to keep them but make them visible in your source code, you can escape them
   |
LL |     println!("{:?}", '\u{202e}');
   |                       ~~~~~~~~
```

vs the previous

```
error: unicode codepoint changing visible direction of text present in literal
  --> $DIR/unicode-control-codepoints.rs:26:22
   |
LL |     println!("{:?}", '');
   |                      ^-
   |                      ||
   |                      |'\u{202e}'
   |                      this literal contains an invisible unicode text flow control codepoint
   |
   = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
   = help: if their presence wasn't intentional, you can remove them
help: if you want to keep them but make them visible in your source code, you can escape them
   |
LL |     println!("{:?}", '\u{202e}');
   |                       ~~~~~~~~
```
@estebank estebank force-pushed the ascii-control-chars branch from aa4f805 to 9dffe95 Compare July 18, 2024 20:08
Comment on lines 1 to 5
error: unknown character escape: `\r`
--> $DIR/trailing-carriage-return-in-string.rs:10:25
|
LL | let bad = "This is \ a test";
LL | let bad = "This is \ a test";
| ^ unknown character escape
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is confusing, because the problem is that \ escape is followed by a non-printable character. This is parsed as \␍, which is kind-of \\r.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2024

bors r plus

@bors rollup

@bors
Copy link
Contributor

bors commented Jul 24, 2024

📌 Commit 9dffe95 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 24, 2024
…i-obk

Replace ASCII control chars with Unicode Control Pictures

Replace ASCII control chars like `CR` with Unicode Control Pictures like `␍`:

```
error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '␍'
   |                                ^
```

Centralize the checking of unicode char width for the purposes of CLI display in one place. Account for the new replacements. Remove unneeded tracking of "zero-width" unicode chars, as we calculate these in the `SourceMap` as needed now.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 24, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#126548 (Improved clarity of documentation for std::fs::create_dir_all)
 - rust-lang#127528 (Replace ASCII control chars with Unicode Control Pictures)
 - rust-lang#127717 (Fix malformed suggestion for repeated maybe unsized bounds)
 - rust-lang#128046 (Fix some `#[cfg_attr(not(doc), repr(..))]`)
 - rust-lang#128122 (Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps`)
 - rust-lang#128135 (std: use duplicate thread local state in tests)
 - rust-lang#128140 (Remove Unnecessary `.as_str()` Conversions)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#128148 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 24, 2024
@estebank
Copy link
Contributor Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Jul 24, 2024

📌 Commit 9bd7680 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#127054 (Reorder trait bound modifiers *after* `for<...>` binder in trait bounds)
 - rust-lang#127528 (Replace ASCII control chars with Unicode Control Pictures)
 - rust-lang#127872 (Migrate `pointer-auth-link-with-c`, `c-dynamic-rlib` and `c-dynamic-dylib` `run-make` tests to rmake)
 - rust-lang#128111 (Do not use question as label)
 - rust-lang#128160 (Don't ICE when auto trait has assoc ty in old solver)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cce2db0 into rust-lang:master Jul 25, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Jul 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2024
Rollup merge of rust-lang#127528 - estebank:ascii-control-chars, r=oli-obk

Replace ASCII control chars with Unicode Control Pictures

Replace ASCII control chars like `CR` with Unicode Control Pictures like `␍`:

```
error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '␍'
   |                                ^
```

Centralize the checking of unicode char width for the purposes of CLI display in one place. Account for the new replacements. Remove unneeded tracking of "zero-width" unicode chars, as we calculate these in the `SourceMap` as needed now.
@Kobzol
Copy link
Contributor

Kobzol commented Jul 25, 2024

@rust-timer build e3343bd

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e3343bd): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.8% [0.2%, 2.9%] 32
Regressions ❌
(secondary)
0.5% [0.3%, 2.2%] 17
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.2%, 2.9%] 32

Max RSS (memory usage)

Results (primary -3.2%, secondary -6.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
-6.1% [-6.1%, -6.1%] 1
All ❌✅ (primary) -3.2% [-3.2%, -3.2%] 1

Cycles

Results (primary 1.2%, secondary 1.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.2% [1.0%, 1.5%] 3
Regressions ❌
(secondary)
1.0% [1.0%, 1.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.2% [1.0%, 1.5%] 3

Binary size

Results (secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) - - 0

Bootstrap: 771.74s -> 769.585s (-0.28%)
Artifact size: 328.91 MiB -> 328.93 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Jul 25, 2024
oli-obk added a commit to oli-obk/rust that referenced this pull request Jul 25, 2024
…rs, r=oli-obk"

This reverts commit cce2db0, reversing
changes made to cfc5f25.
@bugadani
Copy link
Contributor

bugadani commented Aug 1, 2024

This change seems to have a (hopefully unintended) side effect: at least rust-lld on windows seem to end lines with CRLF, so every line of the rust-lld output ends with an ugly .

@estebank
Copy link
Contributor Author

estebank commented Aug 1, 2024

@bugadani I'd noticed that in one test but didn't think too much of it at the time. Yes, we should clean that up.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 2, 2024
…felix

Change output normalization logic to be linear against size of output

Modify the rendered output normalization routine to scan each character *once* and construct a `String` to be printed out to the terminal *once*, instead of using `String::replace` in a loop multiple times. The output doesn't change, but the time spent to prepare a diagnostic is now faster (or rather, closer to what it was before rust-lang#127528).
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
…felix

Change output normalization logic to be linear against size of output

Modify the rendered output normalization routine to scan each character *once* and construct a `String` to be printed out to the terminal *once*, instead of using `String::replace` in a loop multiple times. The output doesn't change, but the time spent to prepare a diagnostic is now faster (or rather, closer to what it was before rust-lang#127528).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants