document some rustc_dump attributes - #161556
Conversation
|
Some changes occurred in compiler/rustc_attr_ir |
There was a problem hiding this comment.
I would've never thought of using #[doc(attribute(…))] within rustc itself, nice! ^^
Regarding the actual pieces of documentation you've added, I have to admit that I'm questioning their value in their current form. Let me elaborate:
- The synopsis / first sentence is basically just restating the name in prose
- The link to the corresponding
AttributeKindshouldn't really be of any interest to the rustc dev looking into utilizing the internal attribute at hand- in 99.9% of cases, they don't intend to modify/extend the attribute; in most cases they just want to use the attribute to dump info for tests or for debugging
- most of these
AttributeKindare trivial/boring by being unit variants (and they would need to grep/jump-to-references separately anyway to find the actual impl) - in the 0.01% of cases where they do plan to modify the attribute itself, they will know how to grep for the impl
- The example code snippet is nice for skimming I suppose but the info where to place the attribute can be derived from taking a look at
ALLOWED_TARGETS/ by trial & error - The copy/pasted compiler output is valuable for understanding what sort of information the given attribute can provide
- however, it's bound to get out of date since it would need to be kept in sync manually, an impossible task
- today, this kind of information can be gathered by grepping
tests/ui/since there's guaranteed to be a corresponding test; and the nice part is: the "example output" is a*.stderrfile which has to be up to date or else the test would fail!
I'm not saying that we shouldn't write documentation for these internal dumping attributes but I'd be a lot more interested in docs that would semi-thoroughly explain the important&interesting parts of the respective debug output if extant (also prone to becoming outdated like all documentation but not as prone as pasted compiler output if it "talks more general concepts" / provides good info beyond the basics).
Right now, we do have a table in the rustc dev guide that's frankly also rather terse: https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#rustc_-test-attributes
I'm sorry if this sounds rather discouraging after you having done all that work!
|
I plan on documenting most (if not all) the interesting/useful/"spicy" attributes. This is just a start :) So keep "what would it look like if everything is documented" in mind.
They are what shows up in the module docs though, see below, and I dislike having gaps there:
It is slightly annoying to figure out what the variant name is, though. Just searching https://doc.rust-lang.org/nightly/nightly-rustc/ and following links is easier than grepping, especially if you don't know what the precise name is. It has annoyed me in the past trying to look that up. And I think that if every attribute was documented like this, it would save me (and hopefully others) some bits of time here and there :)
Like the std attribute docs, I'm not aiming to be thorough and precise (at least not in the dump attributes case). These attributes are very useful for teaching Rust and discussing various rustc implementation details. So it is very nice to be able to able to quickly link to and copy paste from a place like this. This is also why I've written several unstable book entries.
It should be possible to turn these into ui tests and |
| @@ -0,0 +1,759 @@ | |||
| #[cfg_attr(not(bootstrap), doc(attribute = "rustc_dump_clauses"))] | |||
| /// Dumps the clauses of the annotated item. | |||
There was a problem hiding this comment.
Below this, could you add a brief paragraph mentioning query clauses_of (and ty::Clause maybe in some way)? I know we can't intra-doc-link to them but still.
Why is mentioning clauses_of of importance? Well, it's important to know that it doesn't dump the result of query explicit_clauses_of or item_bounds for example. It's worth clarifying since synopsis "the clauses of the annotated item" is (rightly) rather vague unless you already know clauses_of.
Concretely, this actually "dumps a list of clauses that must be proven true at usage sites and which can be assumed at the definition site which consists of the explicit user-written clauses, the inferred outlives-clauses and clause <Self as Trait> if the item is a trait Trait".
I'm imagining the paragraph could be of the form "For more details, see query clauses_of and type ty::Clause." or preferably something akin to "This dumps the list of ty::Clauses as computed by query clauses_of."
Yeah, let's go with that! :) Something like the following should definitely work: ///
/// ```compile_fail
#[doc = include_str!("../../../tests/ui/<bikeshed>/<name>.rs")]
/// ```
///
/// ```text
#[doc = include_str!("../../../tests/ui/<bikeshed>/<name>.stderr")]
/// ```
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I would use the following normalization rule which is the most aggressive: //@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)"that should hopefully address the CI failure (admittedly, I've only skimmed the error log). |
it would (it's what i tried initially), but it turns |
There was a problem hiding this comment.
Could you remove the preexisting tests/ui/dump-clauses.rs? I originally added it when adding the attribute just so we have at least one place where we exercise the clause & item bounds attributes (since it was more meant for local debugging) ... but this file plus the other one for item bounds now serve this exact purpose.
| #[doc(attribute = "rustc_dump_inferred_outlives")] | ||
| /// Dumps the inferred outlives-clauses of the annotated item. | ||
| /// | ||
| /// See also the [`inferred_outlives_of`] query. |
There was a problem hiding this comment.
With "mention the corresponding/backing query (in a following paragraph)" in various review comments I was more thinking of a direct phrasing like
| /// See also the [`inferred_outlives_of`] query. | |
| /// They get computed by the [`inferred_outlives_of`] query. |
but that's on me for being too vague.
"See also" is also fine, so feel free to ignore this.
I will, I pushed feedback changes them as separate commits to make reviewing (and keeping track of) them easier. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=fmease |
|
⌛ Testing commit 52d85d7 with merge 2562a0f... Workflow: https://github.com/rust-lang/rust/actions/runs/33385551665 |
document some rustc_dump attributes r? @fmease I think you're the most familiar with these at this time?
document some rustc_dump attributes r? @fmease I think you're the most familiar with these at this time?
|
@bors yield (enclosing rollup) |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #162056. |
Rollup of 5 pull requests Successful merges: - #161556 (document some rustc_dump attributes) - #161353 (Add test for parallel compiler reproducible build) - #161776 (Add a couple polonius tests and move universal region liveness generation) - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI) - #162049 (Fix a compile error on the ESP-IDF target)
document some rustc_dump attributes r? @fmease I think you're the most familiar with these at this time?
document some rustc_dump attributes r? @fmease I think you're the most familiar with these at this time?
…uwer Rollup of 6 pull requests Successful merges: - #162058 (Port 1.98.1 release notes into main) - #161556 (document some rustc_dump attributes) - #161776 (Add a couple polonius tests and move universal region liveness generation) - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI) - #162049 (Fix a compile error on the ESP-IDF target) - #162054 (Refine InferCtxtInner docs)
…uwer Rollup of 6 pull requests Successful merges: - #162058 (Port 1.98.1 release notes into main) - #161556 (document some rustc_dump attributes) - #161776 (Add a couple polonius tests and move universal region liveness generation) - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI) - #162049 (Fix a compile error on the ESP-IDF target) - #162054 (Refine InferCtxtInner docs)

View all comments
r? @fmease I think you're the most familiar with these at this time?