Skip to content
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

Remove InstanceKind::generates_cgu_internal_copy #136410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Feb 1, 2025

This PR should not contain any behavior changes. Before this PR, the logic for selecting instantiation mode is spread across all of

  • instantiation_mode
  • cross_crate_inlinable
  • generates_cgu_internal_copy
  • requires_inline

The last two of those functions are not well-designed. The function that actually decides if we generate a CGU-internal copy is instantiation_mode, not generates_cgu_internal_copy. The function requires_inline documents that it is about the LLVM inline attribute and that it is a hint. The LLVM attribute is called inlinehint, this function is also used by other codegen backends, and since it is part of instantiation mode selection it is not a hint.

The goal of this PR is to start cleaning up the logic into a sequence of checks that have a more logical flow and are easier to customize in the future (to do things like improve incrementality or improve optimizations without causing obscure linker errors because you forgot to update another part of the compiler).

@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2025

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 1, 2025
@saethlin
Copy link
Member Author

saethlin commented Feb 1, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 1, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 1, 2025
… r=<try>

Remove InstanceKind::generates_cgu_internal_copy

This is on top of rust-lang#136394 for now.

`InstanceKind::generates_cgu_internal_copy` was called in two places:

1. By `reachable_non_generics`, but in that case the caller was guaranteed to not be generic and therefore we always fall through to just calling `cross_crate_inlinable`.
2. By `MonoItem::instantiation_mode`, but in that case the *only* thing that it does is some very complicated logic for selecting the instantiation mode for drop glue, and only very recently do we have a single codegen test for this. So I've touched up the logic in `cross_crate_inlinable` so that we don't try to claim that `drop_in_place` isn't cross-crate-inlinable, because it clearly is.

Now off to perf, and if we get regressions I'll start reintroducing the logic about drop glue but, but this time into `MonoItem::instantiation_mode` where it always should have been.
@bors
Copy link
Contributor

bors commented Feb 1, 2025

⌛ Trying commit 6e9db01 with merge 69c35dc...

@bors
Copy link
Contributor

bors commented Feb 2, 2025

☀️ Try build successful - checks-actions
Build commit: 69c35dc (69c35dcc9e16d4d54ae9eab591266a070edf7235)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (69c35dc): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
11.9% [0.2%, 79.0%] 40
Regressions ❌
(secondary)
8.9% [0.4%, 37.8%] 17
Improvements ✅
(primary)
-4.9% [-9.4%, -0.7%] 4
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 1
All ❌✅ (primary) 10.4% [-9.4%, 79.0%] 44

Max RSS (memory usage)

Results (primary 1.7%, secondary 1.5%)

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)
3.5% [2.3%, 5.6%] 6
Regressions ❌
(secondary)
2.4% [1.2%, 3.8%] 4
Improvements ✅
(primary)
-3.7% [-3.8%, -3.6%] 2
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) 1.7% [-3.8%, 5.6%] 8

Cycles

Results (primary 15.7%, secondary 13.9%)

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)
17.3% [1.0%, 87.6%] 29
Regressions ❌
(secondary)
13.9% [2.5%, 34.3%] 11
Improvements ✅
(primary)
-8.2% [-8.5%, -8.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 15.7% [-8.5%, 87.6%] 31

Binary size

Results (primary 4.0%, secondary -0.2%)

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)
4.5% [0.0%, 18.4%] 44
Regressions ❌
(secondary)
2.3% [0.1%, 4.9%] 14
Improvements ✅
(primary)
-0.6% [-0.8%, -0.6%] 5
Improvements ✅
(secondary)
-11.7% [-12.6%, -9.8%] 3
All ❌✅ (primary) 4.0% [-0.8%, 18.4%] 49

Bootstrap: 777.275s -> 785.803s (1.10%)
Artifact size: 328.69 MiB -> 328.60 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 2, 2025
@saethlin saethlin force-pushed the clean-up-cgu-internal-copy branch from 6e9db01 to d22354c Compare February 8, 2025 02:02
@rust-log-analyzer

This comment has been minimized.

