@@ -55,7 +55,7 @@ static VarDecl *addImplicitDistributedActorIDProperty(
5555 // ==== Synthesize and add 'id' property to the actor decl
5656 Type propertyType = getDistributedActorIDType (nominal);
5757
58- VarDecl *propDecl = new (C)
58+ auto *propDecl = new (C)
5959 VarDecl (/* IsStatic*/ false , VarDecl::Introducer::Let,
6060 SourceLoc (), C.Id_id , nominal);
6161 propDecl->setImplicit ();
@@ -230,20 +230,21 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
230230
231231 // --- Recording invocation details
232232 // -- recordGenericSubstitution(s)
233- if (func ->isGeneric () || nominal->isGeneric ()) {
233+ if (thunk ->isGeneric () || nominal->isGeneric ()) {
234234 auto recordGenericSubstitutionDecl =
235235 C.getRecordGenericSubstitutionOnDistributedInvocationEncoder (invocationEncoderDecl);
236236 assert (recordGenericSubstitutionDecl);
237237 auto recordGenericSubstitutionDeclRef =
238238 UnresolvedDeclRefExpr::createImplicit (
239239 C, recordGenericSubstitutionDecl->getName ());
240240
241- auto sig = func ->getGenericSignature ();
242- for (auto genParamType : sig .getGenericParams ()) {
241+ auto signature = thunk ->getGenericSignature ();
242+ for (auto genParamType : signature .getGenericParams ()) {
243243
244+ auto tyExpr = TypeExpr::createImplicit (thunk->mapTypeIntoContext (genParamType), C);
244245 auto subTypeExpr = new (C) DotSelfExpr (
245- TypeExpr::createImplicit (thunk-> mapTypeIntoContext (genParamType), C) ,
246- sloc, sloc, thunk-> mapTypeIntoContext (genParamType ));
246+ tyExpr ,
247+ sloc, sloc, tyExpr-> getType ( ));
247248
248249 auto recordGenericSubArgsList =
249250 ArgumentList::forImplicitCallTo (
@@ -378,7 +379,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
378379 // -- recordReturnType
379380 if (!isVoidReturn) {
380381 // Result.self
381- auto resultType = func->getResultInterfaceType ();
382+ // Watch out and always map into thunk context
383+ auto resultType = thunk->mapTypeIntoContext (func->getResultInterfaceType ());
382384 auto *metaTypeRef = TypeExpr::createImplicit (resultType, C);
383385 auto *resultTypeExpr =
384386 new (C) DotSelfExpr (metaTypeRef, sloc, sloc, resultType);
@@ -426,9 +428,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
426428 }
427429
428430 // === Prepare the 'RemoteCallTarget'
429- VarDecl *targetVar =
430- new (C) VarDecl (/* isStatic=*/ false , VarDecl::Introducer::Let, sloc,
431- C.Id_target , thunk);
431+ auto *targetVar = new (C) VarDecl (
432+ /* isStatic=*/ false , VarDecl::Introducer::Let, sloc, C.Id_target , thunk);
432433
433434 {
434435 // --- Mangle the thunk name
@@ -510,7 +511,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
510511 // -- returning: Res.Type
511512 if (!isVoidReturn) {
512513 // Result.self
513- auto resultType = func->getResultInterfaceType ();
514+ auto resultType =
515+ func->mapTypeIntoContext (func->getResultInterfaceType ());
514516 auto *metaTypeRef = TypeExpr::createImplicit (resultType, C);
515517 auto *resultTypeExpr =
516518 new (C) DotSelfExpr (metaTypeRef, sloc, sloc, resultType);
@@ -561,7 +563,7 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
561563 genericParamList = genericParams->clone (DC);
562564 }
563565
564- GenericSignature thunkGenSig =
566+ GenericSignature baseSignature =
565567 buildGenericSignature (C, func->getGenericSignature (),
566568 /* addedParameters=*/ {},
567569 /* addedRequirements=*/ {});
@@ -581,9 +583,9 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
581583 }
582584
583585 auto paramDecl = new (C)
584- ParamDecl (SourceLoc (),
585- /* argumentNameLoc=*/ SourceLoc (), funcParam->getArgumentName (),
586- /* parameterNameLoc=*/ SourceLoc (), paramName, DC);
586+ ParamDecl (SourceLoc (),
587+ /* argumentNameLoc=*/ SourceLoc (), funcParam->getArgumentName (),
588+ /* parameterNameLoc=*/ SourceLoc (), paramName, DC);
587589
588590 paramDecl->setImplicit (true );
589591 paramDecl->setSpecifier (funcParam->getSpecifier ());
@@ -593,16 +595,14 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
593595 }
594596 ParameterList *params = ParameterList::create (C, paramDecls); // = funcParams->clone(C);
595597
596- auto thunk = FuncDecl::createImplicit (C, swift::StaticSpellingKind::None,
597- thunkName, SourceLoc (),
598- /* async=*/ true , /* throws=*/ true ,
599- genericParamList,
600- params,
601- func->getResultInterfaceType (),
602- DC);
598+ auto thunk = FuncDecl::createImplicit (
599+ C, swift::StaticSpellingKind::None, thunkName, SourceLoc (),
600+ /* async=*/ true , /* throws=*/ true ,
601+ genericParamList, params,
602+ func->getResultInterfaceType (), DC);
603603 thunk->setSynthesized (true );
604- thunk->getAttrs ().add (new (C) NonisolatedAttr (/* implicit =*/ true ));
605- thunk->setGenericSignature (thunkGenSig );
604+ thunk->getAttrs ().add (new (C) NonisolatedAttr (/* isImplicit =*/ true ));
605+ thunk->setGenericSignature (baseSignature );
606606 thunk->copyFormalAccessFrom (func, /* sourceIsParentContext=*/ false );
607607 thunk->setBodySynthesizer (deriveBodyDistributed_thunk, func);
608608
0 commit comments