@@ -82,6 +82,8 @@ class GenericSignatureBuilder {
82
82
83
83
class FloatingRequirementSource ;
84
84
85
+ class DelayedRequirement ;
86
+
85
87
// / Describes a specific constraint on a potential archetype.
86
88
template <typename T>
87
89
struct Constraint {
@@ -190,6 +192,21 @@ class GenericSignatureBuilder {
190
192
// / The constraint conflicted with existing constraints in some way;
191
193
// / the generic signature is ill-formed.
192
194
Conflicting,
195
+
196
+ // / The constraint could not be resolved immediately.
197
+ Unresolved,
198
+ };
199
+
200
+ // / Enum used to indicate how we should handle a constraint that cannot be
201
+ // / processed immediately for some reason.
202
+ enum class UnresolvedHandlingKind : char {
203
+ // / Generate a new, unresolved constraint and consider the constraint
204
+ // / "resolved" at this point.
205
+ GenerateConstraints = 0 ,
206
+
207
+ // / Do not generate a new constraint; rather, return
208
+ // / \c ConstraintResult::Unresolved and let the caller handle it.
209
+ ReturnUnresolved = 1 ,
193
210
};
194
211
195
212
private:
@@ -207,13 +224,15 @@ class GenericSignatureBuilder {
207
224
208
225
// / When a particular requirement cannot be resolved due to, e.g., a
209
226
// / currently-unresolvable or nested type, this routine should be
210
- // / called to record the unresolved requirement to be reconsidered later .
227
+ // / called to cope with the unresolved requirement.
211
228
// /
212
- // / \returns ConstraintResult::Resolved.
213
- ConstraintResult recordUnresolvedRequirement (RequirementKind kind,
229
+ // / \returns \c ConstraintResult::Resolved or ConstraintResult::Delayed,
230
+ // / as appropriate based on \c unresolvedHandling.
231
+ ConstraintResult handleUnresolvedRequirement (RequirementKind kind,
214
232
UnresolvedType lhs,
215
233
RequirementRHS rhs,
216
- FloatingRequirementSource source);
234
+ FloatingRequirementSource source,
235
+ UnresolvedHandlingKind unresolvedHandling);
217
236
218
237
// / Retrieve the constraint source conformance for the superclass constraint
219
238
// / of the given potential archetype (if present) to the given protocol.
@@ -265,9 +284,11 @@ class GenericSignatureBuilder {
265
284
// /
266
285
// / The types are resolved with \c GenericSignatureBuilder::resolve, and must
267
286
// / not be incompatible concrete types.
268
- ConstraintResult addSameTypeRequirement (UnresolvedType paOrT1,
269
- UnresolvedType paOrT2,
270
- FloatingRequirementSource Source);
287
+ ConstraintResult addSameTypeRequirement (
288
+ UnresolvedType paOrT1,
289
+ UnresolvedType paOrT2,
290
+ FloatingRequirementSource Source,
291
+ UnresolvedHandlingKind unresolvedHandling);
271
292
272
293
// / \brief Add a new same-type requirement between two unresolved types.
273
294
// /
@@ -277,6 +298,7 @@ class GenericSignatureBuilder {
277
298
ConstraintResult
278
299
addSameTypeRequirement (UnresolvedType paOrT1, UnresolvedType paOrT2,
279
300
FloatingRequirementSource Source,
301
+ UnresolvedHandlingKind unresolvedHandling,
280
302
llvm::function_ref<void (Type, Type)> diagnoseMismatch);
281
303
282
304
// / Update the superclass for the equivalence class of \c T.
@@ -300,6 +322,7 @@ class GenericSignatureBuilder {
300
322
UnresolvedType subject,
301
323
UnresolvedType constraint,
302
324
FloatingRequirementSource source,
325
+ UnresolvedHandlingKind unresolvedHandling,
303
326
llvm::SmallPtrSetImpl<ProtocolDecl *> *visited
304
327
= nullptr );
305
328
@@ -334,9 +357,11 @@ class GenericSignatureBuilder {
334
357
const RequirementSource *Source);
335
358
336
359
// / Add a new layout requirement to the subject.
337
- ConstraintResult addLayoutRequirement (UnresolvedType subject,
338
- LayoutConstraint layout,
339
- FloatingRequirementSource source);
360
+ ConstraintResult addLayoutRequirement (
361
+ UnresolvedType subject,
362
+ LayoutConstraint layout,
363
+ FloatingRequirementSource source,
364
+ UnresolvedHandlingKind unresolvedHandling);
340
365
341
366
// / Add the requirements placed on the given type parameter
342
367
// / to the given potential archetype.
@@ -480,6 +505,9 @@ class GenericSignatureBuilder {
480
505
ArrayRef<GenericTypeParamType *> genericParams);
481
506
482
507
private:
508
+ // / Process any delayed requirements that can be handled now.
509
+ void processDelayedRequirements ();
510
+
483
511
// / Describes the relationship between a given constraint and
484
512
// / the canonical constraint of the equivalence class.
485
513
enum class ConstraintRelation {
@@ -1545,6 +1573,15 @@ class GenericSignatureBuilder::PotentialArchetype {
1545
1573
friend class GenericSignatureBuilder ;
1546
1574
};
1547
1575
1576
+ // / Describes a requirement whose processing has been delayed for some reason.
1577
+ class GenericSignatureBuilder ::DelayedRequirement {
1578
+ public:
1579
+ RequirementKind kind;
1580
+ UnresolvedType lhs;
1581
+ RequirementRHS rhs;
1582
+ FloatingRequirementSource source;
1583
+ };
1584
+
1548
1585
// / Whether the given constraint result signals an error.
1549
1586
inline bool isErrorResult (GenericSignatureBuilder::ConstraintResult result) {
1550
1587
switch (result) {
@@ -1553,6 +1590,7 @@ inline bool isErrorResult(GenericSignatureBuilder::ConstraintResult result) {
1553
1590
return true ;
1554
1591
1555
1592
case GenericSignatureBuilder::ConstraintResult::Resolved:
1593
+ case GenericSignatureBuilder::ConstraintResult::Unresolved:
1556
1594
return false ;
1557
1595
}
1558
1596
}
0 commit comments