Skip to content

Commit 8421669

Browse files
committed
Pass down the substitutions of the original pattern when extracting
a subst abstraction pattern from a generic nominal type.
1 parent 280c91a commit 8421669

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,8 +1961,11 @@ class SubstFunctionTypePatternVisitor
19611961
: CanType(CanMetatypeType::get(substInstance));
19621962
}
19631963

1964-
CanType handleGenericNominalType(CanType orig, CanType subst,
1965-
CanGenericSignature origSig) {
1964+
CanType handleGenericNominalType(AbstractionPattern origPattern, CanType subst) {
1965+
CanType orig = origPattern.getType();
1966+
CanGenericSignature origSig = origPattern.getGenericSignatureOrNull();
1967+
auto origPatternSubs = origPattern.getGenericSubstitutions();
1968+
19661969
// If there are no loose type parameters in the pattern here, we don't need
19671970
// to do a recursive visit at all.
19681971
if (!orig->hasTypeParameter()
@@ -2007,6 +2010,7 @@ class SubstFunctionTypePatternVisitor
20072010
if (differentOrigClass) {
20082011
orig = subst;
20092012
origSig = TC.getCurGenericSignature();
2013+
origPatternSubs = SubstitutionMap();
20102014
assert((!subst->hasTypeParameter() || origSig) &&
20112015
"lowering mismatched interface types in a context without "
20122016
"a generic signature");
@@ -2028,7 +2032,8 @@ class SubstFunctionTypePatternVisitor
20282032
->getCanonicalType();
20292033

20302034
replacementTypes[gp->getCanonicalType()->castTo<SubstitutableType>()]
2031-
= visit(substParamTy, AbstractionPattern(origSig, origParamTy));
2035+
= visit(substParamTy,
2036+
AbstractionPattern(origPatternSubs, origSig, origParamTy));
20322037
}
20332038

20342039
auto newSubMap = SubstitutionMap::get(nomGenericSig,
@@ -2048,8 +2053,7 @@ class SubstFunctionTypePatternVisitor
20482053
// If the type is generic (because it's a nested type in a generic context),
20492054
// process the generic type bindings.
20502055
if (!isa<ProtocolDecl>(nomDecl) && nomDecl->isGenericContext()) {
2051-
return handleGenericNominalType(pattern.getType(), nom,
2052-
pattern.getGenericSignatureOrNull());
2056+
return handleGenericNominalType(pattern, nom);
20532057
}
20542058

20552059
// Otherwise, there are no structural type parameters to visit.
@@ -2058,8 +2062,7 @@ class SubstFunctionTypePatternVisitor
20582062

20592063
CanType visitBoundGenericType(CanBoundGenericType bgt,
20602064
AbstractionPattern pattern) {
2061-
return handleGenericNominalType(pattern.getType(), bgt,
2062-
pattern.getGenericSignatureOrNull());
2065+
return handleGenericNominalType(pattern, bgt);
20632066
}
20642067

20652068
CanType visitPackType(CanPackType pack, AbstractionPattern pattern) {
@@ -2085,7 +2088,7 @@ class SubstFunctionTypePatternVisitor
20852088
// the pack substitution for that parameter recorded in the pattern.
20862089

20872090
// Remember that we're within an expansion.
2088-
// FIXME: when we introduce PackReferenceType we'll need to be clear
2091+
// FIXME: when we introduce PackElementType we'll need to be clear
20892092
// about which pack expansions to treat this way.
20902093
llvm::SaveAndRestore<bool> scope(WithinExpansion, true);
20912094

test/SILGen/variadic-generic-closures.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ public struct G<T> {}
99
public func caller<each T>(fn: (repeat G<each T>) -> ()) {
1010
fn(repeat G<each T>())
1111
}
12+
13+
// rdar://107108803
14+
public struct UsesG<each Input> {
15+
public init<E>(builder: (repeat G<each Input>) -> E) {}
16+
}
17+
UsesG<Int, String, Bool> { a, b, c in 0 }

0 commit comments

Comments
 (0)