Skip to content

Commit c813791

Browse files
authored
Merge pull request swiftlang#72789 from slavapestov/two-test-cases-without-a-bug-and-a-bug-without-a-testcase
Two test cases without a bug and a bug without a testcase
2 parents cbf9cb2 + 03467a1 commit c813791

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,6 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
355355
if (!type->isTypeParameter())
356356
return ProtocolConformanceRef::forInvalid();
357357

358-
// If the protocol is invertible, just do a global lookup. This avoids an
359-
// infinite substitution issue by recognizing that these protocols are
360-
// very simple (see rdar://119950540 for the general issue).
361-
if (proto->getInvertibleProtocolKind()) {
362-
auto substType = type.subst(*this);
363-
if (!substType->isTypeParameter())
364-
return proto->getModuleContext()->lookupConformance(substType, proto);
365-
return ProtocolConformanceRef(proto);
366-
}
367-
368358
auto genericSig = getGenericSignature();
369359

370360
auto getSignatureConformance =
@@ -396,6 +386,15 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
396386
return ProtocolConformanceRef::forMissingOrInvalid(substType, proto);
397387
}
398388

389+
// If the protocol is invertible, fall back to a global lookup instead of
390+
// evaluating a conformance path, to avoid an infinite substitution issue.
391+
if (proto->getInvertibleProtocolKind()) {
392+
auto substType = type.subst(*this);
393+
if (!substType->isTypeParameter())
394+
return proto->getModuleContext()->lookupConformance(substType, proto);
395+
return ProtocolConformanceRef(proto);
396+
}
397+
399398
auto path = genericSig->getConformancePath(type, proto);
400399

401400
ProtocolConformanceRef conformance;

test/Generics/rdar124697829.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking
2+
3+
// This is a generics test, but only IRGen exercised the substitution of
4+
// an abstract conformance with a type parameter -- in the type checker and
5+
// SIL, we only deal with archetypes.
6+
7+
public protocol IteratorProtocol {
8+
associatedtype Element
9+
}
10+
11+
public protocol Sequence {
12+
associatedtype Iterator: IteratorProtocol
13+
associatedtype Element where Element == Iterator.Element
14+
}
15+
16+
public struct IndexingIterator<S: Sequence>: IteratorProtocol {
17+
public typealias Element = S.Element
18+
}
19+
20+
public struct Array<Element>: Sequence {
21+
public typealias Iterator = IndexingIterator<Self>
22+
}
23+
24+
public protocol Publisher {
25+
associatedtype Output
26+
}
27+
28+
public struct SequencePublisher<Elements: Sequence>: Publisher {
29+
public typealias Output = Elements.Element
30+
}
31+
32+
public struct Map<Pub: Publisher, Output>: Publisher {}
33+
34+
public func foo<T>(_: T) -> some Publisher {
35+
bar(SequencePublisher<Array<T>>())
36+
}
37+
38+
public func bar<Pub: Publisher>(_: Pub) -> some Publisher {
39+
Map<Pub, Pub.Output>()
40+
}
41+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public protocol P1 {
2+
associatedtype A: Sendable
3+
}
4+
5+
public protocol P2: P1, Sendable where A == any P2 {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/protocol_with_self_conforming_existential_other.swift -emit-module-path %t/protocol_with_self_conforming_existential_other.swiftmodule
3+
// RUN: %target-swift-frontend -emit-silgen %s -I %t
4+
5+
import protocol_with_self_conforming_existential_other
6+
7+
// Declare a type conforming to P2, to force deserializing its
8+
// requirement signature.
9+
10+
struct MyP2: P2 {}
11+

0 commit comments

Comments
 (0)