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

Separate out a hir::Impl struct #79322

Merged
merged 1 commit into from
Jan 13, 2021
Merged

Separate out a hir::Impl struct #79322

merged 1 commit into from
Jan 13, 2021

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Nov 22, 2020

This makes it possible to pass the Impl directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.

See rustc_save_analysis::dump_visitor::process_impl or rustdoc::clean::clean_impl for a good example of how this makes impls easier to work with.

r? @petrochenkov maybe?

@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 22, 2020
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 22, 2020
@jyn514 jyn514 force-pushed the refactor-impl branch 2 times, most recently from a88a906 to c417d8d Compare November 22, 2020 22:53
@jyn514
Copy link
Member Author

jyn514 commented Nov 22, 2020

Another thing I noticed is that it's really common to match on Impl just to see whether it's a trait or an inherent impl - maybe it makes sense to add Impl::is_inherent() so this is easier to write? I can add that either here or in a follow-up.

@petrochenkov
Copy link
Contributor

This would be an excellent use case for rust-lang/rfcs#2593 ("Enum variant types").

@petrochenkov
Copy link
Contributor

I don't know.
This change improves code in one place in dump_visitor, but adds noise in numerous other places.

@jyn514
Copy link
Member Author

jyn514 commented Nov 24, 2020

If it helps, it would also improve some rustdoc code, that was the original use case.

@bors

This comment has been minimized.

@jyn514 jyn514 added the I-needs-decision Issue: In need of a decision. label Nov 24, 2020
@petrochenkov
Copy link
Contributor

Need second opinion.
r? @estebank as GitHub suggests.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

I think that Impl had grown a lot of fields so this makes a lot of sense. I would take more opportunities to use the nested types destructuring to avoid using field access, but this is fine as is.

r=me.

Comment on lines 404 to 420
hir::ItemKind::Impl(ref impl_) => {
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
// them up regardless of where they're located.
if !self.inlining && of_trait.is_none() {
let items =
items.iter().map(|item| self.cx.tcx.hir().impl_item(item.id)).collect();
if !self.inlining && impl_.of_trait.is_none() {
let items = impl_
.items
.iter()
.map(|item| self.cx.tcx.hir().impl_item(item.id))
.collect();
let i = Impl {
unsafety,
polarity,
defaultness,
constness,
generics,
trait_: of_trait,
for_: self_ty,
unsafety: impl_.unsafety,
polarity: impl_.polarity,
defaultness: impl_.defaultness,
constness: impl_.constness,
generics: &impl_.generics,
trait_: &impl_.of_trait,
for_: &impl_.self_ty,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this bit would be slightly nicer by using destructuring as it was before by using hir::ItemKind::Impl(hir::Impl { .. }) => like you do in other places.

Copy link
Member Author

Choose a reason for hiding this comment

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

This whole block of code disappeared when rebasing over #79312; the new changes are in https://github.com/rust-lang/rust/pull/79322/files#diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9R2037. I think you'll agree the new code is a lot nicer :)

@jyn514
Copy link
Member Author

jyn514 commented Dec 16, 2020

I fixed the merge conflicts. @estebank could you take another look? This bitrots rather quickly.

@bors
Copy link
Contributor

bors commented Dec 21, 2020

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

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@camelid camelid added the A-HIR Area: The high-level intermediate representation (HIR) label Dec 22, 2020
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

@jyn514 sorry about the delay. Please rebase and r=me.

self_ty: &'hir Ty<'hir>,
items: &'hir [ImplItemRef<'hir>],
},
Impl(Impl<'hir>),
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if Boxing this would have any perf benefits 👀

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 opened #80961 to find out :)

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
@jyn514
Copy link
Member Author

jyn514 commented Jan 13, 2021

@bors r=estebank rollup=iffy

@bors
Copy link
Contributor

bors commented Jan 13, 2021

📌 Commit a8ff647 has been approved by estebank

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

bors commented Jan 13, 2021

⌛ Testing commit a8ff647 with merge 150d1fe...

@jyn514 jyn514 mentioned this pull request Jan 13, 2021
@bors
Copy link
Contributor

bors commented Jan 13, 2021

☀️ Test successful - checks-actions
Approved by: estebank
Pushing 150d1fe to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 13, 2021
@bors bors merged commit 150d1fe into rust-lang:master Jan 13, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 13, 2021
@jyn514 jyn514 deleted the refactor-impl branch January 13, 2021 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-needs-decision Issue: In need of a decision. 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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants