Skip to content

Commit 030daee

Browse files
authored
Merge pull request #68042 from drexin/wip-layout-strings-work
Improve layout strings runtime code and fix several issues
2 parents f7dcf1d + 97b2dc7 commit 030daee

File tree

12 files changed

+1906
-523
lines changed

12 files changed

+1906
-523
lines changed

include/swift/ABI/Metadata.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,8 @@ struct TargetMetadata {
324324

325325
const uint8_t *getLayoutString() const {
326326
assert(hasLayoutString());
327-
if (isAnyClass()) {
328-
return asFullMetadata(
329-
reinterpret_cast<const TargetAnyClassMetadata<Runtime> *>(
330-
this))
331-
->layoutString;
332-
}
327+
// Classes should not have layout strings
328+
assert(!isAnyClass());
333329
return asFullMetadata(this)->layoutString;
334330
}
335331

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,7 @@ void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
25862586
IGM.Context.LangOpts.hasFeature(
25872587
Feature::LayoutStringValueWitnessesInstantiation) &&
25882588
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
2589-
hasLayoutString |= requiresForeignTypeMetadata(type) ||
2590-
needsSingletonMetadataInitialization(IGM, type) ||
2589+
hasLayoutString |= needsSingletonMetadataInitialization(IGM, type) ||
25912590
(type->isGenericContext() && !isa<FixedTypeInfo>(ti));
25922591
}
25932592
}

lib/IRGen/GenStruct.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,10 @@ namespace {
919919
field.getTypeInfo().buildTypeLayoutEntry(IGM, fieldTy, useStructLayouts));
920920
}
921921

922-
if (fields.size() == 1 && isFixedSize() &&
923-
getBestKnownAlignment() == *fields[0]->fixedAlignment(IGM)) {
924-
return fields[0];
925-
}
922+
// if (fields.size() == 1 && isFixedSize() &&
923+
// getBestKnownAlignment() == *fields[0]->fixedAlignment(IGM)) {
924+
// return fields[0];
925+
// }
926926

927927
return IGM.typeLayoutCache.getOrCreateAlignedGroupEntry(
928928
fields, T, getBestKnownAlignment().getValue(), *this);

lib/IRGen/TypeLayout.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class LayoutStringBuilder {
160160
RefCounting op;
161161
op.kind = RefCountingKind::SinglePayloadEnumFN;
162162
op.singlePayloadEnumFN.tagFn = tagFn;
163-
op.singlePayloadEnumSimple.extraTagByteCount = extraTagByteCount;
163+
op.singlePayloadEnumFN.extraTagByteCount = extraTagByteCount;
164164
op.singlePayloadEnumFN.payload = payload;
165165
refCountings.push_back(op);
166166
}
@@ -360,12 +360,19 @@ class LayoutStringBuilder {
360360
break;
361361
}
362362

363-
default: {
363+
case RefCountingKind::Existential: {
364364
uint64_t op = (static_cast<uint64_t>(refCounting.kind) << 56) | skip;
365365
B.addInt64(op);
366366
refCountBytes += sizeof(uint64_t);
367+
skip = refCounting.size - getFixedBufferSize(IGM).getValue();
368+
break;
369+
}
367370

368-
skip = refCounting.size;
371+
default: {
372+
uint64_t op = (static_cast<uint64_t>(refCounting.kind) << 56) | skip;
373+
B.addInt64(op);
374+
refCountBytes += sizeof(uint64_t);
375+
skip = refCounting.size - IGM.getPointerSize().getValue();
369376
break;
370377
}
371378
}
@@ -1734,7 +1741,7 @@ AlignedGroupEntry::layoutString(IRGenModule &IGM,
17341741

17351742
bool AlignedGroupEntry::refCountString(IRGenModule &IGM, LayoutStringBuilder &B,
17361743
GenericSignature genericSig) const {
1737-
if (!isFixedSize(IGM)) {
1744+
if (!isFixedSize(IGM) || ty.isMoveOnly()) {
17381745
return false;
17391746
}
17401747

stdlib/public/runtime/Array.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//
2323
//===----------------------------------------------------------------------===//
2424

25+
#include "BytecodeLayouts.h"
2526
#include "swift/Runtime/Config.h"
2627
#include "swift/Runtime/HeapObject.h"
2728
#include "swift/Runtime/Metadata.h"
@@ -124,6 +125,10 @@ static void array_copy_operation(OpaqueValue *dest, OpaqueValue *src,
124125
assert(copyKind == ArrayCopy::BackToFront);
125126
assert(count != 0);
126127

128+
if (self->hasLayoutString() && destOp == ArrayDest::Init && srcOp == ArraySource::Copy) {
129+
return swift_generic_arrayInitWithCopy(dest, src, count, stride, self);
130+
}
131+
127132
auto copy = get_witness_function<destOp, srcOp>(wtable);
128133
size_t i = count;
129134
do {
@@ -202,6 +207,10 @@ void swift_arrayDestroy(OpaqueValue *begin, size_t count, const Metadata *self)
202207
return;
203208

204209
auto stride = wtable->getStride();
210+
if (self->hasLayoutString()) {
211+
return swift_generic_arrayDestroy(begin, count, stride, self);
212+
}
213+
205214
for (size_t i = 0; i < count; ++i) {
206215
auto offset = i * stride;
207216
auto *obj = reinterpret_cast<OpaqueValue *>((char *)begin + offset);

0 commit comments

Comments
 (0)