Skip to content

Commit 2cfb5fa

Browse files
committed
[ConstraintLocator] Simplify ConstraintLocator::Profile.
Since each kind of path element stores only one type of data, the path element kind and the raw storage value are sufficient for uniquing the element.
1 parent ce77651 commit 2cfb5fa

File tree

2 files changed

+4
-50
lines changed

2 files changed

+4
-50
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,54 +32,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, ASTNode anchor,
3232
id.AddInteger(path.size());
3333
for (auto elt : path) {
3434
id.AddInteger(elt.getKind());
35-
switch (elt.getKind()) {
36-
case GenericParameter:
37-
id.AddPointer(elt.castTo<LocatorPathElt::GenericParameter>().getType());
38-
break;
39-
40-
case ProtocolRequirement: {
41-
auto reqElt = elt.castTo<LocatorPathElt::ProtocolRequirement>();
42-
id.AddPointer(reqElt.getDecl());
43-
break;
44-
}
45-
46-
case Witness:
47-
id.AddPointer(elt.castTo<LocatorPathElt::Witness>().getDecl());
48-
break;
49-
50-
case KeyPathDynamicMember: {
51-
auto kpElt = elt.castTo<LocatorPathElt::KeyPathDynamicMember>();
52-
id.AddPointer(kpElt.getKeyPathDecl());
53-
break;
54-
}
55-
56-
case PatternMatch:
57-
id.AddPointer(elt.castTo<LocatorPathElt::PatternMatch>().getPattern());
58-
break;
59-
60-
case ArgumentAttribute:
61-
case GenericArgument:
62-
case NamedTupleElement:
63-
case TupleElement:
64-
case ApplyArgToParam:
65-
case OpenedGeneric:
66-
case KeyPathComponent:
67-
case ConditionalRequirement:
68-
case TypeParameterRequirement:
69-
case ContextualType:
70-
case SynthesizedArgument:
71-
case TernaryBranch:
72-
case ClosureBody: {
73-
auto numValues = numNumericValuesInPathElement(elt.getKind());
74-
for (unsigned i = 0; i < numValues; ++i)
75-
id.AddInteger(elt.getValue(i));
76-
break;
77-
}
78-
#define SIMPLE_LOCATOR_PATH_ELT(Name) case Name :
79-
#include "ConstraintLocatorPathElts.def"
80-
// Nothing to do for simple locator elements.
81-
break;
82-
}
35+
id.AddInteger(elt.getRawStorage());
8336
}
8437
}
8538

lib/Sema/ConstraintLocator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
201201
return reinterpret_cast<T *>(storage << 3);
202202
}
203203

204-
friend class ConstraintLocator;
205-
206204
public:
207205
#define LOCATOR_PATH_ELT(Name) class Name;
208206
#include "ConstraintLocatorPathElts.def"
@@ -217,6 +215,9 @@ class ConstraintLocator : public llvm::FoldingSetNode {
217215
/// Retrieve the kind of path element.
218216
PathElementKind getKind() const { return kind; }
219217

218+
/// Retrieve the raw storage value.
219+
uint64_t getRawStorage() const { return storage; }
220+
220221
/// Attempts to cast the path element to a specific \c LocatorPathElt
221222
/// subclass, returning \c None if unsuccessful.
222223
template <class T>

0 commit comments

Comments
 (0)