Skip to content

[SILGen] Handle marker existentials in emitCBridgedToNativeValue. #70553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ static ManagedValue emitCBridgedToNativeValue(
}

// id-to-Any bridging.
if (nativeType->isAny()) {
if (nativeType->isMarkerExistential()) {
// If this is not a call result, use the normal erasure logic.
if (!isCallResult) {
return SGF.emitTransformedValue(loc, unwrapBridgedOptionals(v),
Expand Down Expand Up @@ -1163,10 +1163,18 @@ static ManagedValue emitCBridgedToNativeValue(
auto optionalBridgedTy = SILType::getOptionalType(loweredBridgedTy);
auto optionalMV = SGF.B.createUncheckedBitCast(
loc, unwrapBridgedOptionals(v), optionalBridgedTy);
return SGF.emitApplyOfLibraryIntrinsic(loc,
v = SGF.emitApplyOfLibraryIntrinsic(loc,
SGF.getASTContext().getBridgeAnyObjectToAny(),
SubstitutionMap(), optionalMV, C)
.getAsSingleValue(SGF, loc);

// Convert to the marker existential if necessary.
auto anyType = SGF.getASTContext().getAnyExistentialType();
if (nativeType != anyType) {
v = SGF.emitTransformedValue(loc, v, anyType, nativeType);
}

return v;
}

// Bridge NSError to Error.
Expand Down
1 change: 1 addition & 0 deletions test/SILGen/Inputs/objc_bridging_sendable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

@interface NSBlah: NSObject
- (void) takeSendable: (id __attribute__((swift_attr("@Sendable")))) x;
@property (readonly) id __attribute__((swift_attr("@Sendable"))) x;
@end
6 changes: 5 additions & 1 deletion test/SILGen/objc_bridging_sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
// CHECK: return
public func passSendableToObjC(_ s: Sendable) {
NSBlah().takeSendable(s)
}
}

public func useSendableProperty(_ ns: NSBlah) {
_ = ns.x
}