Skip to content

Commit d3e6770

Browse files
committed
Auto merge of rust-lang#89454 - erikdesjardins:perfattrcheck, r=nikomatsakis
perf: only check for `rustc_trivial_field_reads` attribute on traits, not items, impls, etc. The checks that are removed in this PR (originally added in rust-lang#85200) caused a small perf regression: rust-lang#88824 (comment) Since the attribute is currently only applied to traits, I don't think it's worth keeping the additional checks for now. If/when we decide to apply the attribute somewhere else, we can (partially) revert this and reevaluate the perf impact. r? `@nikomatsakis` cc `@FabianWolff`
2 parents 0eabf25 + bec5a91 commit d3e6770

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

Diff for: compiler/rustc_passes/src/dead.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -243,46 +243,15 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
243243
/// will be ignored for the purposes of dead code analysis (see PR #85200
244244
/// for discussion).
245245
fn should_ignore_item(&self, def_id: DefId) -> bool {
246-
if !self.tcx.has_attr(def_id, sym::automatically_derived)
247-
&& !self
248-
.tcx
249-
.impl_of_method(def_id)
250-
.map_or(false, |impl_id| self.tcx.has_attr(impl_id, sym::automatically_derived))
251-
{
252-
return false;
253-
}
254-
255-
let has_attr = |def_id| self.tcx.has_attr(def_id, sym::rustc_trivial_field_reads);
256-
257-
if has_attr(def_id) {
258-
return true;
259-
}
260-
261246
if let Some(impl_of) = self.tcx.impl_of_method(def_id) {
262-
if has_attr(impl_of) {
263-
return true;
247+
if !self.tcx.has_attr(impl_of, sym::automatically_derived) {
248+
return false;
264249
}
265250

266251
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) {
267-
if has_attr(trait_of) {
252+
if self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) {
268253
return true;
269254
}
270-
271-
if let Some(method_ident) = self.tcx.opt_item_name(def_id) {
272-
if let Some(trait_method) = self
273-
.tcx
274-
.associated_items(trait_of)
275-
.find_by_name_and_kind(self.tcx, method_ident, ty::AssocKind::Fn, trait_of)
276-
{
277-
if has_attr(trait_method.def_id) {
278-
return true;
279-
}
280-
}
281-
}
282-
}
283-
} else if let Some(trait_of) = self.tcx.trait_of_item(def_id) {
284-
if has_attr(trait_of) {
285-
return true;
286255
}
287256
}
288257

@@ -291,10 +260,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
291260

292261
fn visit_node(&mut self, node: Node<'tcx>) {
293262
if let Some(item_def_id) = match node {
294-
Node::Item(hir::Item { def_id, .. })
295-
| Node::ForeignItem(hir::ForeignItem { def_id, .. })
296-
| Node::TraitItem(hir::TraitItem { def_id, .. })
297-
| Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
263+
Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
298264
_ => None,
299265
} {
300266
if self.should_ignore_item(item_def_id) {

0 commit comments

Comments
 (0)