@@ -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;
0 commit comments