Skip to content

Commit 0c2cac2

Browse files
authored
Merge pull request #62111 from apple/egorzhdan/disable-non-rac-cxx-sequence
[cxx-interop] Disable auto-conformance to `CxxSequence` for non-random-access collections
2 parents f7414ed + 40650ba commit 0c2cac2

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ void swift::conformToCxxSequenceIfNeeded(
381381
impl.addSynthesizedTypealias(decl, ctx.Id_Iterator, iteratorTy);
382382
impl.addSynthesizedTypealias(decl, ctx.getIdentifier("RawIterator"),
383383
rawIteratorTy);
384-
impl.addSynthesizedProtocolAttrs(decl, {KnownProtocolKind::CxxSequence});
384+
// Not conforming the type to CxxSequence protocol here:
385+
// The current implementation of CxxSequence triggers extra copies of the C++
386+
// collection when creating a CxxIterator instance. It needs a more efficient
387+
// implementation, which is not possible with the existing Swift features.
388+
// impl.addSynthesizedProtocolAttrs(decl, {KnownProtocolKind::CxxSequence});
385389

386390
// Try to conform to CxxRandomAccessCollection if possible.
387391

test/Interop/Cxx/stdlib/overlay/custom-collection-module-interface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=CustomSequence -source-filename=x -I %S/Inputs -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s
22

3-
// CHECK: struct SimpleArrayWrapper : CxxRandomAccessCollection, CxxSequence {
3+
// CHECK: struct SimpleArrayWrapper : CxxRandomAccessCollection {
44
// CHECK: typealias Element = UnsafePointer<Int32>.Pointee
55
// CHECK: typealias Iterator = CxxIterator<SimpleArrayWrapper>
66
// CHECK: typealias RawIterator = UnsafePointer<Int32>
77
// CHECK: }
88

9-
// CHECK: struct SimpleCollectionNoSubscript : CxxRandomAccessCollection, CxxSequence {
9+
// CHECK: struct SimpleCollectionNoSubscript : CxxRandomAccessCollection {
1010
// CHECK: typealias Element = ConstRACIterator.Pointee
1111
// CHECK: typealias Iterator = CxxIterator<SimpleCollectionNoSubscript>
1212
// CHECK: typealias RawIterator = SimpleCollectionNoSubscript.iterator
1313
// CHECK: }
1414

15-
// CHECK: struct SimpleCollectionReadOnly : CxxRandomAccessCollection, CxxSequence {
15+
// CHECK: struct SimpleCollectionReadOnly : CxxRandomAccessCollection {
1616
// CHECK: typealias Element = ConstRACIteratorRefPlusEq.Pointee
1717
// CHECK: typealias Iterator = CxxIterator<SimpleCollectionReadOnly>
1818
// CHECK: typealias RawIterator = SimpleCollectionReadOnly.iterator

test/Interop/Cxx/stdlib/overlay/custom-sequence-module-interface.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=CustomSequence -source-filename=x -I %S/Inputs -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s
22

3-
// CHECK: struct SimpleSequence : CxxSequence {
3+
// CHECK: struct SimpleSequence {
44
// CHECK: typealias Element = ConstIterator.Pointee
55
// CHECK: typealias Iterator = CxxIterator<SimpleSequence>
66
// CHECK: typealias RawIterator = ConstIterator
77
// CHECK: }
88

9-
// CHECK: struct SimpleSequenceWithOutOfLineEqualEqual : CxxSequence {
9+
// CHECK: struct SimpleSequenceWithOutOfLineEqualEqual {
1010
// CHECK: typealias Element = ConstIteratorOutOfLineEq.Pointee
1111
// CHECK: typealias Iterator = CxxIterator<SimpleSequenceWithOutOfLineEqualEqual>
1212
// CHECK: typealias RawIterator = ConstIteratorOutOfLineEq
1313
// CHECK: }
1414

15-
// CHECK: struct SimpleArrayWrapperNullableIterators : CxxSequence {
15+
// CHECK: struct SimpleArrayWrapperNullableIterators {
1616
// CHECK: typealias Element = Optional<UnsafePointer<Int32>>.Pointee
1717
// CHECK: typealias Iterator = CxxIterator<SimpleArrayWrapperNullableIterators>
1818
// CHECK: typealias RawIterator = UnsafePointer<Int32>?
1919
// CHECK: }
2020

21-
// CHECK: struct SimpleEmptySequence : CxxSequence {
21+
// CHECK: struct SimpleEmptySequence {
2222
// CHECK: typealias Element = Optional<UnsafePointer<Int32>>.Pointee
2323
// CHECK: typealias Iterator = CxxIterator<SimpleEmptySequence>
2424
// CHECK: typealias RawIterator = UnsafePointer<Int32>?
2525
// CHECK: }
2626

27-
// CHECK: struct HasMutatingBeginEnd : CxxSequence {
27+
// CHECK: struct HasMutatingBeginEnd {
2828
// CHECK: typealias Element = ConstIterator.Pointee
2929
// CHECK: typealias Iterator = CxxIterator<HasMutatingBeginEnd>
3030
// CHECK: typealias RawIterator = ConstIterator

test/Interop/Cxx/stdlib/overlay/custom-sequence-typechecker.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop
22

3+
// REQUIRES: rdar102364960
4+
35
import CustomSequence
46

57
func checkIntSequence<S>(_ seq: S) where S: Sequence, S.Element == Int32 {

test/Interop/Cxx/stdlib/overlay/custom-sequence.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// REQUIRES: executable_test
44
// REQUIRES: OS=macosx || OS=linux-gnu
55

6+
// REQUIRES: rdar102364960
7+
68
import StdlibUnittest
79
import CustomSequence
810

0 commit comments

Comments
 (0)