Skip to content

Commit d58bd27

Browse files
authored
Merge pull request #41740 from kavon/assign-actorSystem
[distributed] Require explicit assignment of `actorSystem`
2 parents 1e821f2 + 456140b commit d58bd27

File tree

57 files changed

+886
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+886
-251
lines changed

include/swift/AST/Attr.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ SIMPLE_DECL_ATTR(objcMembers, ObjCMembers,
265265
OnClass |
266266
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
267267
34)
268+
CONTEXTUAL_SIMPLE_DECL_ATTR(_compilerInitialized, CompilerInitialized,
269+
OnVar |
270+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
271+
35)
268272
CONTEXTUAL_SIMPLE_DECL_ATTR(__consuming, Consuming,
269273
OnFunc | OnAccessor |
270274
DeclModifier |

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ ERROR(return_from_init_without_initing_stored_properties,none,
211211
"return from initializer without initializing all"
212212
" stored properties", ())
213213

214+
ERROR(explicit_store_of_compilerinitialized,none,
215+
"illegal assignment to '@_compilerInitialized' storage", ())
214216
ERROR(variable_function_use_uninit,none,
215217
"%select{variable|constant}1 '%0' used by function definition before"
216218
" being initialized",

include/swift/AST/DiagnosticsSema.def

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,17 @@ ERROR(escaping_non_function_parameter,none,
32033203
ERROR(escaping_optional_type_argument, none,
32043204
"closure is already escaping in optional type argument", ())
32053205

3206+
// @_compilerInitialized attribute
3207+
ERROR(incompatible_compilerinitialized_var,none,
3208+
"'@_compilerInitialized' attribute only applies to "
3209+
"let-bound stored properties without a default value", ())
3210+
ERROR(protocol_compilerinitialized,none,
3211+
"'@_compilerInitialized' is not currently supported in protocols", ())
3212+
ERROR(optional_compilerinitialized,none,
3213+
"'@_compilerInitialized' cannot be applied to an Optional let", ())
3214+
ERROR(instancemember_compilerinitialized,none,
3215+
"'@_compilerInitialized' can only be applied to a non-static class or actor member", ())
3216+
32063217
// @_nonEphemeral attribute
32073218
ERROR(non_ephemeral_non_pointer_type,none,
32083219
"@_nonEphemeral attribute only applies to pointer types", ())
@@ -4777,14 +4788,6 @@ ERROR(distributed_actor_func_static,none,
47774788
ERROR(distributed_actor_func_not_in_distributed_actor,none,
47784789
"'distributed' method can only be declared within 'distributed actor'",
47794790
())
4780-
ERROR(distributed_actor_designated_ctor_must_have_one_distributedactorsystem_param,none,
4781-
"designated distributed actor initializer %0 must accept exactly one "
4782-
"DistributedActorSystem parameter, found %1",
4783-
(DeclName, int))
4784-
ERROR(distributed_actor_designated_ctor_missing_transport_param,none,
4785-
"designated distributed actor initializer %0 is missing required "
4786-
"DistributedActorSystem parameter",
4787-
(DeclName))
47884791
ERROR(distributed_actor_user_defined_special_property,none,
47894792
"property %0 cannot be defined explicitly, as it conflicts with "
47904793
"distributed actor synthesized stored property",

include/swift/SILOptimizer/Utils/DistributedActor.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ class SILLocation;
3232
class SILType;
3333
class SILValue;
3434

35-
/// Finds the first `DistributedActorSystem`-compatible parameter of the given function.
36-
/// \returns nullptr if the function does not have such a parameter.
37-
SILArgument *findFirstDistributedActorSystemArg(SILFunction &F);
35+
/// Creates a reference to the distributed actor's \p actorSystem
36+
/// stored property.
37+
SILValue refDistributedActorSystem(SILBuilder &B,
38+
SILLocation loc,
39+
ClassDecl *actorDecl,
40+
SILValue actorInstance);
3841

3942
/// Emit a call to a witness of the DistributedActorSystem protocol.
4043
///
@@ -59,6 +62,11 @@ void emitDistributedActorSystemWitnessCall(
5962
void emitActorReadyCall(SILBuilder &B, SILLocation loc, SILValue actor,
6063
SILValue actorSystem);
6164

65+
/// Emits code to notify the \p actorSystem that the given identity is resigned.
66+
void emitResignIdentityCall(SILBuilder &B, SILLocation loc, ClassDecl* actDecl,
67+
SILValue actor, SILValue identityRef);
68+
69+
6270
} // namespace swift
6371

6472
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- InitializeDistActorIdentity.h - dist actor ID init for SILGen ----===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "Cleanup.h"
14+
15+
namespace swift {
16+
17+
class AllocStackInst;
18+
19+
namespace Lowering {
20+
21+
/// A clean-up designed to emit an initialization of a distributed actor's
22+
/// identity upon successful initialization of the actor's system.
23+
struct InitializeDistActorIdentity : Cleanup {
24+
private:
25+
ConstructorDecl *ctor;
26+
ManagedValue actorSelf;
27+
VarDecl *systemVar;
28+
public:
29+
InitializeDistActorIdentity(ConstructorDecl *ctor, ManagedValue actorSelf);
30+
31+
void emit(SILGenFunction &SGF, CleanupLocation loc,
32+
ForUnwind_t forUnwind) override;
33+
34+
void dump(SILGenFunction &) const override;
35+
36+
VarDecl* getSystemVar() const { return systemVar; }
37+
};
38+
39+
} // end Lowering namespace
40+
} // end swift namespace

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
835835
}
836836
}
837837

838-
// Distributed actor initializers implicitly initialize their transport and id
838+
// Some distributed actor initializers need to init the actorSystem & id now
839839
if (isDesignatedDistActorInit) {
840840
emitDistributedActorImplicitPropertyInits(ctor, selfArg);
841841
}
@@ -1257,4 +1257,3 @@ void SILGenFunction::emitIVarInitializer(SILDeclRef ivarInitializer) {
12571257

12581258
emitEpilog(loc);
12591259
}
1260-

0 commit comments

Comments
 (0)