@@ -986,7 +986,7 @@ ManagedValue Transform::transformTuple(ManagedValue inputTuple,
986
986
void SILGenFunction::collectThunkParams (
987
987
SILLocation loc, SmallVectorImpl<ManagedValue> ¶ms,
988
988
SmallVectorImpl<ManagedValue> *indirectResults,
989
- SmallVectorImpl<ManagedValue> *indirectErrors, ThunkGenOptions options ) {
989
+ SmallVectorImpl<ManagedValue> *indirectErrors) {
990
990
// Add the indirect results.
991
991
for (auto resultTy : F.getConventions ().getIndirectSILResultTypes (
992
992
getTypeExpansionContext ())) {
@@ -5464,7 +5464,7 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
5464
5464
5465
5465
SmallVector<ManagedValue, 8 > params;
5466
5466
SmallVector<ManagedValue, 4 > indirectResultParams;
5467
- SGF.collectThunkParams (loc, params, &indirectResultParams, nullptr , options );
5467
+ SGF.collectThunkParams (loc, params, &indirectResultParams);
5468
5468
5469
5469
// Ignore the self parameter at the SIL level. IRGen will use it to
5470
5470
// recover type metadata.
@@ -6945,10 +6945,6 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
6945
6945
cleanupLoc.markAutoGenerated ();
6946
6946
Scope scope (Cleanups, cleanupLoc);
6947
6947
6948
- SmallVector<ManagedValue, 8 > thunkArgs;
6949
- SmallVector<ManagedValue, 8 > thunkIndirectResults;
6950
- collectThunkParams (loc, thunkArgs, &thunkIndirectResults);
6951
-
6952
6948
CanSILFunctionType derivedFTy;
6953
6949
if (baseLessVisibleThanDerived) {
6954
6950
derivedFTy =
@@ -6973,16 +6969,41 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
6973
6969
->substGenericArgs (subs)->getCanonicalType ());
6974
6970
}
6975
6971
6976
- // Emit the indirect return and arguments.
6977
6972
auto thunkTy = F.getLoweredFunctionType ();
6978
6973
6979
- SmallVector<ManagedValue, 8 > substArgs;
6974
+ using ThunkGenFlag = SILGenFunction::ThunkGenFlag;
6975
+ auto options = SILGenFunction::ThunkGenOptions ();
6980
6976
6977
+ {
6978
+ auto thunkIsolatedParam = thunkTy->maybeGetIsolatedParameter ();
6979
+ if (thunkIsolatedParam &&
6980
+ thunkIsolatedParam->hasOption (SILParameterInfo::ImplicitLeading))
6981
+ options |= ThunkGenFlag::ThunkHasImplicitIsolatedParam;
6982
+ auto derivedIsolatedParam = derivedFTy->maybeGetIsolatedParameter ();
6983
+ if (derivedIsolatedParam &&
6984
+ derivedIsolatedParam->hasOption (SILParameterInfo::ImplicitLeading))
6985
+ options |= ThunkGenFlag::CalleeHasImplicitIsolatedParam;
6986
+ }
6987
+
6988
+ SmallVector<ManagedValue, 8 > thunkArgs;
6989
+ SmallVector<ManagedValue, 8 > thunkIndirectResults;
6990
+ collectThunkParams (loc, thunkArgs, &thunkIndirectResults);
6991
+
6992
+ // Emit the indirect return and arguments.
6993
+ SmallVector<ManagedValue, 8 > substArgs;
6981
6994
AbstractionPattern outputOrigType (outputSubstType);
6982
6995
6996
+ auto derivedFTyParamInfo = derivedFTy->getParameters ();
6997
+
6998
+ // If we are transforming to a callee with an implicit param, drop the
6999
+ // implicit param so that we can insert it again later. This ensures
7000
+ // TranslateArguments does not need to know about this.
7001
+ if (options.contains (ThunkGenFlag::CalleeHasImplicitIsolatedParam))
7002
+ derivedFTyParamInfo = derivedFTyParamInfo.drop_front ();
7003
+
6983
7004
// Reabstract the arguments.
6984
7005
TranslateArguments (*this , loc, thunkArgs, substArgs,
6985
- derivedFTy, derivedFTy-> getParameters () )
7006
+ derivedFTy, derivedFTyParamInfo )
6986
7007
.process (outputOrigType,
6987
7008
outputSubstType.getParams (),
6988
7009
inputOrigType,
@@ -7012,8 +7033,61 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
7012
7033
}
7013
7034
}
7014
7035
7036
+ // Now that we have translated arguments and inserted our thunk indirect
7037
+ // parameters... before we forward those arguments, insert the implicit
7038
+ // leading parameter.
7039
+ if (options.contains (ThunkGenFlag::CalleeHasImplicitIsolatedParam)) {
7040
+ auto baseIsolation =
7041
+ swift::getActorIsolation (base.getAbstractFunctionDecl ());
7042
+ switch (baseIsolation) {
7043
+ case ActorIsolation::Unspecified:
7044
+ case ActorIsolation::Nonisolated:
7045
+ case ActorIsolation::NonisolatedUnsafe:
7046
+ args.push_back (emitNonIsolatedIsolation (loc).getValue ());
7047
+ break ;
7048
+ case ActorIsolation::Erased:
7049
+ llvm::report_fatal_error (" Found erased actor isolation?!" );
7050
+ break ;
7051
+ case ActorIsolation::GlobalActor: {
7052
+ auto globalActor = baseIsolation.getGlobalActor ()->getCanonicalType ();
7053
+ args.push_back (emitGlobalActorIsolation (loc, globalActor).getValue ());
7054
+ break ;
7055
+ }
7056
+ case ActorIsolation::ActorInstance:
7057
+ case ActorIsolation::CallerIsolationInheriting: {
7058
+ auto derivedIsolation =
7059
+ swift::getActorIsolation (derived.getAbstractFunctionDecl ());
7060
+ switch (derivedIsolation) {
7061
+ case ActorIsolation::Unspecified:
7062
+ case ActorIsolation::Nonisolated:
7063
+ case ActorIsolation::NonisolatedUnsafe:
7064
+ args.push_back (emitNonIsolatedIsolation (loc).getValue ());
7065
+ break ;
7066
+ case ActorIsolation::Erased:
7067
+ llvm::report_fatal_error (" Found erased actor isolation?!" );
7068
+ break ;
7069
+ case ActorIsolation::GlobalActor: {
7070
+ auto globalActor =
7071
+ derivedIsolation.getGlobalActor ()->getCanonicalType ();
7072
+ args.push_back (emitGlobalActorIsolation (loc, globalActor).getValue ());
7073
+ break ;
7074
+ }
7075
+ case ActorIsolation::ActorInstance:
7076
+ case ActorIsolation::CallerIsolationInheriting: {
7077
+ auto isolatedArg = F.maybeGetIsolatedArgument ();
7078
+ assert (isolatedArg);
7079
+ args.push_back (isolatedArg);
7080
+ break ;
7081
+ }
7082
+ }
7083
+ break ;
7084
+ }
7085
+ }
7086
+ }
7087
+
7015
7088
// Then, the arguments.
7016
- forwardFunctionArguments (*this , loc, derivedFTy, substArgs, args);
7089
+ forwardFunctionArguments (*this , loc, derivedFTy, substArgs, args,
7090
+ options);
7017
7091
7018
7092
// Create the call.
7019
7093
SILValue derivedRef;
@@ -7316,7 +7390,7 @@ void SILGenFunction::emitProtocolWitness(
7316
7390
7317
7391
SmallVector<ManagedValue, 8 > origParams;
7318
7392
SmallVector<ManagedValue, 8 > thunkIndirectResults;
7319
- collectThunkParams (loc, origParams, &thunkIndirectResults, nullptr , options );
7393
+ collectThunkParams (loc, origParams, &thunkIndirectResults);
7320
7394
7321
7395
if (witness.getDecl ()->requiresUnavailableDeclABICompatibilityStubs ())
7322
7396
emitApplyOfUnavailableCodeReached ();
0 commit comments