Skip to content

Commit 3214627

Browse files
author
Lance Parker
authored
[stdlib] Isolate Array bridging behavior for ABI stability (#14717)
Isolate Array bridging behavior for ABI stability
1 parent 512beb2 commit 3214627

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,15 @@ extension ${Self} {
23812381
%end
23822382

23832383
#if _runtime(_ObjC)
2384+
// We isolate the bridging of the Cocoa Array -> Swift Array here so that
2385+
// in the future, we can eagerly bridge the Cocoa array. We need this function
2386+
// to do the bridging in an ABI safe way. Even though this looks useless,
2387+
// DO NOT DELETE!
2388+
@_versioned internal
2389+
func _bridgeCocoaArray<T>(_ _immutableCocoaArray: _NSArrayCore) -> Array<T> {
2390+
return Array(_buffer: _ArrayBuffer(nsArray: _immutableCocoaArray))
2391+
}
2392+
23842393
extension Array {
23852394
@_inlineable
23862395
public // @SPI(Foundation)
@@ -2414,7 +2423,7 @@ extension Array {
24142423
/// is a reference type).
24152424
@_inlineable
24162425
public init(_immutableCocoaArray: _NSArrayCore) {
2417-
self = Array(_buffer: _ArrayBuffer(nsArray: _immutableCocoaArray))
2426+
self = _bridgeCocoaArray(_immutableCocoaArray)
24182427
}
24192428
}
24202429
#endif

0 commit comments

Comments
 (0)