mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Distributed] move dist. init synthesis to default synthesis
This commit is contained in:
@@ -209,10 +209,14 @@ enum class ImplicitConstructorKind {
|
||||
/// The default constructor, which default-initializes each
|
||||
/// of the instance variables.
|
||||
Default,
|
||||
/// The default constructor of a distributed actor.
|
||||
/// Similarly to a Default one it initializes each of the instance variables,
|
||||
/// however it also implicitly gains an ActorTransport parameter.
|
||||
DefaultDistributedActor,
|
||||
/// The memberwise constructor, which initializes each of
|
||||
/// the instance variables from a parameter of the same type and
|
||||
/// name.
|
||||
Memberwise
|
||||
Memberwise,
|
||||
};
|
||||
|
||||
/// Create an implicit struct or class constructor.
|
||||
@@ -227,16 +231,6 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
|
||||
ASTContext &ctx) {
|
||||
assert(!decl->hasClangNode());
|
||||
|
||||
// Don't synthesize for distributed actors, they're a bit special.
|
||||
//
|
||||
// They have their special inits, and should not get the usual
|
||||
// default/implicit constructor (i.e. `init()` is illegal for them, as they
|
||||
// always must have an associated transport - via `init(transport:)` or
|
||||
// `init(resolve:using:)`).
|
||||
if (auto clazz = dyn_cast<ClassDecl>(decl))
|
||||
if (clazz->isDistributedActor())
|
||||
return nullptr;
|
||||
|
||||
SourceLoc Loc = decl->getLoc();
|
||||
auto accessLevel = AccessLevel::Internal;
|
||||
|
||||
@@ -319,6 +313,23 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
|
||||
|
||||
maybeAddMemberwiseDefaultArg(arg, var, params.size(), ctx);
|
||||
|
||||
params.push_back(arg);
|
||||
}
|
||||
} else if (ICK == ImplicitConstructorKind::DefaultDistributedActor) {
|
||||
assert(isa<ClassDecl>(decl));
|
||||
assert(decl->isDistributedActor() &&
|
||||
"Only 'distributed actor' type can gain implicit distributed actor init");
|
||||
|
||||
if (swift::ensureDistributedModuleLoaded(decl)) {
|
||||
auto transportDecl = ctx.getActorTransportDecl();
|
||||
|
||||
// Create the parameter.
|
||||
auto *arg = new (ctx) ParamDecl(SourceLoc(), Loc, ctx.Id_transport, Loc,
|
||||
ctx.Id_transport, transportDecl);
|
||||
arg->setSpecifier(ParamSpecifier::Default);
|
||||
arg->setInterfaceType(transportDecl->getDeclaredInterfaceType());
|
||||
arg->setImplicit();
|
||||
|
||||
params.push_back(arg);
|
||||
}
|
||||
}
|
||||
@@ -1193,7 +1204,6 @@ static bool shouldAttemptInitializerSynthesis(const NominalTypeDecl *decl) {
|
||||
}
|
||||
|
||||
void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
|
||||
fprintf(stderr, "[%s:%d] (%s) ADD IMPLICIT\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
// If we already added implicit initializers, we're done.
|
||||
if (decl->addedImplicitInitializers())
|
||||
return;
|
||||
@@ -1493,10 +1503,10 @@ SynthesizeDefaultInitRequest::evaluate(Evaluator &evaluator,
|
||||
decl);
|
||||
|
||||
// Create the default constructor.
|
||||
if (auto ctor = createImplicitConstructor(decl,
|
||||
ImplicitConstructorKind::Default,
|
||||
ctx)) {
|
||||
|
||||
auto ctorKind = decl->isDistributedActor() ?
|
||||
ImplicitConstructorKind::DefaultDistributedActor :
|
||||
ImplicitConstructorKind::Default;
|
||||
if (auto ctor = createImplicitConstructor(decl, ctorKind, ctx)) {
|
||||
// Add the constructor.
|
||||
decl->addMember(ctor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user