Skip to content

Commit a483b34

Browse files
committed
[AST] Drop const qualifier from {get/set}Type callbacks
1 parent bd09d0c commit a483b34

File tree

5 files changed

+145
-154
lines changed

5 files changed

+145
-154
lines changed

include/swift/AST/Expr.h

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -475,22 +475,24 @@ class alignas(8) Expr {
475475
///
476476
/// This distinguishes static references to types, like Int, from metatype
477477
/// values, "someTy: Any.Type".
478-
bool isTypeReference(llvm::function_ref<Type(const Expr *)> getType =
479-
[](const Expr *E) -> Type { return E->getType(); },
480-
llvm::function_ref<Decl *(const Expr *)> getDecl =
481-
[](const Expr *E) -> Decl * {
482-
return nullptr;
483-
}) const;
478+
bool isTypeReference(
479+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
480+
return E->getType();
481+
},
482+
llvm::function_ref<Decl *(Expr *)> getDecl = [](Expr *E) -> Decl * {
483+
return nullptr;
484+
}) const;
484485

485486
/// Determine whether this expression refers to a statically-derived metatype.
486487
///
487488
/// This implies `isTypeReference`, but also requires that the referenced type
488489
/// is not an archetype or dependent type.
489490
bool isStaticallyDerivedMetatype(
490-
llvm::function_ref<Type(const Expr *)> getType =
491-
[](const Expr *E) -> Type { return E->getType(); },
492-
llvm::function_ref<bool(const Expr *)> isTypeReference =
493-
[](const Expr *E) { return E->isTypeReference(); }) const;
491+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
492+
return E->getType();
493+
},
494+
llvm::function_ref<bool(Expr *)> isTypeReference =
495+
[](Expr *E) { return E->isTypeReference(); }) const;
494496

495497
/// isImplicit - Determines whether this expression was implicitly-generated,
496498
/// rather than explicitly written in the AST.
@@ -538,11 +540,12 @@ class alignas(8) Expr {
538540

539541
SWIFT_DEBUG_DUMP;
540542
void dump(raw_ostream &OS, unsigned Indent = 0) const;
541-
void dump(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
542-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
543-
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
543+
void dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getType,
544+
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
545+
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
546+
getTypeOfKeyPathComponent,
544547
unsigned Indent = 0) const;
545-
548+
546549
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
547550

548551
// Only allow allocation of Exprs using the allocator in ASTContext
@@ -1183,9 +1186,9 @@ class ObjectLiteralExpr final
11831186
///
11841187
/// Note: prefer to use the second entry point, which separates out
11851188
/// arguments/labels/etc.
1186-
static ObjectLiteralExpr *
1187-
create(ASTContext &ctx, SourceLoc poundLoc, LiteralKind kind, Expr *arg,
1188-
bool implicit, llvm::function_ref<Type(const Expr *)> getType);
1189+
static ObjectLiteralExpr *create(ASTContext &ctx, SourceLoc poundLoc,
1190+
LiteralKind kind, Expr *arg, bool implicit,
1191+
llvm::function_ref<Type(Expr *)> getType);
11891192

11901193
/// Create a new object literal expression.
11911194
static ObjectLiteralExpr *create(ASTContext &ctx, SourceLoc poundLoc,
@@ -1778,11 +1781,12 @@ class DynamicSubscriptExpr final
17781781
///
17791782
/// Note: do not create new callers to this entry point; use the entry point
17801783
/// that takes separate index arguments.
1781-
static DynamicSubscriptExpr *
1782-
create(ASTContext &ctx, Expr *base, Expr *index, ConcreteDeclRef decl,
1783-
bool implicit,
1784-
llvm::function_ref<Type(const Expr *)> getType =
1785-
[](const Expr *E) -> Type { return E->getType(); });
1784+
static DynamicSubscriptExpr *create(
1785+
ASTContext &ctx, Expr *base, Expr *index, ConcreteDeclRef decl,
1786+
bool implicit,
1787+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
1788+
return E->getType();
1789+
});
17861790

17871791
/// getIndex - Retrieve the index of the subscript expression, i.e., the
17881792
/// "offset" into the base value.
@@ -2355,12 +2359,13 @@ class SubscriptExpr final : public LookupExpr,
23552359
///
23562360
/// Note: do not create new callers to this entry point; use the entry point
23572361
/// that takes separate index arguments.
2358-
static SubscriptExpr *
2359-
create(ASTContext &ctx, Expr *base, Expr *index,
2360-
ConcreteDeclRef decl = ConcreteDeclRef(), bool implicit = false,
2361-
AccessSemantics semantics = AccessSemantics::Ordinary,
2362-
llvm::function_ref<Type(const Expr *)> getType =
2363-
[](const Expr *E) -> Type { return E->getType(); });
2362+
static SubscriptExpr *create(
2363+
ASTContext &ctx, Expr *base, Expr *index,
2364+
ConcreteDeclRef decl = ConcreteDeclRef(), bool implicit = false,
2365+
AccessSemantics semantics = AccessSemantics::Ordinary,
2366+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
2367+
return E->getType();
2368+
});
23642369

