Skip to content

Commit eb4ba58

Browse files
perf: only check for rustc_trivial_field_reads attribute on traits
The checks removed here caused a small perf regression: #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 evaluate if the perf impact is acceptable.
1 parent c02371c commit eb4ba58

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

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

+1-23
Original file line numberDiff line numberDiff line change
@@ -254,31 +254,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
254254

255255
let has_attr = |def_id| self.tcx.has_attr(def_id, sym::rustc_trivial_field_reads);
256256

257-
if has_attr(def_id) {
258-
return true;
259-
}
260-
261257
if let Some(impl_of) = self.tcx.impl_of_method(def_id) {
262-
if has_attr(impl_of) {
263-
return true;
264-
}
265-
266258
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) {
267259
if has_attr(trait_of) {
268260
return true;
269261
}
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-
}
282262
}
283263
} else if let Some(trait_of) = self.tcx.trait_of_item(def_id) {
284264
if has_attr(trait_of) {
@@ -291,9 +271,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
291271

292272
fn visit_node(&mut self, node: Node<'tcx>) {
293273
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, .. })
274+
Node::TraitItem(hir::TraitItem { def_id, .. })
297275
| Node::ImplItem(hir::ImplItem { def_id, .. }) => Some(def_id.to_def_id()),
298276
_ => None,
299277
} {

0 commit comments

Comments
 (0)