Skip to content

[lldb] Lazily load Swift ASTContext in GetClangTypeNode #6629

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

Closed
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
15 changes: 11 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,23 @@ TypeSystemSwiftTypeRef::GetClangTypeNode(CompilerType clang_type,
// ClangAdapter.
struct Adapter {
struct Context {
TypeSystemSwiftTypeRef *typeref_ts;
swift::ASTContext *AST;
llvm::StringRef getSwiftName(swift::KnownFoundationEntity entity) {
// Lazy load the SwiftASTContext.
if (!AST)
if (auto *ctx = typeref_ts->GetSwiftASTContext())
AST = ctx->GetASTContext();

if (AST)
return AST->getSwiftName(entity);
return "<error: no Swift context>";
}
Context(swift::ASTContext *ctx) : AST(ctx){};
Context(TypeSystemSwiftTypeRef *typeref_ts) : typeref_ts(typeref_ts){};
} SwiftContext;
Adapter(swift::ASTContext *ctx) : SwiftContext(ctx){};
} Impl(GetSwiftASTContext() ? GetSwiftASTContext()->GetASTContext()
: nullptr);
Adapter(TypeSystemSwiftTypeRef *typeref_ts) : SwiftContext(typeref_ts){};
} Impl(this); // `Impl` is referenced in MappedTypes.def

#define MAP_TYPE(C_TYPE_NAME, C_TYPE_KIND, C_TYPE_BITWIDTH, SWIFT_MODULE_NAME, \
SWIFT_TYPE_NAME, CAN_BE_MISSING, C_NAME_MAPPING) \
if (clang_name.equals(C_TYPE_NAME)) { \
Expand All @@ -321,6 +327,7 @@ TypeSystemSwiftTypeRef::GetClangTypeNode(CompilerType clang_type,
} else
#include "swift/../../lib/ClangImporter/MappedTypes.def"
#undef MAP_TYPE

// The last dangling else in the macro is for this switch.
switch (clang_type.GetTypeClass()) {
case eTypeClassClass:
Expand Down