Skip to content

Avoid a costly SwiftASTContext initialization in SwiftUnsafeTypes for… #8086

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
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
12 changes: 12 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ ExtractChildrenFromSwiftPointerValueObject(ValueObjectSP valobj_sp,
const size_t num_children = unsafe_ptr.GetCount();
const CompilerType element_type = unsafe_ptr.GetElementType();

// Performance optimization. Give up if this is a forward-declared
// Clang type. In that case GetByteStride will attempt to fall back
// to SwiftASTContext, which is generally correct because it could
// be a type imported from an expression, but in this data formatter
// the potential cost of triggering SwiftASTContext is not the right
// trade-off.
auto tss = element_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
CompilerType clang_type;
if (tss && tss->IsImportedType(element_type.GetOpaqueQualType(), &clang_type))
if (!clang_type.IsCompleteType())
return {};

auto stride = element_type.GetByteStride(process_sp.get());
if (!stride)
return {};
Expand Down