-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Make AssocItem
aware of its impl kind
#145186
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @petrochenkov. Use |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_sanitizers cc @rcvalle changes to the core type system Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_passes/src/check_attr.rs This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a Some changes occurred in compiler/rustc_codegen_ssa |
This comment has been minimized.
This comment has been minimized.
0617ff2
to
cfed1ee
Compare
This comment has been minimized.
This comment has been minimized.
cfed1ee
to
77a42ec
Compare
@@ -1258,7 +1258,10 @@ pub(crate) fn clean_impl_item<'tcx>( | |||
})), | |||
hir::ImplItemKind::Fn(ref sig, body) => { | |||
let m = clean_function(cx, sig, impl_.generics, ParamsSrc::Body(body)); | |||
let defaultness = cx.tcx.defaultness(impl_.owner_id); | |||
let defaultness = match impl_.impl_kind { | |||
hir::ImplItemImplKind::Inherent { .. } => hir::Defaultness::Final, |
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 this should be None?
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.
No opinion.
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Make `AssocItem` aware of its impl kind
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (ecc5941): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.4%, secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.3%, secondary 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.3%, secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 463.257s -> 466.12s (0.62%) |
This comment was marked as resolved.
This comment was marked as resolved.
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
77a42ec
to
1d8ed9f
Compare
@rustbot ready (pending CI) |
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Make `AssocItem` aware of its impl kind
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (68df66d): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.4%, secondary -6.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (secondary -0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 464.993s -> 464.709s (-0.06%) |
☔ The latest upstream changes (presumably #145300) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -25,6 +26,7 @@ pub struct AssocItem { | |||
|
|||
/// If this is an item in an impl of a trait then this is the `DefId` of |
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.
The comment is incorrect, this field is currently set to Some
for AssocItemContainer::Trait
as well, but not always (?!)
It should either be consistently set for all AssocItemContainer::Trait
s, or not set for any of them.
In the latter case the conditions container == AssocItemContainer::Trait && trait_item_def_id.is_some()
will become redundant.
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.
In general, there's a lot of duplication in AssocItem
.
trait_item_def_id
is the same asdef_id
for trait itemscontainer
is almost a duplicate oftrait_item_def_id
, except for error recovery cases
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.
The comment is incorrect, this field is currently set to
Some
forAssocItemContainer::Trait
as well, but not always (?!)
It seems to me somebody decided to put Some
there cause it's "free", but it's not the purpose of the field. I could fix this, maybe in a separate PR? Or I could fix the code comment.
container
is almost a duplicate oftrait_item_def_id
, except for error recovery cases
I noticed this as well. This change makes the two things closer to being redundant, but they are still not totally redundant. So ultimately I think this change is good and I don't see a way to simplify 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'm talking about this because changing representation of AssocItem
would require rewriting half of the changes in this PR, so it makes sense to not separate them.
(The HIR change can be landed separately though.)
The non-redundant representation for AssocItem
would be
struct AssocItem {
def_id: DefId,
kind: AssocKind,
other_kind: OtherKind,
}
enum OtherKind {
Trait,
InherentImpl,
TraitImpl(Option<DefId>),
}
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.
Gotcha. I can give that I try.
ty::AssocItemContainer::Trait => impl_ty, | ||
ty::AssocItemContainer::Impl => tcx.associated_item(impl_ty.trait_item_def_id.unwrap()), | ||
ty::AssocItemContainer::TraitImpl => { | ||
tcx.associated_item(impl_ty.trait_item_def_id.unwrap()) |
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 is a sleeping ICE, because trait_item_def_id
can indeed be None
if there are compilation errors.
The general goal is to have fewer query dependencies by making
AssocItem
aware of its parent impl kind (inherent vs. trait) without having to query the parent def_kind.enum hir::ImplItemImplKind::{Inherent, Trait}
atImplItem.impl_kind
which allowsImplItem
to be aware of its containing impl kind, and also move impl-kind-specific fields into corresponding variants.AssocItemContainer::Impl
intoAssocItemContainer::{InherentImpl, TraitImpl}
.AssocItemContainer
in numerous places.