-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Remove CURRENT_DEPTH
thread-local variable
#82815
Conversation
vis.print_with_space(cx.tcx, def_id, &cx.cache), | ||
// FIXME(camelid): this might create broken links! | ||
vis.print_with_space(cx.tcx, def_id, &cx.cache, 0), |
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.
I believe this has the same behavior as before, but we should probably test it.
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.
I think this will break for macros in submodules (e.g. pub mod inner { pub macro foo() {} }
).
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.
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.
Hmm, so it looks like we don't use links in macro visibilities on nightly anyway:
That sounds like a bug, could you open an issue?
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.
Issue: #83000. Nice issue number :)
vis.print_with_space(cx.tcx, def_id, &cx.cache), | ||
// FIXME(camelid): this might create broken links! | ||
vis.print_with_space(cx.tcx, def_id, &cx.cache, 0), |
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.
Same as above.
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache)))); | ||
// FIXME(camelid): I hope passing 0 as the depth doesn't break anything.... | ||
// Then again, I think used to be 0 anyway through CURRENT_DEPTH | ||
// because (I think) rendering hadn't started yet. | ||
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache, 0)))); |
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.
I think same as above.
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.
This change makes me nervous, can you say why you think rendering hadn't started?
I don't know exactly when this path is hit, path.segment.len() == 1
seems really strange because it doesn't leave any space for the crate name and I don't see any other reason to special case 1 path segment. Maybe add an unconditional panic!()
so we have a test case?
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.
This change makes me nervous
I understand, these changes make me a bit nervous too :)
can you say why you think rendering hadn't started?
My understanding is that all clean
ing happens before rendering, so CURRENT_DEPTH
is always its initial value of 0
. Is that not true?
Maybe add an unconditional
panic!()
so we have a test case?
Hmm, can you explain more what you mean?
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.
My understanding is that all cleaning happens before rendering, so CURRENT_DEPTH is always its initial value of 0. Is that not true?
Ok, this makes sense to me. The depth is only updated in context.rs
:
html/render/context.rs
22: CURRENT_DEPTH, INITIAL_IDS,
107: CURRENT_DEPTH.with(|slot| {
421: CURRENT_DEPTH.with(|s| s.set(0));
and cleaning never happens in html
/:
$ rg '\.clean' html/ | wc -l
0
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.
Maybe add an unconditional panic!() so we have a test case?
Hmm, can you explain more what you mean?
I don't know when this line of code will be executed. Can you change it to an unconditional panic and document the standard library so I can see a backtrace of how it happens? If it never happens that probably means the whole thing is unreachable and we don't have to worry about it in the first place.
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.
Can you change it to an unconditional panic and document the standard library so I can see a backtrace of how it happens? If it never happens that probably means the whole thing is unreachable and we don't have to worry about it in the first place.
@jyn514 It turns out it is reachable! It panicked while documenting core
, specifically this path:
DEBUG rustdoc::clean::utils resolve_type(Path { global: false, res: Def(TyParam, DefId(0:140 ~ core[8787]::f32::{impl#0}::to_int_unchecked::Int)), segments: [PathSegment { name: "Int", args: AngleBracketed { args: [], bindings: [] } }] },HirId { owner: DefId(0:139 ~ core[8787]::f32::{impl#0}::to_int_unchecked), local_id: 18 })
I think that path is the Int
in the return type of f32::to_int_unchecked()
.
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.
I think passing a depth of 0
should probably be fine since IIUC paths that resolve to type parameters shouldn't be able to have type parameters themselves...
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.
Ok, that makes sense to me. Could you add a comment about a) when this happens and b) why the depth of 0 is ok?
I think this PR will be very conflict-prone FYI. |
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.
I left some comments on the places where you pointed out a depth of 0. Can you point to where the depth is incremented and decremented? It's hard to find the important changes because the diff is big 😅
vis.print_with_space(cx.tcx, def_id, &cx.cache), | ||
// FIXME(camelid): this might create broken links! | ||
vis.print_with_space(cx.tcx, def_id, &cx.cache, 0), |
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.
I think this will break for macros in submodules (e.g. pub mod inner { pub macro foo() {} }
).
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache)))); | ||
// FIXME(camelid): I hope passing 0 as the depth doesn't break anything.... | ||
// Then again, I think used to be 0 anyway through CURRENT_DEPTH | ||
// because (I think) rendering hadn't started yet. | ||
return Generic(Symbol::intern(&format!("{:#}", path.print(&cx.cache, 0)))); |
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.
This change makes me nervous, can you say why you think rendering hadn't started?
I don't know exactly when this path is hit, path.segment.len() == 1
seems really strange because it doesn't leave any space for the crate name and I don't see any other reason to special case 1 path segment. Maybe add an unconditional panic!()
so we have a test case?
src/librustdoc/html/render/mod.rs
Outdated
@@ -170,6 +170,10 @@ crate struct SharedContext<'tcx> { | |||
} | |||
|
|||
impl<'tcx> Context<'tcx> { | |||
fn depth(&self) -> usize { |
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.
I think you wanted me to put docs on this; leaving a comment so I don't forget.
806fec1
to
bf37b68
Compare
Oh no, massive merge conflicts 😅 |
bf37b68
to
4747a74
Compare
Doing rebase in multiple parts to make it easier—first part done. |
4747a74
to
49879e3
Compare
Finished rebasing. Phew, that was probably one of the hardest rebases I've ever done 😅 |
Still need to squash my "fmt" commit. |
49879e3
to
3057e4b
Compare
I formatted each commit individually and dropped the |
tr.print(&self.ctx.cache), | ||
impl_.for_.print(&self.ctx.cache), | ||
tr.print(&self.ctx.cache, 0), | ||
impl_.for_.print(&self.ctx.cache, 0), |
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.
I used 0
here because this is just for debug output.
debug!("impl {:#} in {}", impl_.for_.print(&self.ctx.cache), filename); | ||
debug!("impl {:#} in {}", impl_.for_.print(&self.ctx.cache, 0), filename); |
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.
Same as above.
This comment has been minimized.
This comment has been minimized.
This part actually wasn't that hard. Ending the use of it in `html/format.rs` is probably going to be *a lot* harder.
Hooray!
3057e4b
to
0e1ff40
Compare
Rebased. Apparently this is even more conflict-prone than I expected! |
☔ The latest upstream changes (presumably #82855) made this pull request unmergeable. Please resolve the merge conflicts. |
AFAIK, this is waiting on:
I would prefer to hear a response to 1 before spending too much more time on this; the rest I can ignore for now while reviewing. |
Where the depth used to be changed or where it is changed now? Or both? |
The old rust/src/librustdoc/html/render/context.rs Lines 113 to 117 in cb0e0db
In this spot, it's being updated right before rendering an item, and it's set to the current length of the
rust/src/librustdoc/html/render/context.rs Line 547 in cb0e0db
and here: rust/src/librustdoc/html/render/context.rs Line 578 in cb0e0db
The other place at which rust/src/librustdoc/html/render/context.rs Line 424 in cb0e0db
This reset is necessary, even though In the new code (without |
Marking as waiting-on-review even though there are conflicts, because they are probably very mechanical to fix and it's probably easier to fix them all at the end or close to the end. |
FYI I plan to review/merge #83237 before this PR, so it's fine not to fix conflicts until then. |
rustdoc: use more precise relative URLs This is a fairly large diff, and will probably conflict with rust-lang#82815 since it reduces (but does not eliminate) the use of the old depth variable. Instead of using a depth counter and adding "../" to get to the top, this commit makes rustdoc actually compare the path of what it's linking from to the path that it's linking to. This makes the resulting HTML shorter. Here's a comparison of one of the largest (non-source) files in the Rust standard library docs (about 4% improvement before gzipping). $ wc -c struct.Wrapping.old.html struct.Wrapping.new.html 2387389 struct.Wrapping.old.html 2298538 struct.Wrapping.new.html Most if it can be efficiently gzipped away. $ wc -c struct.Wrapping.old.html.gz struct.Wrapping.new.html.gz 70679 struct.Wrapping.old.html.gz 70050 struct.Wrapping.new.html.gz But it also makes a difference in the final DOM size, reducing it from 91MiB to 82MiB.
Now that #83237 is merged, I think this approach is no longer necessary - Sorry this won't be merged, I appreciate you putting in the time :) |
Closes #82742. 🎉
This PR has a fairly large diff, but most of the changes are very small - just
threading the new
depth
parameter through a bunch of functions.This PR is draft because there are a few things that need to be resolved
before it should be merged. I have marked those spots with review comments.
r? @jyn514