Skip to content

Commit 85da9b0

Browse files
authored
Merge pull request #35762 from artemcm/54_cherry_NoExtraClangImporterArgsInSubContexts
Avoid false FileDependnecies among Implicitly-built Swift and Clang modules
2 parents 93da975 + dd045cd commit 85da9b0

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,18 +1292,28 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12921292
// required by sourcekitd.
12931293
subClangImporterOpts.DetailedPreprocessingRecord =
12941294
clangImporterOpts.DetailedPreprocessingRecord;
1295+
12951296
// We need to add these extra clang flags because explict module building
12961297
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
12971298
// and -fmodule-file=.
12981299
// If we don't add these flags, the interface will be built with implicit
12991300
// PCMs.
1300-
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
1301-
for (auto arg: subClangImporterOpts.ExtraArgs) {
1302-
GenericArgs.push_back("-Xcc");
1303-
GenericArgs.push_back(ArgSaver.save(arg));
1301+
// FIXME: With Implicit Module Builds, if sub-invocations inherit `-fmodule-map-file=` options,
1302+
// those modulemaps become File dependencies of all downstream PCMs and their depending Swift
1303+
// modules, triggering unnecessary re-builds. We work around this by only inheriting these options
1304+
// when building with explicit modules. While this problem will not manifest with Explicit Modules
1305+
// (which do not use the ClangImporter to build PCMs), we may still need a better way to
1306+
// decide which options must be inherited here.
1307+
if (LoaderOpts.disableImplicitSwiftModule) {
1308+
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
1309+
for (auto arg : subClangImporterOpts.ExtraArgs) {
1310+
GenericArgs.push_back("-Xcc");
1311+
GenericArgs.push_back(ArgSaver.save(arg));
1312+
}
13041313
}
13051314

1306-
// Tell the genericSubInvocation to serialize dependency hashes if asked to do so.
1315+
// Tell the genericSubInvocation to serialize dependency hashes if asked to do
1316+
// so.
13071317
auto &frontendOpts = genericSubInvocation.getFrontendOptions();
13081318
frontendOpts.SerializeModuleInterfaceDependencyHashes =
13091319
serializeDependencyHashes;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void funcCI(void);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -swift-version 5 -enforce-exclusivity=checked -module-name SIMod
3+
import CIMod
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CIMod {
2+
header "CIMod.h"
3+
export *
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Dummy {
2+
header "Dummy.h"
3+
export *
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/ModuleCache)
3+
4+
import SIMod
5+
6+
// Step 0: Copy relevant files into the temp dir which will serve as the search path
7+
// RUN: cp %S/Inputs/implicit-options-inheritance/module.modulemap %t/module.modulemap
8+
// RUN: cp %S/Inputs/implicit-options-inheritance/CIMod.h %t/CIMod.h
9+
// RUN: cp %S/Inputs/implicit-options-inheritance/SIMod.swiftinterface %t/SIMod.swiftinterface
10+
11+
// Step 1: Build this file, causing an implicit build of SIMod and CIMod into the module cache.
12+
// Pass in a clang arg pointing it to a modulemap that has nothing to do with downstream modules and is not on the search path.
13+
14+
// RUN: %target-swift-frontend -emit-module -module-name no-implicit-extra-clang-maps -o %t/no-implicit-extra-clang-maps.swiftmodule %s -I %t -Xcc -fmodule-map-file=%S/Inputs/implicit-options-inheritance/test-dummy.modulemap -module-cache-path %t/ModuleCache
15+
16+
// Step 2: Touch the dummy modulemap we passed in with `-Xcc -fmodule-map-file` above.
17+
// RUN: touch %S/Inputs/implicit-options-inheritance/test-dummy.modulemap
18+
19+
// Step 3: Re-build this file, and ensure we are not re-building SIMod due to a dependency on the dummy file
20+
// RUN: %target-swift-frontend -emit-module -module-name no-implicit-extra-clang-maps -o %t/no-implicit-extra-clang-maps.swiftmodule %s -I %t -Xcc -fmodule-map-file=%S/Inputs/implicit-options-inheritance/test-dummy.modulemap -module-cache-path %t/ModuleCache -Rmodule-interface-rebuild 2>&1 | %FileCheck -allow-empty %s
21+
22+
// Step 4: Ensure that SIMod was not re-built
23+
// CHECK-NOT: remark: rebuilding module 'SIMod' from interface
24+
// CHECK-NOT: note: cached module is out of date
25+
// CHECK-NOT: note: dependency is out of date

0 commit comments

Comments
 (0)