Skip to content

Commit 3c74c0f

Browse files
authored
[stdlib] Change the signature of Dictionary’s bulk initializer (#23758)
The initializer was originally introduced without proper availability; in #23643, we fixed this by applying the `@_alwaysEmitIntoClient` attribute. However, this had the unfortunate side-effect that the symbol disappeared from `libswiftCore.dylib`, which somehow confuses some simulator builds. Try to figure out what’s happening by replacing the third closure argument with an integer return value. This changes the mangled name of the bulk initializer, which should make it more obvious how/why these builds fail. rdar://problem/49479386
1 parent 6fcd874 commit 3c74c0f

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

stdlib/public/Darwin/Foundation/NSDictionary.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ extension Dictionary : _ObjectiveCBridgeable {
238238
let handleDuplicates = (Key.self == String.self)
239239

240240
result = Dictionary(_unsafeUninitializedCapacity: numElems,
241-
allowingDuplicates: handleDuplicates) { (keys, vals, outCount) in
241+
allowingDuplicates: handleDuplicates) { keys, vals in
242242

243243
let objectKeys = UnsafeMutableRawPointer(mutating:
244244
keys.baseAddress!).assumingMemoryBound(to: AnyObject.self)
@@ -253,7 +253,7 @@ extension Dictionary : _ObjectiveCBridgeable {
253253
_forceBridge(objectKeys, count: numElems, to: Key.self)
254254
_forceBridge(objectVals, count: numElems, to: Value.self)
255255

256-
outCount = numElems
256+
return numElems
257257
}
258258
}
259259
}
@@ -293,7 +293,7 @@ extension Dictionary : _ObjectiveCBridgeable {
293293
let handleDuplicates = (Key.self == String.self)
294294

295295
let tmpResult = Dictionary(_unsafeUninitializedCapacity: numElems,
296-
allowingDuplicates: handleDuplicates) { (keys, vals, outCount) in
296+
allowingDuplicates: handleDuplicates) { keys, vals in
297297

298298
let objectKeys = UnsafeMutableRawPointer(mutating:
299299
keys.baseAddress!).assumingMemoryBound(to: AnyObject.self)
@@ -314,7 +314,7 @@ extension Dictionary : _ObjectiveCBridgeable {
314314
Key.self)).deinitialize(count: numElems)
315315
}
316316
}
317-
outCount = success ? numElems : 0
317+
return success ? numElems : 0
318318
}
319319

320320
result = success ? tmpResult : nil

stdlib/public/core/DictionaryBuilder.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,14 @@ extension Dictionary {
7272
/// closure must return the count of the initialized elements, starting at
7373
/// the beginning of the buffer.
7474
@_alwaysEmitIntoClient // Introduced in 5.1
75-
@inlinable
7675
public // SPI(Foundation)
7776
init(
7877
_unsafeUninitializedCapacity capacity: Int,
7978
allowingDuplicates: Bool,
8079
initializingWith initializer: (
8180
_ keys: UnsafeMutableBufferPointer<Key>,
82-
_ values: UnsafeMutableBufferPointer<Value>,
83-
_ initializedCount: inout Int
84-
) -> Void
81+
_ values: UnsafeMutableBufferPointer<Value>
82+
) -> Int
8583
) {
8684
self.init(_native: _NativeDictionary(
8785
_unsafeUninitializedCapacity: capacity,
@@ -92,23 +90,19 @@ extension Dictionary {
9290

9391
extension _NativeDictionary {
9492
@_alwaysEmitIntoClient // Introduced in 5.1
95-
@inlinable
9693
internal init(
9794
_unsafeUninitializedCapacity capacity: Int,
9895
allowingDuplicates: Bool,
9996
initializingWith initializer: (
10097
_ keys: UnsafeMutableBufferPointer<Key>,
101-
_ values: UnsafeMutableBufferPointer<Value>,
102-
_ initializedCount: inout Int
103-
) -> Void
98+
_ values: UnsafeMutableBufferPointer<Value>
99+
) -> Int
104100
) {
105101
self.init(capacity: capacity)
106-
var initializedCount = 0
107-
initializer(
102+
let initializedCount = initializer(
108103
UnsafeMutableBufferPointer(start: _keys, count: capacity),
109-
UnsafeMutableBufferPointer(start: _values, count: capacity),
110-
&initializedCount)
111-
_precondition(count >= 0 && count <= capacity)
104+
UnsafeMutableBufferPointer(start: _values, count: capacity))
105+
_precondition(initializedCount >= 0 && initializedCount <= capacity)
112106
_storage._count = initializedCount
113107

114108
// Hash initialized elements and move each of them into their correct

validation-test/stdlib/Dictionary.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,14 +5700,14 @@ DictionaryTestSuite.test("BulkLoadingInitializer.Unique") {
57005700
let d1 = Dictionary<TestKeyTy, TestEquatableValueTy>(
57015701
_unsafeUninitializedCapacity: c,
57025702
allowingDuplicates: false
5703-
) { keys, values, count in
5703+
) { keys, values in
57045704
let k = keys.baseAddress!
57055705
let v = values.baseAddress!
57065706
for i in 0 ..< c {
57075707
(k + i).initialize(to: TestKeyTy(i))
57085708
(v + i).initialize(to: TestEquatableValueTy(i))
5709-
count += 1
57105709
}
5710+
return c
57115711
}
57125712

57135713
let d2 = Dictionary(
@@ -5727,14 +5727,14 @@ DictionaryTestSuite.test("BulkLoadingInitializer.Nonunique") {
57275727
let d1 = Dictionary<TestKeyTy, TestEquatableValueTy>(
57285728
_unsafeUninitializedCapacity: c,
57295729
allowingDuplicates: true
5730-
) { keys, values, count in
5730+
) { keys, values in
57315731
let k = keys.baseAddress!
57325732
let v = values.baseAddress!
57335733
for i in 0 ..< c {
57345734
(k + i).initialize(to: TestKeyTy(i / 2))
57355735
(v + i).initialize(to: TestEquatableValueTy(i / 2))
5736-
count += 1
57375736
}
5737+
return c
57385738
}
57395739

57405740
let d2 = Dictionary(

0 commit comments

Comments
 (0)