Skip to content

Commit ada2e40

Browse files
authored
Merge pull request #71249 from augusto2112/special-builtins
[NFC] Separate special builtin types into a lazily initialized vector
2 parents ccc6ef8 + 91ed1a0 commit ada2e40

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

lib/IRGen/GenReflection.cpp

+23-16
Original file line numberDiff line numberDiff line change
@@ -1630,26 +1630,33 @@ emitAssociatedTypeMetadataRecord(const RootProtocolConformance *conformance) {
16301630
builder.emit();
16311631
}
16321632

1633-
void IRGenModule::emitBuiltinReflectionMetadata() {
1634-
if (getSwiftModule()->isStdlibModule()) {
1635-
BuiltinTypes.insert(Context.TheNativeObjectType);
1636-
BuiltinTypes.insert(Context.getAnyObjectType());
1637-
BuiltinTypes.insert(Context.TheBridgeObjectType);
1638-
BuiltinTypes.insert(Context.TheRawPointerType);
1639-
BuiltinTypes.insert(Context.TheUnsafeValueBufferType);
1633+
llvm::ArrayRef<CanType> IRGenModule::getOrCreateSpecialStlibBuiltinTypes() {
1634+
if (SpecialStdlibBuiltinTypes.empty()) {
1635+
SpecialStdlibBuiltinTypes.push_back(Context.TheNativeObjectType);
1636+
SpecialStdlibBuiltinTypes.push_back(Context.getAnyObjectType());
1637+
SpecialStdlibBuiltinTypes.push_back(Context.TheBridgeObjectType);
1638+
SpecialStdlibBuiltinTypes.push_back(Context.TheRawPointerType);
1639+
SpecialStdlibBuiltinTypes.push_back(Context.TheUnsafeValueBufferType);
16401640

16411641
// This would not be necessary if RawPointer had the same set of
16421642
// extra inhabitants as these. But maybe it's best not to codify
16431643
// that in the ABI anyway.
1644-
CanType thinFunction = CanFunctionType::get(
1645-
{}, Context.TheEmptyTupleType,
1646-
AnyFunctionType::ExtInfo().withRepresentation(
1647-
FunctionTypeRepresentation::Thin));
1648-
BuiltinTypes.insert(thinFunction);
1649-
1650-
CanType anyMetatype = CanExistentialMetatypeType::get(
1651-
Context.TheAnyType);
1652-
BuiltinTypes.insert(anyMetatype);
1644+
CanType thinFunction =
1645+
CanFunctionType::get({}, Context.TheEmptyTupleType,
1646+
AnyFunctionType::ExtInfo().withRepresentation(
1647+
FunctionTypeRepresentation::Thin));
1648+
SpecialStdlibBuiltinTypes.push_back(thinFunction);
1649+
1650+
CanType anyMetatype = CanExistentialMetatypeType::get(Context.TheAnyType);
1651+
SpecialStdlibBuiltinTypes.push_back(anyMetatype);
1652+
}
1653+
return SpecialStdlibBuiltinTypes;
1654+
}
1655+
1656+
void IRGenModule::emitBuiltinReflectionMetadata() {
1657+
if (getSwiftModule()->isStdlibModule()) {
1658+
auto SpecialBuiltins = getOrCreateSpecialStlibBuiltinTypes();
1659+
BuiltinTypes.insert(SpecialBuiltins.begin(), SpecialBuiltins.end());
16531660
}
16541661

16551662
for (auto builtinType : BuiltinTypes)

lib/IRGen/IRGenModule.h

+8
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,14 @@ class IRGenModule {
14301430
const char *getReflectionTypeRefSectionName();
14311431
const char *getMultiPayloadEnumDescriptorSectionName();
14321432

1433+
/// Returns the special builtin types that should be emitted in the stdlib
1434+
/// module.
1435+
llvm::ArrayRef<CanType> getOrCreateSpecialStlibBuiltinTypes();
1436+
1437+
private:
1438+
/// The special builtin types that should be emitted in the stdlib module.
1439+
llvm::SmallVector<CanType, 7> SpecialStdlibBuiltinTypes;
1440+
14331441
//--- Runtime ---------------------------------------------------------------
14341442
public:
14351443
llvm::Constant *getEmptyTupleMetadata();

0 commit comments

Comments
 (0)