-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add relnotes-api-list
in-tree tool
#143053
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
Draft
pietroalbini
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
pietroalbini:pa-relnotes-api-list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+1,368
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The job Click to see the possible cause of the failure (guessed by this bot)
|
Is there a particular reason for diffing json instead of scanning for |
Stability attributes unfortunately are not mandated on impl blocks, and we want to detect whether a new trait is implemented for a type. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-meta
Area: Issues & PRs about the rust-lang/rust repository itself
T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new in-tree tool called
relnotes-api-list
to generate a simplified JSON representation of the standard library API. This representation will be uploaded as a dist artifact (but it won't be included in the published releases), and it will be used by the relnotes tool to generate the "Stabilized APIs" section by comparing the JSON file of multiple releases.Behind the scenes, the tool consumes the Rustdoc JSON (cc @rust-lang/rustdoc) and depends on the in-tree
src/rustdoc-json-types
crate. Being an in-tree tool, this implies PRs modifying the JSON output will also have to adapt this tool to pass CI.The generated JSON contains a tree structure, with each node containing an item (module, struct, function, etc) and its children (for example, the methods of a struct). This tree representation will allow the relnotes tool (for example) to only show a line for a new module being added instead of also showing all of the structs, functions and methods within that new module.
Outstanding question:
impl
blocksWhile deciding how to represent most items in the JSON is trivial (just the path to the item as the name, and the Rustdoc URL as the URL),
impl
blocks are trickier, and there is no single obvious solution to them.The first problem is whether to include
impl
blocks at all:impl $type {}
is just a container of methods and associated items, and should intuitively be "transparent". Whether an item is in oneimpl
block or another doesn't influence the public API (as long as one of them is notcfg
'd out). Because of this, the code just walks through these kinds ofimpl
blocks without recording them in the resulting JSON (the children are still emitted as if they are children of the type).impl $trait for $type
is the opposite, as the presence or not of theimpl
is load bearing, but the children of theimpl
are not relevant (we don't want a relnotes item for each type implementing a trait when a new trait method is added).So, if we go with these assumptions, we only care about how to represent
impl $trait for $type {}
in the resulting JSON. This has two big open questions though:What name do we put for the impl block? The intuitive answer there (and what I currently implemented in this PR) is to pretty-print the data contained in the Rustdoc JSON, which results in names like this:
The downsides of this approach are:
A lot of implementation complexity, and extra work when a new Rustdoc JSON version wants to land, since we need to exhaustively match a large surface of the Rustdoc JSON API. This is basically the whole purpose of the
pretty_print.rs
module.Little control over what is rendered as the name, since the information comes straight from Rustdoc JSON. In those examples for example we can see relative paths and
$crate
. Resolving them in the tool would be overly complex IMO.The upside of the approach though is that each item is unambiguous, even when complex
where
clauses are used.What URL do we put for the
impl
block? Right now I don't put any URL, as I'm not sure what approach to take. The problem is that the URLs for theimpl
s also require walking through a bunch of the Rustdoc JSON information, and I'd need to spend even more time figuring out how to emit them correctly:Outstanding question: move some of the behavior to Rustdoc JSON?
There is a lot of complexity right now in the tool that could maybe benefit from being uplifted in the Rustdoc JSON emitter:
impl
s, and Rustdoc providing the correct URLs would be immensely helpful.Q&A
Why is this an in-tree tool instead of consuming the Rustdoc JSON from the relnotes tool?
I initially tried to implement this directly in the relnotes tool, but quickly ran into the problem that most releases include a new version of the Rustdoc JSON. We'd then either have to implement our own data structures into the tool supporting multiple Rustdoc JSON versions (and having to figure out what changed in each release), or have multiple copies of the source code for each version. Being in-tree means it will be updated whenever a new Rustdoc JSON version happens.
Why not use cargo-public-api instead of reimplementing it in-tree?
cargo-public-api is very similar to what this PR implements, but it depends on the public
rustdoc-types
crate and only supports one version of Rustdoc JSON at a time. It suffers the same problems as this being an out-of-tree tool (see above), and we don't have a guarantee it will be updated to the new Rustdoc JSON version by the time we need to prepare the release notes.r? @Mark-Simulacrum
cc @rust-lang/release