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: Replace FakeDefId with new ItemId type #86644

Merged
merged 7 commits into from
Jul 6, 2021

Conversation

Stupremee
Copy link
Member

Follow up from #84707

@Manishearth suggested that there should be a new ItemId type that can distinguish between auto traits, normal ids, and blanket impls instead of using FakeDefIds.

This type is introduced by this PR.

There are still some FIXMEs left, because I was unsure what the best solution for them would be.

Especially the naming in general now is a bit weird right now and needs to be cleaned up. Now there are no "fake" ids so the is_fake method on Item does not really make sense and maybe the methods on ItemId should be renamed too?

Also, we need to represent the new item ids in the JSON backend somehow.

@rust-highfive
Copy link
Collaborator

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2021
@Stupremee Stupremee added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 26, 2021
src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Jun 26, 2021

r? @jyn514

@rust-log-analyzer

This comment has been minimized.

@Stupremee Stupremee force-pushed the replace-fakedefids-with-itemid branch from 506b701 to 7a46ba3 Compare June 26, 2021 15:59
@rust-log-analyzer

This comment has been minimized.

src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
src/librustdoc/clean/types.rs Show resolved Hide resolved
src/librustdoc/formats/cache.rs Show resolved Hide resolved
@Stupremee Stupremee force-pushed the replace-fakedefids-with-itemid branch 2 times, most recently from f97138e to ea66dd9 Compare June 26, 2021 18:56
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

I like this a lot, thanks for doing this! I don't really have any feedback that hasn't been brought up already aside from the boxing thing

src/librustdoc/clean/types.rs Show resolved Hide resolved
@Stupremee Stupremee force-pushed the replace-fakedefids-with-itemid branch from ea66dd9 to 6ed4d11 Compare June 27, 2021 08:43
@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Jul 2, 2021

r? @CraftSpider - this looks great other than the JSON IDs. I'm fine with reverting the "Box ImplId" commit.

@rust-highfive rust-highfive assigned CraftSpider and unassigned jyn514 Jul 2, 2021
@Stupremee
Copy link
Member Author

This should be ready now!

r? @CraftSpider

@rust-log-analyzer

This comment has been minimized.

@Stupremee Stupremee force-pushed the replace-fakedefids-with-itemid branch from 772408e to 64e84c3 Compare July 3, 2021 13:43
src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
@@ -96,7 +96,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: ItemId::Blanket { trait_: trait_def_id, for_: item_def_id },
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was unclear: you don't need for_ at all now, you can reconstruct it from the impl_id alone with tcx.impl_trait_ref(impl_def_id).unwrap().self_ty().

Suggested change
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
def_id: ItemId::Blanket { impl_def_id, },

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I do need it, because apparently, only the implementation id is not enough to be unique (?????????).
When I only had the impl_id, I got a panic when documenting std that assert_eq on these two failed:

  left: `Item { id: Id("b:0:2454"), crate_id: 0, name: None, span: Some(Span { filename: "library/core/src/borrow.rs", begin: (208, 0), end: (213, 1) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Impl(Impl { is_unsafe: false, generics: Generics { params: [GenericParamDef { name: "T", kind: Type { bounds: [], default: None } }], where_predicates: [BoundPredicate { ty: Generic("T"), bounds: [TraitBound { trait_: ResolvedPath { name: "Sized", id: Id("0:2854"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }, generic_params: [], modifier: Maybe }] }] }, provided_trait_methods: [], trait_: Some(ResolvedPath { name: "Borrow", id: Id("0:2448"), args: Some(AngleBracketed { args: [Type(Generic("T"))], bindings: [] }), param_names: [] }), for_: ResolvedPath { name: "Wrapping", id: Id("0:24138"), args: Some(AngleBracketed { args: [Type(Generic("T"))], bindings: [] }), param_names: [] }, items: [Id("0:2456")], negative: false, synthetic: false, blanket_impl: Some(Generic("T")) }) }`,
 right: `Item { id: Id("b:0:2454"), crate_id: 0, name: None, span: Some(Span { filename: "library/core/src/borrow.rs", begin: (208, 0), end: (213, 1) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Impl(Impl { is_unsafe: false, generics: Generics { params: [GenericParamDef { name: "T", kind: Type { bounds: [], default: None } }], where_predicates: [BoundPredicate { ty: Generic("T"), bounds: [TraitBound { trait_: ResolvedPath { name: "Sized", id: Id("0:2854"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }, generic_params: [], modifier: Maybe }] }] }, provided_trait_methods: [], trait_: Some(ResolvedPath { name: "Borrow", id: Id("0:2448"), args: Some(AngleBracketed { args: [Type(Generic("T"))], bindings: [] }), param_names: [] }), for_: ResolvedPath { name: "ParseFloatError", id: Id("0:23084"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }, items: [Id("0:2456")], negative: false, synthetic: false, blanket_impl: Some(Generic("T")) }) }`', src/librustdoc/json/mod.rs:179:17

Copy link
Member

Choose a reason for hiding this comment

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

... @CraftSpider why are those separate? I would only expect there to be one item per blanket impl, generating a separate item for every type it could apply to seems both inefficient and not particularly useful.

Copy link
Contributor

@CraftSpider CraftSpider Jul 4, 2021

Choose a reason for hiding this comment

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

I have no clue, I'd expect the same. I'll look into the code tomorrow.
First guess: the equivalent of HTML's 'implements' showing blankets that apply to that type

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we wait with this PR until you found a solution? We can also merge this now and make a follow up PR.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah this seems fine in the meantime. r=me once you fix the conflict.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Josh, this isn't a blocking concern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright. @CraftSpider will you open the follow-up PR with the fix for not emitting duplicate blanket implementations and the fixed ItemId?

@bors
Copy link
Contributor

bors commented Jul 5, 2021

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

@Stupremee Stupremee force-pushed the replace-fakedefids-with-itemid branch from c2f403b to a89912c Compare July 5, 2021 17:52
@Stupremee
Copy link
Member Author

r? @jyn514

@rust-highfive rust-highfive assigned jyn514 and unassigned CraftSpider Jul 5, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 5, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jul 5, 2021

📌 Commit a89912c has been approved by jyn514

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2021
@bors
Copy link
Contributor

bors commented Jul 6, 2021

⌛ Testing commit a89912c with merge 9a27044...

@bors
Copy link
Contributor

bors commented Jul 6, 2021

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing 9a27044 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 6, 2021
@bors bors merged commit 9a27044 into rust-lang:master Jul 6, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 6, 2021
@Stupremee Stupremee deleted the replace-fakedefids-with-itemid branch July 6, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants