-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: Stop cloning the resolver #83761
Comments
I'm not sure what do you mean by freezing the resolver outputs, but I meant the regular rustc's mode of operation
So we need to achieve "freezing" the resolver outputs in rustdoc rather than to avoid it. Regarding eddyb's comment.
Not sure about the details of rustc_interface's work, but yes, resolver should be unique and should not be cloned. |
Ok, I see, I updated the title.
I'm not quite sure I follow - is there a reason the tcx has to freeze the resolver into ResolverOutputs? Or could the tcx store the resolver itself? If it stored the resolver rustdoc could stop cloning it without major changes. To be clear, I don't yet know how much work it would be for rustdoc to move all resolution before creating a TyCtxt, but the model where TyCtxt stores a resolver makes more sense in my head; or at least, it's more flexible. Possible scheme for rustdoc to move resolution before TyCtxt
enum EarlyIntraDocLink {
Resolved(clean::ItemLink),
AssocItem { base_ty: Res, item_name: Symbol, ns: Namespace, /* possibly more fields are necessary */ },
Variant { parent_def: Res, variant: Symbol }, // this might be able to be resolved early since the resolver implements DefIdTree, see https://github.com/rust-lang/rust/blob/d1065e6cefa41fe6c55c9819552cdd61529096fc/src/librustdoc/passes/collect_intra_doc_links.rs#L2121 for the current logic
// This can't be emitted early because it's a HIR lint, it needs a TyCtxt available.
Error { kind: ResolutionFailure, diag: DiagnosticInfo, path_str: String, disambiguator: Disambiguator },
}
For context, these are the current uses of the resolver in collect_intra_doc_links:
|
It may be possible. For now, I'd prefer to normalize to what rustc does and have a single scheme with resolver working early instead. |
Done in #83833 (although I need to clean it up before it can be merged). |
This isn't currently possible because resolving rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 868 to 885 in 2616ab1
Here is a fix (it uses a tcx currently, but the same API is available on CStore): 5d5be02 Original ramblings before I realized this was easyThere are two possible ways forward:
|
Oh wait no I'm dumb, 5d5be02 only helps if the item isn't an impl block. @petrochenkov Is there a way to resolve the If not it's not a giant deal, I'll just have to figure out how to fix the FIXME on line 868. |
Ugh, I have to figure out how to replicate this bit somehow: rust/src/librustdoc/passes/collect_intra_doc_links.rs Lines 1824 to 1833 in 2616ab1
Maybe the early pass could do that? I think the late pass for type-relative paths will need to have a partial resolution anyway, so it shouldn't be too much more work. |
I'm not sure how rustdoc resolves |
Thanks, this is helpful!
Hmm, ok. It can't do precisely the same thing because it uses the tyctxt to look up the type - maybe it could look up the DefKind while visiting the parent item? I have a few different ideas that could work (but I will probably end up just going with "use the DefId directly instead of stringifying" since I think I'll need it anyway). |
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? `@bugadani` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ``@bugadani`` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ```@bugadani``` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? `@bugadani` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ``@bugadani`` maybe? Feel free to reassign :)
rustdoc: Cleanup handling of associated items for intra-doc links Helps with rust-lang#83761 (right now the uses of the resolver are all intermingled with uses of the tyctxt). Best reviewed one commit at a time. r? ```@bugadani``` maybe? Feel free to reassign :)
rustdoc: Store intra-doc links in Cache instead of on items directly Items are first built after rustdoc creates the TyCtxt. To allow resolving the links before the TyCtxt is built, the links can't be stored on `clean::Item` directly. Helps with rust-lang#83761. Opening this early because I think it might decrease memory usage.
This commit implements MCP rust-lang/compiler-team#584 It also removes code that is no longer used, and that includes code cloning resolver, so issue rust-lang#83761 is fixed.
Rustdoc currently creates a copy of the resolver to use for intra-doc links:
rust/src/librustdoc/core.rs
Lines 350 to 354 in d474075
This is a Terrible, Horrible, No Good, Very Bad Idea. In particular, it causes rustdoc's copy of the resolver and the TyCtxt to disagree about what crates exist:
It's also distorting rustc_resolve, since not all of the outputs make sense to clone in the first place: #65625 (comment)
We should refactor rustdoc somehow to allow getting rid of
Resolver::clone_outputs
. @petrochenkov suggests moving anything that needs to touch the resolver before HIR lowering: #68427 (comment).@petrochenkov what do you think about @eddyb's comment in #65625 (comment) ?
Would it be possible for
lower_to_hir
to stop stealing the resolver?rust/compiler/rustc_interface/src/queries.rs
Line 227 in d474075
Then rustdoc wouldn't need to clone it in the first place, it could just call
queries.expansion().peek().1
whenever it needs access to the resolver.See #68427 for previous discussion.
Implementation History
clean::Item
s before resolving intra-doc links: rustdoc: Store intra-doc links in Cache instead of on items directly #83833collect_intra_doc_links
: rustdoc: Move crate loader to collect_intra_doc_links::early #84101preprocess_link
to also take into account the hacks forSelf::
andcrate
:rust/src/librustdoc/passes/collect_intra_doc_links.rs
Line 880 in ef52471
rust/src/librustdoc/passes/collect_intra_doc_links.rs
Lines 1124 to 1153 in ef52471
The text was updated successfully, but these errors were encountered: