* [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>
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.
- 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.