-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement T-types suggested logic for perfect non-local impl detection #122747
Conversation
This comment has been minimized.
This comment has been minimized.
compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd like some style changes, apart from this r=me after perf
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…=<try> Implement T-types suggested logic for perfect non-local impl detection This implement [T-types suggested logic](rust-lang#121621 (comment)) for perfect non-local impl detection: > for each impl, instantiate all local types with inference vars and then assemble candidates for that goal, if there are more than 1 (non-private impls), it does not leak This extension to the current logic is meant to address issues reported in rust-lang#121621. This PR also re-enables the lint `non_local_definitions` to warn-by-default. Implementation was discussed in this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/Implementing.20new.20non-local.20impl.20defs.20logic). r? `@lcnr` *(feel free to re-roll)*
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (c5a16cd): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.21s -> 669.518s (0.05%) |
I've looked locally (with callgrind) at the perf regression and it's the same symptom as in the first implementation #120393 (comment), the version of I have checked that at least from version 2.1.0 (May 2023) and onwards of the crate there is no warnings, I suspect there are no warnings in any >=2 of diesel (but could check due to MSRV issues). One question through, I haven't update the diagnostic message, but I would like to do so before we merge this PR however I don't know what phrasing we should use, the one you proposed (@lcnr), seems a bit to "technical" for users:
Any suggestion for what to replace it instead ? Also, should we suggest or mention the 2 or more impls rule ? |
eed8e95
to
3c8cadc
Compare
something like the following 🤔
and that this is the case if there are more than 1 other global impls is just an implementation detail imo |
3c8cadc
to
ba7f52d
Compare
I've addressed all the review comments (expect for #122747 (comment)), as well as adding a conservative message for "not impacting code outside the item". I believe this is ready for another review or approval (which I cannot do since I don't have r+ rights). |
@lcnr, all the reviews comments have been addressed, but I can't r=you since I don't have r+ rights. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final nits, then r=me
compiler/rustc_lint/messages.ftl
Outdated
@@ -443,7 +443,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, they should be av | |||
[one] `{$body_name}` | |||
*[other] `{$body_name}` and up {$depth} bodies | |||
} | |||
.non_local = an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block | |||
.non_local = an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block and should not impact code outside of that item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sentence seems off to me 🤔
.non_local = an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block and should not impact code outside of that item | |
.non_local = an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl` |
or even ignoring the second sentence, simply using " an impl
definition is non-local if it is nested inside an item and may impact type checking outside of that item."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence also seemed a bit weird to me. Thanks for the suggestions, I ended up using the first one, since it gives a bit more details.
} | ||
|
||
let const_anon = if self.body_depth == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please explain what this if chain is doing? getting the span for an anon const suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's getting the span of the parent const item ident (if there is one) for the const anon suggestion.
I changed to variable name to span_for_const_anon_suggestion
and added a comment to explain what it is doing.
@bors delegate+ |
ba7f52d
to
2f2d5cc
Compare
☀️ Test successful - checks-actions |
Finished benchmarking commit (9d79cd5): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.559s -> 670.251s (0.40%) |
The perf regressions in diesel are due to the lint being triggered and producing nearly 300 warnings (with 155 actually shown). See #122747 (comment) and #120393 (comment) for more details. @rustbot label: +perf-regression-triaged |
This implement T-types suggested logic for perfect non-local impl detection:
This extension to the current logic is meant to address issues reported in #121621.
This PR also re-enables the lint
non_local_definitions
to warn-by-default.Implementation was discussed in this zulip thread.
Fixes #121621
Fixes #121746
r? @lcnr (feel free to re-roll)