Skip to content

Commit 3a86481

Browse files
tbkkameg-gupta
authored andcommitted
Remove RemoteInspection code to fetch no-longer-used reflection metadata
without relying on spare bit information in the reflection metadata (which was added in swiftlang#40906). As a result, we can remove the code from swiftlang#40906. This is the first step in such removal. It removes the RemoteMirror code for looking up such metadata. It leaves behind: * Sufficient stubs for LLDB to continue to build. Once LLDB is updated, these stubs can be removed as well. * The compiler code to emit such metadata. This allows new binaries to still reflect MPEs on older runtimes. This will need to be kept for a transitional period.
1 parent a917cb1 commit 3a86481

File tree

11 files changed

+25
-325
lines changed

11 files changed

+25
-325
lines changed

include/swift/RemoteInspection/DescriptorFinder.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,31 @@ struct FieldDescriptorBase {
9393
getFieldRecords() = 0;
9494
};
9595

96+
// There are no longer any clients of this interface, but we
97+
// need to keep this stubbed out until all the
98+
// implementors have been removed. In particular, LLDB
99+
// still implements this interface.
100+
// TODO: Delete this after Swift 6.0 ships
96101
struct MultiPayloadEnumDescriptorBase {
97-
virtual ~MultiPayloadEnumDescriptorBase(){};
102+
virtual ~MultiPayloadEnumDescriptorBase(){ abort(); };
98103

99-
virtual llvm::StringRef getMangledTypeName() = 0;
100-
101-
virtual uint32_t getContentsSizeInWords() const = 0;
104+
virtual llvm::StringRef getMangledTypeName() { abort(); };
102105

103-
virtual size_t getSizeInBytes() const = 0;
106+
virtual uint32_t getContentsSizeInWords() const { abort(); };
104107

105-
virtual uint32_t getFlags() const = 0;
108+
virtual size_t getSizeInBytes() const { abort(); };
106109

107-
virtual bool usesPayloadSpareBits() const = 0;
110+
virtual uint32_t getFlags() const { abort(); };
108111

109-
virtual uint32_t getPayloadSpareBitMaskByteOffset() const = 0;
112+
virtual bool usesPayloadSpareBits() const { abort(); };
110113

111-
virtual uint32_t getPayloadSpareBitMaskByteCount() const = 0;
114+
virtual uint32_t getPayloadSpareBitMaskByteOffset() const { abort(); };
112115

113-
virtual const uint8_t *getPayloadSpareBits() const = 0;
116+
virtual uint32_t getPayloadSpareBitMaskByteCount() const { abort(); };
114117

118+
virtual const uint8_t *getPayloadSpareBits() const { abort(); };
115119
};
120+
116121
/// Interface for finding type descriptors. Implementors may provide descriptors
117122
/// that live inside or outside reflection metadata.
118123
struct DescriptorFinder {
@@ -125,8 +130,9 @@ struct DescriptorFinder {
125130
virtual std::unique_ptr<FieldDescriptorBase>
126131
getFieldDescriptor(const TypeRef *TR) = 0;
127132

133+
// TODO: Delete this as soon as LLDB no longer attempts to override it
128134
virtual std::unique_ptr<MultiPayloadEnumDescriptorBase>
129-
getMultiPayloadEnumDescriptor(const TypeRef *TR) = 0;
135+
getMultiPayloadEnumDescriptor(const TypeRef *TR) { abort(); };
130136
};
131137

132138
} // namespace reflection

include/swift/RemoteInspection/Records.h

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -378,111 +378,6 @@ class BuiltinTypeDescriptor {
378378
}
379379
};
380380

