-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc_json: improve handling of generic args #142502
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
base: master
Are you sure you want to change the base?
rustdoc_json: improve handling of generic args #142502
Conversation
rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing |
Local measurements indicate some sub-1% instruction count improvements, and some max-rss improvements of up to 2%, in rustdoc-json perf. |
☔ The latest upstream changes (presumably #142335) made this pull request unmergeable. Please resolve the merge conflicts. |
f232c4e
to
27eee69
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.
Behavioral changes make sense, but all of them needs tests.
They live in tests/rustdoc-json
. Sadly, I've not finished the docs for it yet (rust-lang/rustc-dev-guide#2422), but there's a draft here
type/generic_default.rs and gats.rs are probably good examples
27eee69
to
f3c20ca
Compare
These commits modify Please ensure that if you've changed the output:
|
I added a test as a separate commit early in the sequence, so the changes to @rustbot ready |
r=me after #142601 lands, and then this gets rebased to change the "Latest Change" comment. |
☔ The latest upstream changes (presumably #142613) made this pull request unmergeable. Please resolve the merge conflicts. |
f3c20ca
to
81a2aec
Compare
I fixed the conflicts and updated the @bors r=aDotInTheVoid |
…gs, r=aDotInTheVoid rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid`
Rollup of 10 pull requests Successful merges: - #135656 (Add `-Z hint-mostly-unused` to tell rustc that most of a crate will go unused) - #138237 (Get rid of `EscapeDebugInner`.) - #140772 ({aarch64,x86_64}-pc-windows-gnullvm: build host tools) - #140774 (Affirm `-Cforce-frame-pointers=off` does not override) - #141610 (Stabilize `feature(generic_arg_infer)`) - #141864 (Handle win32 separator for cygwin paths) - #142384 (Bringing `rustc_rayon_core` in tree as `rustc_thread_pool`) - #142502 (rustdoc_json: improve handling of generic args) - #142571 (Reason about borrowed classes in CopyProp.) - #142591 (Add spawn APIs for BootstrapCommand to support deferred command execution) r? `@ghost` `@rustbot` modify labels: rollup
☔ The latest upstream changes (presumably #138165) made this pull request unmergeable. Please resolve the merge conflicts. |
rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid` try-job: x86_64-mingw-2
💔 Test failed
|
There was a failure in the new tests for the type sizes, likely caused by |
a172d78
to
2f916c5
Compare
@bors2 try jobs=x86_64-mingw-2 |
rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid` try-job: x86_64-mingw-2
💔 Test failed
|
A lot of these are large! Lots of room for improvement in the future.
A path without generic args, like `Reader`, currently has JSON produced like this: ``` {"path":"Reader","id":286,"args":{"angle_bracketed":{"args":[],"constraints":[]}}} ``` Even though `types::Path::args` is `Option` and allows for "no args", instead it gets represented as "empty args". (More like `Reader<>` than `Reader`.) This is due to a problem in `clean::Path::from_clean`. It only produces `None` if the path is an empty string. This commit changes it to also produce `None` if there are no generic args. The example above becomes: ``` {"path":"Reader","id":286,"args":null} ``` I looked at a few examples and saw this reduce the size of the JSON output by 3-9%. The commit also adds an assertion that non-final segments don't have any generics; something the old code was implicitly relying on. Note: the original sin here is that `clean::PathSegment::args` is not an `Option`, unlike `{ast,hir}::PathSegment::args`. I want to fix that, but it can be done separately.
As per the previous commit, generic args here can only appear on the final segment. So make the comments obey that constraint.
They show up in three places: once as `Option<Box<GenericArgs>>`, once as `Box<GenericArgs>`, and once as `GenericArgs`. The first option is best. It is more compact because generic args are often missing. This commit changes the latter two to the former. Example output, before and after, for the `AssocItemConstraint` change: ``` {"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}},"binding":{...}} {"name":"Offset","args":null,"binding":{...}} ``` Example output, before and after, for the `Type::QualifiedPath` change: ``` {"qualified_path":{"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}}, ...}} {"qualified_path":{"name":"Offset","args":null, ...}} ``` This reduces JSON output size, but not by much (e.g. 0.5%), because `AssocItemConstraint` and `Type::QualifiedPath` are uncommon.
2f916c5
to
91818ba
Compare
Turns out it was because @bors try |
rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid`
@bors2 try jobs=x86_64-mingw-2 |
rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid` try-job: x86_64-mingw-2
☀️ Try build successful - checks-actions |
@bors r=aDotInTheVoid |
…gs, r=aDotInTheVoid rustdoc_json: improve handling of generic args This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types. r? `@aDotInTheVoid`
Rollup of 6 pull requests Successful merges: - #141990 (Implement send_signal for unix child processes) - #142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.) - #142502 (rustdoc_json: improve handling of generic args) - #142629 (Add config builder for bootstrap tests) - #142687 (Reduce uses of `hir_crate`.) - #142714 (add comment to `src/bootstrap/build.rs`) r? `@ghost` `@rustbot` modify labels: rollup
This PR fixes some inconsistencies and inefficiencies in how generic args are handled by rustdoc-json-types.
r? @aDotInTheVoid