1
+ // ===--- SILGenConstructor.cpp - SILGen for constructors ------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2017 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 " ArgumentSource.h"
14
+ #include " Conversion.h"
15
+ #include " ExecutorBreadcrumb.h"
16
+ #include " Initialization.h"
17
+ #include " LValue.h"
18
+ #include " RValue.h"
19
+ #include " SILGenFunction.h"
20
+ #include " SILGenFunctionBuilder.h"
21
+ #include " Scope.h"
22
+ #include " swift/AST/ASTMangler.h"
23
+ #include " swift/AST/ForeignErrorConvention.h"
24
+ #include " swift/AST/GenericEnvironment.h"
25
+ #include " swift/AST/ParameterList.h"
26
+ #include " swift/AST/PropertyWrappers.h"
27
+ #include " swift/Basic/Defer.h"
28
+ #include " swift/SIL/SILArgument.h"
29
+ #include " swift/SIL/SILUndef.h"
30
+ #include " swift/SIL/TypeLowering.h"
31
+
32
+ using namespace swift ;
33
+ using namespace Lowering ;
34
+
35
+ static InitializationPtr
36
+ emitDistributedActorTransportInit (SILGenFunction &SGF, VarDecl *selfDecl,
37
+ Pattern *transportPattern, VarDecl *transportVar) {
38
+ auto self = SGF.emitSelfForMemberInit (SGF, transportPattern, selfDecl);
39
+ InitializationPtr initialization =
40
+ emitPatternBindingInitialization (transportPattern, SOMEDEST);
41
+
42
+ //
43
+ FullExpr Scope (SGF.Cleanups , CleanupLocation (transportVar->getInitializer ()));
44
+ emitExprInto (transportVar->getInitializer ());
45
+ }
46
+
47
+
48
+ void SILGenFunction::initializeDistributedActorImplicitStorageInit (
49
+ ConstructorDecl *ctor, ManagedValue selfArg) {
50
+ VarDecl *selfDecl = ctor->getImplicitSelfDecl ();
51
+ auto *dc = ctor->getDeclContext ();
52
+ auto classDecl = dc->getSelfClassDecl ();
53
+ auto &C = classDecl->getASTContext ();
54
+
55
+ SILLocation prologueLoc = RegularLocation (ctor);
56
+ prologueLoc.markAsPrologue (); // TODO: no idea if this is necessary or makes sense
57
+
58
+ fprintf (stderr, " [%s:%d] (%s) EMIT initializeDistributedActorImplicitStorageInit\n " , __FILE__, __LINE__, __FUNCTION__);
59
+ ctor->dump ();
60
+ fprintf (stderr, " [%s:%d] (%s) CLASS---------------------------------------------\n " , __FILE__, __LINE__, __FUNCTION__);
61
+ classDecl->dump ();
62
+ fprintf (stderr, " [%s:%d] (%s) --------------------------------------------------\n " , __FILE__, __LINE__, __FUNCTION__);
63
+
64
+ // find the transport parameter
65
+ SILValue transportArgValue = F.getArgument (0 );
66
+ ManagedValue transportArgManaged = ManagedValue::forUnmanaged (transportArgValue);
67
+
68
+ auto transportTy = C.getActorTransportType (); // getProtocol(KnownProtocolKind::ActorTransport);
69
+ auto identityProtoTy = C.getActorIdentityType (); // getProtocol(KnownProtocolKind::ActorIdentity);
70
+ auto anyIdentityTy = C.getAnyActorIdentityType ();
71
+
72
+ VarDecl *transportMember;
73
+ VarDecl *idMember;
74
+
75
+ for (auto member : classDecl->getMembers ()) {
76
+ PatternBindingDecl *pbd = dyn_cast<PatternBindingDecl>(member);
77
+ if (!pbd) continue ;
78
+ if (pbd->isStatic ()) continue ;
79
+
80
+ fprintf (stderr, " [%s:%d] (%s) MEMBER\n " , __FILE__, __LINE__, __FUNCTION__);
81
+ member->dump ();
82
+
83
+ Pattern *pattern = pbd->getPattern (0 );
84
+ VarDecl *var = pbd->getSingleVar ();
85
+ if (!var) continue ;
86
+
87
+ if (var->getName () == C.Id_actorTransport &&
88
+ var->getInterfaceType ()->isEqual (transportTy)) {
89
+ transportMember = var;
90
+ fprintf (stderr, " [%s:%d] (%s) FOUND TRANSPORT MEMBER\n " , __FILE__, __LINE__, __FUNCTION__);
91
+ auto transportInit = emitDistributedActorTransportInit (*this , selfDecl, pattern, var);
92
+ } else if (var->getName () == C.Id_id &&
93
+ (var->getInterfaceType ()->isEqual (identityProtoTy) ||
94
+ var->getInterfaceType ()->isEqual (anyIdentityTy))) { // TODO(distributed): stick one way to store, but today we can't yet store the existential
95
+ idMember = var;
96
+ fprintf (stderr, " [%s:%d] (%s) FOUND ID MEMBER\n " , __FILE__, __LINE__, __FUNCTION__);
97
+ auto transportInit = emitDistributedActorTransportInit (*this , selfDecl, pattern, var);
98
+
99
+ }
100
+ if (transportMember && idMember)
101
+ break ; // we found all properties we care about, break out of the loop early
102
+ }
103
+
104
+ assert (transportMember && " Missing DistributedActor.actorTransport member" );
105
+ assert (idMember && " Missing DistributedActor.id member" );
106
+
107
+ }
0 commit comments