Skip to content

Commit 3c533ff

Browse files
Merge pull request #42510 from nate-chandler/cherrypick/release/5.7/rdar85526916
[SILGen] Use opaque AP for ObjC-async returns.
2 parents 70738dd + 3fb0215 commit 3c533ff

File tree

8 files changed

+109
-17
lines changed

8 files changed

+109
-17
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,7 @@ SILType GetAsyncContinuationInstBase::getLoweredResumeType() const {
28392839
auto formalType = getFormalResumeType();
28402840
auto &M = getFunction()->getModule();
28412841
auto c = getFunction()->getTypeExpansionContext();
2842-
return M.Types.getLoweredType(AbstractionPattern(formalType), formalType, c);
2842+
return M.Types.getLoweredType(AbstractionPattern::getOpaque(), formalType, c);
28432843
}
28442844

28452845
ReturnInst::ReturnInst(SILFunction &func, SILDebugLocation debugLoc,

lib/SILGen/ResultPlan.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,8 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
506506
{
507507
// Allocate space to receive the resume value when the continuation is
508508
// resumed.
509-
opaqueResumeType =
510-
SGF.getLoweredType(AbstractionPattern(calleeTypeInfo.substResultType),
511-
calleeTypeInfo.substResultType);
509+
opaqueResumeType = SGF.getLoweredType(AbstractionPattern::getOpaque(),
510+
calleeTypeInfo.substResultType);
512511
resumeBuf = SGF.emitTemporaryAllocation(loc, opaqueResumeType);
513512
}
514513

@@ -707,14 +706,12 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
707706
// The incoming value is the maximally-abstracted result type of the
708707
// continuation. Move it out of the resume buffer and reabstract it if
709708
// necessary.
710-
auto resumeResult = SGF.emitLoad(loc, resumeBuf,
711-
calleeTypeInfo.origResultType
712-
? *calleeTypeInfo.origResultType
713-
: AbstractionPattern(calleeTypeInfo.substResultType),
714-
calleeTypeInfo.substResultType,
715-
SGF.getTypeLowering(calleeTypeInfo.substResultType),
716-
SGFContext(), IsTake);
717-
709+
auto resumeResult =
710+
SGF.emitLoad(loc, resumeBuf, AbstractionPattern::getOpaque(),
711+
calleeTypeInfo.substResultType,
712+
SGF.getTypeLowering(calleeTypeInfo.substResultType),
713+
SGFContext(), IsTake);
714+
718715
return RValue(SGF, loc, calleeTypeInfo.substResultType, resumeResult);
719716
}
720717
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Foundation/Foundation.h>
2+
3+
#pragma clang assume_nonnull begin
4+
5+
@interface PFXObject : NSObject
6+
- (void)performGetStringIdentityWithCompletionHandler:
7+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull)))completionHandler;
8+
- (void)performGetStringAppendWithCompletionHandler:
9+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull)))completionHandler;
10+
- (void)performGetIntegerIdentityWithCompletionHandler:
11+
(void (^)(NSInteger(^ _Nonnull)(NSInteger)))completionHandler;
12+
- (void)performGetIntegerSubtractWithCompletionHandler:
13+
(void (^)(NSInteger(^ _Nonnull)(NSInteger, NSInteger)))completionHandler;
14+
- (void)performGetUIntegerIdentityWithCompletionHandler:
15+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger)))completionHandler;
16+
- (void)performGetUIntegerAddWithCompletionHandler:
17+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger, NSUInteger)))completionHandler;
18+
@end
19+
20+
#pragma clang assume_nonnull end
21+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "rdar85526916.h"
2+
3+
#pragma clang assume_nonnull begin
4+
5+
@implementation PFXObject
6+
- (void)performGetStringIdentityWithCompletionHandler:
7+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull)))completionHandler {
8+
completionHandler(^(NSString * _Nonnull input) {
9+
return input;
10+
});
11+
}
12+
- (void)performGetStringAppendWithCompletionHandler:
13+
(void (^)(NSString * _Nonnull(^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull)))completionHandler {
14+
completionHandler(^(NSString * _Nonnull one, NSString * _Nonnull two) {
15+
return [one stringByAppendingString: two];
16+
});
17+
}
18+
- (void)performGetIntegerIdentityWithCompletionHandler:
19+
(void (^)(NSInteger(^ _Nonnull)(NSInteger)))completionHandler {
20+
completionHandler(^(NSInteger input) {
21+
return input;
22+
});
23+
}
24+
- (void)performGetIntegerSubtractWithCompletionHandler:
25+
(void (^)(NSInteger(^ _Nonnull)(NSInteger, NSInteger)))completionHandler {
26+
completionHandler(^(NSInteger lhs, NSInteger rhs) {
27+
return lhs - rhs;
28+
});
29+
}
30+
- (void)performGetUIntegerIdentityWithCompletionHandler:
31+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger)))completionHandler {
32+
completionHandler(^(NSUInteger input) {
33+
return input;
34+
});
35+
}
36+
- (void)performGetUIntegerAddWithCompletionHandler:
37+
(void (^)(NSUInteger(^ _Nonnull)(NSUInteger, NSUInteger)))completionHandler {
38+
completionHandler(^(NSUInteger lhs, NSUInteger rhs) {
39+
return lhs + rhs;
40+
});
41+
}
42+
@end
43+
44+
#pragma clang assume_nonnull end
45+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-clang %S/Inputs/rdar85526916.m -I %S/Inputs -c -o %t/rdar85526916.o
3+
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -import-objc-header %S/Inputs/rdar85526916.h -Xlinker %t/rdar85526916.o -parse-as-library %s -o %t/main
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: objc_interop
9+
10+
// UNSUPPORTED: use_os_stdlib
11+
// UNSUPPORTED: back_deployment_runtime
12+
13+
func run(on object: PFXObject) async throws {
14+
// CHECK: howdy
15+
print(await object.performGetStringIdentity()("howdy"))
16+
// CHECK: mundo
17+
print(await object.performGetStringAppend()("mun", "do"))
18+
// CHECK: -9035768
19+
print(await object.performGetIntegerIdentity()(-9035768))
20+
// CHECK: 57
21+
print(await object.performGetIntegerSubtract()(60, 3))
22+
// CHECK: 9035768
23+
print(await object.performGetUIntegerIdentity()(9035768))
24+
// CHECK: 3
25+
print(await object.performGetUIntegerAdd()(1+1, 1))
26+
}
27+
28+
@main struct Main {
29+
static func main() async throws {
30+
let object = PFXObject()
31+
try await run(on: object)
32+
}
33+
}
34+

validation-test/compiler_crashers_2_fixed/rdar79383990.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %target-swift-frontend %s -emit-silgen -disable-availability-checking -import-objc-header %S/Inputs/rdar79383990.h
22
// REQUIRES: objc_interop
3-
// REQUIRES: OS=macosx
43

54
import Foundation
65

validation-test/compiler_crashers_2_fixed/rdar81590807.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
// REQUIRES: executable_test
1414
// REQUIRES: OS=macosx || OS=ios
15-
// Enable with rdar://85526879
16-
// UNSUPPORTED: CPU=arm64e
1715

1816
// rdar://82123254
1917
// UNSUPPORTED: use_os_stdlib

validation-test/compiler_crashers_2_fixed/rdar81617749.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
// Enable with rdar://81617749
1111
// UNSUPPORTED: CPU=i386 && OS=watchos
12-
// Enable with rdar://85526916
13-
// UNSUPPORTED: CPU=arm64e
1412

1513
// rdar://82123254
1614
// UNSUPPORTED: use_os_stdlib

0 commit comments

Comments
 (0)