mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Distributed] Fix generic returning distributed funcs
This commit is contained in:
@@ -319,6 +319,8 @@ SILType SILFunction::mapTypeIntoContext(SILType type) const {
|
||||
|
||||
SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
|
||||
SILType type) const {
|
||||
if (type.hasArchetype())
|
||||
type.dump();
|
||||
assert(!type.hasArchetype());
|
||||
|
||||
auto genericSig = getGenericSignature().getCanonicalSignature();
|
||||
|
||||
@@ -118,7 +118,9 @@ static void emitDistributedIfRemoteBranch(SILGenFunction &SGF, SILLocation Loc,
|
||||
"'Distributed' module available?");
|
||||
|
||||
ManagedValue selfAnyObject = B.createInitExistentialRef(
|
||||
Loc, SGF.getLoweredType(ctx.getAnyObjectType()), CanType(selfTy),
|
||||
Loc,
|
||||
/*existentialType=*/SGF.getLoweredType(ctx.getAnyObjectType()),
|
||||
/*formalConcreteType=*/selfValue.getType().getASTType(),
|
||||
selfValue, {});
|
||||
auto result = SGF.emitApplyOfLibraryIntrinsic(
|
||||
Loc, isRemoteFn, SubstitutionMap(), {selfAnyObject}, SGFContext());
|
||||
@@ -379,6 +381,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
|
||||
/// having at least one call to the resolve function.
|
||||
|
||||
auto &C = getASTContext();
|
||||
auto DC = fd->getDeclContext();
|
||||
SILLocation loc = fd;
|
||||
|
||||
// ==== Prepare argument references
|
||||
@@ -392,12 +395,12 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
|
||||
ManagedValue selfArg = ManagedValue::forUnmanaged(selfArgValue);
|
||||
|
||||
// type: SpecificDistributedActor.Type
|
||||
auto selfArgType = F.mapTypeIntoContext(selfArg.getType().getASTType());
|
||||
auto selfArgType = selfArg.getType().getASTType();
|
||||
auto selfMetatype = getLoweredType(selfArgType);
|
||||
SILValue selfMetatypeValue = B.createMetatype(loc, selfMetatype);
|
||||
|
||||
// type: SpecificDistributedActor
|
||||
auto *selfTyDecl = fd->getParent()->getSelfNominalTypeDecl();
|
||||
auto *selfTyDecl = DC->getSelfClassDecl();
|
||||
assert(selfTyDecl->isDistributedActor());
|
||||
auto selfTy = F.mapTypeIntoContext(selfTyDecl->getDeclaredInterfaceType());
|
||||
auto returnTy = getLoweredType(selfTy);
|
||||
@@ -533,7 +536,8 @@ SILGenFunction::emitConditionalResignIdentityCall(SILLocation loc,
|
||||
assert(actorDecl->isDistributedActor() &&
|
||||
"only distributed actors have actorSystem lifecycle hooks in deinit");
|
||||
|
||||
auto selfTy = actorDecl->getDeclaredInterfaceType();
|
||||
auto selfTy = F.mapTypeIntoContext(actorDecl->getDeclaredInterfaceType());
|
||||
fprintf(stderr, "[%s:%d] (%s) OKEY!!!!!\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
|
||||
// we only system.resignID if we are a local actor,
|
||||
// and thus the address was created by system.assignID.
|
||||
|
||||
@@ -183,7 +183,7 @@ void emitActorReadyCall(SILBuilder &B, SILLocation loc, SILValue actor,
|
||||
auto &C = F.getASTContext();
|
||||
emitDistributedActorSystemWitnessCall(
|
||||
B, loc, C.Id_actorReady, actorSystem,
|
||||
F.mapTypeIntoContext(actor->getType()), { actor });
|
||||
actor->getType(), { actor });
|
||||
}
|
||||
|
||||
void emitResignIdentityCall(SILBuilder &B, SILLocation loc,
|
||||
|
||||
@@ -55,7 +55,7 @@ static VarDecl *addImplicitDistributedActorIDProperty(
|
||||
// ==== Synthesize and add 'id' property to the actor decl
|
||||
Type propertyType = getDistributedActorIDType(nominal);
|
||||
|
||||
VarDecl *propDecl = new (C)
|
||||
auto *propDecl = new (C)
|
||||
VarDecl(/*IsStatic*/false, VarDecl::Introducer::Let,
|
||||
SourceLoc(), C.Id_id, nominal);
|
||||
propDecl->setImplicit();
|
||||
@@ -230,7 +230,7 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
|
||||
|
||||
// --- Recording invocation details
|
||||
// -- recordGenericSubstitution(s)
|
||||
if (func->isGeneric() || nominal->isGeneric()) {
|
||||
if (thunk->isGeneric() || nominal->isGeneric()) {
|
||||
auto recordGenericSubstitutionDecl =
|
||||
C.getRecordGenericSubstitutionOnDistributedInvocationEncoder(invocationEncoderDecl);
|
||||
assert(recordGenericSubstitutionDecl);
|
||||
@@ -238,12 +238,13 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
|
||||
UnresolvedDeclRefExpr::createImplicit(
|
||||
C, recordGenericSubstitutionDecl->getName());
|
||||
|
||||
auto sig = func->getGenericSignature();
|
||||
for (auto genParamType : sig.getGenericParams()) {
|
||||
auto signature = thunk->getGenericSignature();
|
||||
for (auto genParamType : signature.getGenericParams()) {
|
||||
|
||||
auto tyExpr = TypeExpr::createImplicit(thunk->mapTypeIntoContext(genParamType), C);
|
||||
auto subTypeExpr = new (C) DotSelfExpr(
|
||||
TypeExpr::createImplicit(thunk->mapTypeIntoContext(genParamType), C),
|
||||
sloc, sloc, thunk->mapTypeIntoContext(genParamType));
|
||||
tyExpr,
|
||||
sloc, sloc, tyExpr->getType());
|
||||
|
||||
auto recordGenericSubArgsList =
|
||||
ArgumentList::forImplicitCallTo(
|
||||
@@ -378,7 +379,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
|
||||
// -- recordReturnType
|
||||
if (!isVoidReturn) {
|
||||
// Result.self
|
||||
auto resultType = func->getResultInterfaceType();
|
||||
// Watch out and always map into thunk context
|
||||
auto resultType = thunk->mapTypeIntoContext(func->getResultInterfaceType());
|
||||
auto *metaTypeRef = TypeExpr::createImplicit(resultType, C);
|
||||
auto *resultTypeExpr =
|
||||
new (C) DotSelfExpr(metaTypeRef, sloc, sloc, resultType);
|
||||
@@ -426,9 +428,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
|
||||
}
|
||||
|
||||
// === Prepare the 'RemoteCallTarget'
|
||||
VarDecl *targetVar =
|
||||
new (C) VarDecl(/*isStatic=*/false, VarDecl::Introducer::Let, sloc,
|
||||
C.Id_target, thunk);
|
||||
auto *targetVar = new (C) VarDecl(
|
||||
/*isStatic=*/false, VarDecl::Introducer::Let, sloc, C.Id_target, thunk);
|
||||
|
||||
{
|
||||
// --- Mangle the thunk name
|
||||
@@ -510,7 +511,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
|
||||
// -- returning: Res.Type
|
||||
if (!isVoidReturn) {
|
||||
// Result.self
|
||||
auto resultType = func->getResultInterfaceType();
|
||||
auto resultType =
|
||||
func->mapTypeIntoContext(func->getResultInterfaceType());
|
||||
auto *metaTypeRef = TypeExpr::createImplicit(resultType, C);
|
||||
auto *resultTypeExpr =
|
||||
new (C) DotSelfExpr(metaTypeRef, sloc, sloc, resultType);
|
||||
@@ -561,7 +563,7 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
|
||||
genericParamList = genericParams->clone(DC);
|
||||
}
|
||||
|
||||
GenericSignature thunkGenSig =
|
||||
GenericSignature baseSignature =
|
||||
buildGenericSignature(C, func->getGenericSignature(),
|
||||
/*addedParameters=*/{},
|
||||
/*addedRequirements=*/{});
|
||||
@@ -593,16 +595,14 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
|
||||
}
|
||||
ParameterList *params = ParameterList::create(C, paramDecls); // = funcParams->clone(C);
|
||||
|
||||
auto thunk = FuncDecl::createImplicit(C, swift::StaticSpellingKind::None,
|
||||
thunkName, SourceLoc(),
|
||||
auto thunk = FuncDecl::createImplicit(
|
||||
C, swift::StaticSpellingKind::None, thunkName, SourceLoc(),
|
||||
/*async=*/true, /*throws=*/true,
|
||||
genericParamList,
|
||||
params,
|
||||
func->getResultInterfaceType(),
|
||||
DC);
|
||||
genericParamList, params,
|
||||
func->getResultInterfaceType(), DC);
|
||||
thunk->setSynthesized(true);
|
||||
thunk->getAttrs().add(new (C) NonisolatedAttr(/*implicit=*/true));
|
||||
thunk->setGenericSignature(thunkGenSig);
|
||||
thunk->getAttrs().add(new (C) NonisolatedAttr(/*isImplicit=*/true));
|
||||
thunk->setGenericSignature(baseSignature);
|
||||
thunk->copyFormalAccessFrom(func, /*sourceIsParentContext=*/false);
|
||||
thunk->setBodySynthesizer(deriveBodyDistributed_thunk, func);
|
||||
|
||||
|
||||
28
test/Distributed/distributed_actor_generic_actor.swift
Normal file
28
test/Distributed/distributed_actor_generic_actor.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
|
||||
// RUN: %target-swift-frontend -typecheck -verify -enable-experimental-distributed -disable-availability-checking -I %t 2>&1 %s
|
||||
// REQUIRES: concurrency
|
||||
// REQUIRES: distributed
|
||||
|
||||
import Distributed
|
||||
import FakeDistributedActorSystems
|
||||
|
||||
distributed actor Worker<Work: Sendable & Codable> {
|
||||
typealias ActorSystem = FakeActorSystem
|
||||
|
||||
distributed func echo(item: Work) -> Work {
|
||||
item
|
||||
}
|
||||
|
||||
distributed func echo(items: [Work]) -> [Work] {
|
||||
items
|
||||
}
|
||||
|
||||
distributed func other<Other: Codable & Sendable>(other: Other) -> Other {
|
||||
other
|
||||
}
|
||||
|
||||
distributed func others<Other: Codable & Sendable>(other: Other) -> [Other] {
|
||||
[other]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user