381-
class MultiPayloadEnumDescriptor {
382-
public:
383-
const RelativeDirectPointer<const char> TypeName;
384-
385-
private:
386-
// This descriptor contains a series of 32-bit words
387-
uint32_t contents[];
388-
389-
// Properties are stored in `contents` at particular indexes:
390-
391-
// uint32_t SizeFlags;
392-
// Upper 16 bits are the size of the contents (in 32-bit words):
393-
// (This allows us to expand this structure in the future;
394-
// new fields should have accessors that test whether the
395-
// size is large enough and return "non-existent" if the
396-
// descriptor isn't large enough to have that field.)
397-
// Lower 16 bits are flag bits
398-
399-
int getSizeFlagsIndex() const { return 0; }
400-
401-
// uint32_t PayloadSpareBitMaskByteOffsetCount;
402-
// Number of bytes in "payload spare bits", and
403-
// offset of them within the payload area
404-
// Only present if `usePayloadSpareBits()`
405-
406-
int getPayloadSpareBitMaskByteCountIndex() const {
407-
return getSizeFlagsIndex() + 1;
408-
}
409-
410-
// uint8_t *PayloadSpareBits;
411-
// Variably-sized bitmask field (padded to a multiple of 4 bytes)
412-
// Only present if `usePayloadSpareBits()`
413-
414-
int getPayloadSpareBitsIndex() const {
415-
int PayloadSpareBitMaskByteCountFieldSize = usesPayloadSpareBits() ? 1 : 0;
416-
return getPayloadSpareBitMaskByteCountIndex() + PayloadSpareBitMaskByteCountFieldSize;
417-
}
418-
419-
// uint32_t foo;
420-
// TODO: Some future field
421-
// int getFooIndex() const {
422-
// int PayloadSpareBitMaskFieldSize = (getPayloadSpareBitMaskByteCount() + 3) / 4;
423-
// return getPayloadSpareBitsIndex() + PayloadSpareBitMaskFieldSize;
424-
// }
425-
426-
// uint32_t getFoo() const {
427-
// if (getFooIndex() < getContentsSizeInWords()) {
428-
// return contents[getFooIndex()];
429-
// } else {
430-
// return 0; // Field isn't present
431-
// }
432-
// }
433-
434-
public:
435-
//
436-
// Data derived from the above...
437-
//
438-
439-
uint32_t getContentsSizeInWords() const {
440-
return contents[getSizeFlagsIndex()] >> 16;
441-
}
442-
443-
size_t getSizeInBytes() const {
444-
// assert(getContentsSizeInWords() > 0 && "Malformed MPEnum reflection record");
445-
size_t sizeInBytes = sizeof(TypeName) + getContentsSizeInWords() * 4;
446-
return sizeInBytes;
447-
}
448-
449-
uint32_t getFlags() const {
450-
assert(getContentsSizeInWords() > 0 && "Malformed MPEnum reflection record");
451-
return contents[getSizeFlagsIndex()] & 0xffff;
452-
}
453-
454-
bool usesPayloadSpareBits() const {
455-
return getFlags() & 1;
456-
}
457-
458-
uint32_t getPayloadSpareBitMaskByteOffset() const {
459-
if (usesPayloadSpareBits()) {
460-
return contents[getPayloadSpareBitMaskByteCountIndex()] >> 16;
461-
} else {
462-
return 0;
463-
}
464-
}
465-
466-
uint32_t getPayloadSpareBitMaskByteCount() const {
467-
if (usesPayloadSpareBits()) {
468-
auto byteCount = contents[getPayloadSpareBitMaskByteCountIndex()] & 0xffff;
469-
assert(getContentsSizeInWords() >= 2 + (byteCount + 3) / 4
470-
&& "Malformed MPEnum reflection record: mask bigger than record");
471-
return byteCount;
472-
} else {
473-
return 0;
474-
}
475-
}
476-
477-
const uint8_t *getPayloadSpareBits() const {
478-
if (usesPayloadSpareBits()) {
479-
return reinterpret_cast<const uint8_t *>(&contents[getPayloadSpareBitsIndex()]);
480-
} else {
481-
return nullptr;
482-
}
483-
}
484-
};
485-
486381
class CaptureTypeRecord {
487382
public:
488383
const RelativeDirectPointer<const char> MangledTypeName;

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,14 @@ class ReflectionContext
335335
ObjectFileFormat.getSectionName(ReflectionSectionKind::reflstr));
336336
auto ConformMdSec = findMachOSectionByName(
337337
ObjectFileFormat.getSectionName(ReflectionSectionKind::conform));
338-
auto MPEnumMdSec = findMachOSectionByName(
339-
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum));
340338

