Skip to content

Commit 5155fae

Browse files
committed
[lldb] Expose explicit modules as language specific data
rdar://136981955
1 parent a3bdac9 commit 5155fae

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,21 @@ SwiftLanguageRuntime::GetLanguageSpecificData(SymbolContext sc) {
11891189
auto is_async = SwiftLanguageRuntime::IsAnySwiftAsyncFunctionSymbol(symbol);
11901190
dict_sp->AddBooleanItem("IsSwiftAsyncFunction", is_async);
11911191

1192+
if (!m_process)
1193+
return dict_sp;
1194+
1195+
auto type_system_or_err =
1196+
m_process->GetTarget().GetScratchTypeSystemForLanguage(
1197+
eLanguageTypeSwift);
1198+
if (!type_system_or_err)
1199+
return dict_sp;
1200+
1201+
if (auto *ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(
1202+
type_system_or_err->get()))
1203+
if (auto *swift_ast_ctx = ts->GetSwiftASTContextOrNull(sc))
1204+
dict_sp->AddBooleanItem("SwiftExplicitModules",
1205+
swift_ast_ctx->HasExplicitModules());
1206+
11921207
return dict_sp;
11931208
}
11941209

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h"
1616
#include "Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.h"
1717

18+
#include "SwiftASTContext.h"
1819
#include "TypeSystemSwift.h"
1920
#include "TypeSystemSwiftTypeRef.h"
2021
#include "lldb/Utility/Log.h"
@@ -1800,11 +1801,18 @@ void SwiftASTContext::AddExtraClangArgs(
18001801
const std::vector<std::string> &module_search_paths,
18011802
const std::vector<std::pair<std::string, bool>> framework_search_paths,
18021803
StringRef overrideOpts) {
1804+
swift::ClangImporterOptions &importer_options = GetClangImporterOptions();
1805+
auto defer = llvm::make_scope_exit([&]() {
1806+
// Detect explicitly-built modules.
1807+
m_has_explicit_modules =
1808+
llvm::any_of(importer_options.ExtraArgs, [](const std::string &arg) {
1809+
return StringRef(arg).starts_with("-fmodule-file=");
1810+
});
1811+
});
1812+
18031813
if (ExtraArgs.empty())
18041814
return;
18051815

1806-
swift::ClangImporterOptions &importer_options = GetClangImporterOptions();
1807-
18081816
// Detect cc1 flags. When DirectClangCC1ModuleBuild is on then the
18091817
// clang arguments in the serialized invocation are clang cc1 flags,
18101818
// which are very specific to one compiler version and cannot
@@ -1835,12 +1843,6 @@ void SwiftASTContext::AddExtraClangArgs(
18351843
applyOverrideOptions(importer_options.ExtraArgs, overrideOpts);
18361844
if (HasNonexistentExplicitModule(importer_options.ExtraArgs))
18371845
RemoveExplicitModules(importer_options.ExtraArgs);
1838-
1839-
// Detect explicitly-built modules.
1840-
m_has_explicit_modules =
1841-
llvm::any_of(importer_options.ExtraArgs, [](const std::string &arg) {
1842-
return StringRef(arg).starts_with("-fmodule-file=");
1843-
});
18441846
}
18451847

18461848
void SwiftASTContext::AddExtraClangCC1Args(
@@ -5488,6 +5490,9 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
54885490
if (!clang_importer_options.BridgingHeader.empty())
54895491
HEALTH_LOG_PRINTF(" Bridging Header : %s",
54905492
clang_importer_options.BridgingHeader.c_str());
5493+
if (auto *expr_ctx = llvm::dyn_cast<SwiftASTContextForExpressions>(this))
5494+
HEALTH_LOG_PRINTF(" Explicit modules : %s",
5495+
expr_ctx->HasExplicitModules() ? "true" : "false");
54915496

54925497
HEALTH_LOG_PRINTF(
54935498
" Extra clang arguments : (%llu items)",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ class SwiftASTContext : public TypeSystemSwift {
535535
void ClearModuleDependentCaches() override;
536536
void LogConfiguration(bool is_repl = false);
537537
bool HasTarget();
538+
bool HasExplicitModules() const { return m_has_explicit_modules; }
538539
bool CheckProcessChanged();
539540

540541
// FIXME: this should be removed once we figure out who should really own the
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SWIFT_SOURCES := main.swift
2+
SWIFT_ENABLE_EXPLICIT_MODULES := YES
23
SWIFTFLAGS_EXTRAS := -parse-as-library
34
include Makefile.rules

lldb/test/API/lang/swift/async/frame/language_specific_data/TestSwiftAsyncLanguageSpecificData.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class TestCase(lldbtest.TestBase):
77

88
mydir = lldbtest.TestBase.compute_mydir(__file__)
99

10+
@no_debug_info_test
1011
@swiftTest
1112
@skipIf(oslist=['windows', 'linux'])
1213
def test(self):
@@ -27,9 +28,13 @@ def test(self):
2728
while process.state == lldb.eStateStopped:
2829
thread = process.GetSelectedThread()
2930
frame = thread.frames[0]
31+
# Spin up the compiler so it can answer the explicit modules question.
32+
self.expect("expression 1")
3033
data = frame.GetLanguageSpecificData()
3134
is_async = data.GetValueForKey("IsSwiftAsyncFunction").GetBooleanValue()
3235
self.assertTrue(is_async)
36+
is_explicit = data.GetValueForKey("SwiftExplicitModules").GetBooleanValue()
37+
self.assertTrue(is_explicit)
3338

3439
process.Continue()
3540

0 commit comments

Comments
 (0)