@@ -203,9 +203,10 @@ class RecordTypeInfoImpl : public Base,
203
203
}
204
204
205
205
if (auto rawLayout = T.getRawLayout ()) {
206
- return takeRawLayout (IGF, dest, src, T, isOutlined,
207
- /* zeroizeIfSensitive */ false , rawLayout,
208
- /* isInit */ false );
206
+ return handleRawLayout (IGF, dest, src, T, isOutlined, rawLayout,
207
+ [&](const TypeInfo &ti, SILType type, Address dest, Address src) {
208
+ ti.assignWithTake (IGF, dest, src, type, isOutlined);
209
+ });
209
210
}
210
211
211
212
if (isOutlined || T.hasParameterizedExistential ()) {
@@ -268,8 +269,10 @@ class RecordTypeInfoImpl : public Base,
268
269
// If the fields are not ABI-accessible, use the value witness table.
269
270
return emitInitializeWithTakeCall (IGF, T, dest, src);
270
271
} else if (auto rawLayout = T.getRawLayout ()) {
271
- return takeRawLayout (IGF, dest, src, T, isOutlined, zeroizeIfSensitive,
272
- rawLayout, /* isInit */ true );
272
+ return handleRawLayout (IGF, dest, src, T, isOutlined, rawLayout,
273
+ [&](const TypeInfo &ti, SILType type, Address dest, Address src) {
274
+ ti.initializeWithTake (IGF, dest, src, type, isOutlined, zeroizeIfSensitive);
275
+ });
273
276
} else if (isOutlined || T.hasParameterizedExistential ()) {
274
277
auto offsets = asImpl ().getNonFixedOffsets (IGF, T);
275
278
for (auto &field : getFields ()) {
@@ -289,31 +292,21 @@ class RecordTypeInfoImpl : public Base,
289
292
fillWithZerosIfSensitive (IGF, src, T);
290
293
}
291
294
292
- void takeRawLayout (IRGenFunction &IGF, Address dest, Address src, SILType T,
293
- bool isOutlined, bool zeroizeIfSensitive,
294
- RawLayoutAttr *rawLayout, bool isInit) const {
295
+ void handleRawLayout (IRGenFunction &IGF, Address dest, Address src, SILType T,
296
+ bool isOutlined, RawLayoutAttr *rawLayout,
297
+ std::function<void
298
+ (const TypeInfo &, SILType, Address, Address)> body) const {
295
299
if (rawLayout->shouldMoveAsLikeType ()) {
296
300
// Because we have a rawlayout attribute, we know this has to be a struct.
297
301
auto structDecl = T.getStructOrBoundGenericStruct ();
298
302
299
- auto take = [&](const TypeInfo &likeTypeInfo, SILType loweredLikeType,
300
- Address dest, Address src) {
301
- if (isInit) {
302
- likeTypeInfo.initializeWithTake (IGF, dest, src, loweredLikeType,
303
- isOutlined, zeroizeIfSensitive);
304
- } else {
305
- likeTypeInfo.assignWithTake (IGF, dest, src, loweredLikeType,
306
- isOutlined);
307
- }
308
- };
309
-
310
303
if (auto likeType = rawLayout->getResolvedScalarLikeType (structDecl)) {
311
304
auto astT = T.getASTType ();
312
305
auto subs = astT->getContextSubstitutionMap ();
313
306
auto loweredLikeType = IGF.IGM .getLoweredType (likeType->subst (subs));
314
307
auto &likeTypeInfo = IGF.IGM .getTypeInfo (loweredLikeType);
315
308
316
- take (likeTypeInfo, loweredLikeType, dest, src);
309
+ body (likeTypeInfo, loweredLikeType, dest, src);
317
310
}
318
311
319
312
if (auto likeArray = rawLayout->getResolvedArrayLikeTypeAndCount (structDecl)) {
@@ -329,7 +322,7 @@ class RecordTypeInfoImpl : public Base,
329
322
IGF.emitLoopOverElements (likeTypeInfo, loweredLikeType,
330
323
countType->getCanonicalType (), dest, src,
331
324
[&](Address dest, Address src) {
332
- take (likeTypeInfo, loweredLikeType, dest, src);
325
+ body (likeTypeInfo, loweredLikeType, dest, src);
333
326
});
334
327
}
335
328
}
@@ -342,6 +335,13 @@ class RecordTypeInfoImpl : public Base,
342
335
return emitDestroyCall (IGF, T, addr);
343
336
}
344
337
338
+ if (auto rawLayout = T.getRawLayout ()) {
339
+ return handleRawLayout (IGF, Address (), addr, T, isOutlined, rawLayout,
340
+ [&](const TypeInfo &ti, SILType type, Address dest, Address src) {
341
+ ti.destroy (IGF, src, type, isOutlined);
342
+ });
343
+ }
344
+
345
345
if (isOutlined || T.hasParameterizedExistential ()) {
346
346
auto offsets = asImpl ().getNonFixedOffsets (IGF, T);
347
347
for (auto &field : getFields ()) {
0 commit comments