@@ -419,16 +419,15 @@ TypeChecker::getDynamicBridgedThroughObjCClass(DeclContext *dc,
419
419
return dc->getASTContext ().getBridgedToObjC (dc, valueType);
420
420
}
421
421
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 ();
426
426
ASTContext &ctx = fromDC->getASTContext ();
427
427
428
428
// If we found a generic parameter, map to the archetype if there is one.
429
429
if (auto genericParam = dyn_cast<GenericTypeParamDecl>(typeDecl)) {
430
- return resolution.mapTypeIntoContext (
431
- genericParam->getDeclaredInterfaceType ());
430
+ return mapTypeIntoContext (genericParam->getDeclaredInterfaceType ());
432
431
}
433
432
434
433
if (!isSpecialized) {
@@ -440,13 +439,12 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
440
439
parentDC = parentDC->getParent ()) {
441
440
auto *parentNominal = parentDC->getSelfNominalTypeDecl ();
442
441
if (parentNominal == nominalType)
443
- return resolution.mapTypeIntoContext (
444
- parentDC->getDeclaredInterfaceType ());
442
+ return mapTypeIntoContext (parentDC->getDeclaredInterfaceType ());
445
443
if (isa<ExtensionDecl>(parentDC)) {
446
444
auto *extendedType = parentNominal;
447
445
while (extendedType != nullptr ) {
448
446
if (extendedType == nominalType)
449
- return resolution. mapTypeIntoContext (
447
+ return mapTypeIntoContext (
450
448
extendedType->getDeclaredInterfaceType ());
451
449
extendedType = extendedType->getParent ()->getSelfNominalTypeDecl ();
452
450
}
@@ -466,11 +464,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
466
464
if (auto *ugAliasDecl =
467
465
dyn_cast<TypeAliasDecl>(unboundGeneric->getAnyGeneric ())) {
468
466
if (ugAliasDecl == aliasDecl) {
469
- if (resolution. getStage () == TypeResolutionStage::Structural &&
467
+ if (getStage () == TypeResolutionStage::Structural &&
470
468
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
471
469
return aliasDecl->getStructuralType ();
472
470
}
473
- return resolution. mapTypeIntoContext (
471
+ return mapTypeIntoContext (
474
472
aliasDecl->getDeclaredInterfaceType ());
475
473
}
476
474
@@ -481,12 +479,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
481
479
if (auto *aliasType =
482
480
dyn_cast<TypeAliasType>(extendedType.getPointer ())) {
483
481
if (aliasType->getDecl () == aliasDecl) {
484
- if (resolution. getStage () == TypeResolutionStage::Structural &&
482
+ if (getStage () == TypeResolutionStage::Structural &&
485
483
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
486
484
return aliasDecl->getStructuralType ();
487
485
}
488
- return resolution.mapTypeIntoContext (
489
- aliasDecl->getDeclaredInterfaceType ());
486
+ return mapTypeIntoContext (aliasDecl->getDeclaredInterfaceType ());
490
487
}
491
488
extendedType = aliasType->getParent ();
492
489
continue ;
@@ -507,12 +504,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
507
504
return aliasDecl->getUnboundGenericType ();
508
505
509
506
// Otherwise, return the appropriate type.
510
- if (resolution. getStage () == TypeResolutionStage::Structural &&
507
+ if (getStage () == TypeResolutionStage::Structural &&
511
508
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
512
509
return aliasDecl->getStructuralType ();
513
510
}
514
- return resolution.mapTypeIntoContext (
515
- aliasDecl->getDeclaredInterfaceType ());
511
+ return mapTypeIntoContext (aliasDecl->getDeclaredInterfaceType ());
516
512
}
517
513
518
514
// When a nominal type used outside its context, return the unbound
@@ -539,12 +535,11 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
539
535
if (!foundDC->getDeclaredInterfaceType ())
540
536
return ErrorType::get (ctx);
541
537
542
- selfType =
543
- resolution.mapTypeIntoContext (foundDC->getDeclaredInterfaceType ());
538
+ selfType = mapTypeIntoContext (foundDC->getDeclaredInterfaceType ());
544
539
} else {
545
540
// Otherwise, we want the protocol 'Self' type for
546
541
// substituting into alias types and associated types.
547
- selfType = resolution. mapTypeIntoContext (foundDC->getSelfInterfaceType ());
542
+ selfType = mapTypeIntoContext (foundDC->getSelfInterfaceType ());
548
543
549
544
if (selfType->is <GenericTypeParamType>()) {
550
545
if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
@@ -559,9 +554,9 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
559
554
// because we use the Sequence.SubSequence default instead of
560
555
// the Collection.SubSequence default, even when the conforming
561
556
// 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 ());
565
560
} else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
566
561
typeDecl = assocType->getAssociatedTypeAnchor ();
567
562
}
@@ -587,8 +582,8 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
587
582
}
588
583
589
584
// 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 ());
592
587
}
593
588
594
589
static TypeResolutionOptions
@@ -685,7 +680,8 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
685
680
// / If the type is itself not generic, this does nothing.
686
681
// /
687
682
// / 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
689
685
// / to be in a correct and valid form.
690
686
// /
691
687
// / \param type The generic type to which to apply arguments.
@@ -697,7 +693,7 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
697
693
// / \returns A BoundGenericType bound to the given arguments, or null on
698
694
// / error.
699
695
// /
700
- // / \see applyUnboundGenericArguments
696
+ // / \see TypeResolution:: applyUnboundGenericArguments
701
697
static Type applyGenericArguments (Type type, TypeResolution resolution,
702
698
GenericParamList *silParams,
703
699
ComponentIdentTypeRepr *comp) {
@@ -831,8 +827,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
831
827
args.push_back (substTy);
832
828
}
833
829
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);
836
832
837
833
// Migration hack.
838
834
bool isMutablePointer;
@@ -888,10 +884,9 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
888
884
}
889
885
890
886
// / 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 {
895
890
assert (genericArgs.size () == decl->getGenericParams ()->size () &&
896
891
" invalid arguments, use applyGenericArguments for diagnostic emitting" );
897
892
@@ -931,9 +926,7 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
931
926
auto genericSig = genericEnv->getGenericSignature ();
932
927
for (auto gp : genericSig->getGenericParams ()) {
933
928
subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
934
- (resolution.usesArchetypes ()
935
- ? genericEnv->mapTypeIntoContext (gp)
936
- : gp);
929
+ (usesArchetypes () ? genericEnv->mapTypeIntoContext (gp) : gp);
937
930
}
938
931
}
939
932
@@ -957,21 +950,19 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
957
950
958
951
// Check the generic arguments against the requirements of the declaration's
959
952
// generic signature.
960
- auto dc = resolution.getDeclContext ();
961
- auto *module = dc->getParentModule ();
953
+ auto *module = getDeclContext ()->getParentModule ();
962
954
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 ()),
968
959
genericSig->getGenericParams (), genericSig->getRequirements (),
969
960
QueryTypeSubstitutionMap{subs});
970
961
971
962
switch (result) {
972
963
case RequirementCheckResult::Failure:
973
964
case RequirementCheckResult::SubstitutionFailure:
974
- return ErrorType::get (dc-> getASTContext ());
965
+ return ErrorType::get (getASTContext ());
975
966
case RequirementCheckResult::Success:
976
967
break ;
977
968
}
@@ -1071,8 +1062,8 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, DeclContext *foundDC,
1071
1062
ComponentIdentTypeRepr *comp) {
1072
1063
// Resolve the type declaration to a specific type. How this occurs
1073
1064
// 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));
1076
1067
1077
1068
if (type->hasError () && foundDC &&
1078
1069
(isa<AssociatedTypeDecl>(typeDecl) || isa<TypeAliasDecl>(typeDecl))) {
@@ -3527,9 +3518,8 @@ TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
3527
3518
return ErrorType::get (getASTContext ());
3528
3519
}
3529
3520
3530
- if (!TypeChecker::applyUnboundGenericArguments (
3531
- dictDecl, nullptr , repr->getStartLoc (), resolution,
3532
- {keyTy, valueTy})) {
3521
+ if (!resolution.applyUnboundGenericArguments (
3522
+ dictDecl, nullptr , repr->getStartLoc (), {keyTy, valueTy})) {
3533
3523
assert (getASTContext ().Diags .hadAnyError ());
3534
3524
return ErrorType::get (getASTContext ());
3535
3525
}
0 commit comments