@saethlin saethlin force-pushed the clean-up-cgu-internal-copy branch 2 times, most recently from 8a8bb0c to 2e0908b Compare February 8, 2025 02:39
@saethlin
Copy link
Member Author

saethlin commented Feb 8, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
@bors
Copy link
Contributor

bors commented Feb 8, 2025

⌛ Trying commit 2e0908b with merge 53335c7...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2025
… r=<try>

Remove InstanceKind::generates_cgu_internal_copy

This is on top of rust-lang#136394 for now.

`InstanceKind::generates_cgu_internal_copy` was called in two places:

1. By `reachable_non_generics`, but in that case the caller was guaranteed to not be generic and therefore we always fall through to just calling `cross_crate_inlinable`.
2. By `MonoItem::instantiation_mode`, but in that case the *only* thing that it does is some very complicated logic for selecting the instantiation mode for drop glue, and only very recently do we have a single codegen test for this. So I've touched up the logic in `cross_crate_inlinable` so that we don't try to claim that `drop_in_place` isn't cross-crate-inlinable, because it clearly is.

Now off to perf, and if we get regressions I'll start reintroducing the logic about drop glue but, but this time into `MonoItem::instantiation_mode` where it always should have been.
@bors
Copy link
Contributor

bors commented Feb 8, 2025

☀️ Try build successful - checks-actions
Build commit: 53335c7 (53335c70a1c5cf7c1e824d8b4da0285df47f6196)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (53335c7): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
10.7% [0.3%, 95.3%] 24
Regressions ❌
(secondary)
2.9% [0.5%, 12.9%] 18
Improvements ✅
(primary)
-3.4% [-11.1%, -0.2%] 7
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 7.5% [-11.1%, 95.3%] 31

Max RSS (memory usage)

Results (primary -2.0%)

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.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.4% [-3.9%, -2.8%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.0% [-3.9%, 2.1%] 4

Cycles

Results (primary 14.1%, secondary 4.8%)

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)
18.3% [0.8%, 105.6%] 15
Regressions ❌
(secondary)
5.9% [2.4%, 11.7%] 8
Improvements ✅
(primary)
-6.8% [-10.5%, -1.7%] 3
Improvements ✅
(secondary)
-4.2% [-4.2%, -4.2%] 1
All ❌✅ (primary) 14.1% [-10.5%, 105.6%] 18

Binary size

Results (primary -0.1%, secondary 2.0%)

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.5% [0.0%, 1.3%] 27
Regressions ❌
(secondary)
2.0% [0.1%, 4.9%] 17
Improvements ✅
(primary)
-0.8% [-1.0%, -0.0%] 21
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-1.0%, 1.3%] 48

Bootstrap: 778.956s -> 782.985s (0.52%)
Artifact size: 329.06 MiB -> 329.02 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
@saethlin
Copy link
Member Author

saethlin commented Feb 8, 2025

codegen tests are expected to fail

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2025
… r=<try>

Remove InstanceKind::generates_cgu_internal_copy

`InstanceKind::generates_cgu_internal_copy` was called in two places:

1. By `reachable_non_generics`, but in that case the caller was guaranteed to not be generic and therefore we always fall through to just calling `cross_crate_inlinable`.
2. By `MonoItem::instantiation_mode`, but in that case the *only* thing that it does is some very complicated logic for selecting the instantiation mode for drop glue, and only very recently do we have a single codegen test for this. So I've touched up the logic in `cross_crate_inlinable` so that we don't try to claim that `drop_in_place` isn't cross-crate-inlinable, because it clearly is.

I've also migrated the logic for drop glue from `generates_cgu_internal_copy` into a helper function that's hopefully a lot more clear. It's a lot more clear to me at least.
@bors
Copy link
Contributor

bors commented Feb 8, 2025

⌛ Trying commit 390ee02 with merge 02543619dc7aa92e5cd2eaca29be7c4d062d008d...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 8, 2025

