Skip to content

Commit 3fdec21

Browse files
authored
Merge pull request #77657 from kubamracek/embedded-more-stdlib
[embedded] Add back lazy collection operations, collection diffing and StaticBigInt to Embedded Stdlib
2 parents 9912c44 + cf75741 commit 3fdec21

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ split_embedded_sources(
7171
EMBEDDED DictionaryCasting.swift
7272
EMBEDDED DictionaryStorage.swift
7373
EMBEDDED DictionaryVariant.swift
74-
NORMAL DiscontiguousSlice.swift
75-
NORMAL DropWhile.swift
74+
EMBEDDED DiscontiguousSlice.swift
75+
EMBEDDED DropWhile.swift
7676
NORMAL Dump.swift
7777
EMBEDDED EmptyCollection.swift
7878
EMBEDDED Equatable.swift
7979
EMBEDDED ErrorType.swift
8080
EMBEDDED ExistentialCollection.swift
81-
NORMAL Filter.swift
82-
NORMAL FlatMap.swift
83-
NORMAL Flatten.swift
81+
EMBEDDED Filter.swift
82+
EMBEDDED FlatMap.swift
83+
EMBEDDED Flatten.swift
8484
EMBEDDED FloatingPoint.swift
8585
EMBEDDED Hashable.swift
8686
# WORKAROUND: This file name is not sorted alphabetically in the list because
@@ -95,7 +95,7 @@ split_embedded_sources(
9595
EMBEDDED InputStream.swift
9696
EMBEDDED IntegerParsing.swift
9797
EMBEDDED Integers.swift
98-
NORMAL Join.swift
98+
EMBEDDED Join.swift
9999
EMBEDDED KeyPath.swift
100100
EMBEDDED KeyValuePairs.swift
101101
EMBEDDED LazyCollection.swift
@@ -104,7 +104,7 @@ split_embedded_sources(
104104
EMBEDDED LifetimeManager.swift
105105
NORMAL Macros.swift
106106
EMBEDDED ManagedBuffer.swift
107-
NORMAL Map.swift
107+
EMBEDDED Map.swift
108108
EMBEDDED MemoryLayout.swift
109109
EMBEDDED UnicodeScalar.swift # ORDER DEPENDENCY: Must precede Mirrors.swift
110110
NORMAL Mirrors.swift
@@ -121,7 +121,7 @@ split_embedded_sources(
121121
EMBEDDED OutputStream.swift
122122
EMBEDDED Pointer.swift
123123
EMBEDDED Policy.swift
124-
NORMAL PrefixWhile.swift
124+
EMBEDDED PrefixWhile.swift
125125
NORMAL Prespecialize.swift
126126
NORMAL Print.swift
127127
EMBEDDED PtrAuth.swift
@@ -220,9 +220,9 @@ split_embedded_sources(
220220
### "NON-ESSENTIAL" SOURCES, LAYERED ON TOP OF THE "ESSENTIAL" ONES
221221
### -- PLEASE KEEP THIS LIST IN ALPHABETICAL ORDER ###
222222
EMBEDDED Availability.swift
223-
NORMAL CollectionDifference.swift
223+
EMBEDDED CollectionDifference.swift
224224
EMBEDDED CollectionOfOne.swift
225-
NORMAL Diffing.swift
225+
EMBEDDED Diffing.swift
226226
EMBEDDED Duration.swift
227227
EMBEDDED DurationProtocol.swift
228228
EMBEDDED FloatingPointRandom.swift
@@ -232,9 +232,9 @@ split_embedded_sources(
232232
NORMAL PlaygroundDisplay.swift
233233
NORMAL CommandLine.swift
234234
EMBEDDED SliceBuffer.swift
235-
NORMAL StaticBigInt.swift
235+
EMBEDDED StaticBigInt.swift
236236
EMBEDDED UInt128.swift
237-
NORMAL UnfoldSequence.swift
237+
EMBEDDED UnfoldSequence.swift
238238
EMBEDDED UnsafeBufferPointerSlice.swift
239239
NORMAL VarArgs.swift
240240
EMBEDDED Zip.swift

stdlib/public/core/CollectionDifference.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ extension CollectionDifference where ChangeElement: Hashable {
386386
}
387387
}
388388

389+
#if !$Embedded
389390
@available(SwiftStdlib 5.1, *)
390391
extension CollectionDifference.Change: Codable where ChangeElement: Codable {
391392
private enum _CodingKeys: String, CodingKey {
@@ -449,6 +450,7 @@ extension CollectionDifference: Codable where ChangeElement: Codable {
449450
try container.encode(removals, forKey: .removals)
450451
}
451452
}
453+
#endif
452454

453455
@available(SwiftStdlib 5.1, *)
454456
extension CollectionDifference: Sendable where ChangeElement: Sendable { }

stdlib/public/core/DiscontiguousSlice.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extension DiscontiguousSlice: Hashable where Base.Element: Hashable {
5353
}
5454

5555
@available(SwiftStdlib 6.0, *)
56+
@_unavailableInEmbedded
5657
extension DiscontiguousSlice: CustomStringConvertible {
5758
public var description: String {
5859
_makeCollectionDescription()
@@ -98,6 +99,7 @@ extension DiscontiguousSlice.Index: Comparable {
9899
}
99100

100101
@available(SwiftStdlib 6.0, *)
102+
@_unavailableInEmbedded
101103
extension DiscontiguousSlice.Index: CustomStringConvertible {
102104
public var description: String {
103105
"<base: \(String(reflecting: base)), rangeOffset: \(_rangeOffset)>"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-run-simple-swift(-parse-as-library -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: executable_test
5+
// REQUIRES: optimized_stdlib
6+
// REQUIRES: OS=macosx
7+
// REQUIRES: swift_feature_Embedded
8+
9+
@main
10+
struct Main {
11+
static func main() {
12+
let a = [1, 2, 3, 4, 5]
13+
let b = [ 2, 3, 4, 6]
14+
let diff = b.difference(from: a)
15+
for entry in diff {
16+
switch entry {
17+
case .remove(let offset, let element, _): print(".remove(\(offset), \(element))")
18+
case .insert(let offset, let element, _): print(".insert(\(offset), \(element))")
19+
}
20+
}
21+
// CHECK: .remove(4, 5)
22+
// CHECK: .remove(0, 1)
23+
// CHECK: .insert(3, 6)
24+
}
25+
}

test/embedded/lazy-collections.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ struct Main {
1616
[1, 2, 3].lazy.map { $0 * 2 }.forEach { print($0, terminator: " ") }
1717
print("")
1818
// CHECK: 2 4 6
19+
20+
[1, 2, 3].lazy.drop(while: { $0 < 2 }).forEach { print($0, terminator: " ") }
21+
print("")
22+
// CHECK: 2 3
23+
24+
[[1, 2, 3], [4, 5, 6]].lazy.joined().forEach { print($0, terminator: " ") }
25+
print("")
26+
// CHECK: 1 2 3 4 5 6
1927
}
2028
}

0 commit comments

Comments
 (0)