Skip to content

Commit 9aa2111

Browse files
authored
Merge pull request swiftlang#36379 from gottesmm/pr-cff5438783955ec4ac3e7b541e54eb87b9cc3b04
[ossa][frontend] Separately namespace enable-ossa-modules in the module cache so that the flag causes recompilation of imported resilient modules.
2 parents 4255a67 + 05f8d93 commit 9aa2111

16 files changed

+489
-133
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,40 @@ struct ModuleInterfaceLoaderOptions {
311311
ModuleInterfaceLoaderOptions() = default;
312312
};
313313

314+
/// Strongly typed enum that represents if we require all SILModules to have
315+
/// OSSA modules emitted. This is implemented by incorporating this bit into the
316+
/// module cache hash.
317+
struct RequireOSSAModules_t {
318+
enum ValueTy {
319+
No = 0,
320+
Yes = 1,
321+
};
322+
323+
ValueTy value;
324+
325+
RequireOSSAModules_t(const SILOptions &opts)
326+
: value(opts.EnableOSSAModules ? RequireOSSAModules_t::Yes
327+
: RequireOSSAModules_t::No) {}
328+
329+
operator ValueTy() const { return value; }
330+
explicit operator bool() const { return bool(value); }
331+
};
332+
314333
class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
315334
friend class ModuleInterfaceLoader;
316335
ASTContext &Ctx;
317336
std::string CacheDir;
318337
std::string PrebuiltCacheDir;
319338
ModuleInterfaceLoaderOptions Opts;
339+
RequireOSSAModules_t RequiresOSSAModules;
320340

321341
public:
322-
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx,
323-
StringRef cacheDir,
342+
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx, StringRef cacheDir,
324343
StringRef prebuiltCacheDir,
325-
ModuleInterfaceLoaderOptions Opts)
326-
: Ctx(Ctx), CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
327-
Opts(Opts) {}
344+
ModuleInterfaceLoaderOptions opts,
345+
RequireOSSAModules_t requiresOSSAModules)
346+
: Ctx(Ctx), CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
347+
Opts(opts), RequiresOSSAModules(requiresOSSAModules) {}
328348

329349
std::vector<std::string>
330350
getCompiledModuleCandidatesForInterface(StringRef moduleName,
@@ -390,13 +410,13 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
390410
///
391411
/// A simplified version of the core logic in #openModuleFiles.
392412
static bool buildSwiftModuleFromSwiftInterface(
393-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
394-
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
395-
const ClangImporterOptions &ClangOpts,
396-
StringRef CacheDir, StringRef PrebuiltCacheDir,
397-
StringRef ModuleName, StringRef InPath, StringRef OutPath,
398-
bool SerializeDependencyHashes, bool TrackSystemDependencies,
399-
ModuleInterfaceLoaderOptions Opts);
413+
SourceManager &SourceMgr, DiagnosticEngine &Diags,
414+
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
415+
const ClangImporterOptions &ClangOpts, StringRef CacheDir,
416+
StringRef PrebuiltCacheDir, StringRef ModuleName, StringRef InPath,
417+
StringRef OutPath, bool SerializeDependencyHashes,
418+
bool TrackSystemDependencies, ModuleInterfaceLoaderOptions Opts,
419+
RequireOSSAModules_t RequireOSSAModules);
400420
};
401421

402422
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
@@ -420,25 +440,24 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
420440
}
421441
return Diags.diagnose(loc, ID, std::move(Args)...);
422442
}
423-
void inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
424-
const LangOptions &LangOpts);
443+
void
444+
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
445+
const LangOptions &LangOpts,
446+
RequireOSSAModules_t requireOSSAModules);
425447
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
426448
SmallVectorImpl<const char *> &SubArgs,
427449
std::string &CompilerVersion,
428450
StringRef interfacePath,
429451
SourceLoc diagnosticLoc);
430452
public:
431-
InterfaceSubContextDelegateImpl(SourceManager &SM,
432-
DiagnosticEngine &Diags,
433-
const SearchPathOptions &searchPathOpts,
434-
const LangOptions &langOpts,
435-
const ClangImporterOptions &clangImporterOpts,
436-
ModuleInterfaceLoaderOptions LoaderOpts,
437-
bool buildModuleCacheDirIfAbsent,
438-
StringRef moduleCachePath,
439-
StringRef prebuiltCachePath,
440-
bool serializeDependencyHashes,
441-
bool trackSystemDependencies);
453+
InterfaceSubContextDelegateImpl(
454+
SourceManager &SM, DiagnosticEngine &Diags,
455+
const SearchPathOptions &searchPathOpts, const LangOptions &langOpts,
456+
const ClangImporterOptions &clangImporterOpts,
457+
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
458+
StringRef moduleCachePath, StringRef prebuiltCachePath,
459+
bool serializeDependencyHashes, bool trackSystemDependencies,
460+
RequireOSSAModules_t requireOSSAModules);
442461
std::error_code runInSubContext(StringRef moduleName,
443462
StringRef interfacePath,
444463
StringRef outputPath,

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,8 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
12451245
/*buildModuleCacheDirIfAbsent*/ false, ModuleCachePath,
12461246
FEOpts.PrebuiltModuleCachePath,
12471247
FEOpts.SerializeModuleInterfaceDependencyHashes,
1248-
FEOpts.shouldTrackSystemDependencies());
1248+
FEOpts.shouldTrackSystemDependencies(),
1249+
RequireOSSAModules_t(instance.getSILOptions()));
12491250