341339
if (FieldMdSec.first == nullptr &&
342340
AssocTySec.first == nullptr &&
343341
BuiltinTySec.first == nullptr &&
344342
CaptureSec.first == nullptr &&
345343
TypeRefMdSec.first == nullptr &&
346344
ReflStrMdSec.first == nullptr &&
347-
ConformMdSec.first == nullptr &&
348-
MPEnumMdSec.first == nullptr)
345+
ConformMdSec.first == nullptr)
349346
return {};
350347

351348
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
@@ -355,7 +352,6 @@ class ReflectionContext
355352
{TypeRefMdSec.first, TypeRefMdSec.second},
356353
{ReflStrMdSec.first, ReflStrMdSec.second},
357354
{ConformMdSec.first, ConformMdSec.second},
358-
{MPEnumMdSec.first, MPEnumMdSec.second},
359355
PotentialModuleNames};
360356

361357
auto InfoID = this->addReflectionInfo(info);
@@ -470,17 +466,14 @@ class ReflectionContext
470466
ObjectFileFormat.getSectionName(ReflectionSectionKind::reflstr));
471467
auto ConformMdSec = findCOFFSectionByName(
472468
ObjectFileFormat.getSectionName(ReflectionSectionKind::conform));
473-
auto MPEnumMdSec = findCOFFSectionByName(
474-
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum));
475469

476470
if (FieldMdSec.first == nullptr &&
477471
AssocTySec.first == nullptr &&
478472
BuiltinTySec.first == nullptr &&
479473
CaptureSec.first == nullptr &&
480474
TypeRefMdSec.first == nullptr &&
481475
ReflStrMdSec.first == nullptr &&
482-
ConformMdSec.first == nullptr &&
483-
MPEnumMdSec.first == nullptr)
476+
ConformMdSec.first == nullptr)
484477
return {};
485478

486479
ReflectionInfo Info = {{FieldMdSec.first, FieldMdSec.second},
@@ -490,7 +483,6 @@ class ReflectionContext
490483
{TypeRefMdSec.first, TypeRefMdSec.second},
491484
{ReflStrMdSec.first, ReflStrMdSec.second},
492485
{ConformMdSec.first, ConformMdSec.second},
493-
{MPEnumMdSec.first, MPEnumMdSec.second},
494486
PotentialModuleNames};
495487
return this->addReflectionInfo(Info);
496488
}
@@ -687,9 +679,6 @@ class ReflectionContext
687679
ObjectFileFormat.getSectionName(ReflectionSectionKind::reflstr), true);
688680
auto ConformMdSec = findELFSectionByName(
689681
ObjectFileFormat.getSectionName(ReflectionSectionKind::conform), true);
690-
auto MPEnumMdSec = findELFSectionByName(
691-
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum), true);
692-
693682
if (Error)
694683
return {};
695684

@@ -699,15 +688,14 @@ class ReflectionContext
699688
// ELF executable.
700689
if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
701690
CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
702-
ConformMdSec.first || MPEnumMdSec.first) {
691+
ConformMdSec.first) {
703692
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
704693
{AssocTySec.first, AssocTySec.second},
705694
{BuiltinTySec.first, BuiltinTySec.second},
706695
{CaptureSec.first, CaptureSec.second},
707696
{TypeRefMdSec.first, TypeRefMdSec.second},
708697
{ReflStrMdSec.first, ReflStrMdSec.second},
709698
{ConformMdSec.first, ConformMdSec.second},
710-
{MPEnumMdSec.first, MPEnumMdSec.second},
711699
PotentialModuleNames};
712700
result = this->addReflectionInfo(info);
713701
}
@@ -730,23 +718,20 @@ class ReflectionContext
730718
ObjectFileFormat.getSectionName(ReflectionSectionKind::reflstr), false);
731719
ConformMdSec = findELFSectionByName(
732720
ObjectFileFormat.getSectionName(ReflectionSectionKind::conform), false);
733-
MPEnumMdSec = findELFSectionByName(
734-
ObjectFileFormat.getSectionName(ReflectionSectionKind::mpenum), false);
735721

