Files
swift-collections/Sources/DequeModule/CMakeLists.txt
T
Karoy Lorentey 5cebba6f29 Refactor DrainableContainer/RangeReplaceableContainer/DynamicContainer
Range replacement operations generally need to invalidate all indices, and that means that we lose our position in the container after each insertion/removal, unless we happen to be using a container with looser index invalidation (such as arrays or deques).

A linked list is an example for a container type where insertions/removals need to invalidate all indices — as we need to track index validation using a single version counter that is stored in the list’s head. However, it would not be acceptable to lose our place whenever we insert a new item to the list; therefore, to mitigate the validation issue, this commit changes all range-replacement operations to return a valid index range to the affected items in the container.

This is a radical break from `RangeReplaceableCollection`. It fixes a long-standing defect with it, but it also makes it tricky to conform the same type to both protocol families, as the two require the “same” methods to return different types (`Void` vs `Range<Index>`).

Given that the LSG has intentionally diverged `UniqueArray.removeAll()` from RangeReplaceableCollection semantics, I expect this isn’t going to be an issue. For example, types with existing collection conformances can expose container views, mitigating such semantic differences.

To allow SubrangeConsumers to work without losing position, add a new protocol, `ContainerDrain` with a consuming `finalize` operation that returns a valid index in the resulting container state.

While we’re here, apply the API tweaks from SE-0527:
- Revert the `replace(removing:…:)` names, rolling back to `replaceSubrange(_:…:)` .
- Similarly, rename `consume(_:)` → `consumeSubrange(_:)`
- Rename `reallocate(capacity:)` → `setCapacity(_:)`.
2026-09-14 20:37:12 -07:00

75 lines
2.6 KiB
CMake

#[[
This source file is part of the Swift Collections Open Source Project
Copyright (c) 2021 - 2026 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
#]]
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name DequeModule)
add_library(DequeModule
${COLLECTIONS_DEQUE_SOURCES})
target_link_libraries(DequeModule PRIVATE
InternalCollectionsUtilities
SpanPreview)
set_target_properties(DequeModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
_install_target(DequeModule)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule)
endif()
target_sources(${module_name} PRIVATE
"_DequeSlot.swift"
"_UnsafeDequeSegments.swift"
"_UnsafeDequeHandle.swift"
"Deque/Deque+Codable.swift"
"Deque/Deque+Collection.swift"
"Deque/Deque+CustomReflectable.swift"
"Deque/Deque+Descriptions.swift"
"Deque/Deque+Equatable.swift"
"Deque/Deque+ExpressibleByArrayLiteral.swift"
"Deque/Deque+Extras.swift"
"Deque/Deque+Hashable.swift"
"Deque/Deque+Testing.swift"
"Deque/Deque._Storage.swift"
"Deque/Deque._UnsafeHandle.swift"
"Deque/Deque.swift"
"Deque/_DequeBuffer.swift"
"Deque/_DequeBufferHeader.swift"
"RigidDeque/RigidDeque+Append.swift"
"RigidDeque/RigidDeque+Consumption.swift"
"RigidDeque/RigidDeque+ContainerOperations.swift"
"RigidDeque/RigidDeque+Descriptions.swift"
"RigidDeque/RigidDeque+Equatable.swift"
"RigidDeque/RigidDeque+Hashable.swift"
"RigidDeque/RigidDeque+Initializers.swift"
"RigidDeque/RigidDeque+Insertions.swift"
"RigidDeque/RigidDeque+Iterable.swift"
"RigidDeque/RigidDeque+Prepend.swift"
"RigidDeque/RigidDeque+Removals.swift"
"RigidDeque/RigidDeque+Replacements.swift"
"RigidDeque/RigidDeque+Testing.swift"
"RigidDeque/RigidDeque.swift"
"UniqueDeque/UniqueDeque+Append.swift"
"UniqueDeque/UniqueDeque+Consumption.swift"
"UniqueDeque/UniqueDeque+ContainerOperations.swift"
"UniqueDeque/UniqueDeque+Deprecated.swift"
"UniqueDeque/UniqueDeque+Descriptions.swift"
"UniqueDeque/UniqueDeque+Equatable.swift"
"UniqueDeque/UniqueDeque+Hashable.swift"
"UniqueDeque/UniqueDeque+Initializers.swift"
"UniqueDeque/UniqueDeque+Insertions.swift"
"UniqueDeque/UniqueDeque+Iterable.swift"
"UniqueDeque/UniqueDeque+Prepend.swift"
"UniqueDeque/UniqueDeque+Removals.swift"
"UniqueDeque/UniqueDeque+Replacements.swift"
"UniqueDeque/UniqueDeque.swift"
)