Skip to content

Commit f8f749b

Browse files
authored
Merge pull request #81416 from artemcm/CXXInteropDarwinCycleFix-62
2 parents 245514c + 7be7ab1 commit f8f749b

File tree

4 files changed

+118
-32
lines changed

4 files changed

+118
-32
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class ModuleDependencyInfo {
690690
storage->importedSwiftModules.assign(dependencyIDs.begin(),
691691
dependencyIDs.end());
692692
}
693-
const ArrayRef<ModuleDependencyID> getImportedSwiftDependencies() const {
693+
ArrayRef<ModuleDependencyID> getImportedSwiftDependencies() const {
694694
return storage->importedSwiftModules;
695695
}
696696

@@ -699,7 +699,7 @@ class ModuleDependencyInfo {
699699
storage->importedClangModules.assign(dependencyIDs.begin(),
700700
dependencyIDs.end());
701701
}
702-
const ArrayRef<ModuleDependencyID> getImportedClangDependencies() const {
702+
ArrayRef<ModuleDependencyID> getImportedClangDependencies() const {
703703
return storage->importedClangModules;
704704
}
705705

@@ -733,7 +733,7 @@ class ModuleDependencyInfo {
733733
}
734734
}
735735
}
736-
const ArrayRef<ModuleDependencyID> getHeaderClangDependencies() const {
736+
ArrayRef<ModuleDependencyID> getHeaderClangDependencies() const {
737737
switch (getKind()) {
738738
case swift::ModuleDependencyKind::SwiftInterface: {
739739
auto swiftInterfaceStorage =
@@ -761,7 +761,7 @@ class ModuleDependencyInfo {
761761
storage->swiftOverlayDependencies.assign(dependencyIDs.begin(),
762762
dependencyIDs.end());
763763
}
764-
const ArrayRef<ModuleDependencyID> getSwiftOverlayDependencies() const {
764+
ArrayRef<ModuleDependencyID> getSwiftOverlayDependencies() const {
765765
return storage->swiftOverlayDependencies;
766766
}
767767

@@ -771,11 +771,11 @@ class ModuleDependencyInfo {
771771
storage->crossImportOverlayModules.assign(dependencyIDs.begin(),
772772
dependencyIDs.end());
773773
}
774-
const ArrayRef<ModuleDependencyID> getCrossImportOverlayDependencies() const {
774+
ArrayRef<ModuleDependencyID> getCrossImportOverlayDependencies() const {
775775
return storage->crossImportOverlayModules;
776776
}
777777

778-
const ArrayRef<LinkLibrary> getLinkLibraries() const {
778+
ArrayRef<LinkLibrary> getLinkLibraries() const {
779779
return storage->linkLibraries;
780780
}
781781

@@ -784,7 +784,7 @@ class ModuleDependencyInfo {
784784
storage->linkLibraries.assign(linkLibraries.begin(), linkLibraries.end());
785785
}
786786

787-
const ArrayRef<std::string> getAuxiliaryFiles() const {
787+
ArrayRef<std::string> getAuxiliaryFiles() const {
788788
return storage->auxiliaryFiles;
789789
}
790790

@@ -796,7 +796,7 @@ class ModuleDependencyInfo {
796796
return false;
797797
}
798798

799-
const ArrayRef<std::string> getHeaderInputSourceFiles() const {
799+
ArrayRef<std::string> getHeaderInputSourceFiles() const {
800800
if (auto *detail = getAsSwiftInterfaceModule())
801801
return detail->textualModuleDetails.bridgingSourceFiles;
802802
if (auto *detail = getAsSwiftSourceModule())
@@ -806,7 +806,7 @@ class ModuleDependencyInfo {
806806
return {};
807807
}
808808

809-
std::vector<std::string> getCommandline() const {
809+
ArrayRef<std::string> getCommandline() const {
810810
if (auto *detail = getAsClangModule())
811811
return detail->buildCommandLine;
812812
if (auto *detail = getAsSwiftInterfaceModule())
@@ -829,7 +829,7 @@ class ModuleDependencyInfo {
829829
llvm_unreachable("Unexpected type");
830830
}
831831

832-
std::vector<std::string> getBridgingHeaderCommandline() const {
832+
ArrayRef<std::string> getBridgingHeaderCommandline() const {
833833
if (auto *detail = getAsSwiftSourceModule())
834834
return detail->bridgingHeaderBuildCommandLine;
835835
return {};

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
675675
// build command to main module to ensure frontend gets the same result.
676676
// This needs to happen after visiting all the top-level decls from all
677677
// SourceFiles.
678-
auto buildArgs = mainDependencies.getCommandline();
678+
std::vector<std::string> buildArgs = mainDependencies.getCommandline();
679679
mainModule->getASTContext().forEachCanImportVersionCheck(
680680
[&](StringRef moduleName, const llvm::VersionTuple &Version,
681681
const llvm::VersionTuple &UnderlyingVersion) {
@@ -1542,25 +1542,33 @@ void ModuleDependencyScanner::resolveSwiftOverlayDependenciesForModule(
15421542
recordResult(clangDep);
15431543

15441544
// C++ Interop requires additional handling
1545-
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop) {
1546-
for (const auto &clangDepName : allClangDependencies) {
1547-
// If this Clang module is a part of the C++ stdlib, and we haven't loaded
1548-
// the overlay for it so far, it is a split libc++ module (e.g.
1549-
// std_vector). Load the CxxStdlib overlay explicitly.
1550-
const auto &clangDepInfo =
1551-
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1552-
.value()
1553-
->getAsClangModule();
1554-
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1555-
!swiftOverlayDependencies.contains(
1556-
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1557-
!swiftOverlayDependencies.contains(
1558-
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1559-
ScanningThreadPool.async(
1560-
scanForSwiftDependency,
1561-
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1562-
ScanningThreadPool.wait();
1563-
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1545+
if (ScanCompilerInvocation.getLangOptions().EnableCXXInterop &&
1546+
moduleID.Kind == ModuleDependencyKind::SwiftInterface) {
1547+
const auto &moduleInfo = cache.findKnownDependency(moduleID);
1548+
const auto commandLine = moduleInfo.getCommandline();
1549+
1550+
// If the textual interface was built without C++ interop, do not query
1551+
// the C++ Standard Library Swift overlay for its compilation.
1552+
if (llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
1553+
commandLine.end()) {
1554+
for (const auto &clangDepName : allClangDependencies) {
1555+
// If this Clang module is a part of the C++ stdlib, and we haven't
1556+
// loaded the overlay for it so far, it is a split libc++ module (e.g.
1557+
// std_vector). Load the CxxStdlib overlay explicitly.
1558+
const auto &clangDepInfo =
1559+
cache.findDependency(clangDepName, ModuleDependencyKind::Clang)
1560+
.value()
1561+
->getAsClangModule();
1562+
if (importer::isCxxStdModule(clangDepName, clangDepInfo->IsSystem) &&
1563+
!swiftOverlayDependencies.contains(
1564+
{clangDepName, ModuleDependencyKind::SwiftInterface}) &&
1565+
!swiftOverlayDependencies.contains(
1566+
{clangDepName, ModuleDependencyKind::SwiftBinary})) {
1567+
scanForSwiftDependency(
1568+
getModuleImportIdentifier(ScanASTContext.Id_CxxStdlib.str()));
1569+
recordResult(ScanASTContext.Id_CxxStdlib.str().str());
1570+
break;
1571+
}
15641572
}
15651573
}
15661574
}
@@ -1615,7 +1623,7 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies(
16151623
// Update the command-line on the main module to
16161624
// disable implicit cross-import overlay search.
16171625
auto mainDep = cache.findKnownDependency(actualMainID);
1618-
auto cmdCopy = mainDep.getCommandline();
1626+
std::vector<std::string> cmdCopy = mainDep.getCommandline();
16191627
cmdCopy.push_back("-disable-cross-import-overlay-search");
16201628
for (auto &entry : overlayFiles) {
16211629
mainDep.addAuxiliaryFile(entry.second);

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ generateFullDependencyGraph(const CompilerInstance &instance,
933933
moduleInfo->details = getModuleDetails();
934934

935935
// Create a link libraries set for this module
936-
auto &linkLibraries = moduleDependencyInfo.getLinkLibraries();
936+
auto linkLibraries = moduleDependencyInfo.getLinkLibraries();
937937
swiftscan_link_library_set_t *linkLibrarySet =
938938
new swiftscan_link_library_set_t;
939939
linkLibrarySet->count = linkLibraries.size();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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/clientWithInteropDep.swift -I %t/deps -cxx-interoperability-mode=default -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -verify
6+
// RUN: cat %t/deps.json | %FileCheck %s -check-prefix=ENABLE-CHECK
7+
8+
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps_no_interop_dep.json %t/clientNoInteropDep.swift -I %t/deps -cxx-interoperability-mode=default -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -verify
9+
// RUN: cat %t/deps_no_interop_dep.json | %FileCheck %s -check-prefix=DISABLE-CHECK
10+
11+
//--- deps/bar.h
12+
void bar(void);
13+
14+
//--- deps/module.modulemap
15+
module std_Bar [system] {
16+
header "bar.h"
17+
export *
18+
}
19+
20+
//--- deps/Foo.swiftinterface
21+
// swift-interface-format-version: 1.0
22+
// swift-module-flags: -module-name Foo -enable-library-evolution
23+
import std_Bar
24+
public struct Foo1 {}
25+
26+
//--- deps/FooNoInterop.swiftinterface
27+
// swift-interface-format-version: 1.0
28+
// swift-module-flags: -module-name FooNoInterop -enable-library-evolution
29+
// swift-module-flags-ignorable: -formal-cxx-interoperability-mode=off
30+
import std_Bar
31+
public struct Foo2 {}
32+
33+
//--- clientWithInteropDep.swift
34+
import Foo
35+
36+
//--- clientNoInteropDep.swift
37+
import FooNoInterop
38+
39+
// Ensure that when the 'Foo' dependency was built with C++ interop enabled,
40+
// it gets the C++ standard library overlay for its 'std_*' dependency
41+
//
42+
// 'Foo' as it appears in direct deps
43+
// ENABLE-CHECK: "swift": "Foo"
44+
// 'Foo' as it appears in source-import deps
45+
// ENABLE-CHECK: "swift": "Foo"
46+
// Actual dependency info node
47+
// ENABLE-CHECK: "swift": "Foo"
48+
// ENABLE-CHECK: "directDependencies": [
49+
// ENABLE-CHECK: {
50+
// ENABLE-CHECK: "swift": "SwiftOnoneSupport"
51+
// ENABLE-CHECK: },
52+
// ENABLE-CHECK: {
53+
// ENABLE-CHECK: "swift": "CxxStdlib"
54+
// ENABLE-CHECK: },
55+
// ENABLE-CHECK: {
56+
// ENABLE-CHECK: "clang": "std_Bar"
57+
// ENABLE-CHECK: }
58+
// ENABLE-CHECK: ],
59+
60+
// Ensure that when the 'Foo' dependency was *not* built with C++ interop enabled,
61+
// it does not get the C++ standard library overlay for its 'std_*' dependency
62+
//
63+
// 'Foo' as it appears in direct deps
64+
// DISABLE-CHECK: "swift": "FooNoInterop"
65+
// 'Foo' as it appears in source-import deps
66+
// DISABLE-CHECK: "swift": "FooNoInterop"
67+
// Actual dependency info node
68+
// DISABLE-CHECK: "swift": "FooNoInterop"
69+
// DISABLE-CHECK: "directDependencies": [
70+
// DISABLE-CHECK: {
71+
// DISABLE-CHECK: "swift": "SwiftOnoneSupport"
72+
// DISABLE-CHECK: },
73+
// DISABLE-CHECK: {
74+
// DISABLE-CHECK: "clang": "std_Bar"
75+
// DISABLE-CHECK: }
76+
// DISABLE-CHECK: ],
77+
78+

0 commit comments

Comments
 (0)