@@ -419,16 +419,15 @@ TypeChecker::getDynamicBridgedThroughObjCClass(DeclContext *dc,
419419 return dc->getASTContext ().getBridgedToObjC (dc, valueType);
420420}
421421
422- Type TypeChecker ::resolveTypeInContext (TypeDecl *typeDecl, DeclContext *foundDC ,
423- TypeResolution resolution ,
424- bool isSpecialized) {
425- auto fromDC = resolution. getDeclContext ();
422+ Type TypeResolution ::resolveTypeInContext (TypeDecl *typeDecl,
423+ DeclContext *foundDC ,
424+ bool isSpecialized) const {
425+ auto fromDC = getDeclContext ();
426426 ASTContext &ctx = fromDC->getASTContext ();
427427
428428 // If we found a generic parameter, map to the archetype if there is one.
429429 if (auto genericParam = dyn_cast<GenericTypeParamDecl>(typeDecl)) {
430- return resolution.mapTypeIntoContext (
431- genericParam->getDeclaredInterfaceType ());
430+ return mapTypeIntoContext (genericParam->getDeclaredInterfaceType ());
432431 }
433432
434433 if (!isSpecialized) {
@@ -440,13 +439,12 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
440439 parentDC = parentDC->getParent ()) {
441440 auto *parentNominal = parentDC->getSelfNominalTypeDecl ();
442441 if (parentNominal == nominalType)
443- return resolution.mapTypeIntoContext (
444- parentDC->getDeclaredInterfaceType ());
442+ return mapTypeIntoContext (parentDC->getDeclaredInterfaceType ());
445443 if (isa<ExtensionDecl>(parentDC)) {
446444 auto *extendedType = parentNominal;
447445 while (extendedType != nullptr ) {
448446 if (extendedType == nominalType)
449- return resolution. mapTypeIntoContext (
447+ return mapTypeIntoContext (
450448 extendedType->getDeclaredInterfaceType ());
451449 extendedType = extendedType->getParent ()->getSelfNominalTypeDecl ();
452450 }
@@ -466,11 +464,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
466464 if (auto *ugAliasDecl =
467465 dyn_cast<TypeAliasDecl>(unboundGeneric->getAnyGeneric ())) {
468466 if (ugAliasDecl == aliasDecl) {
469- if (resolution. getStage () == TypeResolutionStage::Structural &&
467+ if (getStage () == TypeResolutionStage::Structural &&
470468 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
471469 return aliasDecl->getStructuralType ();
472470 }
473- return resolution. mapTypeIntoContext (
471+ return mapTypeIntoContext (
474472 aliasDecl->getDeclaredInterfaceType ());
475473 }
476474
@@ -481,12 +479,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
481479 if (auto *aliasType =
482480 dyn_cast<TypeAliasType>(extendedType.getPointer ())) {
483481 if (aliasType->getDecl () == aliasDecl) {
484- if (resolution. getStage () == TypeResolutionStage::Structural &&
482+ if (getStage () == TypeResolutionStage::Structural &&
485483 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
486484 return aliasDecl->getStructuralType ();
487485 }
488- return resolution.mapTypeIntoContext (
489- aliasDecl->getDeclaredInterfaceType ());
486+ return mapTypeIntoContext (aliasDecl->getDeclaredInterfaceType ());
490487 }
491488 extendedType = aliasType->getParent ();
492489 continue ;
@@ -507,12 +504,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
507504 return aliasDecl->getUnboundGenericType ();
508505
509506 // Otherwise, return the appropriate type.
510- if (resolution. getStage () == TypeResolutionStage::Structural &&
507+ if (getStage () == TypeResolutionStage::Structural &&
511508 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
512509 return aliasDecl->getStructuralType ();
513510 }
514- return resolution.mapTypeIntoContext (
515- aliasDecl->getDeclaredInterfaceType ());
511+ return mapTypeIntoContext (aliasDecl->getDeclaredInterfaceType ());
516512 }
517513
518514 // When a nominal type used outside its context, return the unbound
@@ -539,12 +535,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
539535 if (!foundDC->getDeclaredInterfaceType ())
540536 return ErrorType::get (ctx);
541537
542- selfType =
543- resolution.mapTypeIntoContext (foundDC->getDeclaredInterfaceType ());
538+ selfType = mapTypeIntoContext (foundDC->getDeclaredInterfaceType ());
544539 } else {
545540 // Otherwise, we want the protocol 'Self' type for
546541 // substituting into alias types and associated types.
547- selfType = resolution. mapTypeIntoContext (foundDC->getSelfInterfaceType ());
542+ selfType = mapTypeIntoContext (foundDC->getSelfInterfaceType ());
548543
549544 if (selfType->is <GenericTypeParamType>()) {
550545 if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
@@ -559,9 +554,9 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
559554 // because we use the Sequence.SubSequence default instead of
560555 // the Collection.SubSequence default, even when the conforming
561556 // type wants to conform to Collection.
562- if (resolution. getStage () == TypeResolutionStage::Structural) {
563- return resolution. resolveSelfAssociatedType (selfType, foundDC,
564- typeDecl->getName ());
557+ if (getStage () == TypeResolutionStage::Structural) {
558+ return resolveSelfAssociatedType (selfType, foundDC,
559+ typeDecl->getName ());
565560 } else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
566561 typeDecl = assocType->getAssociatedTypeAnchor ();
567562 }
@@ -587,8 +582,8 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
587582 }
588583
589584 // Finally, substitute the base type into the member type.
590- return substMemberTypeWithBase (fromDC-> getParentModule (), typeDecl, selfType,
591- resolution. usesArchetypes ());
585+ return TypeChecker:: substMemberTypeWithBase (
586+ fromDC-> getParentModule (), typeDecl, selfType, usesArchetypes ());
592587}
593588
594589static TypeResolutionOptions
@@ -685,7 +680,8 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
685680// / If the type is itself not generic, this does nothing.
686681// /
687682// / This function emits diagnostics about an invalid type or the wrong number
688- // / of generic arguments, whereas applyUnboundGenericArguments requires this
683+ // / of generic arguments, whereas
684+ // / \c TypeResolution::applyUnboundGenericArguments requires this
689685// / to be in a correct and valid form.
690686// /
691687// / \param type The generic type to which to apply arguments.
@@ -697,7 +693,7 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
697693// / \returns A BoundGenericType bound to the given arguments, or null on
698694// / error.
699695// /
700- // / \see applyUnboundGenericArguments
696+ // / \see TypeResolution:: applyUnboundGenericArguments
701697static Type applyGenericArguments (Type type, TypeResolution resolution,
702698 GenericParamList *silParams,
703699 ComponentIdentTypeRepr *comp) {
@@ -831,8 +827,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
831827 args.push_back (substTy);
832828 }
833829
834- const auto result = TypeChecker:: applyUnboundGenericArguments (
835- decl, unboundType->getParent (), loc, resolution, args);
830+ const auto result = resolution. applyUnboundGenericArguments (
831+ decl, unboundType->getParent (), loc, args);
836832
837833 // Migration hack.
838834 bool isMutablePointer;
@@ -888,10 +884,9 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
888884}
889885
890886// / Apply generic arguments to the given type.
891- Type TypeChecker::applyUnboundGenericArguments (GenericTypeDecl *decl,
892- Type parentTy, SourceLoc loc,
893- TypeResolution resolution,
894- ArrayRef<Type> genericArgs) {
887+ Type TypeResolution::applyUnboundGenericArguments (
888+ GenericTypeDecl *decl, Type parentTy, SourceLoc loc,
889+ ArrayRef<Type> genericArgs) const {
895890 assert (genericArgs.size () == decl->getGenericParams ()->size () &&
896891 " invalid arguments, use applyGenericArguments for diagnostic emitting" );
897892
@@ -931,9 +926,7 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
931926 auto genericSig = genericEnv->getGenericSignature ();
932927 for (auto gp : genericSig->getGenericParams ()) {
933928 subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
934- (resolution.usesArchetypes ()
935- ? genericEnv->mapTypeIntoContext (gp)
936- : gp);
929+ (usesArchetypes () ? genericEnv->mapTypeIntoContext (gp) : gp);
937930 }
938931 }
939932
@@ -957,21 +950,19 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
957950
958951 // Check the generic arguments against the requirements of the declaration's
959952 // generic signature.
960- auto dc = resolution.getDeclContext ();
961- auto *module = dc->getParentModule ();
953+ auto *module = getDeclContext ()->getParentModule ();
962954
963- if (!skipRequirementsCheck &&
964- resolution.getStage () > TypeResolutionStage::Structural) {
965- auto result = checkGenericArguments (
966- dc, loc, noteLoc,
967- UnboundGenericType::get (decl, parentTy, dc->getASTContext ()),
955+ if (!skipRequirementsCheck && getStage () > TypeResolutionStage::Structural) {
956+ auto result = TypeChecker::checkGenericArguments (
957+ getDeclContext (), loc, noteLoc,
958+ UnboundGenericType::get (decl, parentTy, getASTContext ()),
968959 genericSig->getGenericParams (), genericSig->getRequirements (),
969960 QueryTypeSubstitutionMap{subs});
970961
971962 switch (result) {
972963 case RequirementCheckResult::Failure:
973964 case RequirementCheckResult::SubstitutionFailure:
974- return ErrorType::get (dc-> getASTContext ());
965+ return ErrorType::get (getASTContext ());
975966 case RequirementCheckResult::Success:
976967 break ;
977968 }
@@ -1071,8 +1062,8 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, DeclContext *foundDC,
10711062 ComponentIdentTypeRepr *comp) {
10721063 // Resolve the type declaration to a specific type. How this occurs
10731064 // depends on the current context and where the type was found.
1074- Type type = TypeChecker:: resolveTypeInContext (
1075- typeDecl, foundDC, resolution, isa<GenericIdentTypeRepr>(comp));
1065+ Type type = resolution. resolveTypeInContext (typeDecl, foundDC,
1066+ isa<GenericIdentTypeRepr>(comp));
10761067
10771068 if (type->hasError () && foundDC &&
10781069 (isa<AssociatedTypeDecl>(typeDecl) || isa<TypeAliasDecl>(typeDecl))) {
@@ -3527,9 +3518,8 @@ TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
35273518 return ErrorType::get (getASTContext ());
35283519 }
35293520
3530- if (!TypeChecker::applyUnboundGenericArguments (
3531- dictDecl, nullptr , repr->getStartLoc (), resolution,
3532- {keyTy, valueTy})) {
3521+ if (!resolution.applyUnboundGenericArguments (
3522+ dictDecl, nullptr , repr->getStartLoc (), {keyTy, valueTy})) {
35333523 assert (getASTContext ().Diags .hadAnyError ());
35343524 return ErrorType::get (getASTContext ());
35353525 }
0 commit comments