1313// This file implements type checking support for Swift's concurrency model.
1414//
1515// ===----------------------------------------------------------------------===//
16- # include " MiscDiagnostics.h "
16+
1717#include " TypeCheckConcurrency.h"
18+ #include " MiscDiagnostics.h"
1819#include " TypeCheckDistributed.h"
1920#include " TypeCheckInvertible.h"
20- #include " TypeChecker.h"
2121#include " TypeCheckType.h"
22- #include " swift/Strings .h"
22+ #include " TypeChecker .h"
2323#include " swift/AST/ASTWalker.h"
24+ #include " swift/AST/Concurrency.h"
2425#include " swift/AST/ConformanceLookup.h"
2526#include " swift/AST/DistributedDecl.h"
27+ #include " swift/AST/ExistentialLayout.h"
2628#include " swift/AST/GenericEnvironment.h"
2729#include " swift/AST/ImportCache.h"
2830#include " swift/AST/Initializer.h"
31+ #include " swift/AST/NameLookupRequests.h"
2932#include " swift/AST/ParameterList.h"
3033#include " swift/AST/ProtocolConformance.h"
31- #include " swift/AST/NameLookupRequests.h"
3234#include " swift/AST/TypeCheckRequests.h"
33- #include " swift/AST/ExistentialLayout.h"
3435#include " swift/Basic/Assertions.h"
3536#include " swift/Sema/IDETypeChecking.h"
37+ #include " swift/Strings.h"
3638
3739using namespace swift ;
3840
@@ -840,33 +842,6 @@ SendableCheckContext::implicitSendableDiagnosticBehavior() const {
840842 }
841843}
842844
843- // / Determine whether the given nominal type has an explicit Sendable
844- // / conformance (regardless of its availability).
845- bool swift::hasExplicitSendableConformance (NominalTypeDecl *nominal,
846- bool applyModuleDefault) {
847- ASTContext &ctx = nominal->getASTContext ();
848- auto nominalModule = nominal->getParentModule ();
849-
850- // In a concurrency-checked module, a missing conformance is equivalent to
851- // an explicitly unavailable one. If we want to apply this rule, do so now.
852- if (applyModuleDefault && nominalModule->isConcurrencyChecked ())
853- return true ;
854-
855- // Look for any conformance to `Sendable`.
856- auto proto = ctx.getProtocol (KnownProtocolKind::Sendable);
857- if (!proto)
858- return false ;
859-
860- // Look for a conformance. If it's present and not (directly) missing,
861- // we're done.
862- auto conformance = lookupConformance (
863- nominal->getDeclaredInterfaceType (), proto, /* allowMissing=*/ true );
864- return conformance &&
865- !(isa<BuiltinProtocolConformance>(conformance.getConcrete ()) &&
866- cast<BuiltinProtocolConformance>(
867- conformance.getConcrete ())->isMissing ());
868- }
869-
870845// / Determine the diagnostic behavior for a Sendable reference to the given
871846// / nominal type.
872847DiagnosticBehavior SendableCheckContext::diagnosticBehavior (
@@ -887,43 +862,6 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
887862 return defaultBehavior;
888863}
889864
890- std::optional<DiagnosticBehavior>
891- swift::getConcurrencyDiagnosticBehaviorLimit (NominalTypeDecl *nominal,
892- const DeclContext *fromDC,
893- bool ignoreExplicitConformance) {
894- ModuleDecl *importedModule = nullptr ;
895- if (nominal->getAttrs ().hasAttribute <PreconcurrencyAttr>()) {
896- // If the declaration itself has the @preconcurrency attribute,
897- // respect it.
898- importedModule = nominal->getParentModule ();
899- } else {
900- // Determine whether this nominal type is visible via a @preconcurrency
901- // import.
902- auto import = nominal->findImport (fromDC);
903- auto sourceFile = fromDC->getParentSourceFile ();
904-
905- if (!import || !import ->options .contains (ImportFlags::Preconcurrency))
906- return std::nullopt ;
907-
908- if (sourceFile)
909- sourceFile->setImportUsedPreconcurrency (*import );
910-
911- importedModule = import ->module .importedModule ;
912- }
913-
914- // When the type is explicitly non-Sendable, @preconcurrency imports
915- // downgrade the diagnostic to a warning in Swift 6.
916- if (!ignoreExplicitConformance &&
917- hasExplicitSendableConformance (nominal))
918- return DiagnosticBehavior::Warning;
919-
920- // When the type is implicitly non-Sendable, `@preconcurrency` suppresses
921- // diagnostics until the imported module enables Swift 6.
922- return importedModule->isConcurrencyChecked ()
923- ? DiagnosticBehavior::Warning
924- : DiagnosticBehavior::Ignore;
925- }
926-
927865std::optional<DiagnosticBehavior>
928866SendableCheckContext::preconcurrencyBehavior (
929867 Decl *decl,
0 commit comments