Skip to content

Commit d124615

Browse files
authored
Merge pull request swiftlang#8017 from apple/artemcm/FallbackOnImplicitWhenExplicit
[Explicit Module Builds] Fallback on implicit module builds by filtering out Explicit Module clang arguments from invocation
2 parents 9bb8aee + 32cf95a commit d124615

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,14 @@ static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
11591159
return server_or_err->str();
11601160
}
11611161

1162+
namespace {
1163+
constexpr std::array<std::string_view, 4> g_known_eplicit_module_prefixes =
1164+
{"-fmodule-map-file=",
1165+
"-fmodule-file=",
1166+
"-fno-implicit-modules",
1167+
"-fno-implicit-module-maps"};
1168+
}
1169+
11621170
/// Retrieve the serialized AST data blobs and initialize the compiler
11631171
/// invocation with the concatenated search paths from the blobs.
11641172
/// \returns true if an error was encountered.
@@ -1300,6 +1308,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13001308
<< getImportFailureString(result) << "\n";
13011309
return false;
13021310
}
1311+
13031312
if (discover_implicit_search_paths) {
13041313
for (auto &searchPath : searchPaths) {
13051314
std::string path = remap(searchPath.Path);
@@ -1482,8 +1491,8 @@ bool ConsumeIncludeOption(StringRef &arg, StringRef &prefix) {
14821491
}
14831492

14841493
std::array<StringRef, 2> macro_flags = { "-D", "-U" };
1485-
std::array<StringRef, 5> multi_arg_flags =
1486-
{ "-D", "-U", "-I", "-F", "-working-directory" };
1494+
std::array<StringRef, 6> multi_arg_flags = {
1495+
"-D", "-U", "-I", "-F", "-working-directory", "-triple"};
14871496
std::array<StringRef, 6> args_to_unique = {
14881497
"-D", "-U", "-I", "-F", "-fmodule-file=", "-fmodule-map-file="};
14891498

@@ -1518,7 +1527,25 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
15181527

15191528
llvm::SmallString<128> cur_working_dir;
15201529
llvm::SmallString<128> clang_argument;
1530+
1531+
auto match_explicit_build_option = [](StringRef arg) {
1532+
for (const auto &option : g_known_eplicit_module_prefixes)
1533+
if (arg.starts_with(option))
1534+
return true;
1535+
return false;
1536+
};
1537+
bool has_explicit_builds_enabled =
1538+
llvm::find(source, "-fno-implicit-modules") != source.end();
1539+
15211540
for (const std::string &arg : source) {
1541+
// Ignore the `-triple` flag. First, this is not a driver flag, and second,
1542+
// lldb has its own logic to determine the target. Ignore now, before
1543+
// appending the argument.
1544+
if (clang_argument == "-triple") {
1545+
clang_argument.clear();
1546+
continue;
1547+
}
1548+
15221549
// Join multi-arg options for uniquing.
15231550
clang_argument += arg;
15241551
if (IsMultiArgClangFlag(clang_argument))
@@ -1548,6 +1575,14 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
15481575
if (clang_argument.empty())
15491576
continue;
15501577

1578+
// In case of explicit modules, for now fallback to implicit
1579+
// module loading.
1580+
// TODO: Incorporate loading explicit module dependencies to
1581+
// speedup dependency resolution.
1582+
if (has_explicit_builds_enabled &&
1583+
match_explicit_build_option(clang_argument))
1584+
continue;
1585+
15511586
// Otherwise add the argument to the list.
15521587
if (!IsMacroDefinition(clang_argument))
15531588
ApplyWorkingDir(clang_argument, cur_working_dir);

lldb/test/API/lang/swift/explicit_modules/TestSwiftExplicitModules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class TestSwiftExplicitModules(lldbtest.TestBase):
99

1010
@swiftTest
1111
@skipUnlessDarwin # FIXME.
12-
@expectedFailureAll(bugnumber='rdar://121078994')
1312
def test_any_type(self):
1413
"""Test explicit Swift modules"""
1514
self.build()

0 commit comments

Comments
 (0)