Skip to content

Commit b77a8d9

Browse files
authored
Merge pull request #66798 from eeckstein/fix-generic-specializer
GenericSpecializer: fix a crash when specializing a method with dynamic self
2 parents 46db1a0 + 0b9782a commit b77a8d9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,9 @@ static bool canDropMetatypeArgs(ApplySite apply, SILFunction *callee) {
30623062
if (isUsedAsDynamicSelf(calleeArg))
30633063
return false;
30643064

3065+
if (calleeArg->getType().getASTType()->hasDynamicSelfType())
3066+
return false;
3067+
30653068
// We don't drop metatype arguments of not applied arguments (in case of `partial_apply`).
30663069
if (firstAppliedArgIdx > calleeArgIdx)
30673070
return false;

test/SILOptimizer/specialize_ossa.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,3 +1466,20 @@ bb0:
14661466
return %2 : $@callee_owned (@in_guaranteed Int, @thin GenericKlass<Int>.Type) -> @out Int
14671467
}
14681468

1469+
sil [ossa] @method_with_dynamic_self_arg : $@convention(method) <T> (@thick @dynamic_self GenericKlass<T>.Type) -> () {
1470+
bb0(%0 : $@thick @dynamic_self GenericKlass<T>.Type):
1471+
%2 = tuple ()
1472+
return %2 : $()
1473+
}
1474+
1475+
// CHECK-LABEL: sil [ossa] @callMethodWithDynamicSelfArg :
1476+
// CHECK: = function_ref @$s28method_with_dynamic_self_argSi_Tg5 : $@convention(method) (@thick @dynamic_self GenericKlass<Int>.Type) -> ()
1477+
// CHECK-LABEL: } // end sil function 'callMethodWithDynamicSelfArg'
1478+
sil [ossa] @callMethodWithDynamicSelfArg : $@convention(method) (@guaranteed GenericKlass<Int>) -> () {
1479+
bb0(%0 : @guaranteed $GenericKlass<Int>):
1480+
%1 = metatype $@thick @dynamic_self GenericKlass<Int>.Type
1481+
%2 = function_ref @method_with_dynamic_self_arg : $@convention(method) <T> (@thick @dynamic_self GenericKlass<T>.Type) -> ()
1482+
%3 = apply %2<Int>(%1) : $@convention(method) <T> (@thick @dynamic_self GenericKlass<T>.Type) -> ()
1483+
return %3 : $()
1484+
}
1485+

0 commit comments

Comments
 (0)