Repository navigation
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Prepare to make `rustc_trivial_field_reads` usable in user code
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (e790d10): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf 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 5.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.6%, secondary 2.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 488.816s -> 489.518s (0.14%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Prepare to make `rustc_trivial_field_reads` usable in user code
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a64a0d1): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 490.869s -> 490.424s (-0.09%) |
|
Let's run it again, i think the improvements are spurious. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
I was delaying this PR because I thought #164913 would make it easier to implement. I still think so but some of the semantics for |
Sounds good, if it's not required for this feature let's skip the refactoring.
Ideally the behavior wouldn't change here, but if it easier to fix the bugs while you're at it (rather than emulate the old buggy behavior), I'd rather see the bugs fixed. |
This comment has been minimized.
This comment has been minimized.
Before, when a trivial fn was used from multiple seeds, the "used here but ignored" note would appear twice.
|
I addressed some changes and added some tests and am making this ready for review. This still adds a good amount of complexity to some already complex code, so I'm still interested in the approach in #164913 . Also we definitely have to check perf again - since the last perf checks, I added more complex diagnostics and changed the logic that decides whether items should be scanned or not, so this can definitely have an impact. Open questionsThe two questions in the PR description still apply, the first is a change of behavior in this PR that makes sense to me. The second I think is just a bug? There is also one more decision: An item can be unused but be used from multiple trivial usage sites. In this case, I emit one note per usage site. However, diagnostics are also grouped together (for the fields in a struct, for example, if many of them are unused) and in this case I am now emitting one note per usage site and then point out all the fields that are unused from that particular site. An example diagnostic, taken from the I think this is quite clear, but we could also do this in other ways. Finally, it's not entirely clear what to do about propagation of trivial usage sites from traits to their impls. I don't know whether we have to get this completely right in this PR though |
|
Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Changes to the code generated for builtin derived traits. cc @nnethercote Some changes occurred in compiler/rustc_attr_parsing |
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| // We immediately sort these by span afterwards, so | ||
| // the instability does not matter | ||
| #[allow(rustc::potential_query_instability)] | ||
| let mut notes: Vec<_> = sites | ||
| .into_iter() | ||
| .map(|(usage_site, def_ids)| { | ||
| let usage_site = self.live_symbols.trivial_usage_site_by_id(usage_site); | ||
| let names: Vec<_> = | ||
| def_ids.iter().map(|def_id| self.tcx.item_name(*def_id)).collect(); | ||
| let multiple = names.len() > 1; | ||
| let names = names.into(); | ||
| let (span, usage_kind) = if usage_site.attr_span.in_derive_expansion() { | ||
| (usage_site.attr_span, "in this derive macro") | ||
| } else if usage_site.attr_span.in_external_macro(self.tcx.sess.source_map()) { | ||
| (usage_site.attr_span, "in this macro invocation") | ||
| } else { | ||
| (self.tcx.hir_span(usage_site.hir_id), "here") | ||
| }; | ||
| crate::diagnostics::TrivialUsageSite { names, span, usage_kind, multiple } | ||
| }) | ||
| .collect(); | ||
| notes.sort_unstable_by_key(|note| note.span.lo_hi()); | ||
| notes |
There was a problem hiding this comment.
I am not super sure about this - is this a reasonable approach? They need to be sorted somehow, but I don't know if doing it by span is reasonable.
|
r? @mejrs |
View all comments
Closes #160621
Zulip discussion:
#t-lang > diagnostics attribute to ignore code for unused_code lints
#t-compiler/help > #160621 (Allow ignoring fns for dead code analysis)
Open questions I have:
Debugimpls are not pointed out as usage sites. For example this test:now loses its the note in the error message:
but in my mind this also makes sense - the
Debugimpl never constructs thatVariant1and even ifrustc_trivial_field_readsis removed from the debug impl, the "variant never constructed" warning would still occur. Note that this doesn't apply toCloneimpls, which do technically construct that variant although that brings me to point 2ignored_variant_stackis to make sure we don't mark a variant of an enum live from within a match arm that matches on that exact enum variant. But isn't that exactly what theCloneimpl does? The inner match arm of it would look likeVariant1(x) => Variant1(x). I looked intonecessary_variantsand found that it directly ignores the kind of variant we encounter, namelyPatKind::TupleStruct(hir::QPath::TypeRelative(...))but I don't really understand why and whether that's a bug or whether I am missing something