Skip to content

Commit 1319b53

Browse files
committed
Hide the TypeExpr in ClosureExpr
1 parent f9a506d commit 1319b53

File tree

8 files changed

+17
-28
lines changed

8 files changed

+17
-28
lines changed

include/swift/AST/Expr.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,17 +3769,11 @@ class ClosureExpr : public AbstractClosureExpr {
37693769
return ThrowsLoc;
37703770
}
37713771

3772-
/// Retrieve the explicit result type location information.
3773-
TypeExpr *getExplicitResultTypeExpr() const {
3774-
assert(hasExplicitResultType() && "No explicit result type");
3775-
return ExplicitResultType;
3776-
}
3777-
3778-
void setExplicitResultTypeExpr(TypeExpr *NewResultType) {
3779-
assert(hasExplicitResultType() && "No explicit result type");
3780-
ExplicitResultType = NewResultType;
3772+
Type getExplicitResultType() const {
37813773
assert(hasExplicitResultType() && "No explicit result type");
3774+
return ExplicitResultType->getInstanceType();
37823775
}
3776+
void setExplicitResultType(Type ty);
37833777

37843778
TypeRepr *getExplicitResultTypeRepr() const {
37853779
assert(hasExplicitResultType() && "No explicit result type");

lib/AST/ASTWalker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,8 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
811811
visit(expr->getParameters());
812812

813813
if (expr->hasExplicitResultType()) {
814-
Expr *result = doIt(expr->getExplicitResultTypeExpr());
815-
if (!result) return nullptr;
816-
expr->setExplicitResultTypeExpr(cast<TypeExpr>(result));
814+
if (doIt(expr->getExplicitResultTypeRepr()))
815+
return nullptr;
817816
}
818817

819818
// Handle single-expression closures.

lib/AST/Expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,11 @@ bool ClosureExpr::capturesSelfEnablingImplictSelf() const {
18611861
return false;
18621862
}
18631863

1864+
void ClosureExpr::setExplicitResultType(Type ty) {
1865+
assert(ty && !ty->hasTypeVariable());
1866+
ExplicitResultType->setType(MetatypeType::get(ty));
1867+
}
1868+
18641869
FORWARD_SOURCE_LOCS_TO(AutoClosureExpr, Body)
18651870

18661871
void AutoClosureExpr::setBody(Expr *E) {

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Type swift::ide::getReturnTypeFromContext(const DeclContext *DC) {
211211
return ACE->getResultType();
212212
if (auto CE = dyn_cast<ClosureExpr>(ACE)) {
213213
if (CE->hasExplicitResultType()) {
214-
if (auto ty = CE->getExplicitResultTypeExpr()->getInstanceType()) {
214+
if (auto ty = CE->getExplicitResultType()) {
215215
return ty;
216216
}
217217

lib/IDE/SyntaxModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
663663
SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, E->getSourceRange());
664664
if (Closure->hasExplicitResultType())
665665
SN.TypeRange = charSourceRangeFromSourceRange(SM,
666-
Closure->getExplicitResultTypeExpr()->getSourceRange());
666+
Closure->getExplicitResultTypeRepr()->getSourceRange());
667667

668668
pushStructureNode(SN, Closure);
669669

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7696,6 +7696,10 @@ namespace {
76967696
auto *params = closure->getParameters();
76977697
TypeChecker::coerceParameterListToType(params, closure, fnType);
76987698

7699+
if (closure->hasExplicitResultType()) {
7700+
closure->setExplicitResultType(fnType->getResult());
7701+
}
7702+
76997703
if (auto transform =
77007704
Rewriter.getAppliedBuilderTransform(closure)) {
77017705
// Apply the function builder to the closure. We want to be in the

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,8 +2182,7 @@ namespace {
21822182
return Type();
21832183
}
21842184

2185-
auto *resultExpr = closure->getExplicitResultTypeExpr();
2186-
if (auto declaredTy = resultExpr->getInstanceType()) {
2185+
if (auto declaredTy = closure->getExplicitResultType()) {
21872186
return declaredTy;
21882187
}
21892188

@@ -2218,11 +2217,6 @@ namespace {
22182217
}
22192218
}
22202219

2221-
if (closure->hasExplicitResultType()) {
2222-
CS.setType(closure->getExplicitResultTypeExpr(),
2223-
MetatypeType::get(resultTy));
2224-
}
2225-
22262220
return FunctionType::get(closureParams, resultTy, extInfo);
22272221
}
22282222

lib/Sema/MiscDiagnostics.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,6 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
537537
isa<SubscriptExpr>(ParentExpr)) {
538538
return;
539539
}
540-
541-
if (auto *CE = dyn_cast<ClosureExpr>(ParentExpr)) {
542-
if (CE->hasExplicitResultType() &&
543-
CE->getExplicitResultTypeExpr() == E) {
544-
return;
545-
}
546-
}
547540
}
548541

549542
// Is this a protocol metatype?

0 commit comments

Comments
 (0)