Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Runtimes/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_library(swiftCore
BidirectionalCollection.swift
Bitset.swift
Bool.swift
BorrowIteratorProtocol.swift
BridgeObjectiveC.swift
BridgeStorage.swift
BridgingBuffer.swift
Expand Down Expand Up @@ -93,6 +94,7 @@ add_library(swiftCore
InputStream.swift
IntegerParsing.swift
Integers.swift
Iterable.swift
Join.swift
KeyPath.swift
KeyValuePairs.swift
Expand Down
3 changes: 2 additions & 1 deletion Runtimes/Core/cmake/modules/ExperimentalFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ add_compile_options(
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature BitwiseCopyable>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Extern>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature AllowUnsafeAttribute>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature ValueGenerics>")
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature ValueGenerics>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Lifetimes>")
8 changes: 7 additions & 1 deletion benchmark/single-source/DataBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,20 @@ let large = sampleData(.large)
let array809 = byteArray(size: 809)

struct Count0<S: Sequence> : Sequence {
@available(macOS 9999, *)
public typealias BorrowingIterator = BorrowingIteratorAdapter<S.Iterator>

let base: S
init (_ base:S) { self.base = base }
func makeIterator() -> S.Iterator { return base.makeIterator() }
var underestimatedCount: Int { return 0 }
}

struct Bytes: Sequence, IteratorProtocol {
let count: Int
@available(macOS 9999, *)
public typealias BorrowingIterator = BorrowingIteratorAdapter<Self>

let count: Int
let exact: Bool
var i: Int = 0
init(count: Int, exact: Bool) {
Expand Down
9 changes: 5 additions & 4 deletions stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ function(_add_target_variant_swift_compile_flags
if(SWIFT_STDLIB_OS_VERSIONING)
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
endif()

if(SWIFT_STDLIB_STATIC_PRINT)
list(APPEND result "-D" "SWIFT_STDLIB_STATIC_PRINT")
endif()

if(SWIFT_STDLIB_ENABLE_UNICODE_DATA)
list(APPEND result "-D" "SWIFT_STDLIB_ENABLE_UNICODE_DATA")
endif()

if(SWIFT_STDLIB_ENABLE_VECTOR_TYPES)
list(APPEND result "-D" "SWIFT_STDLIB_ENABLE_VECTOR_TYPES")
endif()
Expand Down Expand Up @@ -612,7 +612,7 @@ function(_compile_swift_files
list(APPEND swift_flags "-autolink-force-load")
endif()

# Don't need to link runtime compatibility libraries for older runtimes
# Don't need to link runtime compatibility libraries for older runtimes
# into the new runtime.
if (SWIFTFILE_IS_STDLIB OR SWIFTFILE_IS_SDK_OVERLAY)
list(APPEND swift_flags "-runtime-compatibility-version" "none")
Expand Down Expand Up @@ -640,6 +640,7 @@ function(_compile_swift_files
list(APPEND swift_flags "-enable-experimental-feature" "LifetimeDependence")
list(APPEND swift_flags "-enable-experimental-feature" "InoutLifetimeDependence")
list(APPEND swift_flags "-enable-experimental-feature" "LifetimeDependenceMutableAccessors")
list(APPEND swift_flags "-enable-experimental-feature" "Lifetimes")

list(APPEND swift_flags "-enable-upcoming-feature" "MemberImportVisibility")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public enum UnderestimatedCountBehavior {
///
/// This sequence is consumed when its generator is advanced.
public struct MinimalSequence<T> : Sequence, CustomDebugStringConvertible {
public typealias Element = T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it might be worth just renaming the generic parameter T to Element, for readability in any case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree... except that it was actually useful that this caught something that stopped working for other reasons (which I guess means we should have test instead)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider this PR probably not landable until this type alias is no longer needed...


public init<S : Sequence>(
elements: S,
underestimatedCount: UnderestimatedCountBehavior = .value(0)
Expand Down
5 changes: 4 additions & 1 deletion stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,8 @@ public enum StdLibVersion: String {
case stdlib_6_0 = "6.0"
case stdlib_6_1 = "6.1"
case stdlib_6_2 = "6.2"

case stdlib_6_3 = "6.3"

var isAvailable: Bool {
switch self {
case .stdlib_5_7:
Expand All @@ -2258,6 +2259,8 @@ public enum StdLibVersion: String {
return if #available(SwiftStdlib 6.1, *) { true } else { false }
case .stdlib_6_2:
return if #available(SwiftStdlib 6.2, *) { true } else { false }
case .stdlib_6_3:
return if #available(SwiftStdlib 6.3, *) { true } else { false }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ internal struct Section {

/// Holds the addresses and sizes of sections related to reflection.
internal struct ReflectionInfo : Sequence {
internal typealias Element = Section?
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
internal typealias BorrowingIterator = BorrowingIteratorAdapter<AnyIterator<Section?>>

/// The name of the loaded image.
internal let imageName: String

Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/Concurrency/Deque/Deque+Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension _Deque: Sequence {
// This custom implementation performs direct storage access to eliminate any
// and all index validation overhead. It also optimizes away repeated
// conversions from indices to storage slots.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
internal typealias BorrowingIterator = BorrowingIteratorAdapter<Iterator>

/// An iterator over the members of a deque.
struct Iterator: IteratorProtocol {
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/RuntimeModule/Base64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public struct Base64Encoder<S: Sequence>: Sequence
public struct Base64Decoder<S: Sequence>: Sequence
where S.Element == UTF8.CodeUnit
{
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public typealias BorrowingIterator = BorrowingIteratorAdapter<Iterator>
public typealias Element = UInt8

var source: S
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/RuntimeModule/Elf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,8 @@ final class ElfImage<SomeElfTraits: ElfTraits>
}

struct Notes: Sequence {
typealias Element = Note

var image: ElfImage<Traits>

struct NoteIterator: IteratorProtocol {
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/RuntimeModule/FramePointerUnwinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
public typealias Context = C
public typealias MemoryReader = M
public typealias Address = Context.Address
public typealias Element = RichFrame<Address>

var pc: Address
var fp: Address
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/StringProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(swift_string_processing_compile_flags)
# will be built with library evolution.
list(APPEND swift_string_processing_compile_flags
"-DRESILIENT_LIBRARIES")
list(APPEND swift_string_processing_compile_flags "-Xfrontend" "-disable-availability-checking")

if(SWIFT_BUILD_STATIC_STDLIB)
# Explicitly autolink swift_RegexParser because it's imported with @_implementationOnly
Expand Down
36 changes: 29 additions & 7 deletions stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ extension Array: _ArrayProtocol {
@inlinable // FIXME(inline-always)
@inline(__always)
get {
return _buffer.owner
return _buffer.owner
}
}

Expand Down Expand Up @@ -814,7 +814,7 @@ extension Array: RandomAccessCollection, MutableCollection {
}
}
}

/// The number of elements in the array.
@inlinable
@_semantics("array.get_count")
Expand Down Expand Up @@ -1249,14 +1249,14 @@ extension Array: RangeReplaceableCollection {
let oldCount = _buffer.mutableCount
let startNewElements = unsafe _buffer.mutableFirstElementAddress + oldCount
let buf = unsafe UnsafeMutableBufferPointer(
start: startNewElements,
start: startNewElements,
count: _buffer.mutableCapacity - oldCount)

var (remainder,writtenUpTo) = unsafe buf.initialize(from: newElements)

// trap on underflow from the sequence's underestimate:
let writtenCount = unsafe buf.distance(from: buf.startIndex, to: writtenUpTo)
_precondition(newElementsCount <= writtenCount,
_precondition(newElementsCount <= writtenCount,
"newElements.underestimatedCount was an overestimate")
// can't check for overflow as sequences can underestimate

Expand Down Expand Up @@ -1440,7 +1440,7 @@ extension Array: RangeReplaceableCollection {
return try unsafe body(bufferPointer)
}
}

@inlinable
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
if let n = _buffer.requestNativeBuffer() {
Expand Down Expand Up @@ -1799,7 +1799,7 @@ extension Array {
// a precondition and Array never lies about its count.
guard var p = buffer.baseAddress
else { _preconditionFailure("Attempt to copy contents into nil buffer pointer") }
_precondition(self.count <= buffer.count,
_precondition(self.count <= buffer.count,
"Insufficient space allocated to copy array contents")

if let s = unsafe _baseAddressIfContiguous {
Expand Down Expand Up @@ -2160,3 +2160,25 @@ internal struct _ArrayAnyHashableBox<Element: Hashable>
}

extension Array: @unchecked Sendable where Element: Sendable { }

// FIXME: This should be accepted, but we get the following:
// error: type 'Array<Element>' does not conform to protocol 'Iterable'
// note: multiple matching functions named '_customContainsEquatableElement' with type '(borrowing Array<Element>.Element) -> Bool?' (aka '(borrowing Element) -> Optional<Bool>')

// @available(SwiftStdlib 6.3, *)
// extension Array: Iterable {
// public typealias BorrowIterator = Span<Element>.BorrowIterator

// @_alwaysEmitIntoClient
// @_transparent
// public var estimatedCount: EstimatedCount {
// .exactly(count)
// }

// @_alwaysEmitIntoClient
// @_lifetime(borrow self)
// @_transparent
// public func startBorrowIteration() -> Span<Element> {
// self.span
// }
// }
Loading