@@ -71,15 +71,12 @@ enum class LiteralBindingKind : uint8_t {
71
71
// / along with information that can be used to construct related
72
72
// / bindings, e.g., the supertypes of a given type.
73
73
struct PotentialBinding {
74
- friend class BindingSet ;
75
-
76
74
// / The type to which the type variable can be bound.
77
75
Type BindingType;
78
76
79
77
// / The kind of bindings permitted.
80
78
AllowedBindingKind Kind;
81
79
82
- protected:
83
80
// / The source of the type information.
84
81
// /
85
82
// / Determines whether this binding represents a "hole" in
@@ -91,7 +88,6 @@ struct PotentialBinding {
91
88
PointerUnion<Constraint *, ConstraintLocator *> source)
92
89
: BindingType(type), Kind(kind), BindingSource(source) {}
93
90
94
- public:
95
91
PotentialBinding (Type type, AllowedBindingKind kind, Constraint *source)
96
92
: PotentialBinding(
97
93
type, kind,
@@ -219,25 +215,11 @@ struct LiteralRequirement {
219
215
220
216
struct PotentialBindings {
221
217
// / The set of all constraints that have been added via infer().
222
- llvm::SmallPtrSet <Constraint *, 2 > Constraints;
218
+ llvm::SmallSetVector <Constraint *, 2 > Constraints;
223
219
224
220
// / The set of potential bindings.
225
221
llvm::SmallVector<PotentialBinding, 4 > Bindings;
226
222
227
- // / The set of protocol requirements placed on this type variable.
228
- llvm::SmallVector<Constraint *, 4 > Protocols;
229
-
230
- // / The set of unique literal protocol requirements placed on this
231
- // / type variable or inferred transitively through subtype chains.
232
- // /
233
- // / Note that ordering is important when it comes to bindings, we'd
234
- // / like to add any "direct" default types first to attempt them
235
- // / before transitive ones.
236
- llvm::SmallPtrSet<Constraint *, 2 > Literals;
237
-
238
- // / The set of constraints which would be used to infer default types.
239
- llvm::SmallPtrSet<Constraint *, 2 > Defaults;
240
-
241
223
// / The set of constraints which delay attempting this type variable.
242
224
llvm::TinyPtrVector<Constraint *> DelayedBy;
243
225
@@ -247,22 +229,17 @@ struct PotentialBindings {
247
229
// / bindings (contained in the binding type e.g. `Foo<$T0>`), or
248
230
// / reachable through subtype/conversion relationship e.g.
249
231
// / `$T0 subtype of $T1` or `$T0 arg conversion $T1`.
250
- llvm::SmallDenseSet<std::pair<TypeVariableType *, Constraint *>, 2 >
251
- AdjacentVars;
252
-
253
- ASTNode AssociatedCodeCompletionToken = ASTNode();
232
+ llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 2 > AdjacentVars;
254
233
255
234
// / A set of all not-yet-resolved type variables this type variable
256
235
// / is a subtype of, supertype of or is equivalent to. This is used
257
236
// / to determine ordering inside of a chain of subtypes to help infer
258
237
// / transitive bindings and protocol requirements.
259
- llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4 > SubtypeOf;
260
- llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4 > SupertypeOf;
261
- llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4 > EquivalentTo;
262
-
263
- void addDefault (Constraint *constraint);
238
+ llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4 > SubtypeOf;
239
+ llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4 > SupertypeOf;
240
+ llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4 > EquivalentTo;
264
241
265
- void addLiteral (Constraint *constraint );
242
+ ASTNode AssociatedCodeCompletionToken = ASTNode( );
266
243
267
244
// / Add a potential binding to the list of bindings,
268
245
// / coalescing supertype bounds when we are able to compute the meet.
@@ -385,28 +362,26 @@ class BindingSet {
385
362
386
363
public:
387
364
swift::SmallSetVector<PotentialBinding, 4 > Bindings;
365
+
366
+ // / The set of protocol conformance requirements placed on this type variable.
367
+ llvm::SmallVector<Constraint *, 4 > Protocols;
368
+
369
+ // / The set of unique literal protocol requirements placed on this
370
+ // / type variable or inferred transitively through subtype chains.
371
+ // /
372
+ // / Note that ordering is important when it comes to bindings, we'd
373
+ // / like to add any "direct" default types first to attempt them
374
+ // / before transitive ones.
388
375
llvm::SmallMapVector<ProtocolDecl *, LiteralRequirement, 2 > Literals;
376
+
389
377
llvm::SmallDenseMap<CanType, Constraint *, 2 > Defaults;
390
378
391
379
// / The set of transitive protocol requirements inferred through
392
380
// / subtype/conversion/equivalence relations with other type variables.
393
381
std::optional<llvm::SmallPtrSet<Constraint *, 4 >> TransitiveProtocols;
394
382
395
383
BindingSet (ConstraintSystem &CS, TypeVariableType *TypeVar,
396
- const PotentialBindings &info)
397
- : CS(CS), TypeVar(TypeVar), Info(info) {
398
- for (const auto &binding : info.Bindings )
399
- addBinding (binding, /* isTransitive=*/ false );
400
-
401
- for (auto *literal : info.Literals )
402
- addLiteralRequirement (literal);
403
-
404
- for (auto *constraint : info.Defaults )
405
- addDefault (constraint);
406
-
407
- for (auto &entry : info.AdjacentVars )
408
- AdjacentVars.insert (entry.first );
409
- }
384
+ const PotentialBindings &info);
410
385
411
386
ConstraintSystem &getConstraintSystem () const { return CS; }
412
387
@@ -512,7 +487,7 @@ class BindingSet {
512
487
}
513
488
514
489
ArrayRef<Constraint *> getConformanceRequirements () const {
515
- return Info. Protocols ;
490
+ return Protocols;
516
491
}
517
492
518
493
unsigned getNumViableLiteralBindings () const ;
0 commit comments