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

rustdoc: simplify handling of plain text output #109246

Closed
wants to merge 5 commits into from

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Mar 17, 2023

Replace use of f.alternate() in format.rs, and offers instead Type::print_plain, and Path::print_plain.

Adopt Askama template for rendering of functions and methods.

Motivation:

In rustdoc we generally emit HTML, but there are a few places where we need to emit a plain text form of clean::Type and/or clean::Path:

  • In the sidebar, under Trait Implementations, we render traits, e.g. AsRef<str>. These should be plain because we don't want to separately link AsRef and str to those respective types; we want a single link that goes to that trait implementation.
  • When creating ids and internal hrefs for headings related to trait implementations, we generate the ids based on a plain text version of the trait (and the type it is implemented for).
  • Similarly, when creating the datastructures used to render "Notable traits", we index those datastructures by a plain text version of the type that has notable trait implementations.
  • When rendering a function or associated function, we decide whether or not to line-wrap the declaration based on whether the plain text form would exceed 80 characters (imitating rustfmt).

Originally, plain text output was controlled via Formatter's f.alternate() mechanism, so you could generate HTML by formatting with {} or plain text by formatting with {:#}. This avoids having to generate HTML only to strip it out. However, it leads to a lot of duplication and branching in format.rs. Since the only HTML we care about comes from within a single module, we can write a very simple HTML remover that strips all tags and only cares about a handful of entities.

This also lets us simplify calculating the width of a function header - we can simply pass a template and count its bytes.

This PR can be reviewed commit-by-commit.

Related: #108868

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2023

r? @notriddle

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 17, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Mar 19, 2023
@jsha jsha force-pushed the no-alternate branch 2 times, most recently from ab52287 to ce9289a Compare March 19, 2023 19:07
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jsha jsha removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Mar 20, 2023
@notriddle
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 20, 2023
@bors
Copy link
Contributor

bors commented Mar 20, 2023

⌛ Trying commit dde3cced5ea68bec455d2b47f49b54621c692c95 with merge 56fa9753c5bb8be807bdabf9018e03618dd75fbf...

@bors
Copy link
Contributor

bors commented Mar 20, 2023

💔 Test failed - checks-actions

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2023
@notriddle
Copy link
Contributor

Looks relevant: https://github.com/rust-lang-ci/rust/actions/runs/4469549308/jobs/7851815712#step:26:40193

thread 'rustc' panicked at 'called Result::unwrap() on an Err value: Error', src/librustdoc/html/format.rs:131:34

@rust-log-analyzer

This comment has been minimized.

@jsha
Copy link
Contributor Author

jsha commented Mar 20, 2023

Yep! Will take a look in a bit. Thanks for digging up the log line.

@fmease
Copy link
Member

fmease commented Mar 22, 2023

Hey :) Does this PR fix #109488 perchance?

@jsha
Copy link
Contributor Author

jsha commented Mar 24, 2023

When I make the example from #109488 into a test, I get a compiler ICE; presumably it needs the code you're working on?

I have a pretty strong suspicion the issue is this line, which I didn't touch yet because it looked fishy and I couldn't figure out the intention:

_ => write!(f, "{}{:#}", assoc.name, assoc.args.print(cx))?,

{:#} is requesting alternate formatting (i.e. plaintext), but in this branch of things, alternate formatting hasn't been requested by the caller. So this is likely emitting < into an HTML context. If you change it to {} in your branch I'm guessing that will fix things.

I should also change it in this branch because {:#} is becoming meaningless.

@jsha
Copy link
Contributor Author

jsha commented Mar 24, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 24, 2023

⌛ Trying commit 236c18f with merge 9c4e97025c634ec4878a1580cc34680aa24ce17e...

@bors
Copy link
Contributor

bors commented Mar 24, 2023

☀️ Try build successful - checks-actions
Build commit: 9c4e97025c634ec4878a1580cc34680aa24ce17e (9c4e97025c634ec4878a1580cc34680aa24ce17e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9c4e97025c634ec4878a1580cc34680aa24ce17e): 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)
2.6% [0.6%, 5.1%] 15
Regressions ❌
(secondary)
3.2% [0.8%, 7.3%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [0.6%, 5.1%] 15

Max RSS (memory usage)

Results

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)
3.6% [3.2%, 4.0%] 2
Regressions ❌
(secondary)
1.3% [0.5%, 2.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-0.8%, -0.4%] 6
All ❌✅ (primary) 3.6% [3.2%, 4.0%] 2

Cycles

Results

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)
2.6% [2.0%, 4.0%] 6
Regressions ❌
(secondary)
1.2% [0.4%, 4.5%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.5%, -0.5%] 1
All ❌✅ (primary) 2.6% [2.0%, 4.0%] 6

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 24, 2023
@jsha
Copy link
Contributor Author

jsha commented Mar 24, 2023

Bummer, looks like performance got worse. I think I can probably iterate and improve it though.

@Dylan-DPC
Copy link
Member

@jsha any updates on this?

@jsha
Copy link
Contributor Author

jsha commented Aug 16, 2023

I'll close this for now and hope to come back to it.

@jsha jsha closed this Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

8 participants