Skip to content

Commit d477420

Browse files
committed
[stdlib] Set, Dictionary: Make Cocoa indices resilient for now
1 parent ee4ad7a commit d477420

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ extension Dictionary.Index: Comparable {
18971897
}
18981898

18991899
extension Dictionary.Index: Hashable {
1900-
@inlinable
1900+
@_effects(readonly) // FIXME(cocoa-index): Make inlinable
19011901
public func hash(into hasher: inout Hasher) {
19021902
#if _runtime(_ObjC)
19031903
switch _variant {

stdlib/public/core/DictionaryBridging.swift

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -450,24 +450,31 @@ extension _CocoaDictionary: _DictionaryBuffer {
450450
@usableFromInline
451451
internal typealias Value = AnyObject
452452

453-
@inlinable
453+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
454454
internal var startIndex: Index {
455-
return Index(self, startIndex: ())
455+
@_effects(releasenone)
456+
get {
457+
return Index(self, startIndex: ())
458+
}
456459
}
457460

458-
@inlinable
461+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
459462
internal var endIndex: Index {
460-
return Index(self, endIndex: ())
463+
@_effects(releasenone)
464+
get {
465+
return Index(self, endIndex: ())
466+
}
461467
}
462468

463-
@inlinable
469+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
470+
@_effects(releasenone)
464471
internal func index(after i: Index) -> Index {
465472
var i = i
466473
formIndex(after: &i)
467474
return i
468475
}
469476

470-
@usableFromInline
477+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
471478
@_effects(releasenone)
472479
internal func formIndex(after i: inout Index) {
473480
_precondition(i.base.object === self.object, "Invalid index")
@@ -476,7 +483,8 @@ extension _CocoaDictionary: _DictionaryBuffer {
476483
i.currentKeyIndex += 1
477484
}
478485

479-
@usableFromInline
486+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
487+
@_effects(releasenone)
480488
internal func index(forKey key: Key) -> Index? {
481489
// Fast path that does not involve creating an array of all keys. In case
482490
// the key is present, this lookup is a penalty for the slow path, but the
@@ -516,24 +524,24 @@ extension _CocoaDictionary: _DictionaryBuffer {
516524
return object.object(forKey: key)
517525
}
518526

519-
@inlinable
520-
@inline(__always)
527+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
528+
@_effects(releasenone)
521529
internal func lookup(_ index: Index) -> (key: Key, value: Value) {
522530
_precondition(index.base.object === self.object, "Invalid index")
523531
let key: Key = index.allKeys[index.currentKeyIndex]
524532
let value: Value = index.base.object.object(forKey: key)!
525533
return (key, value)
526534
}
527535

528-
@inlinable
529-
@inline(__always)
536+
@usableFromInline // FIXME(cocoa-index): Make inlinable
537+
@_effects(releasenone)
530538
func key(at index: Index) -> Key {
531539
_precondition(index.base.object === self.object, "Invalid index")
532540
return index.key
533541
}
534542

535-
@inlinable
536-
@inline(__always)
543+
@usableFromInline // FIXME(cocoa-index): Make inlinable
544+
@_effects(releasenone)
537545
func value(at index: Index) -> Value {
538546
_precondition(index.base.object === self.object, "Invalid index")
539547
let key = index.allKeys[index.currentKeyIndex]
@@ -557,7 +565,7 @@ extension _CocoaDictionary {
557565
}
558566

559567
extension _CocoaDictionary {
560-
@_fixed_layout // FIXME(sil-serialize-all)
568+
// FIXME(cocoa-index): Overhaul and make @_fixed_layout
561569
@usableFromInline
562570
internal struct Index {
563571
// Assumption: we rely on NSDictionary.getObjects when being
@@ -567,35 +575,29 @@ extension _CocoaDictionary {
567575

568576
/// A reference to the NSDictionary, which owns members in `allObjects`,
569577
/// or `allKeys`, for NSSet and NSDictionary respectively.
570-
@usableFromInline // FIXME(sil-serialize-all)
571578
internal let base: _CocoaDictionary
572579
// FIXME: swift-3-indexing-model: try to remove the cocoa reference, but
573580
// make sure that we have a safety check for accessing `allKeys`. Maybe
574581
// move both into the dictionary/set itself.
575582

576583
/// An unowned array of keys.
577-
@usableFromInline // FIXME(sil-serialize-all)
578584
internal var allKeys: _HeapBuffer<Int, AnyObject>
579585

580586
/// Index into `allKeys`
581-
@usableFromInline // FIXME(sil-serialize-all)
582587
internal var currentKeyIndex: Int
583588

584-
@inlinable // FIXME(sil-serialize-all)
585589
internal init(_ base: __owned _CocoaDictionary, startIndex: ()) {
586590
self.base = base
587591
self.allKeys = _stdlib_NSDictionary_allKeys(base.object)
588592
self.currentKeyIndex = 0
589593
}
590594

591-
@inlinable // FIXME(sil-serialize-all)
592595
internal init(_ base: __owned _CocoaDictionary, endIndex: ()) {
593596
self.base = base
594597
self.allKeys = _stdlib_NSDictionary_allKeys(base.object)
595598
self.currentKeyIndex = allKeys.value
596599
}
597600

598-
@inlinable // FIXME(sil-serialize-all)
599601
internal init(
600602
_ base: __owned _CocoaDictionary,
601603
_ allKeys: __owned _HeapBuffer<Int, AnyObject>,
@@ -628,7 +630,8 @@ extension _CocoaDictionary.Index {
628630
}
629631

630632
extension _CocoaDictionary.Index: Equatable {
631-
@inlinable
633+
@usableFromInline // FIXME(cocoa-index): Make inlinable
634+
@_effects(readonly)
632635
internal static func == (
633636
lhs: _CocoaDictionary.Index,
634637
rhs: _CocoaDictionary.Index
@@ -640,7 +643,8 @@ extension _CocoaDictionary.Index: Equatable {
640643
}
641644

642645
extension _CocoaDictionary.Index: Comparable {
643-
@inlinable
646+
@usableFromInline // FIXME(cocoa-index): Make inlinable
647+
@_effects(readonly)
644648
internal static func < (
645649
lhs: _CocoaDictionary.Index,
646650
rhs: _CocoaDictionary.Index

stdlib/public/core/Set.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ extension Set.Index: Hashable {
14181418
///
14191419
/// - Parameter hasher: The hasher to use when combining the components
14201420
/// of this instance.
1421-
@inlinable
1421+
@_effects(readonly) // FIXME(cocoa-index): Make inlinable
14221422
public func hash(into hasher: inout Hasher) {
14231423
#if _runtime(_ObjC)
14241424
switch _variant {

stdlib/public/core/SetBridging.swift

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,31 @@ extension _CocoaSet: _SetBuffer {
324324
@usableFromInline
325325
internal typealias Element = AnyObject
326326

327-
@inlinable
327+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
328328
internal var startIndex: Index {
329-
return Index(self, startIndex: ())
329+
@_effects(releasenone)
330+
get {
331+
return Index(self, startIndex: ())
332+
}
330333
}
331334

332-
@inlinable
335+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
333336
internal var endIndex: Index {
334-
return Index(self, endIndex: ())
337+
@_effects(releasenone)
338+
get {
339+
return Index(self, endIndex: ())
340+
}
335341
}
336342

337-
@inlinable
343+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
344+
@_effects(releasenone)
338345
internal func index(after i: Index) -> Index {
339346
var i = i
340347
formIndex(after: &i)
341348
return i
342349
}
343350

344-
@usableFromInline
351+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
345352
@_effects(releasenone)
346353
internal func formIndex(after i: inout Index) {
347354
_precondition(i.base.object === self.object, "Invalid index")
@@ -350,7 +357,8 @@ extension _CocoaSet: _SetBuffer {
350357
i.currentKeyIndex += 1
351358
}
352359

353-
@usableFromInline
360+
@usableFromInline // FIXME(cocoa-index): Should be inlinable
361+
@_effects(releasenone)
354362
internal func index(for element: AnyObject) -> Index? {
355363
// Fast path that does not involve creating an array of all keys. In case
356364
// the key is present, this lookup is a penalty for the slow path, but the
@@ -384,6 +392,7 @@ extension _CocoaSet: _SetBuffer {
384392
}
385393

386394
@usableFromInline
395+
@_effects(releasenone)
387396
internal func element(at i: Index) -> AnyObject {
388397
let element: AnyObject? = i.element
389398
_sanityCheck(element != nil, "Item not found in underlying NSSet")
@@ -392,7 +401,7 @@ extension _CocoaSet: _SetBuffer {
392401
}
393402

394403
extension _CocoaSet {
395-
@_fixed_layout // FIXME(sil-serialize-all)
404+
// FIXME(cocoa-index): Overhaul and make @_fixed_layout
396405
@usableFromInline
397406
internal struct Index {
398407
// Assumption: we rely on NSDictionary.getObjects when being
@@ -402,35 +411,29 @@ extension _CocoaSet {
402411

403412
/// A reference to the NSSet, which owns members in `allObjects`,
404413
/// or `allKeys`, for NSSet and NSDictionary respectively.
405-
@usableFromInline // FIXME(sil-serialize-all)
406414
internal let base: _CocoaSet
407415
// FIXME: swift-3-indexing-model: try to remove the cocoa reference, but
408416
// make sure that we have a safety check for accessing `allKeys`. Maybe
409417
// move both into the dictionary/set itself.
410418

411419
/// An unowned array of keys.
412-
@usableFromInline // FIXME(sil-serialize-all)
413420
internal var allKeys: _HeapBuffer<Int, AnyObject>
414421

415422
/// Index into `allKeys`
416-
@usableFromInline // FIXME(sil-serialize-all)
417423
internal var currentKeyIndex: Int
418424

419-
@inlinable // FIXME(sil-serialize-all)
420425
internal init(_ base: __owned _CocoaSet, startIndex: ()) {
421426
self.base = base
422427
self.allKeys = _stdlib_NSSet_allObjects(base.object)
423428
self.currentKeyIndex = 0
424429
}
425430

426-
@inlinable // FIXME(sil-serialize-all)
427431
internal init(_ base: __owned _CocoaSet, endIndex: ()) {
428432
self.base = base
429433
self.allKeys = _stdlib_NSSet_allObjects(base.object)
430434
self.currentKeyIndex = allKeys.value
431435
}
432436

433-
@inlinable // FIXME(sil-serialize-all)
434437
internal init(
435438
_ base: __owned _CocoaSet,
436439
_ allKeys: __owned _HeapBuffer<Int, AnyObject>,
@@ -463,7 +466,8 @@ extension _CocoaSet.Index {
463466
}
464467

465468
extension _CocoaSet.Index: Equatable {
466-
@inlinable
469+
@usableFromInline // FIXME(cocoa-index): Make inlinable
470+
@_effects(readonly)
467471
internal static func == (lhs: _CocoaSet.Index, rhs: _CocoaSet.Index) -> Bool {
468472
_precondition(lhs.base.object === rhs.base.object,
469473
"Comparing indexes from different sets")
@@ -472,7 +476,8 @@ extension _CocoaSet.Index: Equatable {
472476
}
473477

474478
extension _CocoaSet.Index: Comparable {
475-
@inlinable
479+
@usableFromInline // FIXME(cocoa-index): Make inlinable
480+
@_effects(readonly)
476481
internal static func < (lhs: _CocoaSet.Index, rhs: _CocoaSet.Index) -> Bool {
477482
_precondition(lhs.base.object === rhs.base.object,
478483
"Comparing indexes from different sets")

0 commit comments

Comments
 (0)