Skip to content

Commit 4e2c059

Browse files
ktosoxedin
authored andcommitted
review feedback, cleanup getting decode func
1 parent dadf301 commit 4e2c059

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,10 +3564,10 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
35643564
VarDecl *getDistributedActorIDProperty() const;
35653565

35663566
/// Find the 'RemoteCallTarget.init(_:)' initializer function.
3567-
ConstructorDecl* getDistributedRemoteCallTargetInitFunction() const;
3567+
ConstructorDecl *getDistributedRemoteCallTargetInitFunction() const;
35683568

35693569
/// Find the 'RemoteCallArgument(label:name:value:)' initializer function.
3570-
ConstructorDecl* getDistributedRemoteCallArgumentInitFunction() const;
3570+
ConstructorDecl *getDistributedRemoteCallArgumentInitFunction() const;
35713571

35723572
/// Collect the set of protocols to which this type should implicitly
35733573
/// conform, such as AnyObject (for classes).

include/swift/AST/DistributedDecl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ Type getDistributedActorIDType(NominalTypeDecl *actor);
5353
Type getDistributedSerializationRequirementType(
5454
NominalTypeDecl *nominal, ProtocolDecl *protocol);
5555

56+
/// Given a distributed thunk declaration, inside a 'distributed actor',
57+
/// finds the ad-hoc witness for 'decodeNextArgument' on the associated
58+
/// 'ActorSystem.InvocationDecoder' of the actor, or null.
59+
AbstractFunctionDecl *
60+
getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
61+
ValueDecl *thunk);
62+
5663
/// Get the specific 'InvocationEncoder' type of a specific distributed actor
5764
/// system.
5865
Type getDistributedActorSystemInvocationEncoderType(NominalTypeDecl *system);

lib/AST/DistributedDecl.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,32 @@ Type swift::getDistributedSerializationRequirementType(
203203
return conformance.getTypeWitnessByName(selfType, ctx.Id_SerializationRequirement);
204204
}
205205

206+
AbstractFunctionDecl *
207+
swift::getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
208+
ValueDecl *thunk) {
209+
assert(thunk);
210+
auto &C = thunk->getASTContext();
211+
212+
auto *actor = thunk->getDeclContext()->getSelfNominalTypeDecl();
213+
if (!actor)
214+
return nullptr;
215+
if (!actor->isDistributedActor())
216+
return nullptr;
217+
218+
auto systemTy = getConcreteReplacementForProtocolActorSystemType(thunk);
219+
if (!systemTy)
220+
return nullptr;
221+
222+
auto decoderTy =
223+
getDistributedActorSystemInvocationDecoderType(
224+
systemTy->getAnyNominal());
225+
if (!decoderTy)
226+
return nullptr;
227+
228+
return C.getDecodeNextArgumentOnDistributedInvocationDecoder(
229+
decoderTy->getAnyNominal());
230+
}
231+
206232
Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
207233
NominalTypeDecl *actor, Identifier member) {
208234
auto &ctx = actor->getASTContext();

lib/IRGen/GenDistributed.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
813813
decoder = instance.claimNext();
814814
}
815815

816+
// TODO(distributed): this can be removed most likely now
816817
if (isa<StructDecl>(decoderDecl) || isa<EnumDecl>(decoderDecl) ||
817818
decoderDecl->isFinal()) {
818819
auto *decodeSIL = IGM.getSILModule().lookUpFunction(SILDeclRef(decodeFn));

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,14 @@ void SILFunctionBuilder::addFunctionAttributes(
220220

221221
F->setDynamicallyReplacedFunction(replacedFunc);
222222
}
223-
}
224-
225-
if (constant.isDistributedThunk()) {
226-
auto *actor = decl->getDeclContext()->getSelfNominalTypeDecl();
227-
if (actor && actor->isDistributedActor()) {
228-
auto &C = decl->getASTContext();
229-
auto systemTy = getConcreteReplacementForProtocolActorSystemType(decl);
230-
assert(systemTy);
231-
232-
auto decoderTy =
233-
getDistributedActorSystemInvocationDecoderType(
234-
systemTy->getAnyNominal());
235-
assert(decoderTy);
236-
237-
auto decodeFunc = C.getDecodeNextArgumentOnDistributedInvocationDecoder(
238-
decoderTy->getAnyNominal());
239-
auto decodeRef = SILDeclRef(decodeFunc);
240-
auto *adHocWitness = getOrCreateDeclaration(decodeFunc, decodeRef);
241-
F->setReferencedAdHocRequirementWitnessFunction(adHocWitness);
223+
} else if (constant.isDistributedThunk()) {
224+
if (auto decodeFuncDecl =
225+
getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
226+
decl)) {
227+
228+
auto decodeRef = SILDeclRef(decodeFuncDecl);
229+
auto *adHocFunc = getOrCreateDeclaration(decodeFuncDecl, decodeRef);
230+
F->setReferencedAdHocRequirementWitnessFunction(adHocFunc);
242231
}
243232
}
244233
}

0 commit comments

Comments
 (0)