23652370
/// Create a new subscript.
23662371
static SubscriptExpr *create(ASTContext &ctx, Expr *base,
@@ -3599,10 +3604,8 @@ class AbstractClosureExpr : public DeclContext, public Expr {
35993604
enum : unsigned { InvalidDiscriminator = 0xFFFF };
36003605

36013606
/// Retrieve the result type of this closure.
3602-
Type getResultType(llvm::function_ref<Type(const Expr *)> getType =
3603-
[](const Expr *E) -> Type {
3604-
return E->getType();
3605-
}) const;
3607+
Type getResultType(llvm::function_ref<Type(Expr *)> getType =
3608+
[](Expr *E) -> Type { return E->getType(); }) const;
36063609

36073610
/// Return whether this closure is throwing when fully applied.
36083611
bool isBodyThrowing() const;
@@ -4263,12 +4266,13 @@ class CallExpr final : public ApplyExpr,
42634266
/// Create a new call expression.
42644267
///
42654268
/// Note: prefer to use the entry points that separate out the arguments.
4266-
static CallExpr *
4267-
create(ASTContext &ctx, Expr *fn, Expr *arg, ArrayRef<Identifier> argLabels,
4268-
ArrayRef<SourceLoc> argLabelLocs, bool hasTrailingClosure,
4269-
bool implicit, Type type = Type(),
4270-
llvm::function_ref<Type(const Expr *)> getType =
4271-
[](const Expr *E) -> Type { return E->getType(); });
4269+
static CallExpr *create(
4270+
ASTContext &ctx, Expr *fn, Expr *arg, ArrayRef<Identifier> argLabels,
4271+
ArrayRef<SourceLoc> argLabelLocs, bool hasTrailingClosure, bool implicit,
4272+
Type type = Type(),
4273+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
4274+
return E->getType();
4275+
});
42724276

42734277
/// Create a new implicit call expression without any source-location
42744278
/// information.
@@ -4277,11 +4281,12 @@ class CallExpr final : public ApplyExpr,
42774281
/// \param args The call arguments, not including a trailing closure (if any).
42784282
/// \param argLabels The argument labels, whose size must equal args.size(),
42794283
/// or which must be empty.
4280-
static CallExpr *
4281-
createImplicit(ASTContext &ctx, Expr *fn, ArrayRef<Expr *> args,
4282-
ArrayRef<Identifier> argLabels,
4283-
llvm::function_ref<Type(const Expr *)> getType =
4284-
[](const Expr *E) -> Type { return E->getType(); }) {
4284+
static CallExpr *createImplicit(
4285+
ASTContext &ctx, Expr *fn, ArrayRef<Expr *> args,
4286+
ArrayRef<Identifier> argLabels,
4287+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
4288+
return E->getType();
4289+
}) {
42854290
return create(ctx, fn, SourceLoc(), args, argLabels, { }, SourceLoc(),
42864291
/*trailingClosure=*/nullptr, /*implicit=*/true, getType);
42874292
}
@@ -4295,12 +4300,13 @@ class CallExpr final : public ApplyExpr,
42954300
/// \param argLabelLocs The locations of the argument labels, whose size must
42964301
/// equal args.size() or which must be empty.
42974302
/// \param trailingClosure The trailing closure, if any.
4298-
static CallExpr *
4299-
create(ASTContext &ctx, Expr *fn, SourceLoc lParenLoc, ArrayRef<Expr *> args,
4300-
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
4301-
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
4302-
llvm::function_ref<Type(const Expr *)> getType =
4303-
[](const Expr *E) -> Type { return E->getType(); });
4303+
static CallExpr *create(
4304+
ASTContext &ctx, Expr *fn, SourceLoc lParenLoc, ArrayRef<Expr *> args,
4305+
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
4306+
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
4307+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
4308+
return E->getType();
4309+
});
43044310

