@@ -165,9 +165,10 @@ static void getAssignByWrapperArgs(SmallVectorImpl<SILValue> &args,
165
165
" initializer or setter has too many arguments" );
166
166
}
167
167
168
- static void lowerAssignByWrapperInstruction (SILBuilderWithScope &b,
169
- AssignByWrapperInst *inst,
170
- SmallSetVector<SILValue, 8 > &toDelete) {
168
+ static void
169
+ lowerAssignByWrapperInstruction (SILBuilderWithScope &b,
170
+ AssignByWrapperInst *inst,
171
+ SmallSetVector<SILValue, 8 > &toDelete) {
171
172
LLVM_DEBUG (llvm::dbgs () << " *** Lowering " << *inst << " \n " );
172
173
173
174
++numAssignRewritten;
@@ -186,29 +187,46 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
186
187
LLVM_FALLTHROUGH;
187
188
case AssignByWrapperInst::Initialization:
188
189
case AssignByWrapperInst::Assign: {
189
- SILValue initFn = inst->getInitializer ();
190
- CanSILFunctionType fTy = initFn->getType ().castTo <SILFunctionType>();
191
- SILFunctionConventions convention (fTy , inst->getModule ());
192
- SmallVector<SILValue, 4 > args;
193
- if (convention.hasIndirectSILResults ()) {
194
- if (inst->getMode () == AssignByWrapperInst::Assign)
195
- b.createDestroyAddr (loc, dest);
196
-
197
- args.push_back (dest);
198
- getAssignByWrapperArgs (args, src, convention, b, forCleanup);
199
- b.createApply (loc, initFn, SubstitutionMap (), args);
200
- } else {
201
- getAssignByWrapperArgs (args, src, convention, b, forCleanup);
202
- SILValue wrappedSrc = b.createApply (loc, initFn, SubstitutionMap (),
203
- args);
190
+ switch (inst->getOriginator ()) {
191
+ case AssignByWrapperInst::Originator::TypeWrapper: {
204
192
if (inst->getMode () == AssignByWrapperInst::Initialization ||
205
193
inst->getDest ()->getType ().isTrivial (*inst->getFunction ())) {
206
- b.createTrivialStoreOr (loc, wrappedSrc, dest,
207
- StoreOwnershipQualifier::Init);
194
+ b.createTrivialStoreOr (loc, src, dest, StoreOwnershipQualifier::Init);
195
+ } else {
196
+ b.createStore (loc, src, dest, StoreOwnershipQualifier::Assign);
197
+ }
198
+ break ;
199
+ }
200
+
201
+ case AssignByWrapperInst::Originator::PropertyWrapper: {
202
+ SILValue initFn = inst->getInitializer ();
203
+ CanSILFunctionType fTy = initFn->getType ().castTo <SILFunctionType>();
204
+ SILFunctionConventions convention (fTy , inst->getModule ());
205
+ SmallVector<SILValue, 4 > args;
206
+ if (convention.hasIndirectSILResults ()) {
207
+ if (inst->getMode () == AssignByWrapperInst::Assign)
208
+ b.createDestroyAddr (loc, dest);
209
+
210
+ args.push_back (dest);
211
+ getAssignByWrapperArgs (args, src, convention, b, forCleanup);
212
+ b.createApply (loc, initFn, SubstitutionMap (), args);
208
213
} else {
209
- b.createStore (loc, wrappedSrc, dest, StoreOwnershipQualifier::Assign);
214
+ getAssignByWrapperArgs (args, src, convention, b, forCleanup);
215
+ SILValue wrappedSrc =
216
+ b.createApply (loc, initFn, SubstitutionMap (), args);
217
+ if (inst->getMode () == AssignByWrapperInst::Initialization ||
218
+ inst->getDest ()->getType ().isTrivial (*inst->getFunction ())) {
219
+ b.createTrivialStoreOr (loc, wrappedSrc, dest,
220
+ StoreOwnershipQualifier::Init);
221
+ } else {
222
+ b.createStore (loc, wrappedSrc, dest,
223
+ StoreOwnershipQualifier::Assign);
224
+ }
210
225
}
226
+ break ;
211
227
}
228
+ }
229
+
212
230
// The unused partial_apply violates memory lifetime rules in case "self"
213
231
// is an inout. Therefore we cannot keep it as a dead closure to be
214
232
// cleaned up later. We have to delete it in this pass.
0 commit comments