@@ -148,16 +148,19 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
148
148
149
149
// / Return true if the conformance has a witness for the given associated
150
150
// / type.
151
- bool hasTypeWitness (AssociatedTypeDecl *assocType) const ;
151
+ bool hasTypeWitness (AssociatedTypeDecl *assocType,
152
+ LazyResolver *resolver = nullptr ) const ;
152
153
153
154
// / Retrieve the type witness for the given associated type.
154
155
Type getTypeWitness (AssociatedTypeDecl *assocType,
156
+ LazyResolver *resolver,
155
157
SubstOptions options = None) const ;
156
158
157
159
// / Retrieve the type witness and type decl (if one exists)
158
160
// / for the given associated type.
159
161
std::pair<Type, TypeDecl *>
160
162
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
163
+ LazyResolver *resolver,
161
164
SubstOptions options = None) const ;
162
165
163
166
// / Apply the given function object to each type witness within this
@@ -170,17 +173,17 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
170
173
// /
171
174
// / \returns true if the function ever returned true
172
175
template <typename F>
173
- bool forEachTypeWitness (F f, bool useResolver= false ) const {
176
+ bool forEachTypeWitness (LazyResolver *resolver, F f ) const {
174
177
const ProtocolDecl *protocol = getProtocol ();
175
178
for (auto assocTypeReq : protocol->getAssociatedTypeMembers ()) {
176
179
if (assocTypeReq->isInvalid ())
177
180
continue ;
178
181
179
182
// If we don't have and cannot resolve witnesses, skip it.
180
- if (!useResolver && !hasTypeWitness (assocTypeReq))
183
+ if (!resolver && !hasTypeWitness (assocTypeReq))
181
184
continue ;
182
185
183
- const auto &TWInfo = getTypeWitnessAndDecl (assocTypeReq);
186
+ const auto &TWInfo = getTypeWitnessAndDecl (assocTypeReq, resolver );
184
187
if (f (assocTypeReq, TWInfo.first , TWInfo.second ))
185
188
return true ;
186
189
}
@@ -190,11 +193,13 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
190
193
191
194
// / Retrieve the value witness declaration corresponding to the given
192
195
// / requirement.
193
- ValueDecl *getWitnessDecl (ValueDecl *requirement) const ;
196
+ ValueDecl *getWitnessDecl (ValueDecl *requirement,
197
+ LazyResolver *resolver) const ;
194
198
195
199
// / Retrieve the witness corresponding to the given value requirement.
196
200
// / TODO: maybe this should return a Witness?
197
- ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement) const ;
201
+ ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement,
202
+ LazyResolver *resolver) const ;
198
203
199
204
private:
200
205
// / Determine whether we have a witness for the given requirement.
@@ -206,7 +211,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
206
211
// /
207
212
// / The function object should accept a \c ValueDecl* for the requirement.
208
213
template <typename F>
209
- void forEachNonWitnessedRequirement (F f) const {
214
+ void forEachNonWitnessedRequirement (LazyResolver *Resolver, F f) const {
210
215
const ProtocolDecl *protocol = getProtocol ();
211
216
for (auto req : protocol->getMembers ()) {
212
217
auto valueReq = dyn_cast<ValueDecl>(req);
@@ -215,7 +220,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
215
220
216
221
if (auto assocTypeReq = dyn_cast<AssociatedTypeDecl>(req)) {
217
222
// If we don't have witness for the associated type, apply the function.
218
- if (getTypeWitness (assocTypeReq)->hasError ()) {
223
+ if (getTypeWitness (assocTypeReq, Resolver )->hasError ()) {
219
224
f (valueReq);
220
225
}
221
226
continue ;
@@ -236,13 +241,15 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
236
241
237
242
// / Given a dependent type expressed in terms of the self parameter,
238
243
// / map it into the context of this conformance.
239
- Type getAssociatedType (Type assocType) const ;
244
+ Type getAssociatedType (Type assocType,
245
+ LazyResolver *resolver = nullptr ) const ;
240
246
241
247
// / Given that the requirement signature of the protocol directly states
242
248
// / that the given dependent type must conform to the given protocol,
243
249
// / return its associated conformance.
244
250
ProtocolConformanceRef
245
- getAssociatedConformance (Type assocType, ProtocolDecl *protocol) const ;
251
+ getAssociatedConformance (Type assocType, ProtocolDecl *protocol,
252
+ LazyResolver *resolver = nullptr ) const ;
246
253
247
254
// / Get the generic parameters open on the conforming type.
248
255
GenericEnvironment *getGenericEnvironment () const ;
@@ -346,11 +353,12 @@ class RootProtocolConformance : public ProtocolConformance {
346
353
AvailabilityContext fromContext) const ;
347
354
348
355
bool hasWitness (ValueDecl *requirement) const ;
349
- Witness getWitness (ValueDecl *requirement) const ;
356
+ Witness getWitness (ValueDecl *requirement, LazyResolver *resolver ) const ;
350
357
351
358
// / Retrieve the witness corresponding to the given value requirement.
352
359
// / TODO: maybe this should return a Witness?
353
- ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement) const ;
360
+ ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement,
361
+ LazyResolver *resolver) const ;
354
362
355
363
// / Apply the given function object to each value witness within this
356
364
// / protocol conformance.
@@ -360,7 +368,7 @@ class RootProtocolConformance : public ProtocolConformance {
360
368
// / witness will only be specialized if the conformance came from the current
361
369
// / file.
362
370
template <typename F>
363
- void forEachValueWitness (F f, bool useResolver= false ) const {
371
+ void forEachValueWitness (LazyResolver *resolver, F f ) const {
364
372
const ProtocolDecl *protocol = getProtocol ();
365
373
for (auto req : protocol->getMembers ()) {
366
374
auto valueReq = dyn_cast<ValueDecl>(req);
@@ -372,10 +380,10 @@ class RootProtocolConformance : public ProtocolConformance {
372
380
continue ;
373
381
374
382
// If we don't have and cannot resolve witnesses, skip it.
375
- if (!useResolver && !hasWitness (valueReq))
383
+ if (!resolver && !hasWitness (valueReq))
376
384
continue ;
377
385
378
- f (valueReq, getWitness (valueReq));
386
+ f (valueReq, getWitness (valueReq, resolver ));
379
387
}
380
388
}
381
389
@@ -589,11 +597,13 @@ class NormalProtocolConformance : public RootProtocolConformance,
589
597
// / for the given associated type.
590
598
std::pair<Type, TypeDecl *>
591
599
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
600
+ LazyResolver *resolver,
592
601
SubstOptions options = None) const ;
593
602
594
603
// / Determine whether the protocol conformance has a type witness for the
595
604
// / given associated type.
596
- bool hasTypeWitness (AssociatedTypeDecl *assocType) const ;
605
+ bool hasTypeWitness (AssociatedTypeDecl *assocType,
606
+ LazyResolver *resolver = nullptr ) const ;
597
607
598
608
// / Set the type witness for the given associated type.
599
609
// / \param typeDecl the type decl the witness type came from, if one exists.
@@ -604,10 +614,11 @@ class NormalProtocolConformance : public RootProtocolConformance,
604
614
// / that the given dependent type must conform to the given protocol,
605
615
// / return its associated conformance.
606
616
ProtocolConformanceRef
607
- getAssociatedConformance (Type assocType, ProtocolDecl *protocol) const ;
617
+ getAssociatedConformance (Type assocType, ProtocolDecl *protocol,
618
+ LazyResolver *resolver = nullptr ) const ;
608
619
609
620
// / Retrieve the value witness corresponding to the given requirement.
610
- Witness getWitness (ValueDecl *requirement) const ;
621
+ Witness getWitness (ValueDecl *requirement, LazyResolver *resolver ) const ;
611
622
612
623
// / Determine whether the protocol conformance has a witness for the given
613
624
// / requirement.
@@ -633,14 +644,20 @@ class NormalProtocolConformance : public RootProtocolConformance,
633
644
// / the normal conformance.
634
645
void setSignatureConformances (ArrayRef<ProtocolConformanceRef> conformances);
635
646
636
- // / Populate the signature conformances without checking if they satisfy
637
- // / requirements. Can only be used with parsed or imported conformances.
638
- void finishSignatureConformances ();
647
+ // / Retrieves a function object that should be called with each of the
648
+ // / conformances required by the requirement signature.
649
+ // /
650
+ // / This can be used to iteratively build up the signature conformances in
651
+ // / the type checker (rather than emitting them in a batch via
652
+ // / \c setSignatureConformances). The callee is responsible for calling
653
+ // / the returned function object with protocol conformances that line up
654
+ // / with the conformance requirements in the requirement signature (in order).
655
+ std::function<void (ProtocolConformanceRef)> populateSignatureConformances ();
639
656
640
657
// / Determine whether the witness for the given type requirement
641
658
// / is the default definition.
642
659
bool usesDefaultDefinition (AssociatedTypeDecl *requirement) const {
643
- TypeDecl *witnessDecl = getTypeWitnessAndDecl (requirement).second ;
660
+ TypeDecl *witnessDecl = getTypeWitnessAndDecl (requirement, nullptr ).second ;
644
661
if (witnessDecl)
645
662
return witnessDecl->isImplicit ();
646
663
// Conservatively assume it does not.
@@ -708,17 +725,20 @@ class SelfProtocolConformance : public RootProtocolConformance {
708
725
llvm_unreachable (" never an implied conformance" );
709
726
}
710
727
711
- bool hasTypeWitness (AssociatedTypeDecl *assocType) const {
728
+ bool hasTypeWitness (AssociatedTypeDecl *assocType,
729
+ LazyResolver *resolver) const {
712
730
llvm_unreachable (" self-conformances never have associated types" );
713
731
}
714
732
715
733
std::pair<Type, TypeDecl *>
716
734
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
735
+ LazyResolver *resolver,
717
736
SubstOptions options) const {
718
737
llvm_unreachable (" self-conformances never have associated types" );
719
738
}
720
739
721
740
Type getTypeWitness (AssociatedTypeDecl *assocType,
741
+ LazyResolver *resolver,
722
742
SubstOptions options) const {
723
743
llvm_unreachable (" self-conformances never have associated types" );
724
744
}
@@ -728,14 +748,15 @@ class SelfProtocolConformance : public RootProtocolConformance {
728
748
}
729
749
730
750
ProtocolConformanceRef getAssociatedConformance (Type assocType,
731
- ProtocolDecl *protocol) const {
751
+ ProtocolDecl *protocol,
752
+ LazyResolver *resolver) const {
732
753
llvm_unreachable (" self-conformances never have associated types" );
733
754
}
734
755
735
756
bool hasWitness (ValueDecl *requirement) const {
736
757
return true ;
737
758
}
738
- Witness getWitness (ValueDecl *requirement) const ;
759
+ Witness getWitness (ValueDecl *requirement, LazyResolver *resolver ) const ;
739
760
740
761
Optional<ArrayRef<Requirement>> getConditionalRequirementsIfAvailable () const {
741
762
return ArrayRef<Requirement>();
@@ -854,22 +875,26 @@ class SpecializedProtocolConformance : public ProtocolConformance,
854
875
return GenericConformance->getImplyingConformance ();
855
876
}
856
877
857
- bool hasTypeWitness (AssociatedTypeDecl *assocType) const ;
878
+ bool hasTypeWitness (AssociatedTypeDecl *assocType,
879
+ LazyResolver *resolver = nullptr ) const ;
858
880
859
881
// / Retrieve the type witness and type decl (if one exists)
860
882
// / for the given associated type.
861
883
std::pair<Type, TypeDecl *>
862
884
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
885
+ LazyResolver *resolver,
863
886
SubstOptions options = None) const ;
864
887
865
888
// / Given that the requirement signature of the protocol directly states
866
889
// / that the given dependent type must conform to the given protocol,
867
890
// / return its associated conformance.
868
891
ProtocolConformanceRef
869
- getAssociatedConformance (Type assocType, ProtocolDecl *protocol) const ;
892
+ getAssociatedConformance (Type assocType, ProtocolDecl *protocol,
893
+ LazyResolver *resolver = nullptr ) const ;
870
894
871
895
// / Retrieve the witness corresponding to the given value requirement.
872
- ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement) const ;
896
+ ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement,
897
+ LazyResolver *resolver) const ;
873
898
874
899
// / Determine whether the witness for the given requirement
875
900
// / is either the default definition or was otherwise deduced.
@@ -964,26 +989,31 @@ class InheritedProtocolConformance : public ProtocolConformance,
964
989
// / Get the protocol conformance which implied this implied conformance.
965
990
NormalProtocolConformance *getImplyingConformance () const { return nullptr ; }
966
991
967
- bool hasTypeWitness (AssociatedTypeDecl *assocType) const {
968
- return InheritedConformance->hasTypeWitness (assocType);
992
+ bool hasTypeWitness (AssociatedTypeDecl *assocType,
993
+ LazyResolver *resolver = nullptr ) const {
994
+ return InheritedConformance->hasTypeWitness (assocType, resolver);
969
995
}
970
996
971
997
// / Retrieve the type witness and type decl (if one exists)
972
998
// / for the given associated type.
973
999
std::pair<Type, TypeDecl *>
974
1000
getTypeWitnessAndDecl (AssociatedTypeDecl *assocType,
1001
+ LazyResolver *resolver,
975
1002
SubstOptions options = None) const {
976
- return InheritedConformance->getTypeWitnessAndDecl (assocType, options);
1003
+ return InheritedConformance->getTypeWitnessAndDecl (assocType, resolver,
1004
+ options);
977
1005
}
978
1006
979
1007
// / Given that the requirement signature of the protocol directly states
980
1008
// / that the given dependent type must conform to the given protocol,
981
1009
// / return its associated conformance.
982
1010
ProtocolConformanceRef
983
- getAssociatedConformance (Type assocType, ProtocolDecl *protocol) const ;
1011
+ getAssociatedConformance (Type assocType, ProtocolDecl *protocol,
1012
+ LazyResolver *resolver = nullptr ) const ;
984
1013
985
1014
// / Retrieve the witness corresponding to the given value requirement.
986
- ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement) const ;
1015
+ ConcreteDeclRef getWitnessDeclRef (ValueDecl *requirement,
1016
+ LazyResolver *resolver) const ;
987
1017
988
1018
// / Determine whether the witness for the given requirement
989
1019
// / is either the default definition or was otherwise deduced.
0 commit comments