Skip to content

Commit 25a075c

Browse files
committed
[IRGen] Remove unused explosion schema from enum payload schema
At some point it might be useful to be able to use an appropriate explosion schema to explode payloads but currently the code that handles this is unused. There are lots of different ways we might add this functionality in the future and it isn't clear that the existing code will be the best way to use explosion schemas in the future. For now remove this dead code so that its presence doesn't obscure the code that is actually in use.
1 parent d417017 commit 25a075c

File tree

3 files changed

+24
-45
lines changed

3 files changed

+24
-45
lines changed

lib/IRGen/EnumPayload.h

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,54 +26,38 @@ namespace swift {
2626
namespace irgen {
2727

2828
/// A description of how to represent an enum payload as a value.
29-
/// A payload can either use a generic word-chunked representation, or attempt
30-
/// to follow the explosion schema of one of its payload types.
29+
/// A payload can either use a generic word-chunked representation,
30+
/// or attempt to follow the explosion schema of one of its payload
31+
/// types.
32+
/// TODO: the current code only ever uses the generic word-chunked
33+
/// representation, it might be better if it used an appropriate
34+
/// explosion schema instead.
3135
class EnumPayloadSchema {
32-
using BitSizeTy = llvm::PointerEmbeddedInt<unsigned, 31>;
33-
34-
const llvm::PointerUnion<ExplosionSchema *, BitSizeTy> Value;
35-
36+
// A size in bits less than 0 indicates that the payload size is
37+
// dynamic.
38+
const int64_t BitSize;
3639
public:
37-
EnumPayloadSchema() : Value((ExplosionSchema *)nullptr) {}
38-
39-
explicit operator bool() {
40-
return Value.getOpaqueValue() != nullptr;
41-
}
40+
/// Create a new schema with a dynamic size.
41+
EnumPayloadSchema() : BitSize(-1) {}
4242

43+
/// Create a new schema with the given fixed size in bits.
4344
explicit EnumPayloadSchema(unsigned bits)
44-
: Value(BitSizeTy(bits)) {}
45-
46-
EnumPayloadSchema(ExplosionSchema &s)
47-
: Value(&s) {}
45+
: BitSize(static_cast<int64_t>(bits)) {}
4846

49-
static EnumPayloadSchema withBitSize(unsigned bits) {
50-
return EnumPayloadSchema(bits);
51-
}
52-
53-
ExplosionSchema *getSchema() const {
54-
return Value.dyn_cast<ExplosionSchema*>();
47+
/// Report whether the schema has a fixed size.
48+
explicit operator bool() const {
49+
return BitSize >= 0;
5550
}
56-
51+
5752
/// Invoke a functor for each element type in the schema.
5853
template<typename TypeFn /* void(llvm::Type *schemaType) */>
5954
void forEachType(IRGenModule &IGM, TypeFn &&fn) const {
60-
// Follow an explosion schema if we have one.
61-
if (auto *explosion = Value.dyn_cast<ExplosionSchema *>()) {
62-
for (auto &element : *explosion) {
63-
auto type = element.getScalarType();
64-
assert(IGM.DataLayout.getTypeSizeInBits(type)
65-
== IGM.DataLayout.getTypeAllocSizeInBits(type)
66-
&& "enum payload schema elements should use full alloc size");
67-
(void) type;
68-
fn(element.getScalarType());
69-
}
70-
return;
71-
}
72-
73-
// Otherwise, chunk into pointer-sized integer values by default.
74-
unsigned bitSize = Value.get<BitSizeTy>();
75-
unsigned pointerSize = IGM.getPointerSize().getValueInBits();
76-
55+
assert(BitSize >= 0 && "payload size must not be dynamic");
56+
57+
// Chunk into pointer-sized integer values.
58+
int64_t bitSize = BitSize;
59+
int64_t pointerSize = IGM.getPointerSize().getValueInBits();
60+
7761
while (bitSize >= pointerSize) {
7862
fn(IGM.SizeTy);
7963
bitSize -= pointerSize;

lib/IRGen/GenEnum.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,11 +1334,6 @@ namespace {
13341334
PayloadBitCount = ~0u;
13351335
}
13361336
}
1337-
1338-
~PayloadEnumImplStrategyBase() override {
1339-
if (auto schema = PayloadSchema.getSchema())
1340-
delete schema;
1341-
}
13421337

13431338
void getSchema(ExplosionSchema &schema) const override {
13441339
if (TIK < Loadable) {

lib/IRGen/TypeLayoutVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ IRGenTypeVerifierFunction::emit(ArrayRef<CanType> formalTypes) {
115115
auto fixedXIOpaque = Builder.CreateBitCast(fixedXIBuf,
116116
IGM.OpaquePtrTy);
117117
auto xiMask = fixedTI->getFixedExtraInhabitantMask(IGM);
118-
auto xiSchema = EnumPayloadSchema::withBitSize(xiMask.getBitWidth());
118+
auto xiSchema = EnumPayloadSchema(xiMask.getBitWidth());
119119

120120
auto maxXiCount = std::min(xiCount, 256u);
121121
auto numCases = llvm::ConstantInt::get(IGM.Int32Ty, maxXiCount);

0 commit comments

Comments
 (0)