Skip to content

Commit fe959c5

Browse files
committed
[NFC] Move resolveTypeInContext to TypeResolution
1 parent 876a0ee commit fe959c5

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,12 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
12911291
// Unqualified reference to a type.
12921292
if (auto typeDecl = dyn_cast<TypeDecl>(value)) {
12931293
// Resolve the reference to this type declaration in our current context.
1294-
auto type = TypeChecker::resolveTypeInContext(
1295-
typeDecl, nullptr,
1294+
auto type =
12961295
TypeResolution::forContextual(useDC, TypeResolverContext::InExpression,
12971296
/*unboundTyOpener*/ nullptr,
1298-
/*placeholderHandler*/ nullptr),
1299-
/*isSpecialized=*/false);
1297+
/*placeholderHandler*/ nullptr)
1298+
.resolveTypeInContext(typeDecl, /*foundDC*/ nullptr,
1299+
/*isSpecialized=*/false);
13001300

13011301
checkNestedTypeConstraints(*this, type, locator);
13021302

lib/Sema/TypeCheckType.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
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

594589
static TypeResolutionOptions
@@ -1071,8 +1066,8 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, DeclContext *foundDC,
10711066
ComponentIdentTypeRepr *comp) {
10721067
// Resolve the type declaration to a specific type. How this occurs
10731068
// depends on the current context and where the type was found.
1074-
Type type = TypeChecker::resolveTypeInContext(
1075-
typeDecl, foundDC, resolution, isa<GenericIdentTypeRepr>(comp));
1069+
Type type = resolution.resolveTypeInContext(typeDecl, foundDC,
1070+
isa<GenericIdentTypeRepr>(comp));
10761071

10771072
if (type->hasError() && foundDC &&
10781073
(isa<AssociatedTypeDecl>(typeDecl) || isa<TypeAliasDecl>(typeDecl))) {

lib/Sema/TypeCheckType.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ class TypeResolution {
407407
/// Determine whether the given two types are equivalent within this
408408
/// type resolution context.
409409
bool areSameType(Type type1, Type type2) const;
410+
411+
/// Resolve a reference to the given type declaration within a particular
412+
/// context.
413+
///
414+
/// This routine aids unqualified name lookup for types by performing the
415+
/// resolution necessary to rectify the declaration found by name lookup with
416+
/// the declaration context from which name lookup started.
417+
///
418+
/// \param typeDecl The type declaration found by name lookup.
419+
/// \param foundDC The declaration context this type reference was found in.
420+
/// \param isSpecialized Whether the type will have generic arguments applied.
421+
///
422+
/// \returns the resolved type.
423+
Type resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
424+
bool isSpecialized);
410425
};
411426

412427
} // end namespace swift

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,6 @@ void checkUnsupportedProtocolType(ASTContext &ctx,
264264
void checkUnsupportedProtocolType(ASTContext &ctx,
265265
GenericParamList *genericParams);
266266

267-
/// Resolve a reference to the given type declaration within a particular
268-
/// context.
269-
///
270-
/// This routine aids unqualified name lookup for types by performing the
271-
/// resolution necessary to rectify the declaration found by name lookup with
272-
/// the declaration context from which name lookup started.
273-
///
274-
/// \param typeDecl The type declaration found by name lookup.
275-
/// \param isSpecialized Whether the type will have generic arguments applied.
276-
/// \param resolution The resolution to perform.
277-
///
278-
/// \returns the resolved type.
279-
Type resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
280-
TypeResolution resolution, bool isSpecialized);
281-
282267
/// Apply generic arguments to the unbound generic type represented by the
283268
/// given declaration and parent type.
284269
///

0 commit comments

Comments
 (0)