Skip to content

Commit a632ee7

Browse files
Merge pull request swiftlang#74131 from nate-chandler/cherrypick/release/6.0/rdar64375208
6.0: [TypeLowering] Return pseudogeneric @autoreleasing.
2 parents 0c97e28 + e27876c commit a632ee7

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,10 +3908,12 @@ namespace {
39083908

39093909
class ObjCSelectorFamilyConventions : public Conventions {
39103910
ObjCSelectorFamily Family;
3911+
bool pseudogeneric;
39113912

39123913
public:
3913-
ObjCSelectorFamilyConventions(ObjCSelectorFamily family)
3914-
: Conventions(ConventionsKind::ObjCSelectorFamily), Family(family) {}
3914+
ObjCSelectorFamilyConventions(ObjCSelectorFamily family, bool pseudogeneric)
3915+
: Conventions(ConventionsKind::ObjCSelectorFamily), Family(family),
3916+
pseudogeneric(pseudogeneric) {}
39153917

39163918
ParameterConvention getIndirectParameter(unsigned index,
39173919
const AbstractionPattern &type,
@@ -3951,8 +3953,9 @@ class ObjCSelectorFamilyConventions : public Conventions {
39513953
// Get the underlying AST type, potentially stripping off one level of
39523954
// optionality while we do it.
39533955
CanType type = tl.getLoweredType().unwrapOptionalType().getASTType();
3954-
if (type->hasRetainablePointerRepresentation()
3955-
|| (type->getSwiftNewtypeUnderlyingType() && !tl.isTrivial()))
3956+
if (type->hasRetainablePointerRepresentation() ||
3957+
(type->getSwiftNewtypeUnderlyingType() && !tl.isTrivial()) ||
3958+
(isa<GenericTypeParamType>(type) && pseudogeneric))
39563959
return ResultConvention::Autoreleased;
39573960

39583961
return ResultConvention::Unowned;
@@ -3982,10 +3985,14 @@ static CanSILFunctionType getSILFunctionTypeForObjCSelectorFamily(
39823985
TypeConverter &TC, ObjCSelectorFamily family, CanAnyFunctionType origType,
39833986
CanAnyFunctionType substInterfaceType, SILExtInfoBuilder extInfoBuilder,
39843987
const ForeignInfo &foreignInfo, std::optional<SILDeclRef> constant) {
3988+
CanGenericSignature genericSig = substInterfaceType.getOptGenericSignature();
3989+
bool pseudogeneric =
3990+
genericSig && constant ? isPseudogeneric(*constant) : false;
39853991
return getSILFunctionType(
39863992
TC, TypeExpansionContext::minimal(), AbstractionPattern(origType),
3987-
substInterfaceType, extInfoBuilder, ObjCSelectorFamilyConventions(family),
3988-
foreignInfo, constant, constant,
3993+
substInterfaceType, extInfoBuilder,
3994+
ObjCSelectorFamilyConventions(family, pseudogeneric), foreignInfo,
3995+
constant, constant,
39893996
/*requirement subs*/ std::nullopt, ProtocolConformanceRef());
39903997
}
39913998

test/PrintAsObjC/extensions.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// Please keep this file in alphabetical order!
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-sil-ownership-verifier -emit-module -o %t %s -disable-objc-attr-requires-foundation-module -Xllvm -sil-disable-pass=MandatoryARCOpts
5-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-sil-ownership-verifier -parse-as-library %t/extensions.swiftmodule -typecheck -emit-objc-header-path %t/extensions.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module -Xllvm -sil-disable-pass=MandatoryARCOpts
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t %s -disable-objc-attr-requires-foundation-module -Xllvm -sil-disable-pass=MandatoryARCOpts
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/extensions.swiftmodule -typecheck -emit-objc-header-path %t/extensions.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module -Xllvm -sil-disable-pass=MandatoryARCOpts
66
// RUN: %FileCheck %s < %t/extensions.h
77
// RUN: %FileCheck --check-prefix=NEGATIVE %s < %t/extensions.h
88
// RUN: %check-in-clang %t/extensions.h
99

10-
// This test generates invalid SIL. It will cause a compiler assert in
11-
// both -Onone and -O builds:
12-
// Error! Found a leaked owned value that was never consumed.
13-
// -disable-sil-ownership-verifier is a temporary workaround.
14-
// rdar://64375208 (Wrong lowering of PrintAsObjC code. Result is
15-
// unowned instead of autoreleased)
16-
1710
// REQUIRES: objc_interop
1811

1912
import Foundation

test/SILGen/Inputs/usr/include/objc_extensions_helper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
- (void)objCBaseMethod;
55
@property (nonatomic, strong) NSString *prop;
66
@end
7+
8+
@protocol Pettable
9+
@end
10+
11+
@interface PettableContainer<T : id<Pettable>> : NSObject
12+
@end

test/SILGen/objc_extensions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,10 @@ func testStaticVarAccess() {
185185
// CHECK: [[ADDR:%.*]] = pointer_to_address [[PTR]]
186186
_ = Base.x
187187
}
188+
189+
extension PettableContainer {
190+
// CHECK-LABEL: sil private [thunk] [ossa] @$sSo17PettableContainerC15objc_extensionsE7extractxyFTo : $@convention(objc_method) @pseudogeneric <T where T : Pettable> (PettableContainer<T>) -> @autoreleased T
191+
@objc public func extract() -> T { fatalError() }
192+
// CHECK-LABEL: sil private [thunk] [ossa] @$sSo17PettableContainerC15objc_extensionsE8extract2xSgyFTo : $@convention(objc_method) @pseudogeneric <T where T : Pettable> (PettableContainer<T>) -> @autoreleased Optional<T>
193+
@objc public func extract2() -> T? { fatalError() }
194+
}

0 commit comments

Comments
 (0)