@@ -46,13 +46,30 @@ namespace {
46
46
47
47
SILValue getAddressOrNull () const override { return SILValue (); }
48
48
49
+ bool canSplitIntoSubelementAddresses () const override {
50
+ return true ;
51
+ }
52
+
53
+ ArrayRef<InitializationPtr>
54
+ getSubInitializationsForTuple (SILGenFunction &gen, CanType type,
55
+ SmallVectorImpl<InitializationPtr> &buf,
56
+ SILLocation Loc) override {
57
+ // "Destructure" an ignored binding into multiple ignored bindings.
58
+ for (auto fieldType : cast<TupleType>(type)->getElementTypes ()) {
59
+ (void ) fieldType;
60
+ buf.push_back (InitializationPtr (new BlackHoleInitialization ()));
61
+ }
62
+ return buf;
63
+ }
64
+
49
65
void copyOrInitValueInto (ManagedValue explodedElement, bool isInit,
50
66
SILLocation loc, SILGenFunction &gen) override {
51
67
// / This just ignores the provided value.
52
68
}
53
-
54
69
};
55
-
70
+ } // end anonymous namespace
71
+
72
+ namespace {
56
73
// / An Initialization of a tuple pattern, such as "var (a,b)".
57
74
class TupleInitialization : public Initialization {
58
75
public:
@@ -69,8 +86,15 @@ namespace {
69
86
else
70
87
return SILValue ();
71
88
}
72
-
73
- ArrayRef<InitializationPtr> getSubInitializations () const {
89
+
90
+ bool canSplitIntoSubelementAddresses () const override {
91
+ return true ;
92
+ }
93
+
94
+ ArrayRef<InitializationPtr>
95
+ getSubInitializationsForTuple (SILGenFunction &gen, CanType type,
96
+ SmallVectorImpl<InitializationPtr> &buf,
97
+ SILLocation Loc) override {
74
98
return subInitializations;
75
99
}
76
100
@@ -83,75 +107,9 @@ namespace {
83
107
SILLocation loc, SILGenFunction &gen) override {
84
108
llvm_unreachable (" tuple initialization not destructured?!" );
85
109
}
86
-
87
110
};
88
- }
89
-
90
- bool Initialization::canForwardInBranch () const {
91
- switch (kind) {
92
- case Kind::Ignored:
93
- case Kind::SingleBuffer:
94
- return true ;
95
-
96
- // These initializations expect to be activated exactly once.
97
- case Kind::LetValue:
98
- case Kind::Translating:
99
- case Kind::Refutable:
100
- return false ;
101
-
102
- case Kind::Tuple:
103
- for (auto &subinit : ((TupleInitialization*)this )->getSubInitializations ()){
104
- if (!subinit->canForwardInBranch ())
105
- return false ;
106
- }
107
- return true ;
108
- }
109
- llvm_unreachable (" bad initialization kind!" );
110
- }
111
-
112
- ArrayRef<InitializationPtr>
113
- Initialization::getSubInitializationsForTuple (SILGenFunction &gen, CanType type,
114
- SmallVectorImpl<InitializationPtr> &buf,
115
- SILLocation Loc) {
116
- assert (canSplitIntoSubelementAddresses () && " Client shouldn't call this" );
117
- switch (kind) {
118
- case Kind::Tuple:
119
- return ((TupleInitialization*)this )->getSubInitializations ();
120
-
121
- case Kind::Ignored:
122
- // "Destructure" an ignored binding into multiple ignored bindings.
123
- for (auto fieldType : cast<TupleType>(type)->getElementTypes ()) {
124
- (void ) fieldType;
125
- buf.push_back (InitializationPtr (new BlackHoleInitialization ()));
126
- }
127
- return buf;
128
- case Kind::LetValue:
129
- case Kind::SingleBuffer: {
130
- // Destructure the buffer into per-element buffers.
131
- auto tupleTy = cast<TupleType>(type);
132
- SILValue baseAddr = getAddress ();
133
- for (unsigned i = 0 , size = tupleTy->getNumElements (); i < size; ++i) {
134
- auto fieldType = tupleTy.getElementType (i);
135
- SILType fieldTy = gen.getLoweredType (fieldType).getAddressType ();
136
- SILValue fieldAddr = gen.B .createTupleElementAddr (Loc,
137
- baseAddr, i,
138
- fieldTy);
111
+ } // end anonymous namespace
139
112
140
- buf.push_back (InitializationPtr (new
141
- KnownAddressInitialization (fieldAddr)));
142
- }
143
- finishInitialization (gen);
144
- return buf;
145
- }
146
- case Kind::Translating:
147
- // This could actually be done by collecting translated values, if
148
- // we introduce new needs for translating initializations.
149
- llvm_unreachable (" cannot destructure a translating initialization" );
150
- case Kind::Refutable:
151
- llvm_unreachable (" cannot destructure a refutable initialization" );
152
- }
153
- llvm_unreachable (" bad initialization kind" );
154
- }
155
113
156
114
namespace {
157
115
class CleanupClosureConstant : public Cleanup {
@@ -184,8 +142,25 @@ void SILGenFunction::visitFuncDecl(FuncDecl *fd) {
184
142
}
185
143
}
186
144
187
- SingleBufferInitialization::~SingleBufferInitialization () {
188
- // vtable anchor.
145
+ ArrayRef<InitializationPtr> SingleBufferInitialization::
146
+ getSubInitializationsForTuple (SILGenFunction &gen, CanType type,
147
+ SmallVectorImpl<InitializationPtr> &buf,
148
+ SILLocation Loc) {
149
+ // Destructure the buffer into per-element buffers.
150
+ auto tupleTy = cast<TupleType>(type);
151
+ SILValue baseAddr = getAddress ();
152
+ for (unsigned i = 0 , size = tupleTy->getNumElements (); i < size; ++i) {
153
+ auto fieldType = tupleTy.getElementType (i);
154
+ SILType fieldTy = gen.getLoweredType (fieldType).getAddressType ();
155
+ SILValue fieldAddr = gen.B .createTupleElementAddr (Loc,
156
+ baseAddr, i,
157
+ fieldTy);
158
+
159
+ buf.push_back (InitializationPtr (new
160
+ KnownAddressInitialization (fieldAddr)));
161
+ }
162
+ finishInitialization (gen);
163
+ return buf;
189
164
}
190
165
191
166
void SingleBufferInitialization::
@@ -408,6 +383,28 @@ class LetValueInitialization : public Initialization {
408
383
return hasAddress ();
409
384
}
410
385
386
+ ArrayRef<InitializationPtr>
387
+ getSubInitializationsForTuple (SILGenFunction &gen, CanType type,
388
+ SmallVectorImpl<InitializationPtr> &buf,
389
+ SILLocation Loc) override {
390
+ // Destructure the buffer into per-element buffers.
391
+ auto tupleTy = cast<TupleType>(type);
392
+ SILValue baseAddr = getAddress ();
393
+ for (unsigned i = 0 , size = tupleTy->getNumElements (); i < size; ++i) {
394
+ auto fieldType = tupleTy.getElementType (i);
395
+ SILType fieldTy = gen.getLoweredType (fieldType).getAddressType ();
396
+ SILValue fieldAddr = gen.B .createTupleElementAddr (Loc,
397
+ baseAddr, i,
398
+ fieldTy);
399
+
400
+ buf.push_back (InitializationPtr (new
401
+ KnownAddressInitialization (fieldAddr)));
402
+ }
403
+ finishInitialization (gen);
404
+ return buf;
405
+ }
406
+
407
+
411
408
void emitDebugValue (SILValue v, SILGenFunction &gen) {
412
409
// Emit a debug_value[_addr] instruction to record the start of this value's
413
410
// lifetime.
0 commit comments