Skip to content

Commit df858a5

Browse files
authored
Merge pull request #70553 from hborla/bridge-to-sendable
2 parents ce3b428 + d3c4264 commit df858a5

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ static ManagedValue emitCBridgedToNativeValue(
11311131
}
11321132

11331133
// id-to-Any bridging.
1134-
if (nativeType->isAny()) {
1134+
if (nativeType->isMarkerExistential()) {
11351135
// If this is not a call result, use the normal erasure logic.
11361136
if (!isCallResult) {
11371137
return SGF.emitTransformedValue(loc, unwrapBridgedOptionals(v),
@@ -1163,10 +1163,18 @@ static ManagedValue emitCBridgedToNativeValue(
11631163
auto optionalBridgedTy = SILType::getOptionalType(loweredBridgedTy);
11641164
auto optionalMV = SGF.B.createUncheckedBitCast(
11651165
loc, unwrapBridgedOptionals(v), optionalBridgedTy);
1166-
return SGF.emitApplyOfLibraryIntrinsic(loc,
1166+
v = SGF.emitApplyOfLibraryIntrinsic(loc,
11671167
SGF.getASTContext().getBridgeAnyObjectToAny(),
11681168
SubstitutionMap(), optionalMV, C)
11691169
.getAsSingleValue(SGF, loc);
1170+
1171+
// Convert to the marker existential if necessary.
1172+
auto anyType = SGF.getASTContext().getAnyExistentialType();
1173+
if (nativeType != anyType) {
1174+
v = SGF.emitTransformedValue(loc, v, anyType, nativeType);
1175+
}
1176+
1177+
return v;
11701178
}
11711179

11721180
// Bridge NSError to Error.

test/SILGen/Inputs/objc_bridging_sendable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
@interface NSBlah: NSObject
44
- (void) takeSendable: (id __attribute__((swift_attr("@Sendable")))) x;
5+
@property (readonly) id __attribute__((swift_attr("@Sendable"))) x;
56
@end

test/SILGen/objc_bridging_sendable.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
// CHECK: return
99
public func passSendableToObjC(_ s: Sendable) {
1010
NSBlah().takeSendable(s)
11-
}
11+
}
12+
13+
public func useSendableProperty(_ ns: NSBlah) {
14+
_ = ns.x
15+
}

0 commit comments

Comments
 (0)