Skip to content

Commit 238aa2d

Browse files
authored
Merge pull request #17561 from jckarter/silfunctiontype-pseudogeneric-iff-generic
SIL: Assert that SILFunctionTypes are only @pseudogeneric when they have generic arguments.
2 parents 7371d27 + 9833fb4 commit 238aa2d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,7 @@ CanSILFunctionType SILFunctionType::get(GenericSignature *genericSig,
39343934
Optional<ProtocolConformanceRef> witnessMethodConformance) {
39353935
assert(coroutineKind == SILCoroutineKind::None || normalResults.empty());
39363936
assert(coroutineKind != SILCoroutineKind::None || yields.empty());
3937+
assert(!ext.isPseudogeneric() || genericSig);
39373938

39383939
llvm::FoldingSetNodeID id;
39393940
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee,

lib/SIL/SILFunctionType.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,9 @@ static CanSILFunctionType getSILFunctionType(
10111011
if (extInfo.hasContext())
10121012
calleeConvention = conventions.getCallee();
10131013

1014-
bool pseudogeneric = (constant ? isPseudogeneric(*constant) : false);
1014+
bool pseudogeneric = genericSig && constant
1015+
? isPseudogeneric(*constant)
1016+
: false;
10151017

10161018
// NOTE: SILFunctionType::ExtInfo doesn't track everything that
10171019
// AnyFunctionType::ExtInfo tracks. For example: 'throws' or 'auto-closure'
@@ -2374,8 +2376,12 @@ class SILTypeSubstituter :
23742376
witnessMethodConformance =
23752377
conformance->subst(selfType, Subst, Conformances);
23762378
}
2379+
2380+
// The substituted type is no longer generic, so it'd never be
2381+
// pseudogeneric.
2382+
auto extInfo = origType->getExtInfo().withIsPseudogeneric(false);
23772383

2378-
return SILFunctionType::get(nullptr, origType->getExtInfo(),
2384+
return SILFunctionType::get(nullptr, extInfo,
23792385
origType->getCoroutineKind(),
23802386
origType->getCalleeConvention(), substParams,
23812387
substYields, substResults, substErrorResult,

test/SILGen/objc_imported_generic.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func genericMethodOnAnyObject(o: AnyObject, b: Bool) -> AnyObject {
1919
}
2020

2121
// CHECK-LABEL: sil @$S21objc_imported_generic0C17MethodOnAnyObject{{[_0-9a-zA-Z]*}}F
22-
// CHECK: objc_method {{%.*}} : $@opened([[TAG:.*]]) AnyObject, #GenericClass.thing!1.foreign : <T where T : AnyObject> (GenericClass<T>) -> () -> T?, $@convention(objc_method) @pseudogeneric (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>
22+
// CHECK: objc_method {{%.*}} : $@opened([[TAG:.*]]) AnyObject, #GenericClass.thing!1.foreign : <T where T : AnyObject> (GenericClass<T>) -> () -> T?, $@convention(objc_method) (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>
2323

2424
public func genericMethodOnAnyObjectChained(o: AnyObject, b: Bool) -> AnyObject? {
2525
return o.thing?()
@@ -30,7 +30,7 @@ public func genericMethodOnAnyObjectChained(o: AnyObject, b: Bool) -> AnyObject?
3030
// CHECK: [[OPENED_ANY:%.*]] = open_existential_ref [[ANY]]
3131
// CHECK: [[OPENED_ANY_COPY:%.*]] = copy_value [[OPENED_ANY]]
3232
// CHECK: dynamic_method_br [[OPENED_ANY_COPY]] : $@opened([[TAG:.*]]) AnyObject, #GenericClass.thing!1.foreign, bb1
33-
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) @pseudogeneric (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
33+
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
3434
// CHECK: } // end sil function '$S21objc_imported_generic0C24MethodOnAnyObjectChained1o1byXlSgyXl_SbtF'
3535

3636
public func genericSubscriptOnAnyObject(o: AnyObject, b: Bool) -> AnyObject? {
@@ -42,7 +42,7 @@ public func genericSubscriptOnAnyObject(o: AnyObject, b: Bool) -> AnyObject? {
4242
// CHCEK: [[OPENED_ANY:%.*]] = open_existential_ref [[ANY]]
4343
// CHECK: [[OPENED_ANY_COPY:%.*]] = copy_value [[OPENED_ANY]]
4444
// CHECK: dynamic_method_br [[OPENED_ANY_COPY]] : $@opened([[TAG:.*]]) AnyObject, #GenericClass.subscript!getter.1.foreign, bb1
45-
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) @pseudogeneric (UInt16, @opened([[TAG]]) AnyObject) -> @autoreleased AnyObject):
45+
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) (UInt16, @opened([[TAG]]) AnyObject) -> @autoreleased AnyObject):
4646
// CHECK: } // end sil function '$S21objc_imported_generic0C20SubscriptOnAnyObject1o1byXlSgyXl_SbtF'
4747

4848
public func genericPropertyOnAnyObject(o: AnyObject, b: Bool) -> AnyObject?? {
@@ -54,7 +54,7 @@ public func genericPropertyOnAnyObject(o: AnyObject, b: Bool) -> AnyObject?? {
5454
// CHECK: [[OPENED_ANY:%.*]] = open_existential_ref [[ANY]]
5555
// CHECK: [[OPENED_ANY_COPY:%.*]] = copy_value [[OPENED_ANY]]
5656
// CHECK: dynamic_method_br [[OPENED_ANY_COPY]] : $@opened([[TAG:.*]]) AnyObject, #GenericClass.propertyThing!getter.1.foreign, bb1
57-
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) @pseudogeneric (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
57+
// CHECK: bb1({{%.*}} : @trivial $@convention(objc_method) (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
5858
// CHECK: } // end sil function '$S21objc_imported_generic0C19PropertyOnAnyObject1o1byXlSgSgyXl_SbtF'
5959

6060
public protocol ThingHolder {

0 commit comments

Comments
 (0)