Skip to content

Commit dc91d08

Browse files
authored
Merge pull request #82772 from artemcm/62_FixDepScanCxxStdlibLookup
[6.2 🍒][Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
2 parents 61a4ee9 + 01e5d44 commit dc91d08

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,39 +1408,41 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
14081408
recordResult(clangDep);
14091409

14101410
// C++ Interop requires additional handling
1411-
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop &&
1412-
moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
1411+
bool lookupCxxStdLibOverlay = ScanCompilerInvocation.getLangOptions().EnableCXXInterop;
1412+
if (lookupCxxStdLibOverlay && moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
14131413
const auto &moduleInfo = cache.findKnownDependency(moduleID);
14141414
const auto commandLine = moduleInfo.getCommandline();
1415-
14161415
// If the textual interface was built without C++ interop, do not query
14171416
// the C++ Standard Library Swift overlay for its compilation.
14181417
//
14191418
// FIXME: We always declare the 'Darwin' module as formally having been built
14201419
// without C++Interop, for compatibility with prior versions. Once we are certain
14211420
// that we are only building against modules built with support of
14221421
// '-formal-cxx-interoperability-mode', this hard-coded check should be removed.
1423-
if (moduleID.ModuleName != "Darwin" &&
1424-
llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
1425-
commandLine.end()) {
1426-
for (const auto &clangDepName : allClangDependencies) {
1427-
// If this Clang module is a part of the C++ stdlib, and we haven't
1428-
// loaded the overlay for it so far, it is a split libc++ module (e.g.
1429-
// std_vector). Load the CxxStdlib overlay explicitly.
1430-
const auto &clangDepInfo =
1431-
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1432-
.value()
1433-
->getAsClangModule();
1434-
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1435-
!swiftOverlayDependencies.contains(
1436-
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1437-
!swiftOverlayDependencies.contains(
1438-
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1439-
scanForSwiftDependency(
1440-
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1441-
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1442-
break;
1443-
}
1422+
if (moduleID.ModuleName == "Darwin" ||
1423+
llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") !=
1424+
commandLine.end())
1425+
lookupCxxStdLibOverlay = false;
1426+
}
1427+
1428+
if (lookupCxxStdLibOverlay) {
1429+
for (const auto &clangDepName : allClangDependencies) {
1430+
// If this Clang module is a part of the C++ stdlib, and we haven't
1431+
// loaded the overlay for it so far, it is a split libc++ module (e.g.
1432+
// std_vector). Load the CxxStdlib overlay explicitly.
1433+
const auto &clangDepInfo =
1434+
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1435+
.value()
1436+
->getAsClangModule();
1437+
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1438+
!swiftOverlayDependencies.contains(
1439+
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1440+
!swiftOverlayDependencies.contains(
1441+
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1442+
scanForSwiftDependency(
1443+
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1444+
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1445+
break;
14441446
}
14451447
}
14461448
}
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)