Skip to content

Commit c70f280

Browse files
committed
[AST] Add CallExpr::createImplicitEmpty
Add a convenience constructor for an implicit nullary call. This will become more useful when the argument parameter starts taking an ArgumentList.
1 parent 1286bbe commit c70f280

File tree

9 files changed

+19
-15
lines changed

9 files changed

+19
-15
lines changed

include/swift/AST/Expr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,6 +4721,14 @@ class CallExpr final : public ApplyExpr,
47214721
/*trailingClosures=*/{}, /*implicit=*/true, getType);
47224722
}
47234723

4724+
/// Create a new implicit call expression with no arguments and no
4725+
/// source-location information.
4726+
///
4727+
/// \param fn The nullary function being called.
4728+
static CallExpr *createImplicitEmpty(ASTContext &ctx, Expr *fn) {
4729+
return createImplicit(ctx, fn, {}, {});
4730+
}
4731+
47244732
/// Create a new call expression.
47254733
///
47264734
/// \param fn The function being called

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ synthesizeStructDefaultConstructorBody(AbstractFunctionDecl *afd,
12781278
FunctionType::ExtInfo info;
12791279
zeroInitializerRef->setType(FunctionType::get({}, selfType, info));
12801280

1281-
auto call = CallExpr::createImplicit(ctx, zeroInitializerRef, {}, {});
1281+
auto call = CallExpr::createImplicitEmpty(ctx, zeroInitializerRef);
12821282
call->setType(selfType);
12831283
call->setThrows(false);
12841284

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ ParserResult<Stmt> Parser::parseStmtDefer() {
968968
auto DRE = new (Context) DeclRefExpr(tempDecl, DeclNameLoc(loc),
969969
/*Implicit*/true,
970970
AccessSemantics::DirectToStorage);
971-
auto call = CallExpr::createImplicit(Context, DRE, { }, { });
971+
auto call = CallExpr::createImplicitEmpty(Context, DRE);
972972

973973
auto DS = new (Context) DeferStmt(DeferLoc, tempDecl, call);
974974
return makeParserResult(Status, DS);

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6057,7 +6057,7 @@ Expr *ExprRewriter::coerceCallArguments(
60576057
cs.buildAutoClosureExpr(arg, closureType, dc,
60586058
isDefaultWrappedValue),
60596059
/*isAutoClosure=*/true);
6060-
arg = CallExpr::createImplicit(ctx, placeholder, {}, {});
6060+
arg = CallExpr::createImplicitEmpty(ctx, placeholder);
60616061
arg->setType(closureType->getResult());
60626062
cs.cacheType(arg);
60636063
}
@@ -8338,8 +8338,7 @@ static Expr *wrapAsyncLetInitializer(
83388338

83398339
// Call the autoclosure so that the AST types line up. SILGen will ignore the
83408340
// actual calls and translate them into a different mechanism.
8341-
auto autoclosureCall = CallExpr::createImplicit(
8342-
ctx, autoclosureExpr, { }, { });
8341+
auto autoclosureCall = CallExpr::createImplicitEmpty(ctx, autoclosureExpr);
83438342
autoclosureCall->setType(initializerType);
83448343
autoclosureCall->setThrows(throws);
83458344

lib/Sema/DebuggerTestingTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class DebuggerTestingTransform : public ASTWalker {
239239
Closure->setBody(ClosureBody, /*isSingleExpression=*/false);
240240

241241
// Call the closure.
242-
auto *ClosureCall = CallExpr::createImplicit(Ctx, Closure, {}, {});
242+
auto *ClosureCall = CallExpr::createImplicitEmpty(Ctx, Closure);
243243
ClosureCall->setThrows(false);
244244

245245
// TODO: typeCheckExpression() seems to assign types to everything here,

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,7 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
14311431

14321432
// container.superDecoder()
14331433
auto *superDecoderCall =
1434-
CallExpr::createImplicit(C, superDecoderRef, ArrayRef<Expr *>(),
1435-
ArrayRef<Identifier>());
1434+
CallExpr::createImplicitEmpty(C, superDecoderRef);
14361435

14371436
// super
14381437
auto *superRef = new (C) SuperRefExpr(initDecl->getImplicitSelfDecl(),
@@ -1477,9 +1476,7 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
14771476
auto *superInitRef = UnresolvedDotExpr::createImplicit(C, superRef,
14781477
initName);
14791478
// super.init() call
1480-
Expr *callExpr = CallExpr::createImplicit(C, superInitRef,
1481-
ArrayRef<Expr *>(),
1482-
ArrayRef<Identifier>());
1479+
Expr *callExpr = CallExpr::createImplicitEmpty(C, superInitRef);
14831480

14841481
// If super.init throws, try super.init()
14851482
if (superInitDecl->hasThrows())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ synthesizeMainBody(AbstractFunctionDecl *fn, void *arg) {
18661866
/*Implicit*/ true);
18671867
memberRefExpr->setImplicit(true);
18681868

1869-
auto *callExpr = CallExpr::createImplicit(context, memberRefExpr, {}, {});
1869+
auto *callExpr = CallExpr::createImplicitEmpty(context, memberRefExpr);
18701870
callExpr->setImplicit(true);
18711871
callExpr->setType(context.TheEmptyTupleType);
18721872

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static Expr* constructCallToSuperInit(ConstructorDecl *ctor,
15951595
SourceLoc(), /*Implicit=*/true);
15961596
Expr *r = UnresolvedDotExpr::createImplicit(
15971597
Context, superRef, DeclBaseName::createConstructor());
1598-
r = CallExpr::createImplicit(Context, r, { }, { });
1598+
r = CallExpr::createImplicitEmpty(Context, r);
15991599

16001600
if (ctor->hasThrows())
16011601
r = new (Context) TryExpr(SourceLoc(), r, Type(), /*implicit=*/true);

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ synthesizeObservedSetterBody(AccessorDecl *Set, TargetImpl target,
15741574
if (arg) {
15751575
Call = CallExpr::createImplicit(Ctx, Callee, {ValueDRE}, {Identifier()});
15761576
} else {
1577-
Call = CallExpr::createImplicit(Ctx, Callee, {}, {});
1577+
Call = CallExpr::createImplicitEmpty(Ctx, Callee);
15781578
}
15791579

15801580
if (auto funcType = type->getAs<FunctionType>())
@@ -1751,7 +1751,7 @@ synthesizeModifyCoroutineBodyWithSimpleDidSet(AccessorDecl *accessor,
17511751
Callee = DSCE;
17521752
}
17531753

1754-
auto *Call = CallExpr::createImplicit(ctx, Callee, {}, {});
1754+
auto *Call = CallExpr::createImplicitEmpty(ctx, Callee);
17551755
if (auto funcType = type->getAs<FunctionType>())
17561756
type = funcType->getResult();
17571757
Call->setType(type);

0 commit comments

Comments
 (0)