Skip to content

Commit ec0ab18

Browse files
committed
[Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
A prior change ensured that we forego this query when looking up Swift overlays for a textual interface which was built without C++ interop. This change introduced a bug where it also caused us to skip this lookup for the main source module. This commit resolves that by preserving the fix above but also ensuring we perform the lookup for the main source module under scan.
1 parent beb2b58 commit ec0ab18

File tree

2 files changed

+71
-30
lines changed

2 files changed

+71
-30
lines changed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,41 +1541,41 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
15411541
recordResult(clangDep);
15421542

15431543
// C++ Interop requires additional handling
1544-
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop &&
1545-
moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
1544+
bool lookupCxxStdLibOverlay = ScanCompilerInvocation.getLangOptions().EnableCXXInterop;
1545+
if (lookupCxxStdLibOverlay && moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
15461546
const auto &moduleInfo = cache.findKnownDependency(moduleID);
15471547
const auto commandLine = moduleInfo.getCommandline();
1548-
15491548
// If the textual interface was built without C++ interop, do not query
15501549
// the C++ Standard Library Swift overlay for its compilation.
15511550
//
1552-
// FIXME: We always declare the 'Darwin' module as formally having been
1553-
// built without C++Interop, for compatibility with prior versions. Once we
1554-
// are certain that we are only building against modules built with support
1555-
// of
1556-
// '-formal-cxx-interoperability-mode', this hard-coded check should be
1557-
// removed.
1558-
if (moduleID.ModuleName != "Darwin" &&
1559-
llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
1560-
commandLine.end()) {
1561-
for (const auto &clangDepName : allClangDependencies) {
1562-
// If this Clang module is a part of the C++ stdlib, and we haven't
1563-
// loaded the overlay for it so far, it is a split libc++ module (e.g.
1564-
// std_vector). Load the CxxStdlib overlay explicitly.
1565-
const auto &clangDepInfo =
1566-
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1567-
.value()
1568-
->getAsClangModule();
1569-
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1570-
!swiftOverlayDependencies.contains(
1571-
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1572-
!swiftOverlayDependencies.contains(
1573-
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1574-
scanForSwiftDependency(
1575-
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1576-
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1577-
break;
1578-
}
1551+
// FIXME: We always declare the 'Darwin' module as formally having been built
1552+
// without C++Interop, for compatibility with prior versions. Once we are certain
1553+
// that we are only building against modules built with support of
1554+
// '-formal-cxx-interoperability-mode', this hard-coded check should be removed.
1555+
if (moduleID.ModuleName == "Darwin" ||
1556+
llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") !=
1557+
commandLine.end())
1558+
lookupCxxStdLibOverlay = false;
1559+
}
1560+
1561+
if (lookupCxxStdLibOverlay) {
1562+
for (const auto &clangDepName : allClangDependencies) {
1563+
// If this Clang module is a part of the C++ stdlib, and we haven't
1564+
// loaded the overlay for it so far, it is a split libc++ module (e.g.
1565+
// std_vector). Load the CxxStdlib overlay explicitly.
1566+
const auto &clangDepInfo =
1567+
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1568+
.value()
1569+
->getAsClangModule();
1570+
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1571+
!swiftOverlayDependencies.contains(
1572+
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1573+
!swiftOverlayDependencies.contains(
1574+
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1575+
scanForSwiftDependency(
1576+
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1577+
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1578+
break;
15791579
}
15801580
}
15811581
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/deps)
3+
// RUN: split-file %s %t
4+
5+
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps.json %t/client.swift -I %t/deps -cxx-interoperability-mode=default -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import
6+
// RUN: cat %t/deps.json | %FileCheck %s
7+
8+
/// --------Main module
9+
// CHECK-LABEL: "modulePath": "deps.swiftmodule",
10+
// CHECK-NEXT: "sourceFiles": [
11+
// CHECK-NEXT: cxx-overlay-source-lookup.swift
12+
// CHECK-NEXT: ],
13+
// CHECK: "directDependencies": [
14+
// CHECK-DAG: "swift": "Swift"
15+
// CHECK-DAG: "swift": "SwiftOnoneSupport"
16+
// CHECK-DAG: "swift": "Cxx"
17+
// CHECK-DAG: "swift": "CxxStdlib"
18+
// CHECK-DAG: "clang": "CxxShim"
19+
// CHECK-DAG: "clang": "Foo"
20+
// CHECK: ],
21+
22+
//--- deps/bar.h
23+
void bar(void);
24+
25+
//--- deps/foo.h
26+
#include "bar.h"
27+
void foo(void);
28+
29+
//--- deps/module.modulemap
30+
module std_Bar [system] {
31+
header "bar.h"
32+
export *
33+
}
34+
35+
module Foo {
36+
header "foo.h"
37+
export *
38+
}
39+
40+
//--- client.swift
41+
import Foo

0 commit comments

Comments
 (0)