@@ -53,90 +53,9 @@ class ConstraintLocator : public llvm::FoldingSetNode {
53
53
// / Describes the kind of a particular path element, e.g.,
54
54
// / "tuple element", "call result", "base of member lookup", etc.
55
55
enum PathElementKind : unsigned char {
56
- // / The argument of function application.
57
- ApplyArgument,
58
- // / The function being applied.
59
- ApplyFunction,
60
- // / Matching an argument to a parameter.
61
- ApplyArgToParam,
62
- // / A generic parameter being opened.
63
- // /
64
- // / Also contains the generic parameter type itself.
65
- GenericParameter,
66
- // / The argument type of a function.
67
- FunctionArgument,
68
- // / The result type of a function.
69
- FunctionResult,
70
- // / A tuple element referenced by position.
71
- TupleElement,
72
- // / A tuple element referenced by name.
73
- NamedTupleElement,
74
- // / An optional payload.
75
- OptionalPayload,
76
- // / A generic argument.
77
- // / FIXME: Add support for named generic arguments?
78
- GenericArgument,
79
- // / A member.
80
- // / FIXME: Do we need the actual member name here?
81
- Member,
82
- // / An unresolved member.
83
- UnresolvedMember,
84
- // / The base of a member expression.
85
- MemberRefBase,
86
- // / The lookup for a subscript member.
87
- SubscriptMember,
88
- // / The lookup for a constructor member.
89
- ConstructorMember,
90
- // / An implicit @lvalue-to-inout conversion; only valid for operator
91
- // / arguments.
92
- LValueConversion,
93
- // / RValue adjustment.
94
- RValueAdjustment,
95
- // / The result of a closure.
96
- ClosureResult,
97
- // / The parent of a nested type.
98
- ParentType,
99
- // / The superclass of a protocol existential type.
100
- ExistentialSuperclassType,
101
- // / The instance of a metatype type.
102
- InstanceType,
103
- // / The element type of a sequence in a for ... in ... loop.
104
- SequenceElementType,
105
- // / An argument passed in an autoclosure parameter
106
- // / position, which must match the autoclosure return type.
107
- AutoclosureResult,
108
- // / The requirement that we're matching during protocol conformance
109
- // / checking.
110
- Requirement,
111
- // / The candidate witness during protocol conformance checking.
112
- Witness,
113
- // / This is referring to a type produced by opening a generic type at the
114
- // / base of the locator.
115
- OpenedGeneric,
116
- // / A component of a key path.
117
- KeyPathComponent,
118
- // / The Nth conditional requirement in the parent locator's conformance.
119
- ConditionalRequirement,
120
- // / A single requirement placed on the type parameters.
121
- TypeParameterRequirement,
122
- // / Locator for a binding from an IUO disjunction choice.
123
- ImplicitlyUnwrappedDisjunctionChoice,
124
- // / A result of an expression involving dynamic lookup.
125
- DynamicLookupResult,
126
- // / The desired contextual type passed in to the constraint system.
127
- ContextualType,
128
- // / The missing argument synthesized by the solver.
129
- SynthesizedArgument,
130
- // / The member looked up via keypath based dynamic lookup.
131
- KeyPathDynamicMember,
132
- // / The type of the key path expression
133
- KeyPathType,
134
- // / The root of a key path
135
- KeyPathRoot,
136
- // / The value of a key path
137
- KeyPathValue,
138
- // / The result type of a key path component. Not used for subscripts.
139
- KeyPathComponentResult,
56
+ #define LOCATOR_PATH_ELT (Name ) Name,
57
+ #define ABSTRACT_LOCATOR_PATH_ELT (Name )
58
+ #include " ConstraintLocatorPathElts.def"
140
59
};
141
60
142
61
// / Determine the number of numeric values used for the given path
@@ -162,7 +81,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
162
81
case ExistentialSuperclassType:
163
82
case SequenceElementType:
164
83
case AutoclosureResult:
165
- case Requirement :
84
+ case ProtocolRequirement :
166
85
case Witness:
167
86
case ImplicitlyUnwrappedDisjunctionChoice:
168
87
case DynamicLookupResult:
@@ -229,7 +148,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
229
148
case GenericArgument:
230
149
case NamedTupleElement:
231
150
case TupleElement:
232
- case Requirement :
151
+ case ProtocolRequirement :
233
152
case Witness:
234
153
case KeyPathComponent:
235
154
case ConditionalRequirement:
@@ -260,7 +179,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
260
179
// / Describes the kind of data stored here.
261
180
enum StoredKind : unsigned char {
262
181
StoredGenericParameter,
263
- StoredRequirement ,
182
+ StoredProtocolRequirement ,
264
183
StoredWitness,
265
184
StoredGenericSignature,
266
185
StoredKeyPathDynamicMemberBase,
@@ -356,23 +275,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
356
275
friend class ConstraintLocator ;
357
276
358
277
public:
359
- class ApplyArgToParam ;
360
- class SynthesizedArgument ;
361
- class AnyTupleElement ;
362
- class TupleElement ;
363
- class NamedTupleElement ;
364
- class KeyPathComponent ;
365
- class GenericArgument ;
366
- class AnyRequirement ;
367
- class ConditionalRequirement ;
368
- class TypeParameterRequirement ;
369
- class ContextualType ;
370
- class Witness ;
371
- class Requirement ;
372
- class GenericParameter ;
373
- class OpenedGeneric ;
374
- class KeyPathDynamicMember ;
375
- class UnresolvedMember ;
278
+ #define LOCATOR_PATH_ELT (Name ) class Name ;
279
+ #include " ConstraintLocatorPathElts.def"
376
280
377
281
PathElement (PathElementKind kind)
378
282
: storage(encodeStorage(kind, 0 )), storedKind(StoredKindAndValue)
@@ -387,8 +291,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
387
291
case StoredGenericParameter:
388
292
return PathElementKind::GenericParameter;
389
293
390
- case StoredRequirement :
391
- return PathElementKind::Requirement ;
294
+ case StoredProtocolRequirement :
295
+ return PathElementKind::ProtocolRequirement ;
392
296
393
297
case StoredWitness:
394
298
return PathElementKind::Witness;
@@ -537,9 +441,13 @@ class ConstraintLocator : public llvm::FoldingSetNode {
537
441
return path[0 ].castTo <T>();
538
442
}
539
443
540
- // / Check whether the last element in the path of this locator
541
- // / is of a given kind.
542
- bool isLastElement (ConstraintLocator::PathElementKind kind) const ;
444
+ // / Check whether the last element in the path of this locator (if any)
445
+ // / is a given \c LocatorPathElt subclass.
446
+ template <class T >
447
+ bool isLastElement () const {
448
+ auto path = getPath ();
449
+ return !path.empty () && path.back ().is <T>();
450
+ }
543
451
544
452
// / Attempts to cast the last path element of the locator to a specific
545
453
// / \c LocatorPathElt subclass, returning \c None if either unsuccessful or
@@ -701,6 +609,16 @@ template <class X>
701
609
inline typename llvm::cast_retty<X, LocatorPathElt>::ret_type
702
610
dyn_cast (const LocatorPathElt &) = delete; // Use LocatorPathElt::getAs instead.
703
611
612
+ #define SIMPLE_LOCATOR_PATH_ELT (Name ) \
613
+ class LocatorPathElt :: Name final : public LocatorPathElt { \
614
+ public: \
615
+ Name () : LocatorPathElt(ConstraintLocator:: Name) {} \
616
+ \
617
+ static bool classof (const LocatorPathElt *elt) { \
618
+ return elt->getKind () == ConstraintLocator:: Name; \
619
+ } \
620
+ };
621
+ #include " ConstraintLocatorPathElts.def"
704
622
705
623
// The following LocatorPathElt subclasses are used to expose accessors for
706
624
// specific path element information. They shouldn't introduce additional
@@ -870,15 +788,15 @@ class LocatorPathElt::Witness final : public LocatorPathElt {
870
788
}
871
789
};
872
790
873
- class LocatorPathElt ::Requirement final : public LocatorPathElt {
791
+ class LocatorPathElt ::ProtocolRequirement final : public LocatorPathElt {
874
792
public:
875
- Requirement (ValueDecl *decl)
876
- : LocatorPathElt(LocatorPathElt::StoredRequirement , decl) {}
793
+ ProtocolRequirement (ValueDecl *decl)
794
+ : LocatorPathElt(LocatorPathElt::StoredProtocolRequirement , decl) {}
877
795
878
796
ValueDecl *getDecl () const { return getStoredPointer<ValueDecl>(); }
879
797
880
798
static bool classof (const LocatorPathElt *elt) {
881
- return elt->getKind () == ConstraintLocator::Requirement ;
799
+ return elt->getKind () == ConstraintLocator::ProtocolRequirement ;
882
800
}
883
801
};
884
802
@@ -928,15 +846,6 @@ class LocatorPathElt::KeyPathDynamicMember final : public LocatorPathElt {
928
846
}
929
847
};
930
848
931
- class LocatorPathElt ::UnresolvedMember final : public LocatorPathElt {
932
- public:
933
- UnresolvedMember () : LocatorPathElt(PathElementKind::UnresolvedMember, 0 ) {}
934
-
935
- static bool classof (const LocatorPathElt *elt) {
936
- return elt->getKind () == ConstraintLocator::UnresolvedMember;
937
- }
938
- };
939
-
940
849
// / A simple stack-only builder object that constructs a
941
850
// / constraint locator without allocating memory.
942
851
// /
0 commit comments