Skip to content

Commit d9417f5

Browse files
committed
---
yaml --- r: 243167 b: refs/heads/swift-5.0-branch c: edb8a73 h: refs/heads/master i: 243165: 4869b4c 243163: d631611 243159: f95feb2 243151: 57ba260 243135: 246bcdc
1 parent b73e7bd commit d9417f5

File tree

6 files changed

+166
-99
lines changed

6 files changed

+166
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2017-12-23-a: b7c074342459a645779f106c42bf4
643643
refs/heads/master-llvm-swift5-transition: 8ace18c8953afb3d7d94cf04cacc0b51a7e5f1e3
644644
"refs/heads/revert-12883-disable_modelio_test_ios": a77ae373b809a0d8cb460cf3d1585d618510d242
645645
refs/heads/revert-13597-master: cccee1df039d072215f9bddc2cbc1e32a8d5d5ee
646-
refs/heads/swift-5.0-branch: b95ba2507df833f8e172802f8057c0c5f5379288
646+
refs/heads/swift-5.0-branch: edb8a73203f08d2ceadf29bcd851b02bb8748f94
647647
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2017-12-23-a: b32214f7e04339dfada623b6b76dbebfb41e4541
648648
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2017-12-24-a: 1eb0be506c0744c7eff0550a10240286046e181d
649649
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2017-12-25-a: f35a91502bad0065c83d8760407c23be7b899f48

branches/swift-5.0-branch/stdlib/public/SwiftShims/GlobalObjects.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ struct _SwiftSetBodyStorage {
6060
void *keys;
6161
};
6262

