Skip to content

Commit 64e8416

Browse files
author
git apple-llvm automerger
committed
Merge commit '4a0987a19d34' from swift/release/5.4 into swift/main
2 parents a9b8270 + 4a0987a commit 64e8416

14 files changed

+124
-12
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class CompilerType {
290290
std::function<bool(const CompilerType &integer_type, ConstString name,
291291
const llvm::APSInt &value)> const &callback) const;
292292

293-
uint32_t GetNumFields() const;
293+
uint32_t GetNumFields(ExecutionContext *exe_ctx = nullptr) const;
294294

295295
CompilerType GetFieldAtIndex(size_t idx, std::string &name,
296296
uint64_t *bit_offset_ptr,

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ class TypeSystem : public PluginInterface {
320320
ConstString name,
321321
const llvm::APSInt &value)> const &callback) {}
322322

323-
virtual uint32_t GetNumFields(lldb::opaque_compiler_type_t type) = 0;
323+
virtual uint32_t GetNumFields(lldb::opaque_compiler_type_t type,
324+
ExecutionContext *exe_ctx = nullptr) = 0;
324325

325326
virtual CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type,
326327
size_t idx, std::string &name,

lldb/include/lldb/Target/SwiftLanguageRuntime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ class SwiftLanguageRuntime : public LanguageRuntime {
270270
bool &child_is_deref_of_parent, ValueObject *valobj,
271271
uint64_t &language_flags);
272272

273+
/// Ask Remote Mirrors about the fields of a composite type.
274+
llvm::Optional<unsigned> GetNumFields(CompilerType type,
275+
ExecutionContext *exe_ctx);
276+
273277
/// Ask Remote Mirrors for the size of a Swift type.
274278
llvm::Optional<uint64_t> GetBitSize(CompilerType type,
275279
ExecutionContextScope *exe_scope);

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ SwiftLanguage::GetHardcodedSynthetics() {
789789
is_imported = true;
790790
}
791791

792-
if (is_imported && type.GetNumFields() == 0)
792+
ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
793+
if (is_imported && type.GetNumFields(&exe_ctx) == 0)
793794
return true;
794795
if (valobj.IsBaseClass() && type.IsRuntimeGeneratedType()) {
795796
auto parent(valobj.GetParent());

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5416,7 +5416,8 @@ void TypeSystemClang::ForEachEnumerator(
54165416

54175417
#pragma mark Aggregate Types
54185418

5419-
uint32_t TypeSystemClang::GetNumFields(lldb::opaque_compiler_type_t type) {
5419+
uint32_t TypeSystemClang::GetNumFields(lldb::opaque_compiler_type_t type,
5420+
ExecutionContext *exe_ctx) {
54205421
if (!type)
54215422
return 0;
54225423

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ class TypeSystemClang : public TypeSystem {
788788
ConstString name,
789789
const llvm::APSInt &value)> const &callback) override;
790790

791-
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
791+
uint32_t GetNumFields(lldb::opaque_compiler_type_t type,
792+
ExecutionContext *exe_ctx = nullptr) override;
792793

793794
CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
794795
std::string &name, uint64_t *bit_offset_ptr,

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6384,7 +6384,8 @@ SwiftASTContext::GetNumDirectBaseClasses(opaque_compiler_type_t opaque_type) {
63846384
return 0;
63856385
}
63866386

6387-
uint32_t SwiftASTContext::GetNumFields(opaque_compiler_type_t type) {
6387+
uint32_t SwiftASTContext::GetNumFields(opaque_compiler_type_t type,
6388+
ExecutionContext *exe_ctx) {
63886389
VALID_OR_RETURN(0);
63896390

63906391
if (!type)

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ class SwiftASTContext : public TypeSystemSwift {
586586
bool omit_empty_base_classes,
587587
const ExecutionContext *exe_ctx) override;
588588

589-
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
589+
uint32_t GetNumFields(lldb::opaque_compiler_type_t type,
590+
ExecutionContext *exe_ctx = nullptr) override;
590591

591592
CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
592593
std::string &name, uint64_t *bit_offset_ptr,

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,9 +2231,31 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
22312231
ReconstructType(type), omit_empty_base_classes, exe_ctx);
22322232
}
22332233

2234-
uint32_t TypeSystemSwiftTypeRef::GetNumFields(opaque_compiler_type_t type) {
2235-
return m_swift_ast_context->GetNumFields(ReconstructType(type));
2234+
uint32_t TypeSystemSwiftTypeRef::GetNumFields(opaque_compiler_type_t type,
2235+
ExecutionContext *exe_ctx) {
2236+
if (exe_ctx)
2237+
if (auto *runtime = SwiftLanguageRuntime::Get(exe_ctx->GetProcessSP()))
2238+
if (auto num_fields =
2239+
runtime->GetNumFields(GetCanonicalType(type), exe_ctx))
2240+
// Use a lambda to intercept & unwrap the `Optional` return value from
2241+
// `SwiftLanguageRuntime::GetNumFields`.
2242+
return [&] {
2243+
auto impl = [&]() -> llvm::Optional<uint32_t> {
2244+
if (!type)
2245+
return 0;
2246+
return num_fields;
2247+
};
2248+
VALIDATE_AND_RETURN(impl, GetNumFields, type,
2249+
(ReconstructType(type), exe_ctx));
2250+
}().getValue();
2251+
2252+
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2253+
"Using SwiftASTContext::GetNumFields fallback for type %s",
2254+
AsMangledName(type));
2255+
2256+
return m_swift_ast_context->GetNumFields(ReconstructType(type), exe_ctx);
22362257
}
2258+
22372259
CompilerType TypeSystemSwiftTypeRef::GetFieldAtIndex(
22382260
opaque_compiler_type_t type, size_t idx, std::string &name,
22392261
uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
152152
uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
153153
bool omit_empty_base_classes,
154154
const ExecutionContext *exe_ctx) override;
155-
uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
155+
uint32_t GetNumFields(lldb::opaque_compiler_type_t type,
156+
ExecutionContext *exe_ctx = nullptr) override;
156157
CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
157158
std::string &name, uint64_t *bit_offset_ptr,
158159
uint32_t *bitfield_bit_size_ptr,

0 commit comments

Comments
 (0)