Skip to content

Commit 0c4bef4

Browse files
committed
[NFC] Fixup references to TypeExpr::getInstanceType
1 parent 7ed1882 commit 0c4bef4

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

include/swift/AST/Expr.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,14 +1340,13 @@ class TypeExpr : public Expr {
13401340
// Create a TypeExpr with location information.
13411341
TypeExpr(TypeRepr *Ty);
13421342

1343-
// The type of a TypeExpr is always a metatype type. Return the instance
1344-
// type, ErrorType if an error, or null if not set yet.
1345-
Type getInstanceType(llvm::function_ref<bool(const Expr *)> hasType =
1346-
[](const Expr *E) -> bool { return !!E->getType(); },
1347-
llvm::function_ref<Type(const Expr *)> getType =
1348-
[](const Expr *E) -> Type {
1349-
return E->getType();
1350-
}) const;
1343+
/// Retrieves the corresponding instance type of the type referenced by this
1344+
/// expression.
1345+
///
1346+
/// If this node has no type, the resulting instance type is also the
1347+
/// null \c Type(). If the type of this node is not a \c MetatypeType, the
1348+
/// resulting instance type is \c ErrorType.
1349+
Type getInstanceType() const;
13511350

13521351
// Create an implicit TypeExpr, which has no location information.
13531352
static TypeExpr *createImplicit(Type Ty, ASTContext &C);
@@ -1389,7 +1388,7 @@ class TypeExpr : public Expr {
13891388
// NOTE: TypeExpr::getType() returns the type of the expr node, which is the
13901389
// metatype of what is stored as an operand type.
13911390

1392-
SourceRange getSourceRange() const { return TypeLoc(Repr).getSourceRange(); }
1391+
SourceRange getSourceRange() const;
13931392
// TODO: optimize getStartLoc() and getEndLoc() when TypeLoc allows it.
13941393

13951394
static bool classof(const Expr *E) {

lib/AST/Expr.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,16 +1938,15 @@ TypeExpr *TypeExpr::createImplicit(Type Ty, ASTContext &C) {
19381938

19391939
// The type of a TypeExpr is always a metatype type. Return the instance
19401940
// type or null if not set yet.
1941-
Type TypeExpr::getInstanceType(
1942-
llvm::function_ref<bool(const Expr *)> hasType,
1943-
llvm::function_ref<Type(const Expr *)> getType) const {
1944-
if (!hasType(this))
1941+
Type TypeExpr::getInstanceType() const {
1942+
auto ty = getType();
1943+
if (!ty)
19451944
return Type();
19461945

1947-
if (auto metaType = getType(this)->getAs<MetatypeType>())
1946+
if (auto metaType = ty->getAs<MetatypeType>())
19481947
return metaType->getInstanceType();
19491948

1950-
return ErrorType::get(getType(this)->getASTContext());
1949+
return ErrorType::get(ty->getASTContext());
19511950
}
19521951

19531952
TypeExpr *TypeExpr::createForDecl(DeclNameLoc Loc, TypeDecl *Decl,
@@ -1956,8 +1955,7 @@ TypeExpr *TypeExpr::createForDecl(DeclNameLoc Loc, TypeDecl *Decl,
19561955
assert(Loc.isValid());
19571956
auto *Repr = new (C) SimpleIdentTypeRepr(Loc, Decl->createNameRef());
19581957
Repr->setValue(Decl, DC);
1959-
auto result = new (C) TypeExpr(Repr);
1960-
return result;
1958+
return new (C) TypeExpr(Repr);
19611959
}
19621960

19631961
TypeExpr *TypeExpr::createImplicitForDecl(DeclNameLoc Loc, TypeDecl *Decl,
@@ -2086,6 +2084,11 @@ TypeExpr *TypeExpr::createImplicitHack(SourceLoc Loc, Type Ty, ASTContext &C) {
20862084
return Res;
20872085
}
20882086

2087+
SourceRange TypeExpr::getSourceRange() const {
2088+
if (!getTypeRepr()) return SourceRange();
2089+
return getTypeRepr()->getSourceRange();
2090+
}
2091+
20892092
bool Expr::isSelfExprOf(const AbstractFunctionDecl *AFD, bool sameBase) const {
20902093
auto *E = getSemanticsProvidingExpr();
20912094

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,13 @@ bool ConstraintSystem::isStaticallyDerivedMetatype(const Expr *E) {
183183
}
184184

185185
Type ConstraintSystem::getInstanceType(const TypeExpr *E) {
186-
return E->getInstanceType([&](const Expr *E) -> bool { return hasType(E); },
187-
[&](const Expr *E) -> Type { return getType(E); });
186+
if (!hasType(E))
187+
return Type();
188+
189+
if (auto metaType = getType(E)->getAs<MetatypeType>())
190+
return metaType->getInstanceType();
191+
192+
return ErrorType::get(getType(E)->getASTContext());
188193
}
189194

190195
Type ConstraintSystem::getResultType(const AbstractClosureExpr *E) {

0 commit comments

Comments
 (0)