diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index c1f5dbbc230f5..7ae24533391be 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -3062,6 +3062,9 @@ static bool canDropMetatypeArgs(ApplySite apply, SILFunction *callee) { if (isUsedAsDynamicSelf(calleeArg)) return false; + if (calleeArg->getType().getASTType()->hasDynamicSelfType()) + return false; + // We don't drop metatype arguments of not applied arguments (in case of `partial_apply`). if (firstAppliedArgIdx > calleeArgIdx) return false; diff --git a/test/SILOptimizer/specialize_ossa.sil b/test/SILOptimizer/specialize_ossa.sil index b7f59edffac5d..ae2c90f957ec8 100644 --- a/test/SILOptimizer/specialize_ossa.sil +++ b/test/SILOptimizer/specialize_ossa.sil @@ -1466,3 +1466,20 @@ bb0: return %2 : $@callee_owned (@in_guaranteed Int, @thin GenericKlass.Type) -> @out Int } +sil [ossa] @method_with_dynamic_self_arg : $@convention(method) (@thick @dynamic_self GenericKlass.Type) -> () { +bb0(%0 : $@thick @dynamic_self GenericKlass.Type): + %2 = tuple () + return %2 : $() +} + +// CHECK-LABEL: sil [ossa] @callMethodWithDynamicSelfArg : +// CHECK: = function_ref @$s28method_with_dynamic_self_argSi_Tg5 : $@convention(method) (@thick @dynamic_self GenericKlass.Type) -> () +// CHECK-LABEL: } // end sil function 'callMethodWithDynamicSelfArg' +sil [ossa] @callMethodWithDynamicSelfArg : $@convention(method) (@guaranteed GenericKlass) -> () { +bb0(%0 : @guaranteed $GenericKlass): + %1 = metatype $@thick @dynamic_self GenericKlass.Type + %2 = function_ref @method_with_dynamic_self_arg : $@convention(method) (@thick @dynamic_self GenericKlass.Type) -> () + %3 = apply %2(%1) : $@convention(method) (@thick @dynamic_self GenericKlass.Type) -> () + return %3 : $() +} +