[AST] Drop const qualifier from {get/set}Type callbacks

This commit is contained in:
Pavel Yaskevich
2020-04-28 11:49:10 -07:00
parent bd09d0c776
commit a483b344ee
5 changed files with 145 additions and 154 deletions

View File

@@ -475,22 +475,24 @@ public:
///
/// This distinguishes static references to types, like Int, from metatype
/// values, "someTy: Any.Type".
bool isTypeReference(llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); },
llvm::function_ref<Decl *(const Expr *)> getDecl =
[](const Expr *E) -> Decl * {
return nullptr;
}) const;
bool isTypeReference(
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
},
llvm::function_ref<Decl *(Expr *)> getDecl = [](Expr *E) -> Decl * {
return nullptr;
}) const;
/// Determine whether this expression refers to a statically-derived metatype.
///
/// This implies `isTypeReference`, but also requires that the referenced type
/// is not an archetype or dependent type.
bool isStaticallyDerivedMetatype(
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); },
llvm::function_ref<bool(const Expr *)> isTypeReference =
[](const Expr *E) { return E->isTypeReference(); }) const;
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
},
llvm::function_ref<bool(Expr *)> isTypeReference =
[](Expr *E) { return E->isTypeReference(); }) const;
/// isImplicit - Determines whether this expression was implicitly-generated,
/// rather than explicitly written in the AST.
@@ -538,11 +540,12 @@ public:
SWIFT_DEBUG_DUMP;
void dump(raw_ostream &OS, unsigned Indent = 0) const;
void dump(raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getType,
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
void dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getType,
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
getTypeOfKeyPathComponent,
unsigned Indent = 0) const;
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
// Only allow allocation of Exprs using the allocator in ASTContext
@@ -1183,9 +1186,9 @@ public:
///
/// Note: prefer to use the second entry point, which separates out
/// arguments/labels/etc.
static ObjectLiteralExpr *
create(ASTContext &ctx, SourceLoc poundLoc, LiteralKind kind, Expr *arg,
bool implicit, llvm::function_ref<Type(const Expr *)> getType);
static ObjectLiteralExpr *create(ASTContext &ctx, SourceLoc poundLoc,
LiteralKind kind, Expr *arg, bool implicit,
llvm::function_ref<Type(Expr *)> getType);
/// Create a new object literal expression.
static ObjectLiteralExpr *create(ASTContext &ctx, SourceLoc poundLoc,
@@ -1778,11 +1781,12 @@ public:
///
/// Note: do not create new callers to this entry point; use the entry point
/// that takes separate index arguments.
static DynamicSubscriptExpr *
create(ASTContext &ctx, Expr *base, Expr *index, ConcreteDeclRef decl,
bool implicit,
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); });
static DynamicSubscriptExpr *create(
ASTContext &ctx, Expr *base, Expr *index, ConcreteDeclRef decl,
bool implicit,
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
});
/// getIndex - Retrieve the index of the subscript expression, i.e., the
/// "offset" into the base value.
@@ -2355,12 +2359,13 @@ public:
///
/// Note: do not create new callers to this entry point; use the entry point
/// that takes separate index arguments.
static SubscriptExpr *
create(ASTContext &ctx, Expr *base, Expr *index,
ConcreteDeclRef decl = ConcreteDeclRef(), bool implicit = false,
AccessSemantics semantics = AccessSemantics::Ordinary,
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); });
static SubscriptExpr *create(
ASTContext &ctx, Expr *base, Expr *index,
ConcreteDeclRef decl = ConcreteDeclRef(), bool implicit = false,
AccessSemantics semantics = AccessSemantics::Ordinary,
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
});
/// Create a new subscript.
static SubscriptExpr *create(ASTContext &ctx, Expr *base,
@@ -3599,10 +3604,8 @@ public:
enum : unsigned { InvalidDiscriminator = 0xFFFF };
/// Retrieve the result type of this closure.
Type getResultType(llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type {
return E->getType();
}) const;
Type getResultType(llvm::function_ref<Type(Expr *)> getType =
[](Expr *E) -> Type { return E->getType(); }) const;
/// Return whether this closure is throwing when fully applied.
bool isBodyThrowing() const;
@@ -4263,12 +4266,13 @@ public:
/// Create a new call expression.
///
/// Note: prefer to use the entry points that separate out the arguments.
static CallExpr *
create(ASTContext &ctx, Expr *fn, Expr *arg, ArrayRef<Identifier> argLabels,
ArrayRef<SourceLoc> argLabelLocs, bool hasTrailingClosure,
bool implicit, Type type = Type(),
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); });
static CallExpr *create(
ASTContext &ctx, Expr *fn, Expr *arg, ArrayRef<Identifier> argLabels,
ArrayRef<SourceLoc> argLabelLocs, bool hasTrailingClosure, bool implicit,
Type type = Type(),
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
});
/// Create a new implicit call expression without any source-location
/// information.
@@ -4277,11 +4281,12 @@ public:
/// \param args The call arguments, not including a trailing closure (if any).
/// \param argLabels The argument labels, whose size must equal args.size(),
/// or which must be empty.
static CallExpr *
createImplicit(ASTContext &ctx, Expr *fn, ArrayRef<Expr *> args,
ArrayRef<Identifier> argLabels,
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); }) {
static CallExpr *createImplicit(
ASTContext &ctx, Expr *fn, ArrayRef<Expr *> args,
ArrayRef<Identifier> argLabels,
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
}) {
return create(ctx, fn, SourceLoc(), args, argLabels, { }, SourceLoc(),
/*trailingClosure=*/nullptr, /*implicit=*/true, getType);
}
@@ -4295,12 +4300,13 @@ public:
/// \param argLabelLocs The locations of the argument labels, whose size must
/// equal args.size() or which must be empty.
/// \param trailingClosure The trailing closure, if any.
static CallExpr *
create(ASTContext &ctx, Expr *fn, SourceLoc lParenLoc, ArrayRef<Expr *> args,
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type { return E->getType(); });
static CallExpr *create(
ASTContext &ctx, Expr *fn, SourceLoc lParenLoc, ArrayRef<Expr *> args,
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
});
SourceLoc getStartLoc() const {
SourceLoc fnLoc = getFn()->getStartLoc();
@@ -5622,18 +5628,15 @@ inline const SourceLoc *CollectionExpr::getTrailingSourceLocs() const {
///
/// \param argLabelLocs The argument label locations, which might be updated by
/// this function.
Expr *packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc,
ArrayRef<Expr *> args,
ArrayRef<Identifier> &argLabels,
ArrayRef<SourceLoc> &argLabelLocs,
SourceLoc rParenLoc,
Expr *trailingClosure, bool implicit,
SmallVectorImpl<Identifier> &argLabelsScratch,
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
llvm::function_ref<Type(const Expr *)> getType =
[](const Expr *E) -> Type {
return E->getType();
});
Expr *packSingleArgument(
ASTContext &ctx, SourceLoc lParenLoc, ArrayRef<Expr *> args,
ArrayRef<Identifier> &argLabels, ArrayRef<SourceLoc> &argLabelLocs,
SourceLoc rParenLoc, Expr *trailingClosure, bool implicit,
SmallVectorImpl<Identifier> &argLabelsScratch,
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
});
void simple_display(llvm::raw_ostream &out, const ClosureExpr *CE);
void simple_display(llvm::raw_ostream &out, const DefaultArgumentExpr *expr);

