Skip to content
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] Add support for associated items in "jump to def" feature #135771

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jan 20, 2025

Fixes #135485.

r? @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 20, 2025
@GuillaumeGomez
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Jan 20, 2025

⌛ Trying commit 0a62c9e with merge 884d495...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
…try>

[PERF for "jump to def"] Re-enable "jump to def" feature on rustc docs

This PR is NOT meant to be merged. `@fmease` and I are using it to check perfs on the "jump to def" feature.

r? `@fmease`
@bors
Copy link
Collaborator

bors commented Jan 20, 2025

☀️ Try build successful - checks-actions
Build commit: 884d495 (884d4952c02212f92d6d2dd3e1c804fd1aa1cd24)

@rust-timer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

Second commit is the interesting part: it overloads visit_qpath.

@@ -231,6 +231,24 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
self.handle_pat(p);
}

fn visit_qpath(&mut self, qpath: &QPath<'tcx>, id: HirId, span: Span) {
Copy link
Member

@fmease fmease Jan 20, 2025

Choose a reason for hiding this comment

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

You should now be able to remove the visit_pat and handle_pat methods entirely thanks to this overwrite. Unless I'm forgetting things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately no because of this case:

match self {
    // Doesn't work.
    Self::Ok(_) => {}
    // Works.
    MyEnum::Err(_) => {}
    // Doesn't work
    Self::Some(_) => {}
    // Works.
    Self::None => {}
}

Copy link
Member

Choose a reason for hiding this comment

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

Right, I'm pretty sure that there's a way to do it (by using the maybe_typeck_results pattern I mentioned back then on Zulip). After all, the cleanup part is all about getting rid of {visit,handle}_pat for me personally.

I'm gonna be afk in a sec, so I can't explain the maybe_typeck_results approach rn and I don't know if you can decipher my past rambling on Zulip. Well, you can check out rustc since it uses the "maybe_typeck_results pattern" quite frequently.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's fine. Gonna give it a try and if I can't gonna let you do it since you seem to have a clear implementation in mind.

Copy link
Member

Choose a reason for hiding this comment

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

I'll experiment later. Ofc, you can always try reading through hir::intravisit and see which methods don't get called in this PR which do get called on master, maybe there's a more obvious 'bug'.

Copy link
Member Author

Choose a reason for hiding this comment

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

I uncovered the maybe_typeck_results dark arcanes and fixed it. I wonder if there is a shorter way though, code still seems longer than it needs to be...

Copy link
Member

Choose a reason for hiding this comment

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

I'll check that soon. In any case, since this fixes things / adds support for more path types, I'd say it'd be fine even if we couldn't simplify it.

Also, with this method rustdoc should now be able to resolve fully-qualified paths (<$Type as $TraitRef>::$assoc), too, and that in all positions (expr, pat, type). On master, we don't support those at all iirc. However, I haven't double-checked if your impl is sufficient or if you still need to hook up some things. Could you add tests for them if this PR makes them work?

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (884d495): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

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

Instruction count

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

Max RSS (memory usage)

Results (primary 1.9%, secondary 2.6%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.9% [0.8%, 2.9%] 4
Regressions ❌
(secondary)
2.6% [1.3%, 4.1%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.9% [0.8%, 2.9%] 4

Cycles

Results (secondary 2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 767.44s -> 767.097s (-0.04%)
Artifact size: 325.97 MiB -> 326.00 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 20, 2025
@GuillaumeGomez
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

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

bors commented Jan 20, 2025

⌛ Trying commit bcd4e2e with merge 4f36aac...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
…try>

[PERF for "jump to def"] Re-enable "jump to def" feature on rustc docs

This PR is NOT meant to be merged. `@fmease` and I are using it to check perfs on the "jump to def" feature.

Used for rust-lang#135485.

r? `@fmease`
@bors
Copy link
Collaborator

bors commented Jan 20, 2025

☀️ Try build successful - checks-actions
Build commit: 4f36aac (4f36aac4606855ed0367291dac471c76ff3e5851)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4f36aac): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

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

Instruction count

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

Max RSS (memory usage)

Results (primary 1.8%, secondary 0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.8% [1.8%, 1.8%] 1
Regressions ❌
(secondary)
1.9% [1.8%, 1.9%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) 1.8% [1.8%, 1.8%] 1

Cycles

Results (secondary -2.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-2.9%, -2.9%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 766.257s -> 767.122s (0.11%)
Artifact size: 325.96 MiB -> 325.97 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 20, 2025
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2025
@GuillaumeGomez
Copy link
Member Author

Made more changes which had some interesting side-effects: we now have items in a same path that can generate links. However, projections still link to where the item is defined in the trait and not in the trait implementation, which is a bit sad...

You can check it here.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jan 29, 2025

☔ The latest upstream changes (presumably #134248) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez GuillaumeGomez force-pushed the jump-to-def-perf branch 2 times, most recently from 6b8b890 to 8f6eac5 Compare February 5, 2025 16:25
@GuillaumeGomez GuillaumeGomez changed the title [PERF for "jump to def"] Re-enable "jump to def" feature on rustc docs [rustdoc] Add support for associated items in "jump to def" feature Feb 5, 2025
@GuillaumeGomez GuillaumeGomez marked this pull request as ready for review February 5, 2025 16:26
@GuillaumeGomez
Copy link
Member Author

Removed the first commit. Seems like PR is ready for review now. :)

@fmease fmease added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 11, 2025
@bors
Copy link
Collaborator

bors commented Mar 7, 2025

☔ The latest upstream changes (presumably #138127) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Mar 7, 2025
@GuillaumeGomez
Copy link
Member Author

Fixed merge conflicts.

@bors
Copy link
Collaborator

bors commented Apr 2, 2025

☔ The latest upstream changes (presumably #139257) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler 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.

Overload visit_qpath instead of using visit_pat in rustdoc "jump to def" implementation
6 participants