43054311
SourceLoc getStartLoc() const {
43064312
SourceLoc fnLoc = getFn()->getStartLoc();
@@ -5622,18 +5628,15 @@ inline const SourceLoc *CollectionExpr::getTrailingSourceLocs() const {
56225628
///
56235629
/// \param argLabelLocs The argument label locations, which might be updated by
56245630
/// this function.
5625-
Expr *packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc,
5626-
ArrayRef<Expr *> args,
5627-
ArrayRef<Identifier> &argLabels,
5628-
ArrayRef<SourceLoc> &argLabelLocs,
5629-
SourceLoc rParenLoc,
5630-
Expr *trailingClosure, bool implicit,
5631-
SmallVectorImpl<Identifier> &argLabelsScratch,
5632-
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
5633-
llvm::function_ref<Type(const Expr *)> getType =
5634-
[](const Expr *E) -> Type {
5635-
return E->getType();
5636-
});
5631+
Expr *packSingleArgument(
5632+
ASTContext &ctx, SourceLoc lParenLoc, ArrayRef<Expr *> args,
5633+
ArrayRef<Identifier> &argLabels, ArrayRef<SourceLoc> &argLabelLocs,
5634+
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
5635+
SmallVectorImpl<Identifier> &argLabelsScratch,
5636+
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
5637+
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
5638+
return E->getType();
5639+
});
56375640

56385641
void simple_display(llvm::raw_ostream &out, const ClosureExpr *CE);
56395642
void simple_display(llvm::raw_ostream &out, const DefaultArgumentExpr *expr);

lib/AST/ASTDumper.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,15 +1774,16 @@ namespace {
17741774
class PrintExpr : public ExprVisitor<PrintExpr> {
17751775
public:
17761776
raw_ostream &OS;
1777-
llvm::function_ref<Type(const Expr *)> GetTypeOfExpr;
1778-
llvm::function_ref<Type(const TypeLoc &)> GetTypeOfTypeLoc;
1779-
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> GetTypeOfKeyPathComponent;
1777+
llvm::function_ref<Type(Expr *)> GetTypeOfExpr;
1778+
llvm::function_ref<Type(TypeLoc &)> GetTypeOfTypeLoc;
1779+
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
1780+
GetTypeOfKeyPathComponent;
17801781
unsigned Indent;
17811782

1782-
PrintExpr(raw_ostream &os,
1783-
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
1784-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
1785-
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
1783+
PrintExpr(raw_ostream &os, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
1784+
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
1785+
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
1786+
getTypeOfKeyPathComponent,
17861787
unsigned indent)
17871788
: OS(os), GetTypeOfExpr(getTypeOfExpr),
17881789
GetTypeOfTypeLoc(getTypeOfTypeLoc),
@@ -2864,21 +2865,19 @@ void Expr::dump() const {
28642865
llvm::errs() << "\n";
28652866
}
28662867

2867-
void Expr::dump(raw_ostream &OS,
2868-
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2869-
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
2870-
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
2871-
unsigned Indent) const {
2868+
void Expr::dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
2869+
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
2870+
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
2871+
getTypeOfKeyPathComponent,
2872+
unsigned Indent) const {
28722873
PrintExpr(OS, getTypeOfExpr, getTypeOfTypeLoc, getTypeOfKeyPathComponent, Indent)
28732874
.visit(const_cast<Expr *>(this));
28742875
}
28752876

28762877
void Expr::dump(raw_ostream &OS, unsigned Indent) const {
2877-
auto getTypeOfExpr = [](const Expr *E) -> Type { return E->getType(); };
2878-
auto getTypeOfTypeLoc = [](const TypeLoc &TL) -> Type {
2879-
return TL.getType();
2880-
};
2881-
auto getTypeOfKeyPathComponent = [](const KeyPathExpr *E, unsigned index) -> Type {
2878+
auto getTypeOfExpr = [](Expr *E) -> Type { return E->getType(); };
2879+
auto getTypeOfTypeLoc = [](TypeLoc &TL) -> Type { return TL.getType(); };
2880+
auto getTypeOfKeyPathComponent = [](KeyPathExpr *E, unsigned index) -> Type {
28822881
return E->getComponents()[index].getComponentType();
28832882
};
28842883
dump(OS, getTypeOfExpr, getTypeOfTypeLoc, getTypeOfKeyPathComponent, Indent);

0 commit comments

Comments
 (0)