2929#include " swift/AST/ExistentialLayout.h"
3030#include " swift/AST/ForeignErrorConvention.h"
3131#include " swift/AST/GenericEnvironment.h"
32- #include " swift/AST/GenericSignatureBuilder.h"
3332#include " swift/AST/NameLookup.h"
3433#include " swift/AST/ParameterList.h"
3534#include " swift/AST/PrettyStackTrace.h"
@@ -75,8 +74,7 @@ TypeResolution::forInterface(DeclContext *dc, TypeResolutionOptions options,
7574 HandlePlaceholderTypeReprFn placeholderHandler) {
7675 TypeResolution result (dc, TypeResolutionStage::Interface, options,
7776 unboundTyOpener, placeholderHandler);
78- result.complete .genericSig = dc->getGenericSignatureOfContext ();
79- result.complete .builder = nullptr ;
77+ result.genericSig = dc->getGenericSignatureOfContext ();
8078 return result;
8179}
8280
@@ -102,32 +100,22 @@ TypeResolution::forContextual(DeclContext *dc, GenericEnvironment *genericEnv,
102100TypeResolution TypeResolution::withOptions (TypeResolutionOptions opts) const {
103101 TypeResolution result (dc, stage, opts, unboundTyOpener, placeholderHandler);
104102 result.genericEnv = genericEnv;
105- result.complete = complete ;
103+ result.genericSig = genericSig ;
106104 return result;
107105}
108106
109107ASTContext &TypeResolution::getASTContext () const {
110108 return dc->getASTContext ();
111109}
112110
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-
123111GenericSignature TypeResolution::getGenericSignature () const {
124112 switch (stage) {
125113 case TypeResolutionStage::Contextual:
126114 return dc->getGenericSignatureOfContext ();
127115
128116 case TypeResolutionStage::Interface:
129- if (complete. genericSig )
130- return complete. genericSig ;
117+ if (genericSig)
118+ return genericSig;
131119
132120 return dc->getGenericSignatureOfContext ();
133121
@@ -197,22 +185,13 @@ Type TypeResolution::resolveDependentMemberType(
197185 if (!genericSig)
198186 return ErrorType::get (baseTy);
199187
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-
210188 // 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)) {
213190 // Record the type we found.
214191 ref->setValue (nestedType, nullptr );
215192 } else {
193+ ASTContext &ctx = DC->getASTContext ();
194+
216195 // Resolve the base to a potential archetype.
217196 // Perform typo correction.
218197 TypoCorrectionResults corrections (ref->getNameRef (), ref->getNameLoc ());
@@ -258,13 +237,6 @@ Type TypeResolution::resolveDependentMemberType(
258237 return DependentMemberType::get (baseTy, assocType);
259238 }
260239
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-
268240 // There are two situations possible here:
269241 //
270242 // 1. Member comes from the protocol, which means that it has been
@@ -280,9 +252,12 @@ Type TypeResolution::resolveDependentMemberType(
280252 // end up using incorrect generic signature while attempting to form
281253 // a substituted type for the member we found.
282254 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+ }
286261 }
287262
288263 return TypeChecker::substMemberTypeWithBase (DC->getParentModule (), concrete,
@@ -305,16 +280,12 @@ Type TypeResolution::resolveSelfAssociatedType(Type baseTy,
305280 }
306281
307282 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)
314285 return ErrorType::get (baseTy);
315286
316287 // Look for a nested type with the given name.
317- auto nestedType = baseEquivClass ->lookupNestedType (*builder , name);
288+ auto nestedType = genericSig ->lookupNestedType (baseTy , name);
318289 assert (nestedType);
319290
320291 // If the nested type has been resolved to an associated type, use it.
@@ -327,9 +298,12 @@ Type TypeResolution::resolveSelfAssociatedType(Type baseTy,
327298 // extension.
328299 //
329300 // 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+ }
333307 assert (baseTy);
334308 }
335309
@@ -925,12 +899,13 @@ Type TypeResolution::applyUnboundGenericArguments(
925899 }
926900
927901 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 ()) {
931904 for (auto gp : genericSig->getGenericParams ()) {
932905 subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
933- (usesArchetypes () ? genericEnv->mapTypeIntoContext (gp) : gp);
906+ (usesArchetypes ()
907+ ? genericSig->getGenericEnvironment ()->mapTypeIntoContext (gp)
908+ : gp);
934909 }
935910 }
936911
0 commit comments