Skip to content

Commit 996acc9

Browse files
authored
Merge pull request #1100 from swiftwasm/swift/release/5.4
[pull] swiftwasm-release/5.4 from swift/release/5.4
2 parents d8be2ea + 84304ad commit 996acc9

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

lldb/scripts/check-ast-context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ def look_for_METHOD(c):
421421
'GetFatalErrors',
422422
'PrintDiagnostics',
423423
'GetASTContext',
424-
'SetTriple'
424+
'SetTriple',
425+
'LogConfiguration'
425426
]
426427

427428
for method in methods:

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,14 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
16941694
m_description,
16951695
target ? target->GetArchitecture().GetTriple() : triple,
16961696
target)));
1697+
bool suppress_config_log = false;
1698+
auto defer_log = llvm::make_scope_exit([swift_ast_sp, &suppress_config_log] {
1699+
// To avoid spamming the log with useless info, we don't log the
1700+
// configuration if everything went fine and the current module
1701+
// doesn't have any Swift contents (i.e., the shared cache dylibs).
1702+
if (!suppress_config_log)
1703+
swift_ast_sp->LogConfiguration();
1704+
});
16971705

16981706
// This is a module AST context, mark it as such.
16991707
swift_ast_sp->m_is_scratch_context = false;
@@ -1706,9 +1714,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
17061714

17071715
bool set_triple = false;
17081716
bool found_swift_modules = false;
1709-
17101717
SymbolFile *sym_file = module.GetSymbolFile();
1711-
17121718
std::string target_triple;
17131719

17141720
if (sym_file) {
@@ -1831,15 +1837,17 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
18311837

18321838
std::vector<std::string> module_names;
18331839
swift_ast_sp->RegisterSectionModules(module, module_names);
1834-
if (module_names.size()) {
1840+
if (!module_names.size()) {
1841+
// This dylib has no Swift contents; logging the configuration is pointless.
1842+
suppress_config_log = true;
1843+
} else {
18351844
swift_ast_sp->ValidateSectionModules(module, module_names);
18361845
if (lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES)) {
18371846
std::lock_guard<std::recursive_mutex> locker(g_log_mutex);
18381847
LOG_PRINTF(LIBLLDB_LOG_TYPES, "((Module*)%p, \"%s\") = %p",
18391848
static_cast<void *>(&module),
18401849
module.GetFileSpec().GetFilename().AsCString("<anonymous>"),
18411850
static_cast<void *>(swift_ast_sp.get()));
1842-
swift_ast_sp->LogConfiguration();
18431851
}
18441852
}
18451853

@@ -1926,6 +1934,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
19261934
// detect if we have a iOS simulator.
19271935
std::shared_ptr<SwiftASTContextForExpressions> swift_ast_sp(
19281936
new SwiftASTContextForExpressions(m_description, target));
1937+
auto defer_log = llvm::make_scope_exit(
1938+
[swift_ast_sp] { swift_ast_sp->LogConfiguration(); });
19291939

19301940
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Target)");
19311941

@@ -2280,7 +2290,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22802290
LOG_PRINTF(LIBLLDB_LOG_TYPES, "((Target*)%p) = %p",
22812291
static_cast<void *>(&target),
22822292
static_cast<void *>(swift_ast_sp.get()));
2283-
swift_ast_sp->LogConfiguration();
22842293

22852294
if (swift_ast_sp->HasFatalErrors()) {
22862295
logError(swift_ast_sp->GetFatalErrors().AsCString());
@@ -4929,8 +4938,8 @@ void SwiftASTContext::ClearModuleDependentCaches() {
49294938
}
49304939

49314940
void SwiftASTContext::LogConfiguration() {
4932-
VALID_OR_RETURN_VOID();
4933-
4941+
// It makes no sense to call VALID_OR_RETURN here. We specifically
4942+
// want the logs in the error case!
49344943
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES));
49354944
if (!log)
49364945
return;

lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffsetRemote
886886
auto frame = instance ? instance->GetExecutionContextRef().GetFrameSP().get()
887887
: nullptr;
888888
if (auto *ti = llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(
889-
GetTypeInfo(instance_type, frame))) {
889+
GetSwiftRuntimeTypeInfo(instance_type, frame))) {
890890
auto fields = ti->getFields();
891891
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
892892
"using record type info");
@@ -1040,10 +1040,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10401040
auto frame =
10411041
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
10421042
const swift::reflection::TypeRef *tr = nullptr;
1043-
auto *ti = GetTypeInfo(type, frame, &tr);
1043+
auto *ti = GetSwiftRuntimeTypeInfo(type, frame, &tr);
1044+
if (!ti)
1045+
return {};
10441046
// Structs and Tuples.
1045-
if (auto *rti =
1046-
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
1047+
if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
10471048
switch (rti->getRecordKind()) {
10481049
case swift::reflection::RecordKind::ExistentialMetatype:
10491050
case swift::reflection::RecordKind::ThickFunction:
@@ -1060,13 +1061,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10601061
return rti->getNumFields();
10611062
}
10621063
}
1063-
if (auto *eti = llvm::dyn_cast_or_null<swift::reflection::EnumTypeInfo>(ti)) {
1064+
if (auto *eti = llvm::dyn_cast<swift::reflection::EnumTypeInfo>(ti)) {
10641065
return eti->getNumPayloadCases();
10651066
}
10661067
// Objects.
1067-
if (auto *rti =
1068-
llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {
1069-
1068+
if (auto *rti = llvm::dyn_cast<swift::reflection::ReferenceTypeInfo>(ti)) {
10701069
switch (rti->getReferenceKind()) {
10711070
case swift::reflection::ReferenceKind::Weak:
10721071
case swift::reflection::ReferenceKind::Unowned:
@@ -1113,7 +1112,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
11131112
using namespace swift::reflection;
11141113
// Try the static type metadata.
11151114
const TypeRef *tr = nullptr;
1116-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1115+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1116+
if (!ti)
1117+
return {};
11171118
// Structs and Tuples.
11181119
switch (ti->getKind()) {
11191120
case TypeInfoKind::Record: {
@@ -1246,7 +1247,9 @@ llvm::Optional<std::string> SwiftLanguageRuntimeImpl::GetEnumCaseName(
12461247
CompilerType type, const DataExtractor &data, ExecutionContext *exe_ctx) {
12471248
using namespace swift::reflection;
12481249
using namespace swift::remote;
1249-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr());
1250+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr());
1251+
if (!ti)
1252+
return {};
12501253
if (ti->getKind() != TypeInfoKind::Enum)
12511254
return {};
12521255

@@ -1278,7 +1281,9 @@ llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
12781281
using namespace swift::reflection;
12791282
// Try the static type metadata.
12801283
const TypeRef *tr = nullptr;
1281-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1284+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1285+
if (!ti)
1286+
return {};
12821287
switch (ti->getKind()) {
12831288
case TypeInfoKind::Record: {
12841289
// Structs and Tuples.
@@ -1391,7 +1396,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
13911396
// Try the static type metadata.
13921397
auto frame =
13931398
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
1394-
auto *ti = GetTypeInfo(type, frame);
1399+
auto *ti = GetSwiftRuntimeTypeInfo(type, frame);
1400+
if (!ti)
1401+
return {};
13951402
// Structs and Tuples.
13961403
if (auto *rti =
13971404
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
@@ -2772,7 +2779,8 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
27722779
return type_ref;
27732780
}
27742781

2775-
const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
2782+
const swift::reflection::TypeInfo *
2783+
SwiftLanguageRuntimeImpl::GetSwiftRuntimeTypeInfo(
27762784
CompilerType type, ExecutionContextScope *exe_scope,
27772785
swift::reflection::TypeRef const **out_tr) {
27782786
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem());
@@ -2814,30 +2822,30 @@ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
28142822
}
28152823

28162824
bool SwiftLanguageRuntimeImpl::IsStoredInlineInBuffer(CompilerType type) {
2817-
if (auto *type_info = GetTypeInfo(type, nullptr))
2825+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
28182826
return type_info->isBitwiseTakable() && type_info->getSize() <= 24;
28192827
return true;
28202828
}
28212829

28222830
llvm::Optional<uint64_t>
28232831
SwiftLanguageRuntimeImpl::GetBitSize(CompilerType type,
28242832
ExecutionContextScope *exe_scope) {
2825-
if (auto *type_info = GetTypeInfo(type, exe_scope))
2833+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
28262834
return type_info->getSize() * 8;
28272835
return {};
28282836
}
28292837

28302838
llvm::Optional<uint64_t>
28312839
SwiftLanguageRuntimeImpl::GetByteStride(CompilerType type) {
2832-
if (auto *type_info = GetTypeInfo(type, nullptr))
2840+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
28332841
return type_info->getStride();
28342842
return {};
28352843
}
28362844

28372845
llvm::Optional<size_t>
28382846
SwiftLanguageRuntimeImpl::GetBitAlignment(CompilerType type,
28392847
ExecutionContextScope *exe_scope) {
2840-
if (auto *type_info = GetTypeInfo(type, exe_scope))
2848+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
28412849
return type_info->getAlignment() * 8;
28422850
return {};
28432851
}

lldb/source/Target/SwiftLanguageRuntimeImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ class SwiftLanguageRuntimeImpl {
7777
Status &error);
7878

7979
/// Ask Remote Mirrors for the type info about a Swift type.
80+
/// This will return a nullptr if the lookup fails.
8081
const swift::reflection::TypeInfo *
81-
GetTypeInfo(CompilerType type, ExecutionContextScope *exe_scope,
82-
swift::reflection::TypeRef const **out_tr = nullptr);
82+
GetSwiftRuntimeTypeInfo(CompilerType type, ExecutionContextScope *exe_scope,
83+
swift::reflection::TypeRef const **out_tr = nullptr);
8384

8485
llvm::Optional<const swift::reflection::TypeInfo *>
8586
lookupClangTypeInfo(CompilerType clang_type);

0 commit comments

Comments
 (0)