Skip to content

[NFC] Separate special builtin types into a lazily initialized vector #71249

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 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 23 additions & 16 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CanType> 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)
Expand Down
8 changes: 8 additions & 0 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,14 @@ class IRGenModule {
const char *getReflectionTypeRefSectionName();
const char *getMultiPayloadEnumDescriptorSectionName();

/// Returns the special builtin types that should be emitted in the stdlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes these types "special" and sets them apart from other builtin types? Is this a techincal term used elsewhere, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're "special" because they're always emitted in the stdlib, whereas other builtins may or may not be emitted.

/// module.
llvm::ArrayRef<CanType> getOrCreateSpecialStlibBuiltinTypes();

private:
/// The special builtin types that should be emitted in the stdlib module.
llvm::SmallVector<CanType, 7> SpecialStdlibBuiltinTypes;

//--- Runtime ---------------------------------------------------------------
public:
llvm::Constant *getEmptyTupleMetadata();
Expand Down