736722
if (Error)
737723
return {};
738724

739725
if (FieldMdSec.first || AssocTySec.first || BuiltinTySec.first ||
740726
CaptureSec.first || TypeRefMdSec.first || ReflStrMdSec.first ||
741-
ConformMdSec.first || MPEnumMdSec.first) {
727+
ConformMdSec.first) {
742728
ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second},
743729
{AssocTySec.first, AssocTySec.second},
744730
{BuiltinTySec.first, BuiltinTySec.second},
745731
{CaptureSec.first, CaptureSec.second},
746732
{TypeRefMdSec.first, TypeRefMdSec.second},
747733
{ReflStrMdSec.first, ReflStrMdSec.second},
748734
{ConformMdSec.first, ConformMdSec.second},
749-
{MPEnumMdSec.first, MPEnumMdSec.second},
750735
PotentialModuleNames};
751736
auto rid = this->addReflectionInfo(info);
752737
if (!result)
@@ -861,7 +846,8 @@ class ReflectionContext
861846
ReflectionSectionKind::fieldmd, ReflectionSectionKind::assocty,
862847
ReflectionSectionKind::builtin, ReflectionSectionKind::capture,
863848
ReflectionSectionKind::typeref, ReflectionSectionKind::reflstr,
864-
ReflectionSectionKind::conform, ReflectionSectionKind::mpenum};
849+
ReflectionSectionKind::conform
850+
};
865851

866852
llvm::SmallVector<std::pair<RemoteRef<void>, uint64_t>, 6> Pairs;
867853
for (auto Section : Sections) {
@@ -887,7 +873,6 @@ class ReflectionContext
887873
{Pairs[4].first, Pairs[4].second},
888874
{Pairs[5].first, Pairs[5].second},
889875
{Pairs[6].first, Pairs[6].second},
890-
{Pairs[7].first, Pairs[7].second},
891876
PotentialModuleNames};
892877
return addReflectionInfo(Info);
893878
}

include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/Swift.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ HANDLE_SWIFT_SECTION(protocs, "__swift5_protos", "swift5_protocols",
3030
".sw5prt$B")
3131
HANDLE_SWIFT_SECTION(acfuncs, "__swift5_acfuncs", "swift5_accessible_functions",
3232
".sw5acfn$B")
33-
HANDLE_SWIFT_SECTION(mpenum, "__swift5_mpenum", "swift5_mpenum", ".sw5mpen$B")

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,6 @@ class CaptureDescriptorIterator
231231
};
232232
using CaptureSection = ReflectionSection<CaptureDescriptorIterator>;
233233

234-
class MultiPayloadEnumDescriptorIterator
235-
: public ReflectionSectionIteratorBase<MultiPayloadEnumDescriptorIterator,
236-
MultiPayloadEnumDescriptor> {
237-
public:
238-
MultiPayloadEnumDescriptorIterator(RemoteRef<void> Cur, uint64_t Size)
239-
: ReflectionSectionIteratorBase(Cur, Size, "MultiPayloadEnum") {}
240-
241-
static uint64_t
242-
getCurrentRecordSize(RemoteRef<MultiPayloadEnumDescriptor> MPER) {
243-
return MPER->getSizeInBytes();
244-
}
245-
};
246-
using MultiPayloadEnumSection =
247-
ReflectionSection<MultiPayloadEnumDescriptorIterator>;
248-
249234
using GenericSection = ReflectionSection<const void *>;
250235

