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: Rename Path::name to path, and give it the path again. #135799

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

aDotInTheVoid
Copy link
Member

@aDotInTheVoid aDotInTheVoid commented Jan 20, 2025

Closes: #135600.

Reverts #134880 (Effectively, but not actually, as the FORMAT_VERSION needs to be bumped, changed docs/tests). CC @AS1100K.

Also CC @obi1kenobi @LukeMathWalker

Still needs before being merge-ready:

r? @GuillaumeGomez

@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 Jan 20, 2025
@rust-log-analyzer

This comment has been minimized.

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.

Thank you for putting this together! 🙏

//@ is "$.index[*][?(@.name=='U3')].inner.type_alias.type.resolved_path.name" '"pub_mod::InPubMod"'
pub type U3 = InPubMod3;

// Check we only have paths for structs at there origonal path
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Check we only have paths for structs at there origonal path
// Check we only have paths for structs at their original path

@AS1100K
Copy link
Contributor

AS1100K commented Jan 21, 2025

Thanks for this PR! A revert was necessary because we need to prevent #134880 from being included in the beta, as it would break tools and we cannot change paths.path from absolute path to public facing path because it is required for generating source URLs by rustdoc and other crates.

@aDotInTheVoid
Copy link
Member Author

aDotInTheVoid commented Jan 21, 2025

A revert was necessary because we need to prevent #134880 from being included in the beta, as it would break tools

N.B: Rustdoc-Json is currently unstable, and not usable on beta/stable. The purpose of the revert is to fix nightly.

we cannot change paths.path from absolute path to public facing path because it is required for generating source URLs by rustdoc and other crates.

I’m not sure i follow.

@LukeMathWalker
Copy link
Contributor

I don't follow the last part either—rustdoc's HTML backend doesn't build on top of the JSON output AFAIK. Even if it did, it doesn't expose private paths for public items.

@AS1100K
Copy link
Contributor

AS1100K commented Jan 21, 2025

we cannot change paths.path from absolute path to public facing path because it is required for generating source URLs by rustdoc and other crates.

Sorry, I wasn't clear. What I meant was

For the code:

#![no_std]

pub type Foo = core::str::SplitAsciiWhitespace<'static>;

The json output will be

{
  "index": {
    "0": {
      "id": 0,
      "inner": {
        "type_alias": {
          "generics": {"params": [], "where_predicates": []},
          "type": {
            "resolved_path": {
              "args": {"angle_bracketed": {"args": [{"lifetime": "'static"}], "constraints": []}},
              "id": 1,
              "name": "SplitAsciiWhitespace"
            }
          }
        }
      },
      "name": "Foo"
    },
    "2": {
      "id": 2,
      "inner": {"module": {"is_crate": true, "is_stripped": false, "items": [0]}},
      "name": "mcve"
    }
  },
  "paths": {
    "0": {"crate_id": 0, "kind": "type_alias", "path": ["mcve", "Foo"]},
    "1": {"crate_id": 1, "kind": "struct", "path": ["core", "str", "iter", "SplitAsciiWhitespace"]}
  },
  "root": 2
}

Here, "path": ["core", "str", "iter", "SplitAsciiWhitespace"] was refered as path.path. I said it because this field is in ItemSummary struct which is constructed from Cache here which is used by HTML backend to get the absolute path i.e. "core", "str", "iter", "SplitAsciiWhitespace" as per above example to get the URL for source file that would be core/str/iter.rs.html and I thought of replacing this path with public facing path that would be core::str::SplitAsciiWhitespace but then thought absolute path could also be important for other libaries (like i am building cargo-wiki) to use this absolute path to generate URL on docs.rs or some other mechanism they might want.

I hope I made it clear but if not please ask me, I might be wrong so please let me know.

@aDotInTheVoid
Copy link
Member Author

rustdoc's HTML backend doesn't build on top of the JSON output AFAIK.

