Skip to content

More exploration of ownership-aware container/iterator algorithms#605

Merged
lorentey merged 10 commits intoapple:mainfrom
lorentey:container-upgrades
Mar 17, 2026
Merged

More exploration of ownership-aware container/iterator algorithms#605
lorentey merged 10 commits intoapple:mainfrom
lorentey:container-upgrades

Conversation

@lorentey
Copy link
Copy Markdown
Member

  • Add implementations of .filter on BorrowingIteratorProtocol, Container, Producer and Drain.
  • Conform the new ownership-aware array and deque types to RandomAccessContainer, DynamicContainer and MutableContainer.
  • Fix over-constrained Producer conformances on lazy algorithms
  • Add a BorrowingIteratorProtocol.copy() algorithm that turns borrowing iterators into producers by copying items.
  • Generalize Producer.collect(into:) to allow populating fixed-capacity targets

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've added benchmarks covering new functionality (if appropriate).
  • I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
  • I've updated the documentation if necessary.

…thods should consume their input

(Because they are running it to completion.)
…eReplaceableContainer

This is getting into dangerous territory, as RRC allows fixed-capacity conformers, where appending a producer must be done extremely carefully. We should be using bulk append operations, but never ask the container to reserve any more slots than the producer is able to actually generate. (When the fixed-capacity RRC was carefully sized to precisely fit the generator’s contents, asking it to provide space for even a single item more would lead to a runtime trap.)

Additionally, the algorithm should work (and be reasonably efficient) even if the RRC happens to be a dynamically sizing container type.

It would be nice if we had a Producer protocol flavor with an exact count; failing that, we can still do this with a bit of acrobatics, as implemented here.  (The `DynamicContainer.append(from:)` algorithm was already implemented this way in a previous commit, with an eye towards this case.)
@lorentey lorentey added this to the 1.4.1 milestone Mar 17, 2026
@lorentey lorentey force-pushed the container-upgrades branch from 0089a80 to f84e5bc Compare March 17, 2026 22:29
…on 6.2 toolchains

“Work” in this case means that they can be enabled without breaking the build — not necessarily that all features are available.

Swift 6.2 is highly prone to runtime crashes in `swift_getTypeByMangledName` in generic code that uses ownership features. Swift 6.3 will resolve that.
@lorentey lorentey force-pushed the container-upgrades branch from f84e5bc to 8f88cce Compare March 17, 2026 22:38
@lorentey lorentey merged commit f9f3c09 into apple:main Mar 17, 2026
41 of 42 checks passed
@lorentey lorentey deleted the container-upgrades branch March 17, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant