-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: normalise type/field names #128667
rustdoc: normalise type/field names #128667
Conversation
rustbot has assigned @GuillaumeGomez. Use |
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing |
Hmm, some of this feels like unnecessary churn - particularly the changes to the boolean field names. For example, I don't think |
This comment has been minimized.
This comment has been minimized.
Hm. I agree For I have no comment on the rest, though. |
src/librustdoc/clean/mod.rs
Outdated
@@ -1143,7 +1143,7 @@ fn clean_fn_decl_with_args<'tcx>( | |||
decl: &hir::FnDecl<'tcx>, | |||
header: Option<&hir::FnHeader>, | |||
args: Arguments, | |||
) -> FnDecl { | |||
) -> FunctionSignature { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Fn*
to Function*
is clearer. Naming it FnSig
or FnDecl
is kinda 🤷 though, but I don't think it necessarily makes sense to diverge from the HIR naming unless it's particularly more clear to call it a signature, which I don't think is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for renaming FnDecl, and the whole PR in general, is to be more friendly to outside users, that might not be in the know about rustc conventions, a function declaration may be understood as fn printf(fmt: &str, ...);,even though what the FnDecl is there is actually just (fmt: &str, ...), which is universally understood to be a function signature
am I right in thinking that anyone using this output will know enough rust to relate the fn
keyword to functions, and probably the Fn*
traits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, fn
is a fundamental keyword in Rust, so fn
<-> function
is a trivial equality to expect the user to understand, the change from Fn
to Function
there is purely for consistency with the existing Function
& FunctionPointer
structures, I don't believe we should be swayed by rustc's naming in rustdoc-json, since rustc is definitely not intended to be public API, unlike rustdoc-json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the change from Decl
to Signature
is explained in my comment a bit below
I love the effort to use clearer and more consistent terminology, and document rustdoc JSON types more thoroughly! Thanks to everyone helping this along 🙏 If possible, I'd just ask that you double-check that the name changes didn't negatively affect the size of generated rustdoc JSON files, e.g. by making an enum discriminant string substantially longer than before.
|
The reason for renaming |
regarding boolean fields, it's fine if we end up deciding to keep their names as they are, however, another reason for this PR was to close the question of naming in rustdoc-json (hence the "Fixes" annotation at the start), thus, I believe whatever renames we happen to decide on in this PR will serve as a precedent for naming conventions for rustdoc-json in the future (I believe @aDotInTheVoid wanted to document those conventions) |
☔ The latest upstream changes (presumably #128673) made this pull request unmergeable. Please resolve the merge conflicts. |
036baf2
to
b70b1cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While there's value for making all the JSON changes in one PR (we batch many small breaking changes into 1 large one), it's not a good idea for the clean
types. If you want to make changes to them, they can be done in later, smaller PR's that just do one thing (so are easier to review).
Should I revert the changes in jsondoclint as well? |
No, jsondoclint uses the types from rustdoc_json_types, so it will need to be changed. |
b70b1cd
to
11518f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I am generally in favor of the renaming of what the fields are called in Rust, I am strongly opposed to the new longer field names in JSON.
I'd like to ask that we consider not introducing the is_
prefixes into the rustdoc JSON itself, to avoid bloating the file and causing perf regressions without any human-visible improvement.
The largest crate that uses cargo-semver-checks
produces a 475MB rustdoc JSON file, and contains ~100k functions and ~400k trait and inherent impls. Deserializing that file is a measurable bottleneck in cargo-semver-checks
— we deserialize two such files per run, and spend about 4-5s wall-clock on it.
The proposed changes in the JSON field names in this PR will increase the file size by about 3-4MB (~1%). There's no real offsetting benefit for this regression, since the JSON is primarily meant to be machine-readable — it isn't even pretty-printed by default. There's very little advantage to having more descriptive field names repeat thousands of times.
Let's please keep the JSON field names short?
That's valid, I was also thinking about that, and I think there's a way to avoid the tug'o'war between the JSON & the Rust repr, which is having certain fields not serialised if they contain the "default" value whatever it happens to be, e.g. E.g. #[serde(default)]
#[serde(skip_serializing_if = "is_default")] // Function to be defined
pub is_async: bool, I'd be eager to implement this after this PR is merged |
I'd love to have both default/omitted fields and short field names as much as possible! 475MB of rustdoc JSON is a lot, and the scary thing is that a year ago that crate "only" produced ~250MB of rustdoc JSON. I'm not sure how much of that is due to format changes vs growth in the crate, but it's not a trend we can sustain for long either way. Short field names are a cheap way to buy a few percent, and especially leaving JSON field names unchanged by only adding the |
@rustbot ready |
@aDotInTheVoid what's your opinion on the changes to the boolean field names? |
I think that if changing the field names to be longer causes a perf regression, that's a problem with the overall serialization/de-serialization strategy, not the type design. I'm strongly opposed to changing field names or using serde defaults to try to fix perf. I want to review this PR solely based on how good the names are. I've opened a zulip thread to discuss potentially compressing or using alternative serialization formats for perf-sensitive users. Please don't have any further discussion around output sizes in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really close, thanks for working on it, and sorry for the review delay.
r=me with field name renamed
b63cbc7
to
bed6554
Compare
This comment has been minimized.
This comment has been minimized.
bed6554
to
aa47412
Compare
aa47412
to
f2696ab
Compare
@its-the-shrimp: 🔑 Insufficient privileges: Not in reviewers |
@bors r+ Thanks so much for working on this! |
…rename, r=aDotInTheVoid rustdoc: normalise type/field names Updates rust-lang#100961 - `Import` -> `Use`, to better reflect the terminology of Rust & its syntax - `TypeBinding` -> `AssocItemConstraint`, to sync up with `clean` - `FnDecl` -> `FunctionSignature`, because that's what it is - `Header` -> `FunctionHeader`, because `Header` is a very word that's very heavily loaded with different meanings - `ItemEnum::AssocType`: `default` -> `type`, because those items appear in `impl` blocks as well, where they're _not_ the "default" - `ItemEnum::AssocConst`: `default` -> `value`, see the previous point - `ForeignType` -> `ExternType`, because "foreign" is not the right word there - boolean fields' names made to consistently be a phrase that can be a yes/no answer, e.g. `async` -> `is_async` The docs of `ItemEnum::AssocType::type_` & of `ItemEnum::AssocConst::value` are also updated to be up to date with the clarification of the name of the fields
…rename, r=aDotInTheVoid rustdoc: normalise type/field names Updates rust-lang#100961 - `Import` -> `Use`, to better reflect the terminology of Rust & its syntax - `TypeBinding` -> `AssocItemConstraint`, to sync up with `clean` - `FnDecl` -> `FunctionSignature`, because that's what it is - `Header` -> `FunctionHeader`, because `Header` is a very word that's very heavily loaded with different meanings - `ItemEnum::AssocType`: `default` -> `type`, because those items appear in `impl` blocks as well, where they're _not_ the "default" - `ItemEnum::AssocConst`: `default` -> `value`, see the previous point - `ForeignType` -> `ExternType`, because "foreign" is not the right word there - boolean fields' names made to consistently be a phrase that can be a yes/no answer, e.g. `async` -> `is_async` The docs of `ItemEnum::AssocType::type_` & of `ItemEnum::AssocConst::value` are also updated to be up to date with the clarification of the name of the fields
…kingjubilee Rollup of 16 pull requests Successful merges: - rust-lang#119229 (Update mingw-w64 + GNU toolchain) - rust-lang#128345 (added support for GNU/Hurd on x86_64) - rust-lang#128667 (rustdoc: normalise type/field names) - rust-lang#128939 (Distribute rustc_codegen_cranelift for Windows) - rust-lang#129529 (Add test to build crates used by r-a on stable) - rust-lang#129624 (Adjust `memchr` pinning and run `cargo update`) - rust-lang#129876 (Use sysroot crates maximally in `rustc_codegen_gcc`.) - rust-lang#130034 ( Fix enabling wasm-component-ld to match other tools ) - rust-lang#130048 (run-make-support: Add llvm-pdbutil) - rust-lang#130068 (Test codegen when setting deployment target) - rust-lang#130070 (Rename variant `AddrOfRegion` of `RegionVariableOrigin` to `BorrowRegion`) - rust-lang#130087 (remove 'const' from 'Option::iter') - rust-lang#130090 (make Result::copied unstably const) - rust-lang#130092 (Fixes typo in wasm32-wasip2 doc comment) - rust-lang#130107 (const: make ptr.is_null() stop execution on ambiguity) - rust-lang#130115 (Remove needless returns detected by clippy in libraries) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 14 pull requests Successful merges: - rust-lang#119229 (Update mingw-w64 + GNU toolchain) - rust-lang#128345 (added support for GNU/Hurd on x86_64) - rust-lang#128667 (rustdoc: normalise type/field names) - rust-lang#129876 (Use sysroot crates maximally in `rustc_codegen_gcc`.) - rust-lang#130034 ( Fix enabling wasm-component-ld to match other tools ) - rust-lang#130048 (run-make-support: Add llvm-pdbutil) - rust-lang#130068 (Test codegen when setting deployment target) - rust-lang#130070 (Rename variant `AddrOfRegion` of `RegionVariableOrigin` to `BorrowRegion`) - rust-lang#130087 (remove 'const' from 'Option::iter') - rust-lang#130090 (make Result::copied unstably const) - rust-lang#130092 (Fixes typo in wasm32-wasip2 doc comment) - rust-lang#130107 (const: make ptr.is_null() stop execution on ambiguity) - rust-lang#130115 (Remove needless returns detected by clippy in libraries) - rust-lang#130130 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128667 - its-the-shrimp:rustdoc_json_types_rename, r=aDotInTheVoid rustdoc: normalise type/field names Updates rust-lang#100961 - `Import` -> `Use`, to better reflect the terminology of Rust & its syntax - `TypeBinding` -> `AssocItemConstraint`, to sync up with `clean` - `FnDecl` -> `FunctionSignature`, because that's what it is - `Header` -> `FunctionHeader`, because `Header` is a very word that's very heavily loaded with different meanings - `ItemEnum::AssocType`: `default` -> `type`, because those items appear in `impl` blocks as well, where they're _not_ the "default" - `ItemEnum::AssocConst`: `default` -> `value`, see the previous point - `ForeignType` -> `ExternType`, because "foreign" is not the right word there - boolean fields' names made to consistently be a phrase that can be a yes/no answer, e.g. `async` -> `is_async` The docs of `ItemEnum::AssocType::type_` & of `ItemEnum::AssocConst::value` are also updated to be up to date with the clarification of the name of the fields
Updates #100961
Import
->Use
, to better reflect the terminology of Rust & its syntaxTypeBinding
->AssocItemConstraint
, to sync up withclean
FnDecl
->FunctionSignature
, because that's what it isHeader
->FunctionHeader
, becauseHeader
is a very word that's very heavily loaded with different meaningsItemEnum::AssocType
:default
->type
, because those items appear inimpl
blocks as well, where they're not the "default"ItemEnum::AssocConst
:default
->value
, see the previous pointForeignType
->ExternType
, because "foreign" is not the right word thereasync
->is_async
The docs of
ItemEnum::AssocType::type_
& ofItemEnum::AssocConst::value
are also updated to be up to date with the clarification of the name of the fields