Skip to content

Commit 7626f9d

Browse files
committed
AST: Small cleanups
- Allow AbstractClosureExpr to be created with null body - Split up ParameterList::CloneFlags::Inherited
1 parent 62d1adb commit 7626f9d

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,7 +3748,8 @@ class AutoClosureExpr : public AbstractClosureExpr {
37483748
DeclContext *Parent)
37493749
: AbstractClosureExpr(ExprKind::AutoClosure, ResultTy, /*Implicit=*/true,
37503750
Discriminator, Parent) {
3751-
setBody(Body);
3751+
if (Body != nullptr)
3752+
setBody(Body);
37523753
}
37533754

37543755
SourceRange getSourceRange() const;

include/swift/AST/ParameterList.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ class alignas(ParamDecl *) ParameterList final :
103103
/// Change the DeclContext of any contained parameters to the specified
104104
/// DeclContext.
105105
void setDeclContextOfParamDecls(DeclContext *DC);
106-
107-
106+
108107
/// Flags used to indicate how ParameterList cloning should operate.
109108
enum CloneFlags {
110109
/// The cloned ParamDecls should be marked implicit.
111110
Implicit = 0x01,
112-
/// The cloned pattern is for an inherited constructor; mark default
113-
/// arguments as inherited, and mark unnamed arguments as named.
111+
/// Mark default arguments as inherited.
114112
Inherited = 0x02,
113+
/// Mark unnamed arguments as named.
114+
NamedArguments = 0x04,
115115
};
116116

117117
friend OptionSet<CloneFlags> operator|(CloneFlags flag1, CloneFlags flag2) {

lib/AST/Parameter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ ParameterList *ParameterList::clone(const ASTContext &C,
6767
if (options & Implicit)
6868
decl->setImplicit();
6969

70-
// If the argument isn't named, and we're cloning for an inherited
71-
// constructor, give the parameter a name so that silgen will produce a
72-
// value for it.
73-
if (decl->getName().empty() && (options & Inherited))
70+
// If the argument isn't named, give the parameter a name so that
71+
// silgen will produce a value for it.
72+
if (decl->getName().empty() && (options & NamedArguments))
7473
decl->setName(C.getIdentifier("argument"));
7574

7675
// If we're inheriting a default argument, mark it as such.

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,7 +4338,8 @@ namespace {
43384338
auto closureTy =
43394339
FunctionType::get({ FunctionType::Param(baseTy) }, leafTy);
43404340
auto closure = new (ctx)
4341-
AutoClosureExpr(E, leafTy, discriminator, cs.DC);
4341+
AutoClosureExpr(/*set body later*/nullptr, leafTy,
4342+
discriminator, cs.DC);
43424343
auto param = new (ctx) ParamDecl(
43434344
SourceLoc(),
43444345
/*argument label*/ SourceLoc(), Identifier(),
@@ -4352,7 +4353,8 @@ namespace {
43524353
auto outerClosureTy =
43534354
FunctionType::get({ FunctionType::Param(keyPathTy) }, closureTy);
43544355
auto outerClosure = new (ctx)
4355-
AutoClosureExpr(closure, closureTy, discriminator, cs.DC);
4356+
AutoClosureExpr(/*set body later*/nullptr, closureTy,
4357+
discriminator, cs.DC);
43564358
auto outerParam =
43574359
new (ctx) ParamDecl(SourceLoc(),
43584360
/*argument label*/ SourceLoc(), Identifier(),

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ createDesignatedInitOverride(ClassDecl *classDecl,
642642
// Create the initializer parameter patterns.
643643
OptionSet<ParameterList::CloneFlags> options
644644
= (ParameterList::Implicit |
645-
ParameterList::Inherited);
645+
ParameterList::Inherited |
646+
ParameterList::NamedArguments);
646647
auto *superclassParams = superclassCtor->getParameters();
647648
auto *bodyParams = superclassParams->clone(ctx, options);
648649

0 commit comments

Comments
 (0)