|
16 | 16 |
|
17 | 17 | #define DEBUG_TYPE "ast-types"
|
18 | 18 |
|
19 |
| -#include "swift/AST/Types.h" |
| 19 | +#include "clang/AST/Type.h" |
20 | 20 | #include "ForeignRepresentationInfo.h"
|
21 | 21 | #include "swift/AST/ASTContext.h"
|
22 | 22 | #include "swift/AST/ClangModuleLoader.h"
|
| 23 | +#include "swift/AST/Concurrency.h" |
23 | 24 | #include "swift/AST/ConformanceLookup.h"
|
24 |
| -#include "swift/AST/ExistentialLayout.h" |
25 |
| -#include "swift/AST/ReferenceCounting.h" |
26 |
| -#include "swift/AST/TypeCheckRequests.h" |
27 |
| -#include "swift/AST/TypeVisitor.h" |
28 |
| -#include "swift/AST/TypeWalker.h" |
29 | 25 | #include "swift/AST/Decl.h"
|
| 26 | +#include "swift/AST/ExistentialLayout.h" |
30 | 27 | #include "swift/AST/GenericEnvironment.h"
|
31 | 28 | #include "swift/AST/LazyResolver.h"
|
32 | 29 | #include "swift/AST/Module.h"
|
33 | 30 | #include "swift/AST/PackConformance.h"
|
34 | 31 | #include "swift/AST/ParameterList.h"
|
35 | 32 | #include "swift/AST/PrettyStackTrace.h"
|
36 | 33 | #include "swift/AST/ProtocolConformance.h"
|
| 34 | +#include "swift/AST/ReferenceCounting.h" |
37 | 35 | #include "swift/AST/SILLayout.h"
|
38 | 36 | #include "swift/AST/SubstitutionMap.h"
|
| 37 | +#include "swift/AST/TypeCheckRequests.h" |
39 | 38 | #include "swift/AST/TypeLoc.h"
|
40 | 39 | #include "swift/AST/TypeRepr.h"
|
41 | 40 | #include "swift/AST/TypeTransform.h"
|
| 41 | +#include "swift/AST/TypeVisitor.h" |
| 42 | +#include "swift/AST/TypeWalker.h" |
| 43 | +#include "swift/AST/Types.h" |
42 | 44 | #include "swift/Basic/Assertions.h"
|
43 | 45 | #include "swift/Basic/Compiler.h"
|
44 |
| -#include "clang/AST/Type.h" |
45 | 46 | #include "llvm/ADT/APFloat.h"
|
| 47 | +#include "llvm/ADT/STLExtras.h" |
46 | 48 | #include "llvm/ADT/SmallPtrSet.h"
|
47 | 49 | #include "llvm/ADT/SmallString.h"
|
48 |
| -#include "llvm/ADT/STLExtras.h" |
49 | 50 | #include "llvm/Support/Compiler.h"
|
50 | 51 | #include "llvm/Support/Debug.h"
|
51 | 52 | #include "llvm/Support/raw_ostream.h"
|
@@ -4874,3 +4875,50 @@ StringRef swift::getNameForParamSpecifier(ParamSpecifier specifier) {
|
4874 | 4875 | return "implicitly_copyable_consuming";
|
4875 | 4876 | }
|
4876 | 4877 | }
|
| 4878 | + |
| 4879 | +std::optional<DiagnosticBehavior> |
| 4880 | +TypeBase::getConcurrencyDiagnosticBehaviorLimit(DeclContext *declCtx) const { |
| 4881 | + auto *self = const_cast<TypeBase *>(this); |
| 4882 | + |
| 4883 | + if (auto *nomDecl = self->getNominalOrBoundGenericNominal()) { |
| 4884 | + // First try to just grab the exact concurrency diagnostic behavior. |
| 4885 | + if (auto result = |
| 4886 | + swift::getConcurrencyDiagnosticBehaviorLimit(nomDecl, declCtx)) { |
| 4887 | + return result; |
| 4888 | + } |
| 4889 | + |
| 4890 | + // But if we get nothing, see if we can come up with diagnostic behavior by |
| 4891 | + // merging our fields if we have a struct. |
| 4892 | + if (auto *structDecl = dyn_cast<StructDecl>(nomDecl)) { |
| 4893 | + std::optional<DiagnosticBehavior> diagnosticBehavior; |
| 4894 | + auto substMap = self->getContextSubstitutionMap(); |
| 4895 | + for (auto storedProperty : structDecl->getStoredProperties()) { |
| 4896 | + auto lhs = diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified); |
| 4897 | + auto astType = storedProperty->getInterfaceType().subst(substMap); |
| 4898 | + auto rhs = astType->getConcurrencyDiagnosticBehaviorLimit(declCtx); |
| 4899 | + auto result = lhs.merge(rhs.value_or(DiagnosticBehavior::Unspecified)); |
| 4900 | + if (result != DiagnosticBehavior::Unspecified) |
| 4901 | + diagnosticBehavior = result; |
| 4902 | + } |
| 4903 | + return diagnosticBehavior; |
| 4904 | + } |
| 4905 | + } |
| 4906 | + |
| 4907 | + // When attempting to determine the diagnostic behavior limit of a tuple, just |
| 4908 | + // merge for each of the elements. |
| 4909 | + if (auto *tupleType = self->getAs<TupleType>()) { |
| 4910 | + std::optional<DiagnosticBehavior> diagnosticBehavior; |
| 4911 | + for (auto tupleType : tupleType->getElements()) { |
| 4912 | + auto lhs = diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified); |
| 4913 | + |
| 4914 | + auto type = tupleType.getType()->getCanonicalType(); |
| 4915 | + auto rhs = type->getConcurrencyDiagnosticBehaviorLimit(declCtx); |
| 4916 | + auto result = lhs.merge(rhs.value_or(DiagnosticBehavior::Unspecified)); |
| 4917 | + if (result != DiagnosticBehavior::Unspecified) |
| 4918 | + diagnosticBehavior = result; |
| 4919 | + } |
| 4920 | + return diagnosticBehavior; |
| 4921 | + } |
| 4922 | + |
| 4923 | + return {}; |
| 4924 | +} |
0 commit comments