12501251
// Explore the dependencies of every module.
12511252
for (unsigned currentModuleIdx = 0; currentModuleIdx < allModules.size();
@@ -1336,7 +1337,8 @@ swift::dependencies::performBatchModuleScan(
13361337
/*buildModuleCacheDirIfAbsent*/ false, ModuleCachePath,
13371338
FEOpts.PrebuiltModuleCachePath,
13381339
FEOpts.SerializeModuleInterfaceDependencyHashes,
1339-
FEOpts.shouldTrackSystemDependencies());
1340+
FEOpts.shouldTrackSystemDependencies(),
1341+
RequireOSSAModules_t(instance.getSILOptions()));
13401342
Optional<ModuleDependencies> rootDeps;
13411343
if (isClang) {
13421344
// Loading the clang module using Clang importer.
@@ -1403,7 +1405,8 @@ swift::dependencies::performBatchModulePrescan(
14031405
/*buildModuleCacheDirIfAbsent*/ false, ModuleCachePath,
14041406
FEOpts.PrebuiltModuleCachePath,
14051407
FEOpts.SerializeModuleInterfaceDependencyHashes,
1406-
FEOpts.shouldTrackSystemDependencies());
1408+
FEOpts.shouldTrackSystemDependencies(),
1409+
RequireOSSAModules_t(instance.getSILOptions()));
14071410
Optional<ModuleDependencies> rootDeps;
14081411
if (isClang) {
14091412
// Loading the clang module using Clang importer.

lib/Frontend/Frontend.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,9 @@ bool CompilerInstance::setUpModuleLoaders() {
524524
auto &FEOpts = Invocation.getFrontendOptions();
525525
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
526526
Context->addModuleInterfaceChecker(
527-
std::make_unique<ModuleInterfaceCheckerImpl>(*Context, ModuleCachePath,
528-
FEOpts.PrebuiltModuleCachePath, LoaderOpts));
527+
std::make_unique<ModuleInterfaceCheckerImpl>(
528+
*Context, ModuleCachePath, FEOpts.PrebuiltModuleCachePath, LoaderOpts,
529+
RequireOSSAModules_t(Invocation.getSILOptions())));
529530
// If implicit modules are disabled, we need to install an explicit module
530531
// loader.
531532
bool ExplicitModuleBuild = Invocation.getFrontendOptions().DisableImplicitModules;
@@ -564,15 +565,14 @@ bool CompilerInstance::setUpModuleLoaders() {
564565
->getClangModuleLoader()->getClangInstance());
565566
auto &FEOpts = Invocation.getFrontendOptions();
566567
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
567-
InterfaceSubContextDelegateImpl ASTDelegate(Context->SourceMgr, Context->Diags,
568-
Context->SearchPathOpts, Context->LangOpts,
569-
Context->ClangImporterOpts,
570-
LoaderOpts,
571-
/*buildModuleCacheDirIfAbsent*/false,
572-
ModuleCachePath,
573-
FEOpts.PrebuiltModuleCachePath,
574-
FEOpts.SerializeModuleInterfaceDependencyHashes,
575-
FEOpts.shouldTrackSystemDependencies());
568+
InterfaceSubContextDelegateImpl ASTDelegate(
569+
Context->SourceMgr, Context->Diags, Context->SearchPathOpts,
570+
Context->LangOpts, Context->ClangImporterOpts, LoaderOpts,
571+
/*buildModuleCacheDirIfAbsent*/ false, ModuleCachePath,
572+
FEOpts.PrebuiltModuleCachePath,
573+
FEOpts.SerializeModuleInterfaceDependencyHashes,
574+
FEOpts.shouldTrackSystemDependencies(),
575+
RequireOSSAModules_t(Invocation.getSILOptions()));
576576
auto mainModuleName = Context->getIdentifier(FEOpts.ModuleName);
577577
std::unique_ptr<PlaceholderSwiftModuleScanner> PSMS =
578578
std::make_unique<PlaceholderSwiftModuleScanner>(*Context,

0 commit comments

Comments
 (0)