Skip to content

A couple of tiny variadic generic fixes [5.9] #66443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {

// For the second step, we're looking into the requirement signature for
// this protocol.
if (conformance.isPack()) {
auto pack = conformance.getPack();
conformance = ProtocolConformanceRef(
pack->getAssociatedConformance(step.first, step.second));
if (conformance.isInvalid())
return conformance;

continue;
}

auto concrete = conformance.getConcrete();
auto normal = concrete->getRootNormalConformance();

Expand Down
4 changes: 3 additions & 1 deletion lib/SIL/IR/SILTypeSubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class SILTypeSubstituter :
ProtocolConformanceRef(conformedProtocol),
conformingReplacementType->getCanonicalType(),
typeExpansionContext);
}, SubstFlags::SubstituteOpaqueArchetypes);
},
SubstFlags::SubstituteOpaqueArchetypes |
SubstFlags::PreservePackExpansionLevel);
}

// Substitute a function type.
Expand Down
13 changes: 13 additions & 0 deletions test/SILGen/variadic_generic_conformances.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %target-swift-frontend -emit-silgen %s -disable-availability-checking

protocol P {
associatedtype A: P
}

struct S: P {
typealias A = S
}

func f<each T: P>(_: repeat each T) -> (repeat each T.A.A.A.A) {}

f(S(), S(), S())
54 changes: 54 additions & 0 deletions validation-test/compiler_crashers_2_fixed/rdar110363503.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking

struct ZipCollection<each C: Collection> {
let c: (repeat each C)
}

extension ZipCollection: Collection {
struct Element {
var elt: (repeat each C.Element)
}

struct Index {
let i: (repeat each C.Index)
}

var startIndex: Index {
Index(i: (repeat (each c).startIndex))
}

var endIndex: Index {
Index(i: (repeat (each c).endIndex))
}

func index(after i: Index) -> Index {
Index(i: (repeat (each c).index(after: each i.i)))
}

subscript(index: Index) -> Element {
Element(elt: (repeat (each c)[each index.i]))
}
}

extension ZipCollection.Index: Equatable {
static func ==(lhs: Self, rhs: Self) -> Bool {
var result = true
repeat result = ((each lhs.i) == (each rhs.i)) && result
return result
}
}

extension ZipCollection.Index: Comparable {
static func <(lhs: Self, rhs: Self) -> Bool {
var result: Bool? = nil
func check<T: Comparable>(_ x: T, _ y: T) {
if result == nil {
if x == y { return }
if x < y { result = true }
if x > y { result = false }
}
}
repeat check(each lhs.i, each rhs.i)
return result ?? false
}
}