|
21 | 21 | #include "TypeCheckType.h" |
22 | 22 | #include "TypoCorrection.h" |
23 | 23 |
|
24 | | -#include "swift/Strings.h" |
25 | 24 | #include "swift/AST/ASTDemangler.h" |
26 | 25 | #include "swift/AST/ASTVisitor.h" |
27 | 26 | #include "swift/AST/ASTWalker.h" |
|
35 | 34 | #include "swift/AST/PrettyStackTrace.h" |
36 | 35 | #include "swift/AST/ProtocolConformance.h" |
37 | 36 | #include "swift/AST/SourceFile.h" |
| 37 | +#include "swift/AST/TypeCheckRequests.h" |
38 | 38 | #include "swift/AST/TypeLoc.h" |
39 | 39 | #include "swift/AST/TypeResolutionStage.h" |
40 | 40 | #include "swift/Basic/SourceManager.h" |
41 | 41 | #include "swift/Basic/Statistic.h" |
42 | 42 | #include "swift/Basic/StringExtras.h" |
43 | 43 | #include "swift/ClangImporter/ClangImporter.h" |
| 44 | +#include "swift/Strings.h" |
44 | 45 | #include "llvm/ADT/APInt.h" |
45 | 46 | #include "llvm/ADT/SmallPtrSet.h" |
46 | 47 | #include "llvm/ADT/SmallString.h" |
@@ -1748,7 +1749,7 @@ bool TypeChecker::validateType(TypeLoc &Loc, TypeResolution resolution) { |
1748 | 1749 | if (auto *Stats = resolution.getASTContext().Stats) |
1749 | 1750 | Stats->getFrontendCounters().NumTypesValidated++; |
1750 | 1751 |
|
1751 | | - Type type = resolution.resolveType(Loc.getTypeRepr()); |
| 1752 | + auto type = resolution.resolveType(Loc.getTypeRepr()); |
1752 | 1753 | Loc.setType(type); |
1753 | 1754 |
|
1754 | 1755 | return type->hasError(); |
@@ -1871,34 +1872,39 @@ namespace { |
1871 | 1872 |
|
1872 | 1873 | Type TypeResolution::resolveType(TypeRepr *TyR) { |
1873 | 1874 | auto &ctx = getASTContext(); |
1874 | | - FrontendStatsTracer StatsTracer(ctx.Stats, |
1875 | | - "resolve-type", TyR); |
1876 | | - PrettyStackTraceTypeRepr stackTrace(ctx, "resolving", TyR); |
1877 | | - |
1878 | | - TypeResolver typeResolver(*this); |
1879 | | - |
1880 | | - auto result = typeResolver.resolveType(TyR, getOptions()); |
| 1875 | + auto Ty = |
| 1876 | + evaluateOrDefault(ctx.evaluator, ResolveTypeRequest{this, TyR}, Type()); |
| 1877 | + if (!Ty) |
| 1878 | + return ErrorType::get(ctx); |
| 1879 | + return Ty; |
| 1880 | +} |
1881 | 1881 |
|
1882 | | - if (result) { |
1883 | | - // If we resolved down to an error, make sure to mark the typeRepr as invalid |
1884 | | - // so we don't produce a redundant diagnostic. |
1885 | | - if (result->hasError()) { |
1886 | | - TyR->setInvalid(); |
1887 | | - return result; |
1888 | | - } |
| 1882 | +Type ResolveTypeRequest::evaluate(Evaluator &evaluator, |
| 1883 | + TypeResolution *resolution, |
| 1884 | + TypeRepr *TyR) const { |
| 1885 | + const auto options = resolution->getOptions(); |
| 1886 | + auto &ctx = resolution->getASTContext(); |
| 1887 | + auto result = |
| 1888 | + TypeResolver(*resolution).resolveType(TyR, resolution->getOptions()); |
1889 | 1889 |
|
1890 | | - auto loc = TyR->getLoc(); |
| 1890 | + // If we resolved down to an error, make sure to mark the typeRepr as invalid |
| 1891 | + // so we don't produce a redundant diagnostic. |
| 1892 | + if (result->hasError()) { |
| 1893 | + TyR->setInvalid(); |
| 1894 | + return result; |
| 1895 | + } |
1891 | 1896 |
|
1892 | | - if (options.contains(TypeResolutionFlags::SILType) |
1893 | | - && !result->isLegalSILType()) { |
1894 | | - ctx.Diags.diagnose(loc, diag::illegal_sil_type, result); |
1895 | | - return ErrorType::get(ctx); |
1896 | | - } |
| 1897 | + auto loc = TyR->getLoc(); |
1897 | 1898 |
|
1898 | | - if (validateAutoClosureAttributeUse(ctx.Diags, TyR, result, options)) |
1899 | | - return ErrorType::get(ctx); |
| 1899 | + if (options.contains(TypeResolutionFlags::SILType) |
| 1900 | + && !result->isLegalSILType()) { |
| 1901 | + ctx.Diags.diagnose(loc, diag::illegal_sil_type, result); |
| 1902 | + return ErrorType::get(ctx); |
1900 | 1903 | } |
1901 | 1904 |
|
| 1905 | + if (validateAutoClosureAttributeUse(ctx.Diags, TyR, result, options)) |
| 1906 | + return ErrorType::get(ctx); |
| 1907 | + |
1902 | 1908 | return result; |
1903 | 1909 | } |
1904 | 1910 |
|
|
0 commit comments