Implement T-types suggested logic for perfect non-local impl detection by Urgau · Pull Request #122747 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation42 Commits5 Checks11 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
This implement T-types suggested logic 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 #121621.
This PR also re-enables the lint non_local_definitions
to warn-by-default.
Implementation was discussed in this zulip thread.
r? @lcnr (feel free to re-roll)
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
This comment has been minimized.
Contributor
lcnr left a 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
This comment has been minimized.
bors added a commit to rust-lang-ci/rust that referenced this pull request
☀️ Try build successful - checks-actions
Build commit: c5a16cd (c5a16cd81a23f6f21bfed93b321b2d9f3420fe10
)
This comment has been minimized.
Finished benchmarking commit (c5a16cd): comparison URL.
Overall result: ❌ regressions - ACTION NEEDED
Benchmarking 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 @rustbot label: +perf-regression-triaged
along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.
@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression
Instruction count
This is a highly reliable metric that was used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | 2.2% | [0.6%, 4.2%] | 12 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | - | - | 0 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | 2.2% | [0.6%, 4.2%] | 12 |
Max RSS (memory usage)
Results
This 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.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | 3.3% | [2.1%, 5.9%] | 9 |
Improvements ✅ (primary) | - | - | 0 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | - | - | 0 |
Cycles
Results
This 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.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | 2.7% | [0.6%, 3.4%] | 7 |
Regressions ❌ (secondary) | 3.0% | [3.0%, 3.0%] | 1 |
Improvements ✅ (primary) | - | - | 0 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | 2.7% | [0.6%, 3.4%] | 7 |
Binary size
This benchmark run did not return any relevant results for this metric.
Bootstrap: 669.21s -> 669.518s (0.05%)
Artifact size: 312.83 MiB -> 315.05 MiB (0.71%)
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 diesel
(v1.4.8) we embed trigger the warnings more than 300 times leading to some unavoidable perf regression.
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:
An item nested inside an expression-containing item (through any level of nesting) may not define an
impl<T0..Tn> [Trait<P1..Pn> for] P0
if it has an observable impact outside of this item
Any suggestion for what to replace it instead ?
Also, should we suggest or mention the 2 or more impls rule ?
something like the following 🤔
Impls inside of an item body should not impact code outside of that item.
and that this is the case if there are more than 1 other global impls is just an implementation detail imo
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.
could you give a quick look at the PR again, thks
Urgau mentioned this pull request
Contributor
lcnr left a 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
@@ -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 |
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."
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 |
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?
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.
✌️ @Urgau, you can now approve this pull request!
If @lcnr told you to "r=me
" after making some further change, please make that change, then do @bors r=@lcnr
📌 Commit 2f2d5cc has been approved by lcnr
It is now in the queue for this repository.
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Finished benchmarking commit (9d79cd5): comparison URL.
Overall result: ❌✅ regressions and improvements - ACTION NEEDED
Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged
along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged
label to this PR.
@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance
Instruction count
This is a highly reliable metric that was used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | 2.3% | [0.6%, 4.4%] | 12 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | -0.3% | [-0.4%, -0.2%] | 9 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | 1.2% | [-0.4%, 4.4%] | 21 |
Max RSS (memory usage)
Results
This 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.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | - | - | 0 |
Improvements ✅ (primary) | -3.2% | [-3.8%, -2.6%] | 2 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | -3.2% | [-3.8%, -2.6%] | 2 |
Cycles
Results
This 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.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | 2.7% | [1.2%, 3.5%] | 7 |
Regressions ❌ (secondary) | 3.1% | [3.1%, 3.1%] | 1 |
Improvements ✅ (primary) | - | - | 0 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | 2.7% | [1.2%, 3.5%] | 7 |
Binary size
This benchmark run did not return any relevant results for this metric.
Bootstrap: 667.559s -> 670.251s (0.40%)
Artifact size: 318.06 MiB -> 318.26 MiB (0.06%)
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
lqd mentioned this pull request
This was referenced
Jul 11, 2024
lcnr mentioned this pull request
12 tasks