@@ -94,14 +94,9 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
94
94
// / conformance definition.
95
95
Type ConformingType;
96
96
97
- // / \brief The interface type that conforms to the protocol.
98
- Type ConformingInterfaceType;
99
-
100
97
protected:
101
- ProtocolConformance (ProtocolConformanceKind kind, Type conformingType,
102
- Type conformingInterfaceType)
103
- : Kind (kind), ConformingType (conformingType),
104
- ConformingInterfaceType (conformingInterfaceType) { }
98
+ ProtocolConformance (ProtocolConformanceKind kind, Type conformingType)
99
+ : Kind (kind), ConformingType (conformingType) { }
105
100
106
101
public:
107
102
// / Determine the kind of protocol conformance.
@@ -110,9 +105,6 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
110
105
// / Get the conforming type.
111
106
Type getType () const { return ConformingType; }
112
107
113
- // / Get the conforming interface type.
114
- Type getInterfaceType () const { return ConformingInterfaceType; }
115
-
116
108
// / Get the protocol being conformed to.
117
109
ProtocolDecl *getProtocol () const ;
118
110
@@ -190,41 +182,16 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
190
182
return false ;
191
183
}
192
184
193
- // / Retrieve the non-type witness for the given requirement.
194
- Witness getWitness (ValueDecl *requirement, LazyResolver *resolver) const ;
185
+ // / Retrieve the value witness declaration corresponding to the given
186
+ // / requirement.
187
+ ValueDecl *getWitnessDecl (ValueDecl *requirement,
188
+ LazyResolver *resolver) const ;
195
189
196
190
private:
197
191
// / Determine whether we have a witness for the given requirement.
198
192
bool hasWitness (ValueDecl *requirement) const ;
199
193
200
194
public:
201
- // / Apply the given function object to each value witness within this
202
- // / protocol conformance.
203
- // /
204
- // / The function object should accept a \c ValueDecl* for the requirement
205
- // / followed by the \c Witness for the witness. Note that a generic
206
- // / witness will only be specialized if the conformance came from the current
207
- // / file.
208
- template <typename F>
209
- void forEachValueWitness (LazyResolver *resolver, F f) const {
210
- const ProtocolDecl *protocol = getProtocol ();
211
- for (auto req : protocol->getMembers ()) {
212
- auto valueReq = dyn_cast<ValueDecl>(req);
213
- if (!valueReq || isa<AssociatedTypeDecl>(valueReq) ||
214
- valueReq->isInvalid ())
215
- continue ;
216
-
217
- if (!valueReq->isProtocolRequirement ())
218
- continue ;
219
-
220
- // If we don't have and cannot resolve witnesses, skip it.
221
- if (!resolver && !hasWitness (valueReq))
222
- continue ;
223
-
224
- f (valueReq, getWitness (valueReq, resolver));
225
- }
226
- }
227
-
228
195
// / Retrieve the protocol conformance for the inherited protocol.
229
196
ProtocolConformance *getInheritedConformance (ProtocolDecl *protocol) const ;
230
197
@@ -357,21 +324,16 @@ class NormalProtocolConformance : public ProtocolConformance,
357
324
NormalProtocolConformance (Type conformingType, ProtocolDecl *protocol,
358
325
SourceLoc loc, DeclContext *dc,
359
326
ProtocolConformanceState state)
360
- : ProtocolConformance(ProtocolConformanceKind::Normal, conformingType,
361
- // FIXME: interface type should be passed in
362
- dc->getDeclaredInterfaceType ()),
327
+ : ProtocolConformance(ProtocolConformanceKind::Normal, conformingType),
363
328
ProtocolAndState (protocol, state), Loc(loc), ContextAndInvalid(dc, false )
364
329
{
365
330
}
366
331
367
332
NormalProtocolConformance (Type conformingType,
368
- Type conformingInterfaceType,
369
333
ProtocolDecl *protocol,
370
334
SourceLoc loc, AbstractStorageDecl *behaviorStorage,
371
335
ProtocolConformanceState state)
372
- : ProtocolConformance(ProtocolConformanceKind::Normal, conformingType,
373
- // FIXME: interface type should be passed in
374
- conformingInterfaceType),
336
+ : ProtocolConformance(ProtocolConformanceKind::Normal, conformingType),
375
337
ProtocolAndState(protocol, state), Loc(loc),
376
338
ContextAndInvalid(behaviorStorage, false )
377
339
{
@@ -457,11 +419,6 @@ class NormalProtocolConformance : public ProtocolConformance,
457
419
LazyResolver *resolver = nullptr ) const ;
458
420
459
421
// / Retrieve the value witness corresponding to the given requirement.
460
- // /
461
- // / Note that a generic witness will only be specialized if the conformance
462
- // / came from the current file.
463
- // /
464
- // / FIXME: The 'only specialized if from the same file' bit is awful.
465
422
Witness getWitness (ValueDecl *requirement, LazyResolver *resolver) const ;
466
423
467
424
// / Determine whether the protocol conformance has a witness for the given
@@ -475,6 +432,33 @@ class NormalProtocolConformance : public ProtocolConformance,
475
432
// / Set the witness for the given requirement.
476
433
void setWitness (ValueDecl *requirement, Witness witness) const ;
477
434
435
+ // / Apply the given function object to each value witness within this
436
+ // / protocol conformance.
437
+ // /
438
+ // / The function object should accept a \c ValueDecl* for the requirement
439
+ // / followed by the \c Witness for the witness. Note that a generic
440
+ // / witness will only be specialized if the conformance came from the current
441
+ // / file.
442
+ template <typename F>
443
+ void forEachValueWitness (LazyResolver *resolver, F f) const {
444
+ const ProtocolDecl *protocol = getProtocol ();
445
+ for (auto req : protocol->getMembers ()) {
446
+ auto valueReq = dyn_cast<ValueDecl>(req);
447
+ if (!valueReq || isa<AssociatedTypeDecl>(valueReq) ||
448
+ valueReq->isInvalid ())
449
+ continue ;
450
+
451
+ if (!valueReq->isProtocolRequirement ())
452
+ continue ;
453
+
454
+ // If we don't have and cannot resolve witnesses, skip it.
455
+ if (!resolver && !hasWitness (valueReq))
456
+ continue ;
457
+
458
+ f (valueReq, getWitness (valueReq, resolver));
459
+ }
460
+ }
461
+
478
462
// / Retrieve the protocol conformances that satisfy the requirements of the
479
463
// / protocol, which line up with the conformance constraints in the
480
464
// / protocol's requirement signature.
@@ -583,10 +567,6 @@ class SpecializedProtocolConformance : public ProtocolConformance,
583
567
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
584
568
LazyResolver *resolver) const ;
585
569
586
- // / Retrieve the value witness corresponding to the given requirement.
587
- Witness getWitness (ValueDecl *requirement, LazyResolver *resolver) const ;
588
-
589
-
590
570
// / Given that the requirement signature of the protocol directly states
591
571
// / that the given dependent type must conform to the given protocol,
592
572
// / return its associated conformance.
@@ -601,17 +581,16 @@ class SpecializedProtocolConformance : public ProtocolConformance,
601
581
}
602
582
603
583
void Profile (llvm::FoldingSetNodeID &ID) {
604
- Profile (ID, getType (), getGenericConformance ());
584
+ Profile (ID, getType (), getGenericConformance (),
585
+ getGenericSubstitutions ());
605
586
}
606
587
607
588
static void Profile (llvm::FoldingSetNodeID &ID, Type type,
608
- ProtocolConformance *genericConformance) {
609
- // FIXME: Consider profiling substitutions here. They could differ in
610
- // some crazy cases that also require major diagnostic work, where the
611
- // substitutions involve conformances of the same type to the same
612
- // protocol drawn from different imported modules.
589
+ ProtocolConformance *genericConformance,
590
+ SubstitutionList subs) {
613
591
ID.AddPointer (type.getPointer ());
614
592
ID.AddPointer (genericConformance);
593
+ profileSubstitutionList (ID, subs);
615
594
}
616
595
617
596
static bool classof (const ProtocolConformance *conformance) {
@@ -640,9 +619,7 @@ class InheritedProtocolConformance : public ProtocolConformance,
640
619
641
620
InheritedProtocolConformance (Type conformingType,
642
621
ProtocolConformance *inheritedConformance)
643
- : ProtocolConformance(ProtocolConformanceKind::Inherited, conformingType,
644
- // FIXME: interface type should be passed in
645
- inheritedConformance->getDeclContext ()->getDeclaredInterfaceType()),
622
+ : ProtocolConformance(ProtocolConformanceKind::Inherited, conformingType),
646
623
InheritedConformance (inheritedConformance)
647
624
{
648
625
}
@@ -686,12 +663,6 @@ class InheritedProtocolConformance : public ProtocolConformance,
686
663
return InheritedConformance->getTypeWitnessAndDecl (assocType, resolver);
687
664
}
688
665
689
- // / Retrieve the value witness corresponding to the given requirement.
690
- Witness getWitness (ValueDecl *requirement, LazyResolver *resolver) const {
691
- // FIXME: Substitute!
692
- return InheritedConformance->getWitness (requirement, resolver);
693
- }
694
-
695
666
// / Given that the requirement signature of the protocol directly states
696
667
// / that the given dependent type must conform to the given protocol,
697
668
// / return its associated conformance.
0 commit comments