29
29
#include " swift/AST/ExistentialLayout.h"
30
30
#include " swift/AST/ForeignErrorConvention.h"
31
31
#include " swift/AST/GenericEnvironment.h"
32
- #include " swift/AST/GenericSignatureBuilder.h"
33
32
#include " swift/AST/NameLookup.h"
34
33
#include " swift/AST/ParameterList.h"
35
34
#include " swift/AST/PrettyStackTrace.h"
@@ -75,8 +74,7 @@ TypeResolution::forInterface(DeclContext *dc, TypeResolutionOptions options,
75
74
HandlePlaceholderTypeReprFn placeholderHandler) {
76
75
TypeResolution result (dc, TypeResolutionStage::Interface, options,
77
76
unboundTyOpener, placeholderHandler);
78
- result.complete .genericSig = dc->getGenericSignatureOfContext ();
79
- result.complete .builder = nullptr ;
77
+ result.genericSig = dc->getGenericSignatureOfContext ();
80
78
return result;
81
79
}
82
80
@@ -102,32 +100,22 @@ TypeResolution::forContextual(DeclContext *dc, GenericEnvironment *genericEnv,
102
100
TypeResolution TypeResolution::withOptions (TypeResolutionOptions opts) const {
103
101
TypeResolution result (dc, stage, opts, unboundTyOpener, placeholderHandler);
104
102
result.genericEnv = genericEnv;
105
- result.complete = complete ;
103
+ result.genericSig = genericSig ;
106
104
return result;
107
105
}
108
106
109
107
ASTContext &TypeResolution::getASTContext () const {
110
108
return dc->getASTContext ();
111
109
}
112
110
113
- GenericSignatureBuilder *TypeResolution::getGenericSignatureBuilder () const {
114
- assert (stage == TypeResolutionStage::Interface);
115
- if (!complete.builder ) {
116
- auto genericSig = getGenericSignature ();
117
- complete.builder = genericSig->getGenericSignatureBuilder ();
118
- }
119
-
120
- return complete.builder ;
121
- }
122
-
123
111
GenericSignature TypeResolution::getGenericSignature () const {
124
112
switch (stage) {
125
113
case TypeResolutionStage::Contextual:
126
114
return dc->getGenericSignatureOfContext ();
127
115
128
116
case TypeResolutionStage::Interface:
129
- if (complete. genericSig )
130
- return complete. genericSig ;
117
+ if (genericSig)
118
+ return genericSig;
131
119
132
120
return dc->getGenericSignatureOfContext ();
133
121
@@ -197,22 +185,13 @@ Type TypeResolution::resolveDependentMemberType(
197
185
if (!genericSig)
198
186
return ErrorType::get (baseTy);
199
187
200
- auto builder = getGenericSignatureBuilder ();
201
- auto baseEquivClass =
202
- builder->resolveEquivalenceClass (
203
- baseTy,
204
- ArchetypeResolutionKind::CompleteWellFormed);
205
- if (!baseEquivClass)
206
- return ErrorType::get (baseTy);
207
-
208
- ASTContext &ctx = baseTy->getASTContext ();
209
-
210
188
// Look for a nested type with the given name.
211
- if (auto nestedType =
212
- baseEquivClass->lookupNestedType (*builder, refIdentifier)) {
189
+ if (auto nestedType = genericSig->lookupNestedType (baseTy, refIdentifier)) {
213
190
// Record the type we found.
214
191
ref->setValue (nestedType, nullptr );
215
192
} else {
193
+ ASTContext &ctx = DC->getASTContext ();
194
+
216
195
// Resolve the base to a potential archetype.
217
196
// Perform typo correction.
218
197
TypoCorrectionResults corrections (ref->getNameRef (), ref->getNameLoc ());
@@ -258,13 +237,6 @@ Type TypeResolution::resolveDependentMemberType(
258
237
return DependentMemberType::get (baseTy, assocType);
259
238
}
260
239
261
- // Otherwise, the nested type comes from a concrete type,
262
- // or it's a typealias declared in protocol or protocol extension.
263
- // Substitute the base type into it.
264
-
265
- // Make sure that base type didn't get replaced along the way.
266
- assert (baseTy->isTypeParameter ());
267
-
268
240
// There are two situations possible here:
269
241
//
270
242
// 1. Member comes from the protocol, which means that it has been
@@ -280,9 +252,12 @@ Type TypeResolution::resolveDependentMemberType(
280
252
// end up using incorrect generic signature while attempting to form
281
253
// a substituted type for the member we found.
282
254
if (!concrete->getDeclContext ()->getSelfProtocolDecl ()) {
283
- baseTy = baseEquivClass->concreteType ? baseEquivClass->concreteType
284
- : baseEquivClass->superclass ;
285
- assert (baseTy);
255
+ if (auto concreteTy = genericSig->getConcreteType (baseTy))
256
+ baseTy = concreteTy;
257
+ else {
258
+ baseTy = genericSig->getSuperclassBound (baseTy);
259
+ assert (baseTy);
260
+ }
286
261
}
287
262
288
263
return TypeChecker::substMemberTypeWithBase (DC->getParentModule (), concrete,
@@ -305,16 +280,12 @@ Type TypeResolution::resolveSelfAssociatedType(Type baseTy,
305
280
}
306
281
307
282
assert (stage == TypeResolutionStage::Interface);
308
- auto builder = getGenericSignatureBuilder ();
309
- auto baseEquivClass =
310
- builder->resolveEquivalenceClass (
311
- baseTy,
312
- ArchetypeResolutionKind::CompleteWellFormed);
313
- if (!baseEquivClass)
283
+ auto genericSig = getGenericSignature ();
284
+ if (!genericSig)
314
285
return ErrorType::get (baseTy);
315
286
316
287
// Look for a nested type with the given name.
317
- auto nestedType = baseEquivClass ->lookupNestedType (*builder , name);
288
+ auto nestedType = genericSig ->lookupNestedType (baseTy , name);
318
289
assert (nestedType);
319
290
320
291
// If the nested type has been resolved to an associated type, use it.
@@ -327,9 +298,12 @@ Type TypeResolution::resolveSelfAssociatedType(Type baseTy,
327
298
// extension.
328
299
//
329
300
// Get the superclass of the 'Self' type parameter.
330
- baseTy = (baseEquivClass->concreteType
331
- ? baseEquivClass->concreteType
332
- : baseEquivClass->superclass );
301
+ if (auto concreteTy = genericSig->getConcreteType (baseTy))
302
+ baseTy = concreteTy;
303
+ else {
304
+ baseTy = genericSig->getSuperclassBound (baseTy);
305
+ assert (baseTy);
306
+ }
333
307
assert (baseTy);
334
308
}
335
309
@@ -925,12 +899,13 @@ Type TypeResolution::applyUnboundGenericArguments(
925
899
}
926
900
927
901
skipRequirementsCheck |= parentTy->hasTypeVariable ();
928
- } else if (auto genericEnv =
929
- decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
930
- auto genericSig = genericEnv->getGenericSignature ();
902
+ } else if (auto genericSig =
903
+ decl->getDeclContext ()->getGenericSignatureOfContext ()) {
931
904
for (auto gp : genericSig->getGenericParams ()) {
932
905
subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
933
- (usesArchetypes () ? genericEnv->mapTypeIntoContext (gp) : gp);
906
+ (usesArchetypes ()
907
+ ? genericSig->getGenericEnvironment ()->mapTypeIntoContext (gp)
908
+ : gp);
934
909
}
935
910
}
936
911
0 commit comments