63-
struct _SwiftEmptyDictionaryStorage {
63+
struct _SwiftEmptyDictionarySingleton {
6464
struct HeapObject header;
6565
struct _SwiftDictionaryBodyStorage body;
6666
__swift_uintptr_t entries;
6767
};
6868

69-
struct _SwiftEmptySetStorage {
69+
struct _SwiftEmptySetSingleton {
7070
struct HeapObject header;
7171
struct _SwiftSetBodyStorage body;
7272
__swift_uintptr_t entries;
7373
};
7474

7575
SWIFT_RUNTIME_STDLIB_API
76-
struct _SwiftEmptyDictionaryStorage _swiftEmptyDictionaryStorage;
76+
struct _SwiftEmptyDictionarySingleton _swiftEmptyDictionarySingleton;
7777

7878
SWIFT_RUNTIME_STDLIB_API
79-
struct _SwiftEmptySetStorage _swiftEmptySetStorage;
79+
struct _SwiftEmptySetSingleton _swiftEmptySetSingleton;
8080

8181
struct _SwiftHashingParameters {
8282
__swift_uint64_t seed0;
@@ -91,9 +91,9 @@ struct _SwiftHashingParameters _swift_stdlib_Hashing_parameters;
9191

9292
static_assert(std::is_pod<_SwiftEmptyArrayStorage>::value,
9393
"empty array type should be POD");
94-
static_assert(std::is_pod<_SwiftEmptyDictionaryStorage>::value,
94+
static_assert(std::is_pod<_SwiftEmptyDictionarySingleton>::value,
9595
"empty dictionary type should be POD");
96-
static_assert(std::is_pod<_SwiftEmptySetStorage>::value,
96+
static_assert(std::is_pod<_SwiftEmptySetSingleton>::value,
9797
"empty set type should be POD");
9898

9999
}} // extern "C", namespace swift

branches/swift-5.0-branch/stdlib/public/core/Dictionary.swift

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,14 +1807,13 @@ internal protocol _DictionaryBuffer {
18071807
@_fixed_layout // FIXME(sil-serialize-all)
18081808
@usableFromInline
18091809
@_objc_non_lazy_realization
1810-
internal class _RawNativeDictionaryStorage
1811-
: _SwiftNativeNSDictionary, _NSDictionaryCore
1812-
{
1810+
internal class _RawNativeDictionaryStorage: _SwiftNativeNSDictionary {
18131811
@usableFromInline // FIXME(sil-serialize-all)
18141812
@nonobjc
18151813
internal final var bucketCount: Int
18161814

18171815
@usableFromInline // FIXME(sil-serialize-all)
1816+
@objc
18181817
internal final var count: Int
18191818

18201819
@usableFromInline // FIXME(sil-serialize-all)
@@ -1838,36 +1837,36 @@ internal class _RawNativeDictionaryStorage
18381837
return UnsafeMutablePointer(Builtin.projectTailElems(self, UInt.self))
18391838
}
18401839

1841-
/// The empty singleton that is used for every single Dictionary that is
1842-
/// created without any elements. The contents of the storage should never
1843-
/// be mutated.
1844-
@inlinable
1845-
@nonobjc
1846-
internal static var empty: _RawNativeDictionaryStorage {
1847-
return Builtin.bridgeFromRawPointer(
1848-
Builtin.addressof(&_swiftEmptyDictionaryStorage))
1849-
}
1850-
18511840
// This type is made with allocWithTailElems, so no init is ever called.
18521841
// But we still need to have an init to satisfy the compiler.
18531842
@nonobjc
18541843
internal init(_doNotCallMe: ()) {
18551844
_sanityCheckFailure("Only create this by using the `empty` singleton")
18561845
}
1846+
}
18571847

1858-
#if _runtime(_ObjC)
1859-
//
1860-
// NSDictionary implementation, assuming Self is the empty singleton
1861-
//
1848+
/// The storage class for the singleton empty set.
1849+
/// The single instance of this class is created by the runtime.
1850+
@_fixed_layout
1851+
@usableFromInline
1852+
internal class _EmptyDictionarySingleton
1853+
: _RawNativeDictionaryStorage, _NSDictionaryCore {
1854+
@nonobjc
1855+
internal override init(_doNotCallMe: ()) {
1856+
_sanityCheckFailure("Only create this by using the `empty` singleton")
1857+
}
18621858

1863-
/// Get the NSEnumerator implementation for self.
1864-
/// _HashableTypedNativeDictionaryStorage overloads this to give
1865-
/// _NativeSelfNSEnumerator proper type parameters.
1859+
#if _runtime(_ObjC)
18661860
@objc
1867-
internal func enumerator() -> _NSEnumerator {
1868-
return _SwiftDictionaryNSEnumerator<AnyObject, AnyObject>(
1869-
_NativeDictionary(_storage: self))
1861+
internal required init(objects: UnsafePointer<AnyObject?>, count: Int) {
1862+
_sanityCheckFailure("Don't call this designated initializer")
18701863
}
1864+
#endif
1865+
1866+
#if _runtime(_ObjC)
1867+
//
1868+
// NSDictionary implementation
1869+
//
18711870

18721871
@objc(copyWithZone:)
18731872
internal func copy(with zone: _SwiftNSZone?) -> AnyObject {
@@ -1907,8 +1906,9 @@ internal class _RawNativeDictionaryStorage
19071906
return nil
19081907
}
19091908

1909+
@objc(keyEnumerator)
19101910
internal func keyEnumerator() -> _NSEnumerator {
1911-
return enumerator()
1911+
return _SwiftEmptyNSEnumerator()
19121912
}
19131913

19141914
@objc(getObjects:andKeys:count:)
@@ -1921,6 +1921,19 @@ internal class _RawNativeDictionaryStorage
19211921
#endif
19221922
}
19231923

1924+
1925+
extension _RawNativeDictionaryStorage {
1926+
/// The empty singleton that is used for every single Dictionary that is
1927+
/// created without any elements. The contents of the storage should never
1928+
/// be mutated.
1929+
@inlinable
1930+
@nonobjc
1931+
internal static var empty: _EmptyDictionarySingleton {
1932+
return Builtin.bridgeFromRawPointer(
1933+
Builtin.addressof(&_swiftEmptyDictionarySingleton))
1934+
}
1935+
}
1936+
19241937
// See the docs at the top of this file for a description of this type
19251938
@_fixed_layout // FIXME(sil-serialize-all)
19261939
@usableFromInline
@@ -1972,7 +1985,7 @@ internal class _TypedNativeDictionaryStorage<Key, Value>
19721985
@_fixed_layout // FIXME(sil-serialize-all)
19731986
@usableFromInline
19741987
final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
1975-
: _TypedNativeDictionaryStorage<Key, Value> {
1988+
: _TypedNativeDictionaryStorage<Key, Value>, _NSDictionaryCore {
19761989
// This type is made with allocWithTailElems, so no init is ever called.
19771990
// But we still need to have an init to satisfy the compiler.
19781991
@nonobjc
@@ -1990,14 +2003,19 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
19902003
return _NativeDictionary(_storage: self)
19912004
}
19922005

1993-
@objc
1994-
internal override func enumerator() -> _NSEnumerator {
2006+
@objc(keyEnumerator)
2007+
internal func keyEnumerator() -> _NSEnumerator {
19952008
return _SwiftDictionaryNSEnumerator<Key, Value>(
19962009
_NativeDictionary(_storage: self))
19972010
}
19982011

2012+
@objc(copyWithZone:)
2013+
internal func copy(with zone: _SwiftNSZone?) -> AnyObject {
2014+
return self
2015+
}
2016+
19992017
@objc(countByEnumeratingWithState:objects:count:)
2000-
internal override func countByEnumerating(
2018+
internal func countByEnumerating(
20012019
with state: UnsafeMutablePointer<_SwiftNSFastEnumerationState>,
20022020
objects: UnsafeMutablePointer<AnyObject>?, count: Int
20032021
) -> Int {
@@ -2059,13 +2077,13 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
20592077
}
20602078

20612079
@objc(objectForKey:)
2062-
override func objectFor(_ aKey: AnyObject) -> AnyObject? {
2080+
func objectFor(_ aKey: AnyObject) -> AnyObject? {
20632081
return getObjectFor(aKey)
20642082
}
20652083

20662084
// We also override the following methods for efficiency.
20672085
@objc(getObjects:andKeys:count:)
2068-
override func getObjects(
2086+
func getObjects(
20692087
_ objects: UnsafeMutablePointer<AnyObject>?,
20702088
andKeys keys: UnsafeMutablePointer<AnyObject>?,
20712089
count: Int) {
@@ -2414,20 +2432,23 @@ extension _NativeDictionary where Key: Hashable {
24142432
// or if we're the empty singleton.
24152433

24162434
// Temporary var for SOME type safety before a cast.
2417-
let nsSet: _NSDictionaryCore
2418-
2419-
if (_isBridgedVerbatimToObjectiveC(Key.self) &&
2420-
_isBridgedVerbatimToObjectiveC(Value.self)) ||
2421-
self._storage === _RawNativeDictionaryStorage.empty {
2422-
nsSet = self._storage
2435+
let nsDictionary: _NSDictionaryCore
2436+
2437+
if _storage === _RawNativeDictionaryStorage.empty {
2438+
nsDictionary = _RawNativeDictionaryStorage.empty
2439+
} else if _isBridgedVerbatimToObjectiveC(Key.self),
2440+
_isBridgedVerbatimToObjectiveC(Value.self) {
2441+
nsDictionary = unsafeDowncast(
2442+
_storage,
2443+
to: _HashableTypedNativeDictionaryStorage<Key, Value>.self)
24232444
} else {
2424-
nsSet = _SwiftDeferredNSDictionary(self)
2445+
nsDictionary = _SwiftDeferredNSDictionary(self)
24252446
}
24262447

24272448
// Cast from "minimal NSDictionary" to "NSDictionary"
24282449
// Note that if you actually ask Swift for this cast, it will fail.
24292450
// Never trust a shadow protocol!
2430-
return unsafeBitCast(nsSet, to: _NSDictionary.self)
2451+
return unsafeBitCast(nsDictionary, to: _NSDictionary.self)
24312452
}
24322453
#endif
24332454

branches/swift-5.0-branch/stdlib/public/core/Hashing.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@ internal struct _UnmanagedAnyObjectArray {
6767
}
6868
}
6969
}
70+
71+
#if _runtime(_ObjC)
72+
/// An NSEnumerator implementation returning zero elements. This is useful when
73+
/// a concrete element type is not recoverable from the empty singleton.
74+
final internal class _SwiftEmptyNSEnumerator
75+
: _SwiftNativeNSEnumerator, _NSEnumerator {
76+
internal override required init() {}
77+
78+
@objc
79+
internal func nextObject() -> AnyObject? {
80+
return nil
81+
}
82+
83+
@objc(countByEnumeratingWithState:objects:count:)
84+
internal func countByEnumerating(
85+
with state: UnsafeMutablePointer<_SwiftNSFastEnumerationState>,
86+
objects: UnsafeMutablePointer<AnyObject>,
87+
count: Int
88+
) -> Int {
89+
// Even though we never do anything in here, we need to update the
90+
// state so that callers know we actually ran.
91+
var theState = state.pointee
92+
if theState.state == 0 {
93+
theState.state = 1 // Arbitrary non-zero value.
94+
theState.itemsPtr = AutoreleasingUnsafeMutablePointer(objects)
95+
theState.mutationsPtr = _fastEnumerationStorageMutationsPtr
96+
}
97+
state.pointee = theState
98+
return 0
99+
}
100+
}
101+
#endif

0 commit comments

Comments
 (0)