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.
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:
|
|
r? @mejrs |
There was a problem hiding this comment.
Can you remove the Closes #160621 from the PR description? This is just the first step for doing that :)
I think 1) is fine.
As for 2), I'm not totally sure, I need to play with this myself. Note though, that in
match x { Variant1(x) => Variant1(x) }left and right two different things, the left is a pattern, the right is a function call (enum constructors are functions) call or a struct literal expression if we did this but with a struct.
It seems that ignore_variant_stack is dead? I was able to remove it with no effect on the test suite. Maybe since #148262? In any case, let's not do that in this PR.
| 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") | ||
| }; |
There was a problem hiding this comment.
This produces notes such as
`f` is used in this derive macro
and then the note points out where the macro is used, but this approach is flawed because that is not always shown, for example people might be reading it in ide mouseover (which typically only shows the text). In that case "this" is not very helpful.
Can you name the macro in the note? You can get the macro's name from the span as well, with span.ctxt().outer_expn_data().
Typical parlance is smth like "originates in the macro foo", "used in the expansion of derive macro foo", etc.
There was a problem hiding this comment.
Makes sense, I changed it in 51b6620
Now reads
error: field `0` is never read
--> $DIR/from-macro.rs:11:15
|
LL | struct Struct(usize);
| ------ ^^^^^
| |
| field in this struct
|
= help: consider removing this field
note: `0` is used in the expansion of the derive macro `Clone`, but this is intentionally ignored during dead code analysis
--> $DIR/from-macro.rs:10:10
|
LL | #[derive(Clone)]
| ^^^^^
note: `0` is used in the expansion of the macro `foo`, but this is intentionally ignored during dead code analysis
--> $DIR/from-macro.rs:16:9
|
LL | fn foo(s: &Struct) {
| ^^^^^^^^^^^^^^^^^^
...
LL | foo!();
| ------ in this macro invocation
note: `0` is used in the expansion of the macro `bar`, but this is intentionally ignored during dead code analysis
--> $DIR/from-macro.rs:23:1
|
LL | bar!(Struct);
| ^^^^^^^^^^^^
Oh right - done
Ok, I can check this in more detail and maybe open an issue afterwards. I applied your suggestions from above. |
View all comments
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