Skip to content

Commit b663a15

Browse files
committed
Add tests for raw layout vector
1 parent 8b773dc commit b663a15

File tree

2 files changed

+445
-73
lines changed

2 files changed

+445
-73
lines changed

lib/IRGen/GenRecord.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ class RecordTypeInfoImpl : public Base,
203203
}
204204

205205
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+
});
209210
}
210211

211212
if (isOutlined || T.hasParameterizedExistential()) {
@@ -268,8 +269,10 @@ class RecordTypeInfoImpl : public Base,
268269
// If the fields are not ABI-accessible, use the value witness table.
269270
return emitInitializeWithTakeCall(IGF, T, dest, src);
270271
} 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+
});
273276
} else if (isOutlined || T.hasParameterizedExistential()) {
274277
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
275278
for (auto &field : getFields()) {
@@ -289,31 +292,21 @@ class RecordTypeInfoImpl : public Base,
289292
fillWithZerosIfSensitive(IGF, src, T);
290293
}
291294

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 {
295299
if (rawLayout->shouldMoveAsLikeType()) {
296300
// Because we have a rawlayout attribute, we know this has to be a struct.
297301
auto structDecl = T.getStructOrBoundGenericStruct();
298302

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-
310303
if (auto likeType = rawLayout->getResolvedScalarLikeType(structDecl)) {
311304
auto astT = T.getASTType();
312305
auto subs = astT->getContextSubstitutionMap();
313306
auto loweredLikeType = IGF.IGM.getLoweredType(likeType->subst(subs));
314307
auto &likeTypeInfo = IGF.IGM.getTypeInfo(loweredLikeType);
315308

316-
take(likeTypeInfo, loweredLikeType, dest, src);
309+
body(likeTypeInfo, loweredLikeType, dest, src);
317310
}
318311

319312
if (auto likeArray = rawLayout->getResolvedArrayLikeTypeAndCount(structDecl)) {
@@ -329,7 +322,7 @@ class RecordTypeInfoImpl : public Base,
329322
IGF.emitLoopOverElements(likeTypeInfo, loweredLikeType,
330323
countType->getCanonicalType(), dest, src,
331324
[&](Address dest, Address src) {
332-
take(likeTypeInfo, loweredLikeType, dest, src);
325+
body(likeTypeInfo, loweredLikeType, dest, src);
333326
});
334327
}
335328
}
@@ -342,6 +335,13 @@ class RecordTypeInfoImpl : public Base,
342335
return emitDestroyCall(IGF, T, addr);
343336
}
344337

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+
345345
if (isOutlined || T.hasParameterizedExistential()) {
346346
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
347347
for (auto &field : getFields()) {

0 commit comments

Comments
 (0)