Skip to content

Remove InstanceKind::generates_cgu_internal_copy#136410

Merged
bors merged 1 commit into
rust-lang:masterfrom
saethlin:clean-up-cgu-internal-copy
Mar 25, 2025
Merged

Remove InstanceKind::generates_cgu_internal_copy#136410
bors merged 1 commit into
rust-lang:masterfrom
saethlin:clean-up-cgu-internal-copy

Conversation

@saethlin

@saethlin saethlin commented Feb 1, 2025

Copy link
Copy Markdown
Member

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

rustbot commented Feb 1, 2025

Copy link
Copy Markdown
Collaborator

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

saethlin commented Feb 1, 2025

Copy link
Copy Markdown
Member Author

@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

bors commented Feb 1, 2025

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator

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

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
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

saethlin commented Feb 8, 2025

Copy link
Copy Markdown
Member Author

@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

bors commented Feb 8, 2025

Copy link
Copy Markdown
Collaborator

⌛ 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

bors commented Feb 8, 2025

Copy link
Copy Markdown
Collaborator

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

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
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

saethlin commented Feb 8, 2025

Copy link
Copy Markdown
Member Author

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

bors commented Feb 8, 2025

Copy link
Copy Markdown
Collaborator

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

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
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

saethlin commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

@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
@saethlin

Copy link
Copy Markdown
Member Author

r? compiler

@rustbot rustbot assigned estebank and unassigned wesleywiser Mar 13, 2025
return None;
}

// Functions marked with #[inline] are codegened with "internal"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why'd you remove the comment? Seems valid still to mention the interaction w/ inline.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because the logic for the inline attribute and extern indicators is in cross_crate_inlinable. I can put back a comment if you want 🤷 but one of the purposes of tcx.cross_crate_inlinable is to be the single point in the compiler that juggles those interactions.

Comment thread compiler/rustc_middle/src/mir/mono.rs Outdated
fn opt_incr_drop_glue_mode<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InstantiationMode {
// Non-ADTs can't have a Drop impl. This case is mostly hit by closures whose captures require
// dropping.
let Some(adt_def) = ty.ty_adt_def() else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer let ty::Adt(adt_def, _) = ty.kind() over ty_adt_def.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that's better.


// Types that don't have a direct Drop impl, but have fields that require dropping.
let Some(dtor) = adt_def.destructor(tcx) else {
if adt_def.is_enum() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what motivates this choice of making enums act differently than structs? I mean, both of them have fields after all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know something. I've added a comment that explains what I know and references the PR that landed the logic that I'm rewriting.

@compiler-errors

Copy link
Copy Markdown
Contributor

r=me after nits or not

@saethlin saethlin force-pushed the clean-up-cgu-internal-copy branch from 2c32926 to 817e2c5 Compare March 25, 2025 00:30
@rustbot

rustbot commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@compiler-errors

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 817e2c5 has been approved by compiler-errors

It is now in the queue for this repository.

@bors 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 Mar 25, 2025
@bors

bors commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 817e2c5 with merge 7d49ae9...

@bors

bors commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 7d49ae9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 25, 2025
@bors bors merged commit 7d49ae9 into rust-lang:master Mar 25, 2025
@rustbot rustbot added this to the 1.87.0 milestone Mar 25, 2025
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing e61403a (parent) -> 7d49ae9 (this PR)

Test differences

Show 4 test diffs

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7d49ae9): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (primary 2.8%, 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)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
2.7% [2.6%, 2.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.3%, -2.6%] 2
All ❌✅ (primary) 2.8% [2.8%, 2.8%] 1

Cycles

Results (secondary 4.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)
- - 0
Regressions ❌
(secondary)
4.9% [2.8%, 6.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 776.063s -> 777.441s (0.18%)
Artifact size: 365.84 MiB -> 365.81 MiB (-0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Mar 25, 2025
@saethlin saethlin deleted the clean-up-cgu-internal-copy branch May 4, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants