13
13
// This file implements type checking support for Swift's concurrency model.
14
14
//
15
15
// ===----------------------------------------------------------------------===//
16
- # include " MiscDiagnostics.h "
16
+
17
17
#include " TypeCheckConcurrency.h"
18
+ #include " MiscDiagnostics.h"
18
19
#include " TypeCheckDistributed.h"
19
20
#include " TypeCheckInvertible.h"
20
- #include " TypeChecker.h"
21
21
#include " TypeCheckType.h"
22
- #include " swift/Strings .h"
22
+ #include " TypeChecker .h"
23
23
#include " swift/AST/ASTWalker.h"
24
+ #include " swift/AST/Concurrency.h"
24
25
#include " swift/AST/ConformanceLookup.h"
25
26
#include " swift/AST/DistributedDecl.h"
27
+ #include " swift/AST/ExistentialLayout.h"
26
28
#include " swift/AST/GenericEnvironment.h"
27
29
#include " swift/AST/ImportCache.h"
28
30
#include " swift/AST/Initializer.h"
31
+ #include " swift/AST/NameLookupRequests.h"
29
32
#include " swift/AST/ParameterList.h"
30
33
#include " swift/AST/ProtocolConformance.h"
31
- #include " swift/AST/NameLookupRequests.h"
32
34
#include " swift/AST/TypeCheckRequests.h"
33
- #include " swift/AST/ExistentialLayout.h"
34
35
#include " swift/Basic/Assertions.h"
35
36
#include " swift/Sema/IDETypeChecking.h"
37
+ #include " swift/Strings.h"
36
38
37
39
using namespace swift ;
38
40
@@ -840,33 +842,6 @@ SendableCheckContext::implicitSendableDiagnosticBehavior() const {
840
842
}
841
843
}
842
844
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
-
870
845
// / Determine the diagnostic behavior for a Sendable reference to the given
871
846
// / nominal type.
872
847
DiagnosticBehavior SendableCheckContext::diagnosticBehavior (
@@ -887,43 +862,6 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
887
862
return defaultBehavior;
888
863
}
889
864
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
-
927
865
std::optional<DiagnosticBehavior>
928
866
SendableCheckContext::preconcurrencyBehavior (
929
867
Decl *decl,
0 commit comments