Skip to content

Commit 2c5166d

Browse files
committed
[NFC] Move applyUnboundGenericArguments to TypeResolution
1 parent fe959c5 commit 2c5166d

File tree

4 files changed

+42
-51
lines changed

4 files changed

+42
-51
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,9 @@ Type ConstraintSystem::openUnboundGenericType(
702702
// pointing at a generic TypeAliasDecl here. If we find a way to
703703
// handle generic TypeAliases elsewhere, this can just become a
704704
// call to BoundGenericType::get().
705-
return TypeChecker::applyUnboundGenericArguments(
706-
decl, parentTy, SourceLoc(),
707-
TypeResolution::forContextual(DC, None, /*unboundTyOpener*/ nullptr,
708-
/*placeholderHandler*/ nullptr),
709-
arguments);
705+
return TypeResolution::forContextual(DC, None, /*unboundTyOpener*/ nullptr,
706+
/*placeholderHandler*/ nullptr)
707+
.applyUnboundGenericArguments(decl, parentTy, SourceLoc(), arguments);
710708
}
711709

712710
static void checkNestedTypeConstraints(ConstraintSystem &cs, Type type,

lib/Sema/TypeCheckType.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ TypeChecker::getDynamicBridgedThroughObjCClass(DeclContext *dc,
421421

422422
Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
423423
DeclContext *foundDC,
424-
bool isSpecialized) {
424+
bool isSpecialized) const {
425425
auto fromDC = getDeclContext();
426426
ASTContext &ctx = fromDC->getASTContext();
427427

@@ -680,7 +680,8 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
680680
/// If the type is itself not generic, this does nothing.
681681
///
682682
/// This function emits diagnostics about an invalid type or the wrong number
683-
/// of generic arguments, whereas applyUnboundGenericArguments requires this
683+
/// of generic arguments, whereas
684+
/// \c TypeResolution::applyUnboundGenericArguments requires this
684685
/// to be in a correct and valid form.
685686
///
686687
/// \param type The generic type to which to apply arguments.
@@ -692,7 +693,7 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc);
692693
/// \returns A BoundGenericType bound to the given arguments, or null on
693694
/// error.
694695
///
695-
/// \see applyUnboundGenericArguments
696+
/// \see TypeResolution::applyUnboundGenericArguments
696697
static Type applyGenericArguments(Type type, TypeResolution resolution,
697698
GenericParamList *silParams,
698699
ComponentIdentTypeRepr *comp) {
@@ -826,8 +827,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
826827
args.push_back(substTy);
827828
}
828829

829-
const auto result = TypeChecker::applyUnboundGenericArguments(
830-
decl, unboundType->getParent(), loc, resolution, args);
830+
const auto result = resolution.applyUnboundGenericArguments(
831+
decl, unboundType->getParent(), loc, args);
831832

832833
// Migration hack.
833834
bool isMutablePointer;
@@ -883,10 +884,9 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
883884
}
884885

