Skip to content

Consider mangling ID's in rustdoc-json #91609

Closed

Description

@aDotInTheVoid

Currently JSON ID's are (approximatly) the underling DefId's which means they are not realy opaque, despite what we've said in the RFC.

They happen to be the compiler internal DefId for that item, but in the JSON blob they should be treated as opaque as they aren't guaranteed to be stable across compiler invocations

The problem with this is that their is no obligation to treet the ID's as opaque (for a concreet example see scrabsha/scrabsha.github.io#2). If we want to garentee our ability to change the ID format, we should make it so that no one relies on the specific values of ID's by making them not cary information. Eg 0:0 lets the user know things, wheras a3aefbcbf31fa0bc12b9a73bc9d67976 (md5 hash) doesnt.

Potential Drawbacks

  • Non determinism
  • Harder to debug
  • Slower to build
  • Larger output

Which of these are actualy a problem, or just unfounded concerns I'm not sure:

If you want to change this: heres the places to look:

root: types::Id(String::from("0:0")),

ItemId::DefId(did) => Id(format!("{}", DisplayDefId(did))),

I'm not sure if this is a good idea, and would love feedback

@rustbot modify labels: +C-discussion +A-rustdoc-json

Activity

  1. added
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    on Dec 6, 2021
  2. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Dec 13, 2021
  3. camelid commented on Dec 13, 2021

    @camelid
    Member

    MD5 hashes should be deterministic, so non-determinism would only be introduced if we used a random number generator.

  4. CraftSpider commented on Jan 12, 2022

    @CraftSpider
    Contributor

    I think MD5 hashes would be okay, though I would also support simply encoding the output in a less 'human readable' way. I'm okay with information being conveyed, if it's more obvious that the user isn't meant to access/rely on that information (think base64 or such)

  5. changed the title [-]Consider mangaling ID's in rustdoc-json[/-] [+]Consider mangling ID's in rustdoc-json[/+] on Jan 12, 2022
  6. aDotInTheVoid commented on May 14, 2024

    @aDotInTheVoid
    MemberAuthor
  7. aDotInTheVoid commented on May 14, 2024

    @aDotInTheVoid
    MemberAuthor

    CC @zjp-CN. If there's information that's only availible by parsing the (supposed-to-be) opaque identifiers, I'd love to hear that. Otherwise just be aware that you're relying on an implementation detail, and it's liable to break without notice.

  8. zjp-CN commented on May 15, 2024

    @zjp-CN
    Contributor

    Hi, I did try to parse an id to learn about what it means in the testing, but haven't depended on it much in the app.

    There is missing information on parsing type: rustdoc_types::Impl doesn't tell if it's an auto impl, whereas an id starting with a can just tell it is.

  9. added a commit that references this issue on May 16, 2024
  10. added a commit that references this issue on May 16, 2024
  11. zjp-CN commented on Apr 20, 2025

    @zjp-CN
    Contributor

    Looks like this is not a problem now, since #130078 has landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-jsonArea: Rustdoc JSON backendC-discussionCategory: Discussion or questions that doesn't represent real issues.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions