Skip to content

[pull] swiftwasm-release/5.4 from swift/release/5.4 #1100

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 4 commits into from
Feb 3, 2021
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
3 changes: 2 additions & 1 deletion lldb/scripts/check-ast-context.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ def look_for_METHOD(c):
'GetFatalErrors',
'PrintDiagnostics',
'GetASTContext',
'SetTriple'
'SetTriple',
'LogConfiguration'
]

for method in methods:
Expand Down
23 changes: 16 additions & 7 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,14 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
m_description,
target ? target->GetArchitecture().GetTriple() : triple,
target)));
bool suppress_config_log = false;
auto defer_log = llvm::make_scope_exit([swift_ast_sp, &suppress_config_log] {
// To avoid spamming the log with useless info, we don't log the
// configuration if everything went fine and the current module
// doesn't have any Swift contents (i.e., the shared cache dylibs).
if (!suppress_config_log)
swift_ast_sp->LogConfiguration();
});

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

bool set_triple = false;
bool found_swift_modules = false;

SymbolFile *sym_file = module.GetSymbolFile();

std::string target_triple;

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

std::vector<std::string> module_names;
swift_ast_sp->RegisterSectionModules(module, module_names);
if (module_names.size()) {
if (!module_names.size()) {
// This dylib has no Swift contents; logging the configuration is pointless.
suppress_config_log = true;
} else {
swift_ast_sp->ValidateSectionModules(module, module_names);
if (lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES)) {
std::lock_guard<std::recursive_mutex> locker(g_log_mutex);
LOG_PRINTF(LIBLLDB_LOG_TYPES, "((Module*)%p, \"%s\") = %p",
static_cast<void *>(&module),
module.GetFileSpec().GetFilename().AsCString("<anonymous>"),
static_cast<void *>(swift_ast_sp.get()));
swift_ast_sp->LogConfiguration();
}
}

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

LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Target)");

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

if (swift_ast_sp->HasFatalErrors()) {
logError(swift_ast_sp->GetFatalErrors().AsCString());
Expand Down Expand Up @@ -4929,8 +4938,8 @@ void SwiftASTContext::ClearModuleDependentCaches() {
}

void SwiftASTContext::LogConfiguration() {
VALID_OR_RETURN_VOID();

// It makes no sense to call VALID_OR_RETURN here. We specifically
// want the logs in the error case!
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES));
if (!log)
return;
Expand Down
42 changes: 25 additions & 17 deletions lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffsetRemote
auto frame = instance ? instance->GetExecutionContextRef().GetFrameSP().get()
: nullptr;
if (auto *ti = llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(
GetTypeInfo(instance_type, frame))) {
GetSwiftRuntimeTypeInfo(instance_type, frame))) {
auto fields = ti->getFields();
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
"using record type info");
Expand Down Expand Up @@ -1040,10 +1040,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
auto frame =
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
const swift::reflection::TypeRef *tr = nullptr;
auto *ti = GetTypeInfo(type, frame, &tr);
auto *ti = GetSwiftRuntimeTypeInfo(type, frame, &tr);
if (!ti)
return {};
// Structs and Tuples.
if (auto *rti =
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
switch (rti->getRecordKind()) {
case swift::reflection::RecordKind::ExistentialMetatype:
case swift::reflection::RecordKind::ThickFunction:
Expand All @@ -1060,13 +1061,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
return rti->getNumFields();
}
}
if (auto *eti = llvm::dyn_cast_or_null<swift::reflection::EnumTypeInfo>(ti)) {
if (auto *eti = llvm::dyn_cast<swift::reflection::EnumTypeInfo>(ti)) {
return eti->getNumPayloadCases();
}
// Objects.
if (auto *rti =
llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {

if (auto *rti = llvm::dyn_cast<swift::reflection::ReferenceTypeInfo>(ti)) {
switch (rti->getReferenceKind()) {
case swift::reflection::ReferenceKind::Weak:
case swift::reflection::ReferenceKind::Unowned:
Expand Down Expand Up @@ -1113,7 +1112,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
using namespace swift::reflection;
// Try the static type metadata.
const TypeRef *tr = nullptr;
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
if (!ti)
return {};
// Structs and Tuples.
switch (ti->getKind()) {
case TypeInfoKind::Record: {
Expand Down Expand Up @@ -1246,7 +1247,9 @@ llvm::Optional<std::string> SwiftLanguageRuntimeImpl::GetEnumCaseName(
CompilerType type, const DataExtractor &data, ExecutionContext *exe_ctx) {
using namespace swift::reflection;
using namespace swift::remote;
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr());
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr());
if (!ti)
return {};
if (ti->getKind() != TypeInfoKind::Enum)
return {};

Expand Down Expand Up @@ -1278,7 +1281,9 @@ llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
using namespace swift::reflection;
// Try the static type metadata.
const TypeRef *tr = nullptr;
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
if (!ti)
return {};
switch (ti->getKind()) {
case TypeInfoKind::Record: {
// Structs and Tuples.
Expand Down Expand Up @@ -1391,7 +1396,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
// Try the static type metadata.
auto frame =
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
auto *ti = GetTypeInfo(type, frame);
auto *ti = GetSwiftRuntimeTypeInfo(type, frame);
if (!ti)
return {};
// Structs and Tuples.
if (auto *rti =
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
Expand Down Expand Up @@ -2772,7 +2779,8 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
return type_ref;
}

const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
const swift::reflection::TypeInfo *
SwiftLanguageRuntimeImpl::GetSwiftRuntimeTypeInfo(
CompilerType type, ExecutionContextScope *exe_scope,
swift::reflection::TypeRef const **out_tr) {
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem());
Expand Down Expand Up @@ -2814,30 +2822,30 @@ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
}

bool SwiftLanguageRuntimeImpl::IsStoredInlineInBuffer(CompilerType type) {
if (auto *type_info = GetTypeInfo(type, nullptr))
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
return type_info->isBitwiseTakable() && type_info->getSize() <= 24;
return true;
}

llvm::Optional<uint64_t>
SwiftLanguageRuntimeImpl::GetBitSize(CompilerType type,
ExecutionContextScope *exe_scope) {
if (auto *type_info = GetTypeInfo(type, exe_scope))
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
return type_info->getSize() * 8;
return {};
}

llvm::Optional<uint64_t>
SwiftLanguageRuntimeImpl::GetByteStride(CompilerType type) {
if (auto *type_info = GetTypeInfo(type, nullptr))
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
return type_info->getStride();
return {};
}

llvm::Optional<size_t>
SwiftLanguageRuntimeImpl::GetBitAlignment(CompilerType type,
ExecutionContextScope *exe_scope) {
if (auto *type_info = GetTypeInfo(type, exe_scope))
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
return type_info->getAlignment() * 8;
return {};
}
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Target/SwiftLanguageRuntimeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class SwiftLanguageRuntimeImpl {
Status &error);

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

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