View File

@@ -1774,15 +1774,16 @@ namespace {
class PrintExpr : public ExprVisitor<PrintExpr> {
public:
raw_ostream &OS;
llvm::function_ref<Type(const Expr *)> GetTypeOfExpr;
llvm::function_ref<Type(const TypeLoc &)> GetTypeOfTypeLoc;
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> GetTypeOfKeyPathComponent;
llvm::function_ref<Type(Expr *)> GetTypeOfExpr;
llvm::function_ref<Type(TypeLoc &)> GetTypeOfTypeLoc;
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
GetTypeOfKeyPathComponent;
unsigned Indent;
PrintExpr(raw_ostream &os,
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
PrintExpr(raw_ostream &os, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
getTypeOfKeyPathComponent,
unsigned indent)
: OS(os), GetTypeOfExpr(getTypeOfExpr),
GetTypeOfTypeLoc(getTypeOfTypeLoc),
@@ -2864,21 +2865,19 @@ void Expr::dump() const {
llvm::errs() << "\n";
}
void Expr::dump(raw_ostream &OS,
llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(const KeyPathExpr *E, unsigned index)> getTypeOfKeyPathComponent,
unsigned Indent) const {
void Expr::dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
getTypeOfKeyPathComponent,
unsigned Indent) const {
PrintExpr(OS, getTypeOfExpr, getTypeOfTypeLoc, getTypeOfKeyPathComponent, Indent)
.visit(const_cast<Expr *>(this));
}
void Expr::dump(raw_ostream &OS, unsigned Indent) const {
auto getTypeOfExpr = [](const Expr *E) -> Type { return E->getType(); };
auto getTypeOfTypeLoc = [](const TypeLoc &TL) -> Type {
return TL.getType();
};
auto getTypeOfKeyPathComponent = [](const KeyPathExpr *E, unsigned index) -> Type {
auto getTypeOfExpr = [](Expr *E) -> Type { return E->getType(); };
auto getTypeOfTypeLoc = [](TypeLoc &TL) -> Type { return TL.getType(); };
auto getTypeOfKeyPathComponent = [](KeyPathExpr *E, unsigned index) -> Type {
return E->getComponents()[index].getComponentType();
};
dump(OS, getTypeOfExpr, getTypeOfTypeLoc, getTypeOfKeyPathComponent, Indent);

View File

@@ -458,14 +458,14 @@ void Expr::forEachChildExpr(llvm::function_ref<Expr *(Expr *)> callback) {
this->walk(ChildWalker(callback));
}
bool Expr::isTypeReference(
llvm::function_ref<Type(const Expr *)> getType,
llvm::function_ref<Decl *(const Expr *)> getDecl) const {
bool Expr::isTypeReference(llvm::function_ref<Type(Expr *)> getType,
llvm::function_ref<Decl *(Expr *)> getDecl) const {
Expr *expr = const_cast<Expr *>(this);
// If the result isn't a metatype, there's nothing else to do.
if (!getType(this)->is<AnyMetatypeType>())
if (!getType(expr)->is<AnyMetatypeType>())
return false;
const Expr *expr = this;
do {
// Skip syntax.
expr = expr->getSemanticsProvidingExpr();
@@ -504,15 +504,15 @@ bool Expr::isTypeReference(
}
bool Expr::isStaticallyDerivedMetatype(
llvm::function_ref<Type(const Expr *)> getType,
llvm::function_ref<bool(const Expr *)> isTypeReference) const {
llvm::function_ref<Type(Expr *)> getType,
llvm::function_ref<bool(Expr *)> isTypeReference) const {
// The expression must first be a type reference.
if (!isTypeReference(this))
if (!isTypeReference(const_cast<Expr *>(this)))
return false;
auto type = getType(this)
->castTo<AnyMetatypeType>()
->getInstanceType();
auto type = getType(const_cast<Expr *>(this))
->castTo<AnyMetatypeType>()
->getInstanceType();
// Archetypes are never statically derived.
if (type->is<ArchetypeType>())
@@ -883,7 +883,7 @@ static ArrayRef<Identifier> getArgumentLabelsFromArgument(
Expr *arg, SmallVectorImpl<Identifier> &scratch,
SmallVectorImpl<SourceLoc> *sourceLocs = nullptr,
bool *hasTrailingClosure = nullptr,
llvm::function_ref<Type(const Expr *)> getType = [](const Expr *E) -> Type {
llvm::function_ref<Type(Expr *)> getType = [](Expr *E) -> Type {
return E->getType();
}) {
if (sourceLocs) sourceLocs->clear();
@@ -934,13 +934,13 @@ static ArrayRef<Identifier> getArgumentLabelsFromArgument(
// FIXME: Shouldn't get here.
scratch.clear();
scratch.push_back(Identifier());
return scratch;
return scratch;
}
/// Compute the type of an argument to a call (or call-like) AST
static void
computeSingleArgumentType(ASTContext &ctx, Expr *arg, bool implicit,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(Expr *)> getType) {
// Propagate 'implicit' to the argument.
if (implicit) {
arg->setImplicit(true);
@@ -970,16 +970,15 @@ computeSingleArgumentType(ASTContext &ctx, Expr *arg, bool implicit,
arg->setType(TupleType::get(typeElements, ctx));
}
Expr *
swift::packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc,
ArrayRef<Expr *> args,
ArrayRef<Identifier> &argLabels,
ArrayRef<SourceLoc> &argLabelLocs,
SourceLoc rParenLoc,
Expr *trailingClosure, bool implicit,
SmallVectorImpl<Identifier> &argLabelsScratch,
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
llvm::function_ref<Type(const Expr *)> getType) {
Expr *swift::packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc,
ArrayRef<Expr *> args,
ArrayRef<Identifier> &argLabels,
ArrayRef<SourceLoc> &argLabelLocs,
SourceLoc rParenLoc, Expr *trailingClosure,
bool implicit,
SmallVectorImpl<Identifier> &argLabelsScratch,
SmallVectorImpl<SourceLoc> &argLabelLocsScratch,
llvm::function_ref<Type(Expr *)> getType) {
// Clear out our scratch space.
argLabelsScratch.clear();
argLabelLocsScratch.clear();
@@ -1081,7 +1080,7 @@ ObjectLiteralExpr::ObjectLiteralExpr(SourceLoc PoundLoc, LiteralKind LitKind,
ObjectLiteralExpr *
ObjectLiteralExpr::create(ASTContext &ctx, SourceLoc poundLoc, LiteralKind kind,
Expr *arg, bool implicit,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(Expr *)> getType) {
// Inspect the argument to dig out the argument labels, their location, and
// whether there is a trailing closure.
SmallVector<Identifier, 4> argLabelsScratch;
@@ -1459,11 +1458,10 @@ SubscriptExpr::SubscriptExpr(Expr *base, Expr *index,
initializeCallArguments(argLabels, argLabelLocs, hasTrailingClosure);
}
SubscriptExpr *
SubscriptExpr::create(ASTContext &ctx, Expr *base, Expr *index,
ConcreteDeclRef decl, bool implicit,
AccessSemantics semantics,
llvm::function_ref<Type(const Expr *)> getType) {
SubscriptExpr *SubscriptExpr::create(ASTContext &ctx, Expr *base, Expr *index,
ConcreteDeclRef decl, bool implicit,
AccessSemantics semantics,
llvm::function_ref<Type(Expr *)> getType) {
// Inspect the argument to dig out the argument labels, their location, and
// whether there is a trailing closure.
SmallVector<Identifier, 4> argLabelsScratch;
@@ -1528,7 +1526,7 @@ DynamicSubscriptExpr::DynamicSubscriptExpr(Expr *base, Expr *index,
DynamicSubscriptExpr *
DynamicSubscriptExpr::create(ASTContext &ctx, Expr *base, Expr *index,
ConcreteDeclRef decl, bool implicit,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(Expr *)> getType) {
// Inspect the argument to dig out the argument labels, their location, and
// whether there is a trailing closure.
SmallVector<Identifier, 4> argLabelsScratch;
@@ -1652,7 +1650,7 @@ CallExpr *CallExpr::create(ASTContext &ctx, Expr *fn, Expr *arg,
ArrayRef<Identifier> argLabels,
ArrayRef<SourceLoc> argLabelLocs,
bool hasTrailingClosure, bool implicit, Type type,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(Expr *)> getType) {
SmallVector<Identifier, 4> argLabelsScratch;
SmallVector<SourceLoc, 4> argLabelLocsScratch;
if (argLabels.empty()) {
@@ -1678,7 +1676,7 @@ CallExpr *CallExpr::create(ASTContext &ctx, Expr *fn, SourceLoc lParenLoc,
ArrayRef<SourceLoc> argLabelLocs,
SourceLoc rParenLoc, Expr *trailingClosure,
bool implicit,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(Expr *)> getType) {
SmallVector<Identifier, 4> argLabelsScratch;
SmallVector<SourceLoc, 4> argLabelLocsScratch;
Expr *arg = packSingleArgument(ctx, lParenLoc, args, argLabels, argLabelLocs,
@@ -1787,11 +1785,12 @@ void AbstractClosureExpr::setParameterList(ParameterList *P) {
}
Type AbstractClosureExpr::getResultType(
llvm::function_ref<Type(const Expr *)> getType) const {
if (getType(this)->hasError())
return getType(this);
llvm::function_ref<Type(Expr *)> getType) const {
auto *E = const_cast<AbstractClosureExpr *>(this);
if (getType(E)->hasError())
return getType(E);
return getType(this)->castTo<FunctionType>()->getResult();
return getType(E)->castTo<FunctionType>()->getResult();
}
bool AbstractClosureExpr::isBodyThrowing() const {

View File

@@ -114,7 +114,7 @@ ConstraintLocator *Solution::getCalleeLocator(ConstraintLocator *locator,
auto &cs = getConstraintSystem();
return cs.getCalleeLocator(
locator, lookThroughApply,
[&](const Expr *expr) -> Type { return getType(expr); },
[&](Expr *expr) -> Type { return getType(expr); },
[&](Type type) -> Type { return simplifyType(type)->getRValueType(); },
[&](ConstraintLocator *locator) -> Optional<SelectedOverload> {
return getOverloadChoiceIfAvailable(locator);
@@ -122,7 +122,7 @@ ConstraintLocator *Solution::getCalleeLocator(ConstraintLocator *locator,
}
ConstraintLocator *
Solution::getConstraintLocator(TypedNode anchor,
Solution::getConstraintLocator(ASTNode anchor,
ArrayRef<LocatorPathElt> path) const {
auto &cs = getConstraintSystem();
return cs.getConstraintLocator(anchor, path);
@@ -153,10 +153,10 @@ getImplicitMemberReferenceAccessSemantics(Expr *base, VarDecl *member,
/// This extends functionality of `Expr::isTypeReference` with
/// support for `UnresolvedDotExpr` and `UnresolvedMemberExpr`.
/// This method could be used on not yet fully type-checked AST.
bool ConstraintSystem::isTypeReference(const Expr *E) {
bool ConstraintSystem::isTypeReference(Expr *E) {
return E->isTypeReference(
[&](const Expr *E) -> Type { return simplifyType(getType(E)); },
[&](const Expr *E) -> Decl * {
[&](Expr *E) -> Type { return simplifyType(getType(E)); },
[&](Expr *E) -> Decl * {
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
return findResolvedMemberRef(
getConstraintLocator(UDE, ConstraintLocator::Member));
@@ -175,13 +175,13 @@ bool ConstraintSystem::isTypeReference(const Expr *E) {
});
}
bool ConstraintSystem::isStaticallyDerivedMetatype(const Expr *E) {
bool ConstraintSystem::isStaticallyDerivedMetatype(Expr *E) {
return E->isStaticallyDerivedMetatype(
[&](const Expr *E) -> Type { return simplifyType(getType(E)); },
[&](const Expr *E) -> bool { return isTypeReference(E); });
[&](Expr *E) -> Type { return simplifyType(getType(E)); },
[&](Expr *E) -> bool { return isTypeReference(E); });
}
Type ConstraintSystem::getInstanceType(const TypeExpr *E) {
Type ConstraintSystem::getInstanceType(TypeExpr *E) {
if (!hasType(E))
return Type();
@@ -192,7 +192,7 @@ Type ConstraintSystem::getInstanceType(const TypeExpr *E) {
}
Type ConstraintSystem::getResultType(const AbstractClosureExpr *E) {
return E->getResultType([&](const Expr *E) -> Type { return getType(E); });
return E->getResultType([&](Expr *E) -> Type { return getType(E); });
}
static bool buildObjCKeyPathString(KeyPathExpr *E,
@@ -882,9 +882,9 @@ namespace {
// the base is implicit or not. This helps maintain some invariants around
// source ranges.
if (selfParamRef->isImplicit()) {
selfCall =
CallExpr::createImplicit(context, ref, selfOpenedRef, { },
[&](const Expr *E) { return cs.getType(E); });
selfCall =
CallExpr::createImplicit(context, ref, selfOpenedRef, {},
[&](Expr *E) { return cs.getType(E); });
selfCall->setType(refTy->getResult());
cs.cacheType(selfCall);
@@ -1778,9 +1778,7 @@ namespace {
if (!index)
return nullptr;
auto getType = [&](const Expr *E) -> Type {
return cs.getType(E);
};
auto getType = [&](Expr *E) -> Type { return cs.getType(E); };
// Handle dynamic lookup.
if (choice.getKind() == OverloadChoiceKind::DeclViaDynamic ||
@@ -1968,7 +1966,7 @@ namespace {
anchor = SubscriptExpr::create(
ctx, dotExpr, origComponent.getIndexExpr(), ConcreteDeclRef(),
/*implicit=*/true, AccessSemantics::Ordinary,
[&](const Expr *expr) { return simplifyType(cs.getType(expr)); });
[&](Expr *expr) { return simplifyType(cs.getType(expr)); });
} else {
return nullptr;
}
@@ -2742,9 +2740,7 @@ namespace {
if (!result)
return nullptr;
auto getType = [&](const Expr *E) -> Type {
return cs.getType(E);
};
auto getType = [&](Expr *E) -> Type { return cs.getType(E); };
// If there was an argument, apply it.
if (auto arg = expr->getArgument()) {
@@ -3242,7 +3238,7 @@ namespace {
// solver was allowed to return free or unresolved types, which can
// happen while running diagnostics on one of the expressions.
if (!overload) {
const auto *base = expr->getBase();
auto *base = expr->getBase();
auto &de = cs.getASTContext().Diags;
auto baseType = cs.getType(base);
@@ -7237,9 +7233,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
OpaqueValueExpr(apply->getFn()->getSourceRange(), Type());
cs.setType(escapable, escapableParams[0].getOldType());
auto getType = [&](const Expr *E) -> Type {
return cs.getType(E);
};
auto getType = [&](Expr *E) -> Type { return cs.getType(E); };
auto callSubExpr = CallExpr::createImplicit(ctx, body,
{escapable}, {}, getType);
@@ -7294,10 +7288,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
auto opaqueValue =
new (ctx) OpaqueValueExpr(apply->getSourceRange(), openedTy);
cs.setType(opaqueValue, openedTy);
auto getType = [&](const Expr *E) -> Type {
return cs.getType(E);
};
auto getType = [&](Expr *E) -> Type { return cs.getType(E); };
auto callSubExpr = CallExpr::createImplicit(ctx, body, {opaqueValue}, {}, getType);
cs.cacheSubExprTypes(callSubExpr);
@@ -7809,7 +7801,7 @@ namespace {
explicit CompareExprSourceLocs(SourceManager &sourceMgr)
: sourceMgr(sourceMgr) { }
bool operator()(TypedNode lhs, TypedNode rhs) const {
bool operator()(ASTNode lhs, ASTNode rhs) const {
if (static_cast<bool>(lhs) != static_cast<bool>(rhs)) {
return static_cast<bool>(lhs);
}
@@ -7829,15 +7821,14 @@ namespace {
/// able to emit an error message, or false if none of the fixits worked out.
bool ConstraintSystem::applySolutionFixes(const Solution &solution) {
/// Collect the fixes on a per-expression basis.
llvm::SmallDenseMap<TypedNode, SmallVector<ConstraintFix *, 4>>
fixesPerAnchor;
llvm::SmallDenseMap<ASTNode, SmallVector<ConstraintFix *, 4>> fixesPerAnchor;
for (auto *fix : solution.Fixes) {
fixesPerAnchor[fix->getAnchor()].push_back(fix);
}
// Collect all of the expressions that have fixes, and sort them by
// source ordering.
SmallVector<TypedNode, 4> orderedAnchors;
SmallVector<ASTNode, 4> orderedAnchors;
for (const auto &fix : fixesPerAnchor) {
orderedAnchors.push_back(fix.getFirst());
}
@@ -8416,7 +8407,7 @@ ProtocolConformanceRef Solution::resolveConformance(
return ProtocolConformanceRef::forInvalid();
}
Type Solution::getType(TypedNode node) const {
Type Solution::getType(ASTNode node) const {
auto result = nodeTypes.find(node);
if (result != nodeTypes.end())
return result->second;

View File

@@ -188,7 +188,7 @@ Expr *ConstraintLocatorBuilder::trySimplifyToExpr() const {
// Locators are not guaranteed to have an anchor
// if constraint system is used to verify generic
// requirements.
if (!anchor.is<const Expr *>())
if (!anchor.is<Expr *>())
return nullptr;
ArrayRef<LocatorPathElt> path = pathBuffer;
@@ -3021,18 +3021,17 @@ void ConstraintSystem::dump(Expr *E) const {
}
void ConstraintSystem::print(raw_ostream &out, Expr *E) const {
auto getTypeOfExpr = [&](const Expr *E) -> Type {
auto getTypeOfExpr = [&](Expr *E) -> Type {
if (hasType(E))
return getType(E);
return Type();
};
auto getTypeOfTypeLoc = [&](const TypeLoc &TL) -> Type {
auto getTypeOfTypeLoc = [&](TypeLoc &TL) -> Type {
if (hasType(TL))
return getType(TL);
return Type();
};
auto getTypeOfKeyPathComponent =
[&](const KeyPathExpr *KP, unsigned I) -> Type {
auto getTypeOfKeyPathComponent = [&](KeyPathExpr *KP, unsigned I) -> Type {
if (hasType(KP, I))
return getType(KP, I);
return Type();