Skip to content

Commit b816a3e

Browse files
authored
Merge pull request #71624 from artemcm/DepScanCxxInteropImportNo
[Dependency Scanning] Interface-scanning sub-invocations should not attempt to import `CxxShims`
2 parents d9c447f + bb5e20d commit b816a3e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ class FrontendOptions {
336336
/// for testing purposes only.
337337
bool DisableBuildingInterface = false;
338338

339+
/// Is this frontend configuration of an interface dependency scan sub-invocation
340+
bool DependencyScanningSubInvocation = false;
341+
339342
/// When performing a dependency scanning action, only identify and output all imports
340343
/// of the main Swift module's source files.
341344
bool ImportPrescan = false;

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,14 @@ bool CompilerInstance::canImportCxxShim() const {
11691169
ImportPath::Module::Builder builder(
11701170
getASTContext().getIdentifier(CXX_SHIM_NAME));
11711171
auto modulePath = builder.get();
1172+
// Currently, Swift interfaces are not to expose their
1173+
// C++ dependencies. Which means that when scanning them we should not
1174+
// bring in such dependencies, including CxxShims.
11721175
return getASTContext().testImportModule(modulePath) &&
11731176
!Invocation.getFrontendOptions()
1174-
.InputsAndOutputs.hasModuleInterfaceOutputPath();
1177+
.InputsAndOutputs.hasModuleInterfaceOutputPath() &&
1178+
!Invocation.getFrontendOptions()
1179+
.DependencyScanningSubInvocation;
11751180
}
11761181

11771182
bool CompilerInstance::supportCaching() const {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18081808
// in the Swift compile commands, when different.
18091809
inheritedParentContextClangArgs =
18101810
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
1811+
genericSubInvocation.getFrontendOptions()
1812+
.DependencyScanningSubInvocation = true;
18111813
} else if (LoaderOpts.strictImplicitModuleContext) {
18121814
// If the compiler has been asked to be strict with ensuring downstream
18131815
// dependencies get the parent invocation's context, inherit the extra Clang
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/deps)
4+
// RUN: split-file %s %t
5+
// RUN: mv %t/Foo.swiftinterface %t/deps/
6+
7+
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps.json %t/a.swift -I %t/deps -verify
8+
9+
//--- Foo.swiftinterface
10+
// swift-interface-format-version: 1.0
11+
// swift-module-flags: -module-name Foo -cxx-interoperability-mode=default
12+
public struct S1 {}
13+
14+
//--- a.swift
15+
import Foo
16+
17+
// RUN: cat %t/deps.json | %FileCheck %s
18+
// CHECK-NOT: "CxxShim"

0 commit comments

Comments
 (0)