☀️ Try build successful - checks-actions
Build commit: 0254361 (02543619dc7aa92e5cd2eaca29be7c4d062d008d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0254361): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
16.2% [0.3%, 103.2%] 18
Regressions ❌
(secondary)
4.0% [0.5%, 14.5%] 16
Improvements ✅
(primary)
-3.8% [-18.7%, -0.3%] 21
Improvements ✅
(secondary)
-2.4% [-7.3%, -0.3%] 7
All ❌✅ (primary) 5.4% [-18.7%, 103.2%] 39

Max RSS (memory usage)

Results (primary -1.4%, secondary -1.2%)

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)
4.0% [3.0%, 5.0%] 3
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-4.7% [-6.3%, -2.8%] 5
Improvements ✅
(secondary)
-3.0% [-3.7%, -2.4%] 2
All ❌✅ (primary) -1.4% [-6.3%, 5.0%] 8

Cycles

Results (primary 8.5%, secondary 2.0%)

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)
20.9% [0.7%, 114.1%] 15
Regressions ❌
(secondary)
5.5% [2.0%, 12.6%] 11
Improvements ✅
(primary)
-5.9% [-18.5%, -0.8%] 13
Improvements ✅
(secondary)
-3.3% [-7.8%, -0.8%] 7
All ❌✅ (primary) 8.5% [-18.5%, 114.1%] 28

Binary size

Results (primary -0.3%, secondary 1.3%)

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)
1.8% [0.2%, 6.4%] 23
Regressions ❌
(secondary)
5.9% [1.7%, 13.9%] 14
Improvements ✅
(primary)
-1.1% [-9.2%, -0.0%] 54
Improvements ✅
(secondary)
-0.2% [-1.7%, -0.1%] 41
All ❌✅ (primary) -0.3% [-9.2%, 6.4%] 77

Bootstrap: 781.002s -> 768.021s (-1.66%)
Artifact size: 329.08 MiB -> 329.08 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
@saethlin saethlin force-pushed the clean-up-cgu-internal-copy branch from 390ee02 to 2c32926 Compare February 8, 2025 21:14
@saethlin
Copy link
Member Author

saethlin commented Feb 8, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2025
… r=<try>

Remove InstanceKind::generates_cgu_internal_copy

This PR should not contain any behavior changes. Before this PR, the logic for selecting instantiation mode is spread across all of
* `instantiation_mode`
* `cross_crate_inlinable`
* `generates_cgu_internal_copy`
* `requires_inline`

The last two of those functions are not well-designed. The function that actually decides if we generate a CGU-internal copy is `instantiation_mode`, _not_ `generates_cgu_internal_copy`. The function `requires_inline` documents that it is about the LLVM `inline` attribute and that it is a hint. The LLVM attribute is called `inlinehint`, this function is also used by other codegen backends, and since it is part of instantiation mode selection it is *not* a hint.

The goal of this PR is to start cleaning up the logic into a sequence of checks that have a more logical flow and are easier to customize in the future (to do things like improve incrementality or improve optimizations without causing obscure linker errors because you forgot to update another part of the compiler).
@bors
Copy link
Contributor

bors commented Feb 8, 2025

⌛ Trying commit 2c32926 with merge 6a752a8...

@bors
Copy link
Contributor

bors commented Feb 8, 2025

☀️ Try build successful - checks-actions
Build commit: 6a752a8 (6a752a87a5c108106cfdd90e2ff6ee784585c55d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6a752a8): comparison URL.

Overall result: ❌ regressions - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
3.2% [3.2%, 3.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.2% [3.2%, 3.2%] 1

Max RSS (memory usage)

Results (secondary -0.4%)

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)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary 3.6%, secondary -3.3%)

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)
3.6% [3.6%, 3.6%] 1
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.0% [-8.3%, -3.7%] 2
All ❌✅ (primary) 3.6% [3.6%, 3.6%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 779.565s -> 781.025s (0.19%)
Artifact size: 329.13 MiB -> 329.08 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 9, 2025
@saethlin saethlin marked this pull request as ready for review February 9, 2025 00:59
@saethlin
Copy link
Member Author

saethlin commented Feb 9, 2025

@rustbot label: +perf-regression-triaged
bimodal benchmark, not a regression.

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants