@@ -986,7 +986,7 @@ ManagedValue Transform::transformTuple(ManagedValue inputTuple,
986986void SILGenFunction::collectThunkParams (
987987 SILLocation loc, SmallVectorImpl<ManagedValue> ¶ms,
988988 SmallVectorImpl<ManagedValue> *indirectResults,
989- SmallVectorImpl<ManagedValue> *indirectErrors, ThunkGenOptions options ) {
989+ SmallVectorImpl<ManagedValue> *indirectErrors) {
990990 // Add the indirect results.
991991 for (auto resultTy : F.getConventions ().getIndirectSILResultTypes (
992992 getTypeExpansionContext ())) {
@@ -5464,7 +5464,7 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
54645464
54655465 SmallVector<ManagedValue, 8 > params;
54665466 SmallVector<ManagedValue, 4 > indirectResultParams;
5467- SGF.collectThunkParams (loc, params, &indirectResultParams, nullptr , options );
5467+ SGF.collectThunkParams (loc, params, &indirectResultParams);
54685468
54695469 // Ignore the self parameter at the SIL level. IRGen will use it to
54705470 // recover type metadata.
@@ -6945,10 +6945,6 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
69456945 cleanupLoc.markAutoGenerated ();
69466946 Scope scope (Cleanups, cleanupLoc);
69476947
6948- SmallVector<ManagedValue, 8 > thunkArgs;
6949- SmallVector<ManagedValue, 8 > thunkIndirectResults;
6950- collectThunkParams (loc, thunkArgs, &thunkIndirectResults);
6951-
69526948 CanSILFunctionType derivedFTy;
69536949 if (baseLessVisibleThanDerived) {
69546950 derivedFTy =
@@ -6973,16 +6969,41 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
69736969 ->substGenericArgs (subs)->getCanonicalType ());
69746970 }
69756971
6976- // Emit the indirect return and arguments.
69776972 auto thunkTy = F.getLoweredFunctionType ();
69786973
6979- SmallVector<ManagedValue, 8 > substArgs;
6974+ using ThunkGenFlag = SILGenFunction::ThunkGenFlag;
6975+ auto options = SILGenFunction::ThunkGenOptions ();
69806976
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;
69816994 AbstractionPattern outputOrigType (outputSubstType);
69826995
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+
69837004 // Reabstract the arguments.
69847005 TranslateArguments (*this , loc, thunkArgs, substArgs,
6985- derivedFTy, derivedFTy-> getParameters () )
7006+ derivedFTy, derivedFTyParamInfo )
69867007 .process (outputOrigType,
69877008 outputSubstType.getParams (),
69887009 inputOrigType,
@@ -7012,8 +7033,61 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
70127033 }
70137034 }
70147035
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+
70157088 // Then, the arguments.
7016- forwardFunctionArguments (*this , loc, derivedFTy, substArgs, args);
7089+ forwardFunctionArguments (*this , loc, derivedFTy, substArgs, args,
7090+ options);
70177091
70187092 // Create the call.
70197093 SILValue derivedRef;
@@ -7316,7 +7390,7 @@ void SILGenFunction::emitProtocolWitness(
73167390
73177391 SmallVector<ManagedValue, 8 > origParams;
73187392 SmallVector<ManagedValue, 8 > thunkIndirectResults;
7319- collectThunkParams (loc, origParams, &thunkIndirectResults, nullptr , options );
7393+ collectThunkParams (loc, origParams, &thunkIndirectResults);
73207394
73217395 if (witness.getDecl ()->requiresUnavailableDeclABICompatibilityStubs ())
73227396 emitApplyOfUnavailableCodeReached ();
0 commit comments