Skip to content

Improve layout strings runtime code and fix several issues #68042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c25b3b4
[Runtime] Restructure BytecodeLayouts
drexin Aug 21, 2023
ec3a2dc
[Runtime] Templatize shared functionality in BytecodeLayouts
drexin Aug 21, 2023
2f61e2a
[Runtime] Further abstract shared functionality in BytecodeLayouts
drexin Aug 21, 2023
4a395cb
[Runtime+IRGen] Some fixes and optimizations for layout strings
drexin Aug 21, 2023
31de67c
[IRGen+Runtime] Further fixes for layout strings
drexin Aug 21, 2023
27b1764
[Runtime+IRGen] Fix layout string flag in type layout and add array f…
drexin Aug 21, 2023
30d6282
[IRGen+Runtime] Make more fine grained copies in layout string runtim…
drexin Aug 21, 2023
4f6e69b
[Runtime] Reduce instruction count in simple layout string operations
drexin Aug 21, 2023
8ab845f
[Runtime+IRGen] Fix offsets of existentials in layout strings
drexin Aug 21, 2023
7c0203d
[Runtime] Combine copy and destroy in assignWithCopy
drexin Aug 21, 2023
8b3aaf5
[Runtime] Compute end before looping over single payload ref count
drexin Aug 21, 2023
56048ac
[Runtime+IRGen] Fix existential offset for multiple protocol witnesses
drexin Aug 21, 2023
7e3f56d
[Runtime] Fix generic existentials in layout strings
drexin Aug 21, 2023
734e9b8
[IRGen] Make enum metadata non-const for instantiated layout strings
drexin Aug 21, 2023
fd967fd
[Runtime] Properly handle boxed references in layout string instantia…
drexin Aug 21, 2023
0ff7f1d
[IRGen] Don't generate layout strings for moveonly types
drexin Aug 21, 2023
21f4064
[Runtime] Fix singlePayloadEnumSimpleAssignWithCopy
drexin Aug 21, 2023
a0e48a3
[Runtime] Assert when trying to get layout string from class
drexin Aug 21, 2023
904418f
[Test] Remove accidentally commited broken test code
drexin Aug 21, 2023
b7bde13
Merge branch 'wip-layout-strings-work'
drexin Aug 22, 2023
e3a1bac
[Runtime] Use copy of addrOffset in single payload assign with copy
drexin Aug 24, 2023
97b2dc7
[IRGen] Assign extraTagByteCount to the correct union field in addSin…
drexin Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,8 @@ struct TargetMetadata {

const uint8_t *getLayoutString() const {
assert(hasLayoutString());
if (isAnyClass()) {
return asFullMetadata(
reinterpret_cast<const TargetAnyClassMetadata<Runtime> *>(
this))
->layoutString;
}
// Classes should not have layout strings
assert(!isAnyClass());
return asFullMetadata(this)->layoutString;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,8 +2586,7 @@ void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
IGM.Context.LangOpts.hasFeature(
Feature::LayoutStringValueWitnessesInstantiation) &&
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
hasLayoutString |= requiresForeignTypeMetadata(type) ||
needsSingletonMetadataInitialization(IGM, type) ||
hasLayoutString |= needsSingletonMetadataInitialization(IGM, type) ||
(type->isGenericContext() && !isa<FixedTypeInfo>(ti));
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/IRGen/GenStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,10 @@ namespace {
field.getTypeInfo().buildTypeLayoutEntry(IGM, fieldTy, useStructLayouts));
}

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

return IGM.typeLayoutCache.getOrCreateAlignedGroupEntry(
fields, T, getBestKnownAlignment().getValue(), *this);
Expand Down
15 changes: 11 additions & 4 deletions lib/IRGen/TypeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class LayoutStringBuilder {
RefCounting op;
op.kind = RefCountingKind::SinglePayloadEnumFN;
op.singlePayloadEnumFN.tagFn = tagFn;
op.singlePayloadEnumSimple.extraTagByteCount = extraTagByteCount;
op.singlePayloadEnumFN.extraTagByteCount = extraTagByteCount;
op.singlePayloadEnumFN.payload = payload;
refCountings.push_back(op);
}
Expand Down Expand Up @@ -360,12 +360,19 @@ class LayoutStringBuilder {
break;
}

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

skip = refCounting.size;
default: {
uint64_t op = (static_cast<uint64_t>(refCounting.kind) << 56) | skip;
B.addInt64(op);
refCountBytes += sizeof(uint64_t);
skip = refCounting.size - IGM.getPointerSize().getValue();
break;
}
}
Expand Down Expand Up @@ -1734,7 +1741,7 @@ AlignedGroupEntry::layoutString(IRGenModule &IGM,

bool AlignedGroupEntry::refCountString(IRGenModule &IGM, LayoutStringBuilder &B,
GenericSignature genericSig) const {
if (!isFixedSize(IGM)) {
if (!isFixedSize(IGM) || ty.isMoveOnly()) {
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions stdlib/public/runtime/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//
//===----------------------------------------------------------------------===//

#include "BytecodeLayouts.h"
#include "swift/Runtime/Config.h"
#include "swift/Runtime/HeapObject.h"
#include "swift/Runtime/Metadata.h"
Expand Down Expand Up @@ -124,6 +125,10 @@ static void array_copy_operation(OpaqueValue *dest, OpaqueValue *src,
assert(copyKind == ArrayCopy::BackToFront);
assert(count != 0);

if (self->hasLayoutString() && destOp == ArrayDest::Init && srcOp == ArraySource::Copy) {
return swift_generic_arrayInitWithCopy(dest, src, count, stride, self);
}

auto copy = get_witness_function<destOp, srcOp>(wtable);
size_t i = count;
do {
Expand Down Expand Up @@ -202,6 +207,10 @@ void swift_arrayDestroy(OpaqueValue *begin, size_t count, const Metadata *self)
return;

auto stride = wtable->getStride();
if (self->hasLayoutString()) {
return swift_generic_arrayDestroy(begin, count, stride, self);
}

for (size_t i = 0; i < count; ++i) {
auto offset = i * stride;
auto *obj = reinterpret_cast<OpaqueValue *>((char *)begin + offset);
Expand Down
Loading