Skip to content

Commit 8acfbd8

Browse files
authored
Merge pull request #67866 from apple/egorzhdan/cxx-mutable-rac-iter
[cxx-interop] Add `UnsafeCxxMutableRandomAccessIterator` protocol
2 parents cd64d52 + 3723ff1 commit 8acfbd8

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ PROTOCOL(CxxVector)
119119
PROTOCOL(UnsafeCxxInputIterator)
120120
PROTOCOL(UnsafeCxxMutableInputIterator)
121121
PROTOCOL(UnsafeCxxRandomAccessIterator)
122+
PROTOCOL(UnsafeCxxMutableRandomAccessIterator)
122123

123124
PROTOCOL(AsyncSequence)
124125
PROTOCOL(AsyncIteratorProtocol)

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
11431143
case KnownProtocolKind::UnsafeCxxInputIterator:
11441144
case KnownProtocolKind::UnsafeCxxMutableInputIterator:
11451145
case KnownProtocolKind::UnsafeCxxRandomAccessIterator:
1146+
case KnownProtocolKind::UnsafeCxxMutableRandomAccessIterator:
11461147
M = getLoadedModule(Id_Cxx);
11471148
break;
11481149
default:

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,12 @@ void swift::conformToCxxIteratorIfNeeded(
563563
return;
564564

565565
impl.addSynthesizedTypealias(decl, ctx.getIdentifier("Distance"), distanceTy);
566-
impl.addSynthesizedProtocolAttrs(
567-
decl, {KnownProtocolKind::UnsafeCxxRandomAccessIterator});
566+
if (pointeeSettable)
567+
impl.addSynthesizedProtocolAttrs(
568+
decl, {KnownProtocolKind::UnsafeCxxMutableRandomAccessIterator});
569+
else
570+
impl.addSynthesizedProtocolAttrs(
571+
decl, {KnownProtocolKind::UnsafeCxxRandomAccessIterator});
568572
}
569573

570574
void swift::conformToCxxOptionalIfNeeded(

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,6 +6314,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
63146314
case KnownProtocolKind::UnsafeCxxInputIterator:
63156315
case KnownProtocolKind::UnsafeCxxMutableInputIterator:
63166316
case KnownProtocolKind::UnsafeCxxRandomAccessIterator:
6317+
case KnownProtocolKind::UnsafeCxxMutableRandomAccessIterator:
63176318
case KnownProtocolKind::Executor:
63186319
case KnownProtocolKind::SerialExecutor:
63196320
case KnownProtocolKind::Sendable:

stdlib/public/Cxx/UnsafeCxxIterators.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ public protocol UnsafeCxxRandomAccessIterator: UnsafeCxxInputIterator {
8080
extension UnsafePointer: UnsafeCxxRandomAccessIterator {}
8181

8282
extension UnsafeMutablePointer: UnsafeCxxRandomAccessIterator {}
83+
84+
public protocol UnsafeCxxMutableRandomAccessIterator: UnsafeCxxRandomAccessIterator, UnsafeCxxMutableInputIterator {}
85+
86+
extension UnsafeMutablePointer: UnsafeCxxMutableRandomAccessIterator {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
// CHECK: typealias Pointee = Int32
139139
// CHECK: }
140140

141-
// CHECK: struct MutableRACIterator : UnsafeCxxRandomAccessIterator, UnsafeCxxMutableInputIterator {
141+
// CHECK: struct MutableRACIterator : UnsafeCxxMutableRandomAccessIterator, UnsafeCxxMutableInputIterator {
142142
// CHECK: func successor() -> MutableRACIterator
143143
// CHECK: var pointee: Int32
144144
// CHECK: typealias Pointee = Int32

0 commit comments

Comments
 (0)