diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index d645a3f95419e..4d14591f859b8 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -1630,26 +1630,33 @@ emitAssociatedTypeMetadataRecord(const RootProtocolConformance *conformance) { builder.emit(); } -void IRGenModule::emitBuiltinReflectionMetadata() { - if (getSwiftModule()->isStdlibModule()) { - BuiltinTypes.insert(Context.TheNativeObjectType); - BuiltinTypes.insert(Context.getAnyObjectType()); - BuiltinTypes.insert(Context.TheBridgeObjectType); - BuiltinTypes.insert(Context.TheRawPointerType); - BuiltinTypes.insert(Context.TheUnsafeValueBufferType); +llvm::ArrayRef IRGenModule::getOrCreateSpecialStlibBuiltinTypes() { + if (SpecialStdlibBuiltinTypes.empty()) { + SpecialStdlibBuiltinTypes.push_back(Context.TheNativeObjectType); + SpecialStdlibBuiltinTypes.push_back(Context.getAnyObjectType()); + SpecialStdlibBuiltinTypes.push_back(Context.TheBridgeObjectType); + SpecialStdlibBuiltinTypes.push_back(Context.TheRawPointerType); + SpecialStdlibBuiltinTypes.push_back(Context.TheUnsafeValueBufferType); // This would not be necessary if RawPointer had the same set of // extra inhabitants as these. But maybe it's best not to codify // that in the ABI anyway. - CanType thinFunction = CanFunctionType::get( - {}, Context.TheEmptyTupleType, - AnyFunctionType::ExtInfo().withRepresentation( - FunctionTypeRepresentation::Thin)); - BuiltinTypes.insert(thinFunction); - - CanType anyMetatype = CanExistentialMetatypeType::get( - Context.TheAnyType); - BuiltinTypes.insert(anyMetatype); + CanType thinFunction = + CanFunctionType::get({}, Context.TheEmptyTupleType, + AnyFunctionType::ExtInfo().withRepresentation( + FunctionTypeRepresentation::Thin)); + SpecialStdlibBuiltinTypes.push_back(thinFunction); + + CanType anyMetatype = CanExistentialMetatypeType::get(Context.TheAnyType); + SpecialStdlibBuiltinTypes.push_back(anyMetatype); + } + return SpecialStdlibBuiltinTypes; +} + +void IRGenModule::emitBuiltinReflectionMetadata() { + if (getSwiftModule()->isStdlibModule()) { + auto SpecialBuiltins = getOrCreateSpecialStlibBuiltinTypes(); + BuiltinTypes.insert(SpecialBuiltins.begin(), SpecialBuiltins.end()); } for (auto builtinType : BuiltinTypes) diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 708c6585ab33a..45db78ea3acda 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1430,6 +1430,14 @@ class IRGenModule { const char *getReflectionTypeRefSectionName(); const char *getMultiPayloadEnumDescriptorSectionName(); + /// Returns the special builtin types that should be emitted in the stdlib + /// module. + llvm::ArrayRef getOrCreateSpecialStlibBuiltinTypes(); + +private: + /// The special builtin types that should be emitted in the stdlib module. + llvm::SmallVector SpecialStdlibBuiltinTypes; + //--- Runtime --------------------------------------------------------------- public: llvm::Constant *getEmptyTupleMetadata();