@@ -2389,19 +2389,66 @@ void SourceFile::setImportUsedPreconcurrency(
23892389 PreconcurrencyImportsUsed.insert (import );
23902390}
23912391
2392- bool HasImplementationOnlyImportsRequest::evaluate (Evaluator &evaluator,
2393- SourceFile *SF) const {
2394- return llvm::any_of (SF->getImports (),
2395- [](AttributedImport<ImportedModule> desc) {
2396- return desc.options .contains (ImportFlags::ImplementationOnly);
2397- });
2392+ bool HasImportsMatchingFlagRequest::evaluate (Evaluator &evaluator,
2393+ SourceFile *SF,
2394+ ImportFlags flag) const {
2395+ for (auto desc : SF->getImports ()) {
2396+ if (desc.options .contains (flag))
2397+ return true ;
2398+ }
2399+ return false ;
2400+ }
2401+
2402+ Optional<bool > HasImportsMatchingFlagRequest::getCachedResult () const {
2403+ SourceFile *sourceFile = std::get<0 >(getStorage ());
2404+ ImportFlags flag = std::get<1 >(getStorage ());
2405+ if (sourceFile->validCachedImportOptions .contains (flag))
2406+ return sourceFile->cachedImportOptions .contains (flag);
2407+
2408+ return None;
2409+ }
2410+
2411+ void HasImportsMatchingFlagRequest::cacheResult (bool value) const {
2412+ SourceFile *sourceFile = std::get<0 >(getStorage ());
2413+ ImportFlags flag = std::get<1 >(getStorage ());
2414+
2415+ sourceFile->validCachedImportOptions |= flag;
2416+ if (value)
2417+ sourceFile->cachedImportOptions |= flag;
2418+ }
2419+
2420+ void swift::simple_display (llvm::raw_ostream &out, ImportOptions options) {
2421+ using Flag = std::pair<ImportFlags, StringRef>;
2422+ Flag possibleFlags[] = {
2423+ #define FLAG (Name ) {ImportFlags::Name, #Name},
2424+ FLAG (Exported)
2425+ FLAG (Testable)
2426+ FLAG (PrivateImport)
2427+ FLAG (ImplementationOnly)
2428+ FLAG (SPIAccessControl)
2429+ FLAG (Preconcurrency)
2430+ FLAG (WeakLinked)
2431+ FLAG (Reserved)
2432+ #undef FLAG
2433+ };
2434+
2435+ auto flagsToPrint = llvm::make_filter_range (
2436+ possibleFlags, [&](Flag flag) { return options & flag.first ; });
2437+
2438+ out << " { " ;
2439+ interleave (
2440+ flagsToPrint, [&](Flag flag) { out << flag.second ; },
2441+ [&] { out << " , " ; });
2442+ out << " }" ;
23982443}
23992444
24002445bool SourceFile::hasImplementationOnlyImports () const {
24012446 auto &ctx = getASTContext ();
24022447 auto *mutableThis = const_cast <SourceFile *>(this );
2403- return evaluateOrDefault (
2404- ctx.evaluator , HasImplementationOnlyImportsRequest{mutableThis}, false );
2448+ return evaluateOrDefault (ctx.evaluator ,
2449+ HasImportsMatchingFlagRequest{
2450+ mutableThis, ImportFlags::ImplementationOnly},
2451+ false );
24052452}
24062453
24072454bool SourceFile::hasTestableOrPrivateImport (
0 commit comments