Correct, both of them built of clean, a rustdoc internal IR (that's in turn built from HIR & MIR)

as per above example to get the URL for source file that would be ...

For source URL's, rustdoc-html goes through the Span infrastructure (as should rustdoc-json consumers): See https://github.com/rust-lang/rust/blob/ed43cbcb882e7c06870abdd9305dc1f17eb9bab9/src/librustdoc/html/sources.rs for details.


The issue is that paths comes from an implementation detail of HTML (see #93522), so it's kinda arbitrary what's there. As some point it'll need to be properly thought through (possibly alongside the long-awaited cross-crate id solution.

@aDotInTheVoid
Copy link
Member Author

aDotInTheVoid commented Jan 21, 2025

A though while doing the docs: Should this field be renamed to not name? Having name: String actually be a path seems really surprising and goofy. How'd people feel about it being path instead?

@aDotInTheVoid aDotInTheVoid marked this pull request as ready for review January 21, 2025 23:34
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

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

@aDotInTheVoid aDotInTheVoid changed the title [WIP] rustdoc-json: Made Path::name have the full name again. rustdoc-json: Rename Path::name to path, and give it the path again. Jan 21, 2025
@aDotInTheVoid
Copy link
Member Author

@GuillaumeGomez the code can be reviewed as-is, it's ready. But don't merge it yet, I want to squash commits before that. (But don't want to yet, incase we decide to not do the field rename, as it'd be easier to revert).

@rust-log-analyzer

This comment has been minimized.

@LukeMathWalker
Copy link
Contributor

A though while doing the docs: Should this field be renamed to not name? Having name: String actually be a path seems really surprising and goofy. How'd people feel about it being path instead?

It'd definitely be a better match for what it currently contains. It works for me.

Comment on lines 1041 to 1042
/// This will be the path where the type is *used*, so it may be a
/// re-export.
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion, feel free to take it or leave it: I'm not 100% sure what "used" means in this context. Is it the path referenced in the code being documented, either directly or via an import? AKA "what path would we have to remove to break the code being documented"

Perhaps an example could help?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an example:

pub type Vec1 = std::vec::Vec<i32>; // path: "std::vec::Vec"
pub type Vec2 = Vec<i32>; // path: "Vec"
pub type Vec3 = std::prelude::v1::Vec<i32>; // path: "std::prelude::v1::Vec"

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

@aDotInTheVoid
Copy link
Member Author

Docs improved. Commits squashed.

@obi1kenobi
Copy link
Member

Looks good to me, thank you! Seems ready to merge, if I'm not mistaken?

I'm eager to use it in cargo-semver-checks ASAP, so that we narrow the window of nightlies with which we're incompatible :)

@GuillaumeGomez
Copy link
Member

I already approve so it's up to @aDotInTheVoid whenever they want. :)

@aDotInTheVoid
Copy link
Member Author

@bors r=GuillaumeGomez rollup

(Sorry, I didn't realize github's green check meant r=you here. I don't think there's a norm here)

@bors
Copy link
Contributor

bors commented Jan 23, 2025

📌 Commit 9c0e32b has been approved by GuillaumeGomez

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 Jan 23, 2025
@GuillaumeGomez
Copy link
Member

Ah sorry, miscommunication I think. You said you wanted my approval but not my merge because you wanted to make another small change. So I approved and for me it was all done. Should have precised. ^^'

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 24, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#133605 (Add extensive set of drop order tests)
 - rust-lang#135489 (remove pointless allowed_through_unstable_modules on TryFromSliceError)
 - rust-lang#135757 (Add NuttX support for AArch64 and ARMv7-A targets)
 - rust-lang#135799 (rustdoc-json: Rename `Path::name` to `path`, and give it the path again.)
 - rust-lang#135865 (For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks.)
 - rust-lang#135890 (Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`)
 - rust-lang#135914 (Remove usages of `QueryNormalizer` in the compiler)
 - rust-lang#135936 (fix reify-intrinsic test)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 40e2858 into rust-lang:master Jan 24, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 24, 2025
Rollup merge of rust-lang#135799 - aDotInTheVoid:skrrt-skrrt-revrrt, r=GuillaumeGomez

rustdoc-json: Rename `Path::name` to `path`, and give it the path again.

Closes: rust-lang#135600.

Reverts rust-lang#134880 (Effectively, but not actually, as the `FORMAT_VERSION` needs to be bumped, changed docs/tests). CC `@AS1100K.`

Also CC `@obi1kenobi` `@LukeMathWalker`

Still needs before being merge-ready:
- [x] Tests for cross-crate paths
- [x] (Maybe) Document what the field does.
- [x] Decide if the field rename is good (rust-lang#135799 (comment))
- [ ] Squash commits.

r? `@GuillaumeGomez`
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 27, 2025
…meGomez

rustdoc-json: Rename `Path::name` to `path`, and give it the path again.

Closes: #135600.

Reverts #134880 (Effectively, but not actually, as the `FORMAT_VERSION` needs to be bumped, changed docs/tests). CC `@AS1100K.`

Also CC `@obi1kenobi` `@LukeMathWalker`

Still needs before being merge-ready:
- [x] Tests for cross-crate paths
- [x] (Maybe) Document what the field does.
- [x] Decide if the field rename is good (rust-lang/rust#135799 (comment))
- [ ] Squash commits.

r? `@GuillaumeGomez`
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

rustdoc-json: Not enough info after paths change.
8 participants