@@ -389,13 +389,49 @@ static void recordTypeWitness(NormalProtocolConformance *conformance,
389
389
}
390
390
}
391
391
392
+ // / Determine whether this is the AsyncIteratorProtocol.Failure associated type.
393
+ static bool isAsyncIteratorProtocolFailure (AssociatedTypeDecl *assocType) {
394
+ auto proto = assocType->getProtocol ();
395
+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol))
396
+ return false ;
397
+
398
+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
399
+ }
400
+
401
+ // / Determine whether this is the AsyncSequence.Failure associated type.
402
+ static bool isAsyncSequenceFailure (AssociatedTypeDecl *assocType) {
403
+ auto proto = assocType->getProtocol ();
404
+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
405
+ return false ;
406
+
407
+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
408
+ }
409
+
410
+ // / Determine whether this is the AsyncIteratorProtocol.Failure or
411
+ // / AsyncSequence.Failure associated type.
412
+ static bool isAsyncIteratorOrSequenceFailure (AssociatedTypeDecl *assocType) {
413
+ auto proto = assocType->getProtocol ();
414
+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol) &&
415
+ !proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
416
+ return false ;
417
+
418
+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
419
+ }
420
+
392
421
// / Attempt to resolve a type witness via member name lookup.
393
422
static ResolveWitnessResult resolveTypeWitnessViaLookup (
394
423
NormalProtocolConformance *conformance,
395
424
AssociatedTypeDecl *assocType) {
396
425
auto *dc = conformance->getDeclContext ();
397
426
auto &ctx = dc->getASTContext ();
398
427
428
+ // Prior to Swift 6, don't look for a named type witness for
429
+ // AsyncSequence.Failure. We'll always infer it from
430
+ // AsyncIteratorProtocol.Failure.
431
+ if (isAsyncSequenceFailure (assocType) &&
432
+ !ctx.LangOpts .isSwiftVersionAtLeast (6 ))
433
+ return ResolveWitnessResult::Missing;
434
+
399
435
// Conformances constructed by the ClangImporter should have explicit type
400
436
// witnesses already.
401
437
if (isa<ClangModuleUnit>(dc->getModuleScopeContext ())) {
@@ -1816,25 +1852,15 @@ next_witness:;
1816
1852
return result;
1817
1853
}
1818
1854
1819
- // / Determine whether this is AsyncIteratorProtocol.Failure or
1820
- // / AsyncSequenceProtoco.Failure associated type.
1821
- static bool isAsyncIteratorProtocolFailure (AssociatedTypeDecl *assocType) {
1822
- auto proto = assocType->getProtocol ();
1823
- if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol) &&
1824
- !proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
1825
- return false ;
1826
-
1827
- return assocType->getName () == assocType->getASTContext ().Id_Failure ;
1828
- }
1829
-
1830
1855
// / Determine whether this is AsyncIteratorProtocol.next() function.
1831
1856
static bool isAsyncIteratorProtocolNext (ValueDecl *req) {
1832
1857
auto proto = dyn_cast<ProtocolDecl>(req->getDeclContext ());
1833
1858
if (!proto ||
1834
1859
!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol))
1835
1860
return false ;
1836
1861
1837
- return req->getName ().getBaseName () == req->getASTContext ().Id_next ;
1862
+ return req->getName ().getBaseName () == req->getASTContext ().Id_next &&
1863
+ req->getName ().getArgumentNames ().empty ();
1838
1864
}
1839
1865
1840
1866
InferredAssociatedTypes
@@ -2537,8 +2563,7 @@ std::optional<AbstractTypeWitness>
2537
2563
AssociatedTypeInference::computeFailureTypeWitness (
2538
2564
AssociatedTypeDecl *assocType,
2539
2565
ArrayRef<std::pair<ValueDecl *, ValueDecl *>> valueWitnesses) const {
2540
- // Inference only applies to AsyncIteratorProtocol.Failure and
2541
- // AsyncSequence.Failure.
2566
+ // Inference only applies to AsyncIteratorProtocol.Failure.
2542
2567
if (!isAsyncIteratorProtocolFailure (assocType))
2543
2568
return std::nullopt;
2544
2569
@@ -2582,7 +2607,7 @@ AssociatedTypeInference::computeDefaultTypeWitness(
2582
2607
AssociatedTypeDecl *assocType) const {
2583
2608
// Ignore the default for AsyncIteratorProtocol.Failure and
2584
2609
// AsyncSequence.Failure.
2585
- if (isAsyncIteratorProtocolFailure (assocType))
2610
+ if (isAsyncIteratorOrSequenceFailure (assocType))
2586
2611
return std::nullopt;
2587
2612
2588
2613
// Go find a default definition.
@@ -2683,8 +2708,8 @@ AssociatedTypeInference::computeAbstractTypeWitness(
2683
2708
2684
2709
// Don't consider the generic parameter names for AsyncSequence.Failure or
2685
2710
// AsyncIteratorProtocol.Failure; we always rely on inference from next() or
2686
- // next(_ :).
2687
- if (isAsyncIteratorProtocolFailure (assocType)) {
2711
+ // next(isolation :).
2712
+ if (isAsyncIteratorOrSequenceFailure (assocType)) {
2688
2713
// If this is specifically AsyncSequence.Failure with the older associated
2689
2714
// type inference implementation, our abstract witness is
2690
2715
// "AsyncIterator.Failure". The new implementation is smart enough to do
@@ -2727,7 +2752,7 @@ Type AssociatedTypeInference::computeGenericParamWitness(
2727
2752
if (auto genericSig = dc->getGenericSignatureOfContext ()) {
2728
2753
// Ignore the generic parameters for AsyncIteratorProtocol.Failure and
2729
2754
// AsyncSequence.Failure.
2730
- if (!isAsyncIteratorProtocolFailure (assocType)) {
2755
+ if (!isAsyncIteratorOrSequenceFailure (assocType)) {
2731
2756
for (auto *gp : genericSig.getInnermostGenericParams ()) {
2732
2757
// Packs cannot witness associated type requirements.
2733
2758
if (gp->isParameterPack ())
0 commit comments