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-json: change item ID's repr from a string to an int #130078

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

Conversation

its-the-shrimp
Copy link
Contributor

@its-the-shrimp its-the-shrimp commented Sep 7, 2024

Following this discussion on Zulip, I've changed the repr of rustdoc_json_types::Id from a String to a u32, by adding a clean::ItemId interner to JsonRenderer

r? @aDotInTheVoid

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend 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 Sep 7, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 7, 2024

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

Copy link
Member

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

I'm broadly speaking quite unfamiliar with the librustdoc portion of the codebase, so apologies for my ignorant questions here.

src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types.
pub struct Id(pub String);
pub struct Id(pub u32);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to recover the string ID from the numeric ID given a rustdoc JSON file? Or are you confident that isn't a capability that would be useful in any use case, so it isn't necessary to add?

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean "recover the string ID"? If you want to find what the Id would have been under the old schem, then no, this won't be possible, but I'm fine with that.

Rustdoc makes no guarantees about the inner value of Id’s. Applications should treat them as opaque keys to lookup items, and avoid attempting to parse them, or otherwise depend on any implementation details.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

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

This PR's doing alot, and needs major rework, so I've only tried to review it at a high level, as I don't think the in-the-weeds stuff is worth it yet.

  1. The changes to ItemId are intrusive to most of the rustdoc codebase, and not motivated at all. If these are nessessary, could that be explained, and send in a different, tighter-scoped, PR (that would be landed before this)
  2. Making Cache be the only source of state for the clean->json lowering is quite a bad idea:
    • It requires adding a TyCtxt, which produces more changes to the rest of rustdoc.
    • It adds the interner field which isn't used for HTML, but is still present, which is unfortunate.
    • In present, it requires adding a Lock, but I don't think this is inherent.
  3. There seem to be unrelated cleanups (like the removal of FormatRenderer::cache). These are should be merged into rustdoc, but not here! Again, the answer is a smaller, seperate PR, that just does one thing, and will be much easier to review.

src/librustdoc/formats/cache.rs Outdated Show resolved Hide resolved
src/librustdoc/formats/cache.rs Outdated Show resolved Hide resolved
src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
@aDotInTheVoid aDotInTheVoid 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 Sep 8, 2024
@rust-log-analyzer

This comment has been minimized.

@jalil-salame
Copy link

Some tests are failing to compile due to them expecting the id to be Id(String): https://github.com/rust-lang/rust/actions/runs/10769404806/job/29860558315?pr=130078#step:25:6101

@bors
Copy link
Contributor

bors commented Sep 9, 2024

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

@its-the-shrimp its-the-shrimp force-pushed the rustdoc-types-compress-ids branch 3 times, most recently from 10aae07 to c8bf3ef Compare September 10, 2024 11:31
@its-the-shrimp
Copy link
Contributor Author

@rustbot ready

This time the interner is restricted to the JsonRenderer, however I still couldn't get rid of the lock on the interner because of borrow checking errors

@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 Sep 10, 2024
@its-the-shrimp
Copy link
Contributor Author

its-the-shrimp commented Sep 10, 2024

It could be possible to get rid of it if we were to change the way formats::run_format drives the renderer forward, currently it clones the renderer at least once (and for JSON it'll do so only once), which means the ID interner has to be in an Rc, which is unfortunate since that clone is completely redundant (I'll probably do that after this commit is merged)

@its-the-shrimp
Copy link
Contributor Author

Or I can do it in this PR, the change should be very minimal

@its-the-shrimp
Copy link
Contributor Author

should the FORMAT_VERSION be bumped for this?

@jalil-salame
Copy link

should the FORMAT_VERSION be bumped for this?

Most likely yes, it is an API change (rustdoc-types will be unable to parse files with Id(u32)).

@its-the-shrimp
Copy link
Contributor Author

should the FORMAT_VERSION be bumped for this?

Most likely yes, it is an API change (rustdoc-types will be unable to parse files with Id(u32)).

The representation of IDs doesn't have any guarantees associated with it though, and rustdoc-types can get a new major version without incrementing FORMAT_VERSION

@obi1kenobi
Copy link
Member

obi1kenobi commented Sep 11, 2024 via email

@aDotInTheVoid
Copy link
Member

Yeah, bumping the format version needs to happen whenever we do something that breaks deserialisation (and I don’t know any times it’s been done for other reasons, but would be interested).

The representation of IDs doesn't have any guarantees associated with it though

Previously we guaranteed they were strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants