Skip to content

Commit 955f0f3

Browse files
committed
[ConstraintSystem] Switch ConstraintLocator to use ASTNode as an anchor type
1 parent 87b8f79 commit 955f0f3

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
using namespace swift;
2727
using namespace constraints;
2828

29-
void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, TypedNode anchor,
29+
void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, ASTNode anchor,
3030
ArrayRef<PathElement> path) {
3131
id.AddPointer(anchor.getOpaqueValue());
3232
id.AddInteger(path.size());
@@ -247,6 +247,10 @@ bool ConstraintLocator::isForOptionalTry() const {
247247
return directlyAt<OptionalTryExpr>();
248248
}
249249

250+
template <typename E> bool ConstraintLocator::directlyAt() const {
251+
return isExpr<E>(getAnchor()) && getPath().empty();
252+
}
253+
250254
GenericTypeParamType *ConstraintLocator::getGenericParameter() const {
251255
// Check whether we have a path that terminates at a generic parameter.
252256
return isForGenericParameter() ?
@@ -270,7 +274,7 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
270274

271275
out << "locator@" << (void*) this << " [";
272276

273-
if (auto *expr = anchor.dyn_cast<const Expr *>()) {
277+
if (auto *expr = anchor.dyn_cast<Expr *>()) {
274278
out << Expr::getKindName(expr->getKind());
275279
if (sm) {
276280
out << '@';

lib/Sema/ConstraintLocator.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "swift/Basic/Debug.h"
2222
#include "swift/Basic/LLVM.h"
23+
#include "swift/AST/ASTNode.h"
2324
#include "swift/AST/Type.h"
2425
#include "swift/AST/Types.h"
2526
#include "llvm/ADT/ArrayRef.h"
@@ -43,10 +44,6 @@ namespace constraints {
4344

4445
class ConstraintSystem;
4546

46-
/// An AST node that can gain type information while solving.
47-
using TypedNode = llvm::PointerUnion<const Expr *, const TypeLoc *,
48-
const VarDecl *, const Pattern *>;
49-
5047
/// Locates a given constraint within the expression being
5148
/// type-checked, which may refer down into subexpressions and parts of
5249
/// the types of those subexpressions.
@@ -310,7 +307,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
310307
}
311308

312309
/// Retrieve the expression that anchors this locator.
313-
TypedNode getAnchor() const { return anchor; }
310+
ASTNode getAnchor() const { return anchor; }
314311

315312
/// Retrieve the path that extends from the anchor to a specific
316313
/// subcomponent.
@@ -384,12 +381,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
384381
bool isForOptionalTry() const;
385382

386383
/// Determine whether this locator points directly to a given expression.
387-
template <class E> bool directlyAt() const {
388-
if (auto *anchor = getAnchor().dyn_cast<const Expr *>()) {
389-
return isa<E>(anchor) && getPath().empty();
390-
}
391-
return false;
392-
}
384+
template <typename E> bool directlyAt() const;
393385

394386
/// Attempts to cast the first path element of the locator to a specific
395387
/// \c LocatorPathElt subclass, returning \c None if either unsuccessful or
@@ -502,7 +494,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
502494
GenericTypeParamType *getGenericParameter() const;
503495

504496
/// Produce a profile of this locator, for use in a folding set.
505-
static void Profile(llvm::FoldingSetNodeID &id, TypedNode anchor,
497+
static void Profile(llvm::FoldingSetNodeID &id, ASTNode anchor,
506498
ArrayRef<PathElement> path);
507499

508500
/// Produce a profile of this locator, for use in a folding set.
@@ -518,8 +510,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
518510

519511
private:
520512
/// Initialize a constraint locator with an anchor and a path.
521-
ConstraintLocator(TypedNode anchor, ArrayRef<PathElement> path,
522-
unsigned flags)
513+
ConstraintLocator(ASTNode anchor, ArrayRef<PathElement> path, unsigned flags)
523514
: anchor(anchor), numPathElements(path.size()), summaryFlags(flags) {
524515
// FIXME: Alignment.
525516
std::copy(path.begin(), path.end(),
@@ -533,7 +524,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
533524
/// of the locator. The ConstraintSystem object is responsible for
534525
/// uniquing via the FoldingSet.
535526
static ConstraintLocator *create(llvm::BumpPtrAllocator &allocator,
536-
TypedNode anchor, ArrayRef<PathElement> path,
527+
ASTNode anchor, ArrayRef<PathElement> path,
537528
unsigned flags) {
538529
// FIXME: Alignment.
539530
unsigned size = sizeof(ConstraintLocator)
@@ -543,7 +534,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
543534
}
544535

545536
/// The expression at which this locator is anchored.
546-
TypedNode anchor;
537+
ASTNode anchor;
547538

548539
/// The number of path elements in this locator.
549540
///
@@ -942,7 +933,7 @@ class ConstraintLocatorBuilder {
942933
}
943934

944935
/// Get anchor expression associated with this locator builder.
945-
TypedNode getAnchor() const {
936+
ASTNode getAnchor() const {
946937
for (auto prev = this; prev;
947938
prev = prev->previous.dyn_cast<ConstraintLocatorBuilder *>()) {
948939
if (auto *locator = prev->previous.dyn_cast<ConstraintLocator *>())
@@ -954,7 +945,7 @@ class ConstraintLocatorBuilder {
954945

955946
/// Retrieve the components of the complete locator, which includes
956947
/// the anchor expression and the path.
957-
TypedNode getLocatorParts(SmallVectorImpl<LocatorPathElt> &path) const {
948+
ASTNode getLocatorParts(SmallVectorImpl<LocatorPathElt> &path) const {
958949
for (auto prev = this;
959950
prev;
960951
prev = prev->previous.dyn_cast<ConstraintLocatorBuilder *>()) {

0 commit comments

Comments
 (0)