Skip to content

lib: specialize Clone of array IntoIter#156634

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Paladynee:lib/array-intoiter-spec-clone
May 29, 2026
Merged

lib: specialize Clone of array IntoIter#156634
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Paladynee:lib/array-intoiter-spec-clone

Conversation

@Paladynee

@Paladynee Paladynee commented May 16, 2026

Copy link
Copy Markdown
Contributor

This PR adds the TrivialClone specialization to the PolymorphicIter type, which array::IntoIter uses. I also added another coretest for the default case (already existing test catches the specialized one).

There are no unwinding concerns since TrivialClone means cloning = copying and we never call Clone::clone.

array:IntoIter is being used on a lot of places in both core and in user code, and array::IntoIter (nor does its users) override Clone often and just delegate to the inner type PolymorphicIter which does not yet do the TrivialClone specialization and is burdened by the iterator and unwind safety shenanigans for all types, so this PR should address some of that. This should in turn slightly reduce both stack usage and remove unwinding prologue/epilogue etc. from such functions and improve our -Cno-prepopulate-passes codegen too.

perf: https://godbolt.org/z/eTPjj3hP3

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2026
@rustbot

rustbot commented May 16, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates

@Paladynee Paladynee force-pushed the lib/array-intoiter-spec-clone branch from 1ef1a4b to 5cec957 Compare May 16, 2026 08:31
@joboet

joboet commented May 28, 2026

Copy link
Copy Markdown
Member

@bors r+
r? joboet

Great, thanks!

@rust-bors

rust-bors Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5cec957 has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 May 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 28, 2026
…clone, r=joboet

lib: specialize Clone of array IntoIter

This PR adds the `TrivialClone` specialization to the `PolymorphicIter` type, which `array::IntoIter` uses. I also added another coretest for the default case (already existing test catches the specialized one).

There are no unwinding concerns since `TrivialClone` means cloning = copying and we never call `Clone::clone`.

`array:IntoIter` is being used on a lot of places in both `core` and in user code, and `array::IntoIter` (nor does its users) override `Clone` often and just delegate to the inner type `PolymorphicIter` which does not yet do the `TrivialClone` specialization and is burdened by the iterator and unwind safety shenanigans for all types, so this PR should address some of that. This should in turn slightly reduce both stack usage and remove unwinding prologue/epilogue etc. from such functions and improve our `-Cno-prepopulate-passes` codegen too.

perf: https://godbolt.org/z/eTPjj3hP3
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 28, 2026
…clone, r=joboet

lib: specialize Clone of array IntoIter

This PR adds the `TrivialClone` specialization to the `PolymorphicIter` type, which `array::IntoIter` uses. I also added another coretest for the default case (already existing test catches the specialized one).

There are no unwinding concerns since `TrivialClone` means cloning = copying and we never call `Clone::clone`.

`array:IntoIter` is being used on a lot of places in both `core` and in user code, and `array::IntoIter` (nor does its users) override `Clone` often and just delegate to the inner type `PolymorphicIter` which does not yet do the `TrivialClone` specialization and is burdened by the iterator and unwind safety shenanigans for all types, so this PR should address some of that. This should in turn slightly reduce both stack usage and remove unwinding prologue/epilogue etc. from such functions and improve our `-Cno-prepopulate-passes` codegen too.

perf: https://godbolt.org/z/eTPjj3hP3
rust-bors Bot pushed a commit that referenced this pull request May 28, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #153957 (Add bootstrap step for stdarch-verify)
 - #156634 (lib: specialize Clone of array IntoIter)
 - #157050 (Couple of changes to help with moving LTO to the link phase)
 - #156931 (Add splitting caveats to `{read,write}_volatile`)
 - #157071 (Fix `cfg` typo in rustdoc book)
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 29, 2026
@rust-bors

rust-bors Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: joboet
Duration: 3h 10m 13s
Pushing dc375db to main...

@rust-bors rust-bors Bot merged commit dc375db into rust-lang:main May 29, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone May 29, 2026
@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 cced03b (parent) -> dc375db (this PR)

Test differences

Show 4 test diffs

Stage 1

  • array::iterator_clone_spec: [missing] -> pass (J0)

Stage 2

  • array::iterator_clone_spec: [missing] -> pass (J1)

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

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard dc375db7d8df0aa450e622c529147c95eee756f5 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-mingw-1: 2h 18m -> 2h 56m (+27.8%)
  2. x86_64-gnu-gcc-core-tests: 6m 13s -> 7m 47s (+24.9%)
  3. dist-arm-linux-musl: 1h 20m -> 1h 40m (+24.2%)
  4. dist-android: 30m 1s -> 22m 52s (-23.8%)
  5. x86_64-msvc-ext2: 1h 56m -> 1h 29m (-23.2%)
  6. x86_64-gnu-miri: 1h 6m -> 1h 22m (+23.0%)
  7. x86_64-mingw-2: 2h 35m -> 2h 6m (-18.8%)
  8. dist-x86_64-apple: 2h 17m -> 1h 52m (-18.6%)
  9. dist-aarch64-apple: 1h 52m -> 2h 11m (+16.0%)
  10. aarch64-apple: 2h 38m -> 3h 2m (+14.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (dc375db): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (primary 5.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 511.528s -> 510.27s (-0.25%)
Artifact size: 400.68 MiB -> 400.65 MiB (-0.01%)

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants