about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-07 03:42:05 +0000
committerbors <bors@rust-lang.org>2021-10-07 03:42:05 +0000
commitd3e6770efbd76c4ad1e17468895b538a2efec4bd (patch)
tree0db3025d27155b10571b04c4b6fc65004d1c5918
parent0eabf25b90396dead0b2a1aaa275af18a1ae6008 (diff)
parentbec5a91450d58a821c8a41a93dd2563fc7eb4606 (diff)
downloadrust-d3e6770efbd76c4ad1e17468895b538a2efec4bd.tar.gz
rust-d3e6770efbd76c4ad1e17468895b538a2efec4bd.zip
Auto merge of #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 #85200) caused a small perf regression: https://github.com/rust-lang/rust/pull/88824#issuecomment-932664761

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`
-rw-r--r--compiler/rustc_passes/src/dead.rs42
1 files changed, 4 insertions, 38 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index d05961b7e37..77279132401 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -243,46 +243,15 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
     /// will be ignored for the purposes of dead code analysis (see PR #85200
     /// for discussion).
     fn should_ignore_item(&self, def_id: DefId) -> bool {
-        if !self.tcx.has_attr(def_id, sym::automatically_derived)
-            && !self
-                .tcx
-                .impl_of_method(def_id)
-                .map_or(false, |impl_id| self.tcx.has_attr(impl_id, sym::automatically_derived))
-        {
-            return false;
-        }
-
-        let has_attr = |def_id| self.tcx.has_attr(def_id, sym::rustc_trivial_field_reads);
-
-        if has_attr(def_id) {
-            return true;
-        }
-
         if let Some(impl_of) = self.tcx.impl_of_method(def_id) {
-            if has_attr(impl_of) {
-                return true;
+            if !self.tcx.has_attr(impl_of, sym::automatically_derived) {
+                return false;
             }
 
             if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) {
-                if has_attr(trait_of) {
+                if self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) {
                     return true;
                 }
-
-                if let Some(method_ident) = self.tcx.opt_item_name(def_id) {
-                    if let Some(trait_method) = self
-                        .tcx
-                        .associated_items(trait_of)
-                        .find_by_name_and_kind(self.tcx, method_ident, ty::AssocKind::Fn, trait_of)
-                    {
-                        if has_attr(trait_method.def_id) {
-                            return true;
-                        }
-                    }
-                }
-            }
-        } else if let Some(trait_of) = self.tcx.trait_of_item(def_id) {
-            if has_attr(trait_of) {
-                return true;
             }
         }
 
@@ -291,10 +260,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
 
     fn visit_node(&mut self, node: Node<'tcx>) {
         if let Some(item_def_id) = match node {
-            Node::Item(hir::Item { def_id, .. })
-            | Node::ForeignItem(hir::ForeignItem { def_id, .. })
-            | Node::TraitItem(hir::TraitItem { def_id, .. })
-            | Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
+            Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
             _ => None,
         } {
             if self.should_ignore_item(item_def_id) {