@@ -2821,6 +2821,42 @@ bool ConvertFunctionInst::onlyConvertsSendable() const {
2821
2821
getNonSendableFuncType(getType());
2822
2822
}
2823
2823
2824
+ static CanSILFunctionType getDerivedFunctionTypeForHopToMainActorIfNeeded(
2825
+ SILFunction *fn, CanSILFunctionType inputFunctionType,
2826
+ SubstitutionMap subMap) {
2827
+ inputFunctionType = inputFunctionType->substGenericArgs(
2828
+ fn->getModule(), subMap, fn->getTypeExpansionContext());
2829
+ bool needsSubstFunctionType = false;
2830
+ for (auto param : inputFunctionType->getParameters()) {
2831
+ needsSubstFunctionType |= param.getInterfaceType()->hasTypeParameter();
2832
+ }
2833
+ for (auto result : inputFunctionType->getResults()) {
2834
+ needsSubstFunctionType |= result.getInterfaceType()->hasTypeParameter();
2835
+ }
2836
+ for (auto yield : inputFunctionType->getYields()) {
2837
+ needsSubstFunctionType |= yield.getInterfaceType()->hasTypeParameter();
2838
+ }
2839
+
2840
+ SubstitutionMap appliedSubs;
2841
+ if (needsSubstFunctionType) {
2842
+ appliedSubs = inputFunctionType->getCombinedSubstitutions();
2843
+ }
2844
+
2845
+ auto extInfoBuilder =
2846
+ inputFunctionType->getExtInfo()
2847
+ .intoBuilder()
2848
+ .withRepresentation(SILFunctionType::Representation::Thick)
2849
+ .withIsPseudogeneric(false);
2850
+
2851
+ return SILFunctionType::get(
2852
+ nullptr, extInfoBuilder.build(), inputFunctionType->getCoroutineKind(),
2853
+ ParameterConvention::Direct_Guaranteed,
2854
+ inputFunctionType->getParameters(), inputFunctionType->getYields(),
2855
+ inputFunctionType->getResults(),
2856
+ inputFunctionType->getOptionalErrorResult(), appliedSubs,
2857
+ SubstitutionMap(), inputFunctionType->getASTContext());
2858
+ }
2859
+
2824
2860
static CanSILFunctionType
2825
2861
getDerivedFunctionTypeForIdentityThunk(SILFunction *fn,
2826
2862
CanSILFunctionType inputFunctionType,
@@ -2873,6 +2909,9 @@ ThunkInst::Kind::getDerivedFunctionType(SILFunction *fn,
2873
2909
case Identity:
2874
2910
return getDerivedFunctionTypeForIdentityThunk(fn, inputFunctionType,
2875
2911
subMap);
2912
+ case HopToMainActorIfNeeded:
2913
+ return getDerivedFunctionTypeForHopToMainActorIfNeeded(
2914
+ fn, inputFunctionType, subMap);
2876
2915
}
2877
2916
2878
2917
llvm_unreachable("Covered switch isn't covered?!");
0 commit comments