@@ -810,38 +810,6 @@ static bool hasExplicitSendableConformance(NominalTypeDecl *nominal,
810810 conformance.getConcrete ())->isMissing ());
811811}
812812
813- // / Find the import that makes the given declaration available.
814- static llvm::Optional<AttributedImport<ImportedModule>>
815- findImportFor (const DeclContext *dc, const DeclContext *fromDC) {
816- // If the type is from the current module, there's no import.
817- auto module = dc->getParentModule ();
818- if (module == fromDC->getParentModule ())
819- return llvm::None;
820-
821- auto fromSourceFile = fromDC->getParentSourceFile ();
822- if (!fromSourceFile)
823- return llvm::None;
824-
825- // Look to see if the owning module was directly imported.
826- for (const auto &import : fromSourceFile->getImports ()) {
827- if (import .module .importedModule == module )
828- return import ;
829- }
830-
831- // Now look for transitive imports.
832- auto &importCache = dc->getASTContext ().getImportCache ();
833- for (const auto &import : fromSourceFile->getImports ()) {
834- auto &importSet = importCache.getImportSet (import .module .importedModule );
835- for (const auto &transitive : importSet.getTransitiveImports ()) {
836- if (transitive.importedModule == module ) {
837- return import ;
838- }
839- }
840- }
841-
842- return llvm::None;
843- }
844-
845813// / Determine the diagnostic behavior for a Sendable reference to the given
846814// / nominal type.
847815DiagnosticBehavior SendableCheckContext::diagnosticBehavior (
@@ -870,7 +838,7 @@ SendableCheckContext::preconcurrencyBehavior(Decl *decl) const {
870838 if (auto *nominal = dyn_cast<NominalTypeDecl>(decl)) {
871839 // Determine whether this nominal type is visible via a @preconcurrency
872840 // import.
873- auto import = findImportFor ( nominal, fromDC);
841+ auto import = nominal-> findImport ( fromDC);
874842 auto sourceFile = fromDC->getParentSourceFile ();
875843
876844 if (!import || !import ->options .contains (ImportFlags::Preconcurrency))
@@ -937,7 +905,7 @@ bool swift::diagnoseSendabilityErrorBasedOn(
937905 // This type was imported from another module; try to find the
938906 // corresponding import.
939907 llvm::Optional<AttributedImport<swift::ImportedModule>> import =
940- findImportFor ( nominal, fromContext.fromDC );
908+ nominal-> findImport ( fromContext.fromDC );
941909
942910 // If we found the import that makes this nominal type visible, remark
943911 // that it can be @preconcurrency import.
@@ -3012,8 +2980,7 @@ namespace {
30122980 return false ;
30132981 }
30142982
3015- const auto import =
3016- findImportFor (var->getDeclContext (), getDeclContext ());
2983+ const auto import = var->findImport (getDeclContext ());
30172984 const bool isPreconcurrencyImport =
30182985 import && import ->options .contains (ImportFlags::Preconcurrency);
30192986 const auto isPreconcurrencyUnspecifiedIsolation =
0 commit comments