Skip to content

rustdoc: turn is_unnamable into a compiler query #145021

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

as discussed in #143849 (comment)

first time adding a compiler query, so i'm not sure if i have all the options and caching strategies configured right.

need someone to run a perf job for me on this.

once this is merged i may send a followup to also use this query to inhibit normalization into unnamable types.

as discussed in #143849 (comment)

r? @GuillaumeGomez

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Aug 6, 2025
@@ -107,3 +107,25 @@ impl Linker {
codegen_backend.link(sess, codegen_results, self.metadata, &self.output_filenames)
}
}

/// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about:

Suggested change
/// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
/// Checks if the given `DefId` refers to an unnamable item like:
///
/// ```
/// pub fn f() {
/// // In here, `X` is not reachable outside of `f`, making it unnamable.
/// pub struct X;
/// }
/// ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that the rustdoc module view and possibly some IDEs will just show "Checks if the given DefId refers to an unnamable item like:" as the summary.

In any case, this is the private query implementation, so any in-depth doc comment should probably go on the query itself so it can easily be found.

Copy link
Member

Choose a reason for hiding this comment

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

I'd advise to put the doc comment in both places then. :)

Also, I don't have an IDE providing doc comments for an item (which sounds really nice) but I don't think it's an argument in favor of having shorter doc comments. More like a bug to report on the IDE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not advising for shorter docs, I'm just trying to follow the official style guide for docs.

The point is the first sentence needs to make sense on its own.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not advising for shorter docs, I'm just trying to follow the official style guide for docs.

Which I co-wrote. I'm ashamed. You're absolutely right.

What about:

Suggested change
/// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
/// Checks if the given `DefId` refers to an unnamable item, such as one defined in a function.
///
/// Example:
///
/// ```
/// pub fn f() {
/// // In here, `X` is not reachable outside of `f`, making it unnamable.
/// pub struct X;
/// }
/// ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's incredibly similar to what I just pushed, curious if you think that's good enough.

@GuillaumeGomez
Copy link
Member

Might be better to have someone more used to compiler queries to ensure it's all good.

r? oli-obk

@rustbot rustbot assigned oli-obk and unassigned GuillaumeGomez Aug 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@lolbinarycat lolbinarycat force-pushed the rustdoc-is_unnamable-query branch from 4933a06 to 497d2c4 Compare August 6, 2025 21:58
@GuillaumeGomez
Copy link
Member

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 6, 2025
rustdoc: turn is_unnamable into a compiler query
@rust-bors
Copy link

rust-bors bot commented Aug 6, 2025

⌛ Trying commit 497d2c4 with merge 787c9d7

To cancel the try build, run the command @bors try cancel.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 6, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 7, 2025

☀️ Try build successful (CI)
Build commit: 787c9d7 (787c9d7e38acab303eaa25b513554d777e1e9ca3, parent: 29cdc6a109ee98a382f974bf89d3971b4385399c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (787c9d7): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.6% [0.5%, 0.6%] 3
Improvements ✅
(primary)
-0.3% [-0.5%, -0.2%] 12
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -0.3% [-0.5%, -0.2%] 12

Max RSS (memory usage)

Results (primary -2.8%, secondary 2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-2.8% [-6.3%, -1.0%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-6.3%, -1.0%] 3

Cycles

Results (primary 5.7%, secondary -0.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
5.7% [5.7%, 5.7%] 1
Regressions ❌
(secondary)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.6%, -2.3%] 2
All ❌✅ (primary) 5.7% [5.7%, 5.7%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 464.98s -> 464.656s (-0.07%)
Artifact size: 377.39 MiB -> 377.37 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 7, 2025
@GuillaumeGomez
Copy link
Member

The perf gain is much smaller than I hoped though. :-/

@lolbinarycat
Copy link
Contributor Author

I think it might be possible to return to the idea of running is_unnamable only when needed, but we'll need to run it at normalization and when displaying associated types in traits, which may require a little bit more work.

}
}
return false;
}
Copy link
Contributor

@cjgillot cjgillot Aug 7, 2025

Choose a reason for hiding this comment

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

Could you put this in compiler/rustc_interface/src/passes.rs? compiler/rustc_interface/src/queries.rs refers to a completely different kind of queries, that were eventually extinguished.

/// // In here, `X` is not reachable outside of `f`, making it unnamable.
/// pub struct X;
/// }
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need docs here when we have the query's?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants