9
9
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
- #include " GenericTypeResolver.h"
13
- #include " TypeChecker.h"
14
- #include " swift/Sema/TypeCheckRequests.h"
12
+ #include " swift/AST/TypeCheckRequests.h"
15
13
#include " swift/AST/Decl.h"
16
- #include " swift/AST/ExistentialLayout .h"
14
+ #include " swift/AST/DiagnosticsCommon .h"
17
15
#include " swift/AST/TypeLoc.h"
18
16
#include " swift/AST/Types.h"
19
- #include " swift/Subsystems.h"
20
17
21
18
using namespace swift ;
22
19
23
20
namespace swift {
24
- // Implement the type checker type zone (zone 10).
21
+ // Implement the type checker type zone (zone 10).
25
22
#define SWIFT_TYPEID_ZONE 10
26
- #define SWIFT_TYPEID_HEADER " swift/Sema /TypeCheckerTypeIDZone.def"
23
+ #define SWIFT_TYPEID_HEADER " swift/AST /TypeCheckerTypeIDZone.def"
27
24
#include " swift/Basic/ImplementTypeIDZone.h"
28
25
29
26
}
@@ -54,71 +51,6 @@ TypeLoc &InheritedTypeRequest::getTypeLoc(
54
51
return decl.get <ExtensionDecl *>()->getInherited ()[index];
55
52
}
56
53
57
- Type InheritedTypeRequest::evaluate (
58
- Evaluator &evaluator,
59
- llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
60
- unsigned index) const {
61
- // Figure out how to resolve types.
62
- TypeResolutionOptions options;
63
- DeclContext *dc;
64
- if (auto typeDecl = decl.dyn_cast <TypeDecl *>()) {
65
- if (auto nominal = dyn_cast<NominalTypeDecl>(typeDecl)) {
66
- dc = nominal;
67
- options |= TypeResolutionFlags::GenericSignature;
68
- options |= TypeResolutionFlags::InheritanceClause;
69
- options |= TypeResolutionFlags::AllowUnavailableProtocol;
70
- } else {
71
- dc = typeDecl->getDeclContext ();
72
-
73
- if (isa<GenericTypeParamDecl>(typeDecl)) {
74
- // For generic parameters, we want name lookup to look at just the
75
- // signature of the enclosing entity.
76
- if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
77
- dc = nominal;
78
- options |= TypeResolutionFlags::GenericSignature;
79
- } else if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
80
- dc = ext;
81
- options |= TypeResolutionFlags::GenericSignature;
82
- } else if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
83
- dc = func;
84
- options |= TypeResolutionFlags::GenericSignature;
85
- } else if (!dc->isModuleScopeContext ()) {
86
- // Skip the generic parameter's context entirely.
87
- dc = dc->getParent ();
88
- }
89
- }
90
- }
91
- } else {
92
- auto ext = decl.get <ExtensionDecl *>();
93
- dc = ext;
94
- options |= TypeResolutionFlags::GenericSignature;
95
- options |= TypeResolutionFlags::InheritanceClause;
96
- options |= TypeResolutionFlags::AllowUnavailableProtocol;
97
- }
98
-
99
- ProtocolRequirementTypeResolver protoResolver;
100
- GenericTypeToArchetypeResolver archetypeResolver (dc);
101
- GenericTypeResolver *resolver;
102
- if (isa<ProtocolDecl>(dc)) {
103
- resolver = &protoResolver;
104
- } else {
105
- resolver = &archetypeResolver;
106
- }
107
-
108
- // FIXME: Hack for calls through here when we have no type checker.
109
- auto lazyResolver = dc->getASTContext ().getLazyResolver ();
110
- if (!lazyResolver) return ErrorType::get (dc->getASTContext ());
111
-
112
- TypeChecker &tc = *static_cast <TypeChecker *>(lazyResolver);
113
- TypeLoc &typeLoc = getTypeLoc (decl, index);
114
-
115
- Type inheritedType =
116
- tc.resolveType (typeLoc.getTypeRepr (), dc, options, resolver);
117
- if (inheritedType && !isa<ProtocolDecl>(dc))
118
- inheritedType = inheritedType->mapTypeOutOfContext ();
119
- return inheritedType ? inheritedType : ErrorType::get (tc.Context );
120
- }
121
-
122
54
void InheritedTypeRequest::diagnoseCycle (DiagnosticEngine &diags) const {
123
55
const auto &storage = getStorage ();
124
56
auto &typeLoc = getTypeLoc (std::get<0 >(storage), std::get<1 >(storage));
@@ -149,40 +81,6 @@ void InheritedTypeRequest::cacheResult(Type value) const {
149
81
// ----------------------------------------------------------------------------//
150
82
// Superclass computation.
151
83
// ----------------------------------------------------------------------------//
152
- Type SuperclassTypeRequest::evaluate (Evaluator &evaluator,
153
- NominalTypeDecl *nominalDecl) const {
154
- assert (isa<ClassDecl>(nominalDecl) || isa<ProtocolDecl>(nominalDecl));
155
-
156
- for (unsigned int idx : indices (nominalDecl->getInherited ())) {
157
- Type inheritedType = evaluator (InheritedTypeRequest{nominalDecl, idx});
158
- if (!inheritedType) continue ;
159
-
160
- // If we found a class, return it.
161
- if (inheritedType->getClassOrBoundGenericClass ()) {
162
- if (inheritedType->hasArchetype ())
163
- return inheritedType->mapTypeOutOfContext ();
164
-
165
- return inheritedType;
166
- }
167
-
168
- // If we found an existential with a superclass bound, return it.
169
- if (inheritedType->isExistentialType ()) {
170
- if (auto superclassType =
171
- inheritedType->getExistentialLayout ().superclass ) {
172
- if (superclassType->getClassOrBoundGenericClass ()) {
173
- if (superclassType->hasArchetype ())
174
- return superclassType->mapTypeOutOfContext ();
175
-
176
- return superclassType;
177
- }
178
- }
179
- }
180
- }
181
-
182
- // No superclass.
183
- return Type ();
184
- }
185
-
186
84
void SuperclassTypeRequest::diagnoseCycle (DiagnosticEngine &diags) const {
187
85
// FIXME: Improve this diagnostic.
188
86
auto nominalDecl = std::get<0 >(getStorage ());
@@ -223,26 +121,6 @@ void SuperclassTypeRequest::cacheResult(Type value) const {
223
121
// ----------------------------------------------------------------------------//
224
122
// Enum raw type computation.
225
123
// ----------------------------------------------------------------------------//
226
- Type EnumRawTypeRequest::evaluate (Evaluator &evaluator,
227
- EnumDecl *enumDecl) const {
228
- for (unsigned int idx : indices (enumDecl->getInherited ())) {
229
- Type inheritedType = evaluator (InheritedTypeRequest{enumDecl, idx});
230
- if (!inheritedType) continue ;
231
-
232
- // Skip existential types.
233
- if (inheritedType->isExistentialType ()) continue ;
234
-
235
- // We found a raw type; return it.
236
- if (inheritedType->hasArchetype ())
237
- return inheritedType->mapTypeOutOfContext ();
238
-
239
- return inheritedType;
240
- }
241
-
242
- // No raw type.
243
- return Type ();
244
- }
245
-
246
124
void EnumRawTypeRequest::diagnoseCycle (DiagnosticEngine &diags) const {
247
125
// FIXME: Improve this diagnostic.
248
126
auto enumDecl = std::get<0 >(getStorage ());
@@ -267,16 +145,3 @@ void EnumRawTypeRequest::cacheResult(Type value) const {
267
145
auto enumDecl = std::get<0 >(getStorage ());
268
146
enumDecl->LazySemanticInfo .RawType .setPointerAndInt (value, true );
269
147
}
270
-
271
- // Define request evaluation functions for each of the type checker requests.
272
- static AbstractRequestFunction *typeCheckerRequestFunctions[] = {
273
- #define SWIFT_TYPEID (Name ) \
274
- reinterpret_cast <AbstractRequestFunction *>(&Name::evaluateRequest),
275
- #include " swift/Sema/TypeCheckerTypeIDZone.def"
276
- #undef SWIFT_TYPEID
277
- };
278
-
279
- void swift::registerTypeCheckerRequestFunctions (Evaluator &evaluator) {
280
- evaluator.registerRequestFunctions (SWIFT_TYPE_CHECKER_REQUESTS_TYPEID_ZONE,
281
- typeCheckerRequestFunctions);
282
- }
0 commit comments