Skip to content

Commit b68540f

Browse files
committed
[NFC] Remove Non-Mutating Usages of Typechecker::validateType
1 parent 5dc060e commit b68540f

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/ParameterList.h"
2424
#include "swift/AST/PrettyStackTrace.h"
2525
#include "swift/AST/SubstitutionMap.h"
26+
#include "swift/AST/TypeCheckRequests.h"
2627
#include "swift/Sema/IDETypeChecking.h"
2728
#include "swift/Subsystems.h"
2829
#include "llvm/ADT/APInt.h"
@@ -1713,13 +1714,12 @@ namespace {
17131714
for (size_t i = 0, size = specializations.size(); i < size; ++i) {
17141715
TypeResolutionOptions options(TypeResolverContext::InExpression);
17151716
options |= TypeResolutionFlags::AllowUnboundGenerics;
1716-
auto tyLoc = TypeLoc{specializations[i]};
1717-
if (TypeChecker::validateType(
1718-
tyLoc, TypeResolution::forContextual(CS.DC, options)))
1717+
auto result = TypeResolution::forContextual(CS.DC, options)
1718+
.resolveType(specializations[i]);
1719+
if (result->hasError())
17191720
return Type();
17201721

1721-
CS.addConstraint(ConstraintKind::Bind,
1722-
typeVars[i], tyLoc.getType(),
1722+
CS.addConstraint(ConstraintKind::Bind, typeVars[i], result,
17231723
locator);
17241724
}
17251725

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,12 +1916,11 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
19161916
TypeResolutionOptions options(TypeResolverContext::InExpression);
19171917
options |= TypeResolutionFlags::AllowUnboundGenerics;
19181918

1919-
typeLoc = TypeLoc(typeExpr->getTypeRepr(), Type());
1920-
bool hadError = TypeChecker::validateType(
1921-
typeLoc, TypeResolution::forContextual(DC, options));
1922-
1923-
if (hadError)
1919+
auto result = TypeResolution::forContextual(DC, options)
1920+
.resolveType(typeExpr->getTypeRepr());
1921+
if (result->hasError())
19241922
return nullptr;
1923+
typeLoc = TypeLoc{typeExpr->getTypeRepr(), result};
19251924
}
19261925

19271926
if (!typeLoc.getType() || !typeLoc.getType()->getAnyNominal())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,15 +1431,13 @@ static NominalTypeDecl *resolveSingleNominalTypeDecl(
14311431
TypeResolutionFlags flags = TypeResolutionFlags(0)) {
14321432
auto *TyR = new (Ctx) SimpleIdentTypeRepr(DeclNameLoc(loc),
14331433
DeclNameRef(ident));
1434-
TypeLoc typeLoc = TypeLoc(TyR);
14351434

14361435
TypeResolutionOptions options = TypeResolverContext::TypeAliasDecl;
14371436
options |= flags;
1438-
if (TypeChecker::validateType(typeLoc,
1439-
TypeResolution::forInterface(DC, options)))
1437+
auto result = TypeResolution::forInterface(DC, options).resolveType(TyR);
1438+
if (result->hasError())
14401439
return nullptr;
1441-
1442-
return typeLoc.getType()->getAnyNominal();
1440+
return result->getAnyNominal();
14431441
}
14441442

14451443
bool swift::checkDesignatedTypes(OperatorDecl *OD,
@@ -1768,13 +1766,13 @@ UnderlyingTypeRequest::evaluate(Evaluator &evaluator,
17681766
return ErrorType::get(typeAlias->getASTContext());
17691767
}
17701768

1771-
auto underlyingLoc = TypeLoc(typeAlias->getUnderlyingTypeRepr());
1772-
if (TypeChecker::validateType(
1773-
underlyingLoc, TypeResolution::forInterface(typeAlias, options))) {
1769+
auto result = TypeResolution::forInterface(typeAlias, options)
1770+
.resolveType(underlyingRepr);
1771+
if (result->hasError()) {
17741772
typeAlias->setInvalid();
17751773
return ErrorType::get(typeAlias->getASTContext());
17761774
}
1777-
return underlyingLoc.getType();
1775+
return result;
17781776
}
17791777

17801778
/// Bind the given function declaration, which declares an operator, to the
@@ -2119,16 +2117,14 @@ static Type validateParameterType(ParamDecl *decl) {
21192117
TypeResolverContext::FunctionInput);
21202118
options |= TypeResolutionFlags::Direct;
21212119

2122-
auto TL = TypeLoc(decl->getTypeRepr());
2123-
21242120
auto &ctx = dc->getASTContext();
2125-
auto resolution = TypeResolution::forInterface(dc, options);
2126-
if (TypeChecker::validateType(TL, resolution)) {
2121+
auto Ty = TypeResolution::forInterface(dc, options)
2122+
.resolveType(decl->getTypeRepr());
2123+
if (Ty->hasError()) {
21272124
decl->setInvalid();
21282125
return ErrorType::get(ctx);
21292126
}
21302127

2131-
Type Ty = TL.getType();
21322128
if (decl->isVariadic()) {
21332129
Ty = TypeChecker::getArraySliceType(decl->getStartLoc(), Ty);
21342130
if (Ty.isNull()) {
@@ -2145,7 +2141,7 @@ static Type validateParameterType(ParamDecl *decl) {
21452141

21462142
return Ty;
21472143
}
2148-
return TL.getType();
2144+
return Ty;
21492145
}
21502146

21512147
Type

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
131131
// Try to resolve the constraint repr. It should be some kind of existential
132132
// type.
133133
TypeResolutionOptions options(TypeResolverContext::GenericRequirement);
134-
TypeLoc constraintTypeLoc(repr->getConstraint());
135134
// Pass along the error type if resolving the repr failed.
136-
auto resolution = TypeResolution::forInterface(
137-
dc, dc->getGenericSignatureOfContext(), options);
138-
bool validationError =
139-
TypeChecker::validateType(constraintTypeLoc, resolution);
140-
auto constraintType = constraintTypeLoc.getType();
141-
if (validationError)
135+
auto constraintType = TypeResolution::forInterface(
136+
dc, dc->getGenericSignatureOfContext(), options)
137+
.resolveType(repr->getConstraint());
138+
if (constraintType->hasError())
142139
return nullptr;
143140

144141
// Error out if the constraint type isn't a class or existential type.

0 commit comments

Comments
 (0)