251236
struct ReflectionInfo {
@@ -256,7 +241,6 @@ struct ReflectionInfo {
256241
GenericSection TypeReference;
257242
GenericSection ReflectionString;
258243
GenericSection Conformance;
259-
MultiPayloadEnumSection MultiPayloadEnum;
260244
llvm::SmallVector<llvm::StringRef, 1> PotentialModuleNames;
261245
};
262246

@@ -490,10 +474,6 @@ class TypeRefBuilder {
490474
/// Get the unsubstituted capture types for a closure context.
491475
ClosureContextInfo getClosureContextInfo(RemoteRef<CaptureDescriptor> CD);
492476

493-
/// Get the multipayload enum projection information for a given TR
494-
std::unique_ptr<MultiPayloadEnumDescriptorBase>
495-
getMultiPayloadEnumDescriptor(const TypeRef *TR) override;
496-
497477
const TypeRef *lookupTypeWitness(const std::string &MangledTypeName,
498478
const std::string &Member,
499479
StringRef Protocol);
@@ -516,8 +496,6 @@ class TypeRefBuilder {
516496
/// Load unsubstituted field types for a nominal type.
517497
RemoteRef<FieldDescriptor> getFieldTypeInfo(const TypeRef *TR);
518498

519-
RemoteRef<MultiPayloadEnumDescriptor> getMultiPayloadEnumInfo(const TypeRef *TR);
520-
521499
void populateFieldTypeInfoCacheWithReflectionAtIndex(size_t Index);
522500

523501
std::optional<RemoteRef<FieldDescriptor>>
@@ -567,8 +545,7 @@ class TypeRefBuilder {
567545

568546
public:
569547
///
570-
/// Dumping typerefs, field declarations, builtin types, captures,
571-
/// multi-payload enums
548+
/// Dumping typerefs, field declarations, builtin types, captures
572549
///
573550
void dumpTypeRef(RemoteRef<char> MangledName, std::ostream &stream,
574551
bool printTypeName = false);
@@ -577,7 +554,6 @@ class TypeRefBuilder {
577554
void dumpFieldSection(std::ostream &stream);
578555
void dumpBuiltinTypeSection(std::ostream &stream);
579556
void dumpCaptureSection(std::ostream &stream);
580-
void dumpMultiPayloadEnumSection(std::ostream &stream);
581557

582558
template <template <typename Runtime> class ObjCInteropKind,
583559
unsigned PointerSize>
@@ -817,10 +793,6 @@ class TypeRefBuilder {
817793
stream << "=============\n";
818794
dumpConformanceSection<ObjCInteropKind, PointerSize>(stream);
819795
stream << "\n";
820-
stream << "MULTI-PAYLOAD ENUM DESCRIPTORS:\n";
821-
stream << "===============================\n";
822-
dumpMultiPayloadEnumSection(stream);
823-
stream << "\n";
824796
}
825797
};
826798
friend struct ReflectionTypeDescriptorFinder;
@@ -1577,17 +1549,10 @@ class TypeRefBuilder {
15771549
return RDF.getClosureContextInfo(CD);
15781550
}
15791551

1580-
/// Get the multipayload enum projection information for a given TR
1581-
std::unique_ptr<MultiPayloadEnumDescriptorBase>
1582-
getMultiPayloadEnumDescriptor(const TypeRef *TR);
1583-
15841552
private:
15851553
/// Get the primitive type lowering for a builtin type.
15861554
RemoteRef<BuiltinTypeDescriptor> getBuiltinTypeInfo(const TypeRef *TR);
15871555

1588-
RemoteRef<MultiPayloadEnumDescriptor>
1589-
getMultiPayloadEnumInfo(const TypeRef *TR);
1590-
15911556
std::optional<uint64_t> multiPayloadEnumPointerMask;
15921557

15931558
public:
@@ -1617,6 +1582,7 @@ class TypeRefBuilder {
16171582
}
16181583
return multiPayloadEnumPointerMask.value();
16191584
}
1585+
16201586
FieldTypeCollectionResult
16211587
collectFieldTypes(std::optional<std::string> forMangledTypeName) {
16221588
return RDF.collectFieldTypes(forMangledTypeName);

0 commit comments

Comments
 (0)