9 Commits
Author SHA1 Message Date
844289ac45 fix: guard InputSpan methods against nil base address in debug builds (#795)
* [BorrowingMapProducer] Fix skip(by:) hanging at end of iterator

When a BorrowingMapProducer's Failure is not Never, skip(by:) drove a
loop over nextSpan calls. Once the base iterator was exhausted,
nextSpan kept returning an empty span (count == 0), so the counter
never decremented and the loop ran forever.

Add a guard that exits the loop when the span is empty, matching the
skip(by:) contract: return with the remaining count when the iterator
runs out of elements before n reaches 0.

Adds a regression test that builds a RigidArray from a
mapError+map chain. RigidArray.init(capacity:from:) calls _expectEnd,
which exercises exactly the exhausted-iterator code path.

Fixes #773

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: guard InputSpan methods against nil base address in debug builds

removeFirst(_:), prepend(repeating:count:), and consumePrefix(upTo:) each
call _unsafeRawAddressOfSlot(uncheckedOffset:) before checking whether
there is anything to do.  That helper calls _start(), which calls
_pointer.unsafelyUnwrapped and traps in debug builds when the base
address is nil — which happens for InputSpan(), for empty ranges handed
to consumeSubrange closures, and for SubrangeConsumer drains once the
range is exhausted.

Add an early return for the zero-work case in each method, the same
pattern that removeAll() and deinit already use.  Release builds were
unaffected in practice because unsafelyUnwrapped skips the nil check
under -O, but the behaviour is formally undefined; this fix makes both
build modes consistent and safe.

Fixes #788

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Resolve conflict

Co-authored-by: Karoy Lorentey <klorentey@apple.com>

* Prefer guard for succinct exit conditionals

This follows our preferred coding style, and also syncs this code with OutputSpan's implementation in the stdlib.

Co-authored-by: Karoy Lorentey <klorentey@apple.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-10-22 18:10:28 -07:00
Guillaume Lessard ff3c6e58ce Empty OutputSpan before closure can throw in _consumeAll() 2026-10-16 17:58:04 -07:00
Guillaume Lessard 4ff4e75436 Fix implementation of removeAll() 2026-10-14 17:28:49 -07:00
Karoy Lorentey 1b936eda0b Disable strict memory safety on older toolchains
It would take too much effort to try to mitigate stdlib differences.

Fix low-hanging warnings, but turn off `.strictMemorySafety` on older toolchains by splitting the package manifest.
2026-10-01 13:40:27 -07:00
Karoy Lorentey d07dc32dfa Sources: Add unsafe keywords where needed 2026-10-01 11:14:29 -07:00
Karoy Lorentey 537bf9cbfb Drop support for Swift 6.0 and 6.1
This allows the use of Span types without `#if compiler` guards.
2026-09-21 13:34:39 -07:00
Karoy Lorentey d392f0cbff MutableContainer: Add tests; resolve issues uncovered 2026-09-21 09:54:29 -07:00
Karoy Lorentey c031de73d0 MutableContainer: Add some bulk update operations 2026-09-16 19:58:28 -07:00
Karoy Lorentey 842f125c47 Invert dependencies to ContainersPreview, moving all container APIs there
- Move `InputSpan` into its own module, `SpanPreview`. Add dependencies to it.
- Invert dependencies to `ContainersPreview`, so that no production target imports it, but it now depends on its previous dependents.
- Move all generic APIs and conformances using `Producer`/`Drain`/`Container` to the `ContainersPreview` module.
- Remove `UnstableContainersPreview` conditions around `Iterable` APIs

In summary, importing `BasicContainers` and `DequeModule` continue to get us the basic definitions for `RigidArray`, `UniqueSet`, `RigidDeque` etc., without most of their unstable APIs. (With the exception of core APIs that require `InputSpan`.)

To get any API that uses an unstable protocol like `Container` or `Drain`, we’ll now need to import `ContainersPreview` in addition to the type-defining module.

This will provide a slightly less horrible migration path when (if) the container/producer protocol family gets adopted/adapted into the stdlib.
2026-08-25 18:29:58 -07:00