885886
/// Apply generic arguments to the given type.
886-
Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
887-
Type parentTy, SourceLoc loc,
888-
TypeResolution resolution,
889-
ArrayRef<Type> genericArgs) {
887+
Type TypeResolution::applyUnboundGenericArguments(
888+
GenericTypeDecl *decl, Type parentTy, SourceLoc loc,
889+
ArrayRef<Type> genericArgs) const {
890890
assert(genericArgs.size() == decl->getGenericParams()->size() &&
891891
"invalid arguments, use applyGenericArguments for diagnostic emitting");
892892

@@ -926,9 +926,7 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
926926
auto genericSig = genericEnv->getGenericSignature();
927927
for (auto gp : genericSig->getGenericParams()) {
928928
subs[gp->getCanonicalType()->castTo<GenericTypeParamType>()] =
929-
(resolution.usesArchetypes()
930-
? genericEnv->mapTypeIntoContext(gp)
931-
: gp);
929+
(usesArchetypes() ? genericEnv->mapTypeIntoContext(gp) : gp);
932930
}
933931
}
934932

@@ -952,21 +950,19 @@ Type TypeChecker::applyUnboundGenericArguments(GenericTypeDecl *decl,
952950

953951
// Check the generic arguments against the requirements of the declaration's
954952
// generic signature.
955-
auto dc = resolution.getDeclContext();
956-
auto *module = dc->getParentModule();
953+
auto *module = getDeclContext()->getParentModule();
957954

958-
if (!skipRequirementsCheck &&
959-
resolution.getStage() > TypeResolutionStage::Structural) {
960-
auto result = checkGenericArguments(
961-
dc, loc, noteLoc,
962-
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()),
963959
genericSig->getGenericParams(), genericSig->getRequirements(),
964960
QueryTypeSubstitutionMap{subs});
965961

966962
switch (result) {
967963
case RequirementCheckResult::Failure:
968964
case RequirementCheckResult::SubstitutionFailure:
969-
return ErrorType::get(dc->getASTContext());
965+
return ErrorType::get(getASTContext());
970966
case RequirementCheckResult::Success:
971967
break;
972968
}
@@ -3522,9 +3518,8 @@ TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
35223518
return ErrorType::get(getASTContext());
35233519
}
35243520

3525-
if (!TypeChecker::applyUnboundGenericArguments(
3526-
dictDecl, nullptr, repr->getStartLoc(), resolution,
3527-
{keyTy, valueTy})) {
3521+
if (!resolution.applyUnboundGenericArguments(
3522+
dictDecl, nullptr, repr->getStartLoc(), {keyTy, valueTy})) {
35283523
assert(getASTContext().Diags.hadAnyError());
35293524
return ErrorType::get(getASTContext());
35303525
}

lib/Sema/TypeCheckType.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,27 @@ class TypeResolution {
421421
///
422422
/// \returns the resolved type.
423423
Type resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
424-
bool isSpecialized);
424+
bool isSpecialized) const;
425+
426+
/// Apply generic arguments to the unbound generic type represented by the
427+
/// given declaration and parent type.
428+
///
429+
/// This function requires the correct number of generic arguments,
430+
/// whereas applyGenericArguments emits diagnostics in those cases.
431+
///
432+
/// \param decl The declaration that the resulting bound generic type
433+
/// shall reference.
434+
/// \param parentTy The parent type.
435+
/// \param loc The source location for diagnostic reporting.
436+
/// \param genericArgs The list of generic arguments to apply.
437+
///
438+
/// \returns A BoundGenericType bound to the given arguments, or null on
439+
/// error.
440+
///
441+
/// \see applyGenericArguments
442+
Type applyUnboundGenericArguments(GenericTypeDecl *decl, Type parentTy,
443+
SourceLoc loc,
444+
ArrayRef<Type> genericArgs) const;
425445
};
426446

427447
} // end namespace swift

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class GenericSignatureBuilder;
4343
class NominalTypeDecl;
4444
class NormalProtocolConformance;
4545
class RootProtocolConformance;
46-
class TypeResolution;
4746
class TypeResolutionOptions;
4847
class TypoCorrectionResults;
4948
class ExprPattern;
@@ -264,27 +263,6 @@ void checkUnsupportedProtocolType(ASTContext &ctx,
264263
void checkUnsupportedProtocolType(ASTContext &ctx,
265264
GenericParamList *genericParams);
266265

267-
/// Apply generic arguments to the unbound generic type represented by the
268-
/// given declaration and parent type.
269-
///
270-
/// This function requires the correct number of generic arguments,
271-
/// whereas applyGenericArguments emits diagnostics in those cases.
272-
///
273-
/// \param decl The declaration that the resulting bound generic type
274-
/// shall reference.
275-
/// \param parentTy The parent type.
276-
/// \param loc The source location for diagnostic reporting.
277-
/// \param resolution The type resolution.
278-
/// \param genericArgs The list of generic arguments to apply.
279-
///
280-
/// \returns A BoundGenericType bound to the given arguments, or null on
281-
/// error.
282-
///
283-
/// \see applyGenericArguments
284-
Type applyUnboundGenericArguments(GenericTypeDecl *decl, Type parentTy,
285-
SourceLoc loc, TypeResolution resolution,
286-
ArrayRef<Type> genericArgs);
287-
288266
/// Substitute the given base type into the type of the given nested type,
289267
/// producing the effective type that the nested type will have.
290268
///

0 commit comments

Comments
 (0)