@@ -220,50 +220,6 @@ Type TypeResolution::resolveDependentMemberType(
220220 baseTy);
221221}
222222
223- Type TypeResolution::resolveSelfAssociatedType (Type baseTy,
224- DeclContext *DC,
225- Identifier name) const {
226- switch (stage) {
227- case TypeResolutionStage::Structural:
228- return DependentMemberType::get (baseTy, name);
229-
230- case TypeResolutionStage::Interface:
231- // Handled below.
232- break ;
233- }
234-
235- assert (stage == TypeResolutionStage::Interface);
236- auto genericSig = getGenericSignature ();
237- if (!genericSig)
238- return ErrorType::get (baseTy);
239-
240- // Look for a nested type with the given name.
241- auto nestedType = genericSig->lookupNestedType (baseTy, name);
242- assert (nestedType);
243-
244- // If the nested type has been resolved to an associated type, use it.
245- if (auto assocType = dyn_cast<AssociatedTypeDecl>(nestedType)) {
246- return DependentMemberType::get (baseTy, assocType);
247- }
248-
249- if (nestedType->getDeclContext ()->getSelfClassDecl ()) {
250- // We found a member of a class from a protocol or protocol
251- // extension.
252- //
253- // Get the superclass of the 'Self' type parameter.
254- if (auto concreteTy = genericSig->getConcreteType (baseTy))
255- baseTy = concreteTy;
256- else {
257- baseTy = genericSig->getSuperclassBound (baseTy);
258- assert (baseTy);
259- }
260- assert (baseTy);
261- }
262-
263- return TypeChecker::substMemberTypeWithBase (DC->getParentModule (), nestedType,
264- baseTy);
265- }
266-
267223bool TypeResolution::areSameType (Type type1, Type type2) const {
268224 if (type1->isEqual (type2))
269225 return true ;
@@ -450,23 +406,14 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
450406
451407 if (selfType->is <GenericTypeParamType>()) {
452408 if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
453- if (isa<AssociatedTypeDecl>(typeDecl) ||
454- (isa<TypeAliasDecl>(typeDecl) &&
455- !cast<TypeAliasDecl>(typeDecl)->isGeneric ())) {
456- // FIXME: We should use this lookup method for the Interface
457- // stage too, but right now that causes problems with
458- // Sequence.SubSequence vs Collection.SubSequence; the former
459- // is more canonical, but if we return that instead of the
460- // latter, we infer the wrong associated type in some cases,
461- // because we use the Sequence.SubSequence default instead of
462- // the Collection.SubSequence default, even when the conforming
463- // type wants to conform to Collection.
464- if (getStage () == TypeResolutionStage::Structural) {
465- return resolveSelfAssociatedType (selfType, foundDC,
466- typeDecl->getName ());
467- } else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
468- typeDecl = assocType->getAssociatedTypeAnchor ();
469- }
409+ auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl);
410+ if (getStage () == TypeResolutionStage::Structural &&
411+ aliasDecl && !aliasDecl->isGeneric ()) {
412+ return aliasDecl->getStructuralType ();
413+ }
414+
415+ if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
416+ typeDecl = assocType->getAssociatedTypeAnchor ();
470417 }
471418 }
472419
@@ -543,10 +490,6 @@ bool TypeChecker::checkContextualRequirements(GenericTypeDecl *decl,
543490 noteLoc = loc;
544491 }
545492
546- if (contextSig) {
547- parentTy = contextSig.getGenericEnvironment ()->mapTypeIntoContext (parentTy);
548- }
549-
550493 const auto subMap = parentTy->getContextSubstitutions (decl->getDeclContext ());
551494 const auto genericSig = decl->getGenericSignature ();
552495
@@ -556,7 +499,16 @@ bool TypeChecker::checkContextualRequirements(GenericTypeDecl *decl,
556499 decl->getDeclaredInterfaceType (),
557500 genericSig.getGenericParams (),
558501 genericSig.getRequirements (),
559- QueryTypeSubstitutionMap{subMap});
502+ [&](SubstitutableType *type) -> Type {
503+ auto result = QueryTypeSubstitutionMap{subMap}(type);
504+ if (result->hasTypeParameter ()) {
505+ if (contextSig) {
506+ auto *genericEnv = contextSig.getGenericEnvironment ();
507+ return genericEnv->mapTypeIntoContext (result);
508+ }
509+ }
510+ return result;
511+ });
560512
561513 switch (result) {
562514 case RequirementCheckResult::Failure:
@@ -845,15 +797,6 @@ Type TypeResolution::applyUnboundGenericArguments(
845797 // Check the generic arguments against the requirements of the declaration's
846798 // generic signature.
847799
848- // First, map substitutions into context.
849- TypeSubstitutionMap contextualSubs = subs;
850- if (const auto contextSig = getGenericSignature ()) {
851- auto *genericEnv = contextSig.getGenericEnvironment ();
852- for (auto &pair : contextualSubs) {
853- pair.second = genericEnv->mapTypeIntoContext (pair.second );
854- }
855- }
856-
857800 SourceLoc noteLoc = decl->getLoc ();
858801 if (noteLoc.isInvalid ())
859802 noteLoc = loc;
@@ -862,7 +805,16 @@ Type TypeResolution::applyUnboundGenericArguments(
862805 module , loc, noteLoc,
863806 UnboundGenericType::get (decl, parentTy, getASTContext ()),
864807 genericSig.getGenericParams (), genericSig.getRequirements (),
865- QueryTypeSubstitutionMap{contextualSubs});
808+ [&](SubstitutableType *type) -> Type {
809+ auto result = QueryTypeSubstitutionMap{subs}(type);
810+ if (result->hasTypeParameter ()) {
811+ if (const auto contextSig = getGenericSignature ()) {
812+ auto *genericEnv = contextSig.getGenericEnvironment ();
813+ return genericEnv->mapTypeIntoContext (result);
814+ }
815+ }
816+ return result;
817+ });
866818
867819 switch (result) {
868820 case RequirementCheckResult::Failure:
@@ -2478,14 +2430,7 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
24782430 // context, and then set isNoEscape if @escaping is not present.
24792431 if (!ty) ty = resolveType (repr, instanceOptions);
24802432 if (!ty || ty->hasError ()) return ty;
2481-
2482- // Type aliases inside protocols are not yet resolved in the structural
2483- // stage of type resolution
2484- if (ty->is <DependentMemberType>() &&
2485- resolution.getStage () == TypeResolutionStage::Structural) {
2486- return ty;
2487- }
2488-
2433+
24892434 // Handle @escaping
24902435 if (ty->is <FunctionType>()) {
24912436 if (attrs.has (TAK_escaping)) {
@@ -3463,7 +3408,7 @@ NeverNullType TypeResolver::resolveArrayType(ArrayTypeRepr *repr,
34633408 return ErrorType::get (getASTContext ());
34643409 }
34653410
3466- ASTContext &ctx = baseTy-> getASTContext ();
3411+ ASTContext &ctx = getASTContext ();
34673412 // If the standard library isn't loaded, we ought to let the user know
34683413 // something has gone terribly wrong, since the rest of the compiler is going
34693414 // to assume it can canonicalize [T] to Array<T>.
0 commit comments