Skip to content

Commit 86a0896

Browse files
authored
Merge pull request #66443 from slavapestov/zip-collect-attempt-fixes-5.9
A couple of tiny variadic generic fixes [5.9]
2 parents 089b8b8 + 1e95d65 commit 86a0896

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
418418

419419
// For the second step, we're looking into the requirement signature for
420420
// this protocol.
421+
if (conformance.isPack()) {
422+
auto pack = conformance.getPack();
423+
conformance = ProtocolConformanceRef(
424+
pack->getAssociatedConformance(step.first, step.second));
425+
if (conformance.isInvalid())
426+
return conformance;
427+
428+
continue;
429+
}
430+
421431
auto concrete = conformance.getConcrete();
422432
auto normal = concrete->getRootNormalConformance();
423433

lib/SIL/IR/SILTypeSubstitution.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class SILTypeSubstituter :
7777
ProtocolConformanceRef(conformedProtocol),
7878
conformingReplacementType->getCanonicalType(),
7979
typeExpansionContext);
80-
}, SubstFlags::SubstituteOpaqueArchetypes);
80+
},
81+
SubstFlags::SubstituteOpaqueArchetypes |
82+
SubstFlags::PreservePackExpansionLevel);
8183
}
8284

8385
// Substitute a function type.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s -disable-availability-checking
2+
3+
protocol P {
4+
associatedtype A: P
5+
}
6+
7+
struct S: P {
8+
typealias A = S
9+
}
10+
11+
func f<each T: P>(_: repeat each T) -> (repeat each T.A.A.A.A) {}
12+
13+
f(S(), S(), S())
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking
2+
3+
struct ZipCollection<each C: Collection> {
4+
let c: (repeat each C)
5+
}
6+
7+
extension ZipCollection: Collection {
8+
struct Element {
9+
var elt: (repeat each C.Element)
10+
}
11+
12+
struct Index {
13+
let i: (repeat each C.Index)
14+
}
15+
16+
var startIndex: Index {
17+
Index(i: (repeat (each c).startIndex))
18+
}
19+
20+
var endIndex: Index {
21+
Index(i: (repeat (each c).endIndex))
22+
}
23+
24+
func index(after i: Index) -> Index {
25+
Index(i: (repeat (each c).index(after: each i.i)))
26+
}
27+
28+
subscript(index: Index) -> Element {
29+
Element(elt: (repeat (each c)[each index.i]))
30+
}
31+
}
32+
33+
extension ZipCollection.Index: Equatable {
34+
static func ==(lhs: Self, rhs: Self) -> Bool {
35+
var result = true
36+
repeat result = ((each lhs.i) == (each rhs.i)) && result
37+
return result
38+
}
39+
}
40+
41+
extension ZipCollection.Index: Comparable {
42+
static func <(lhs: Self, rhs: Self) -> Bool {
43+
var result: Bool? = nil
44+
func check<T: Comparable>(_ x: T, _ y: T) {
45+
if result == nil {
46+
if x == y { return }
47+
if x < y { result = true }
48+
if x > y { result = false }
49+
}
50+
}
51+
repeat check(each lhs.i, each rhs.i)
52+
return result ?? false
53+
}
54+
}

0 commit comments

Comments
 (0)