Skip to content

Commit 2cda7a7

Browse files
authored
Merge pull request #67004 from slavapestov/rdar111219086-5.9
SIL: Pass SubstFlags::PreservePackExpansionLevel in a few places [5.9]
2 parents d348e3d + abda4dd commit 2cda7a7

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class SubstitutionMap {
168168

169169
/// Query whether any replacement types in the map contain an opened
170170
/// existential.
171-
bool hasOpenedExistential() const;
171+
bool hasLocalArchetypes() const;
172172

173173
/// Query whether any replacement types in the map contain dynamic Self.
174174
bool hasDynamicSelf() const;

include/swift/SIL/SILCloner.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
192192
// If we have local archetypes to substitute, check whether that's
193193
// relevant to this particular substitution.
194194
if (!LocalArchetypeSubs.empty()) {
195-
for (auto ty : Subs.getReplacementTypes()) {
195+
if (Subs.hasLocalArchetypes()) {
196196
// If we found a type containing a local archetype, substitute
197197
// open existentials throughout the substitution map.
198-
if (ty->hasLocalArchetype()) {
199-
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{
200-
LocalArchetypeSubs},
201-
MakeAbstractConformanceForGenericType());
202-
break;
203-
}
198+
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
199+
MakeAbstractConformanceForGenericType(),
200+
SubstFlags::PreservePackExpansionLevel);
204201
}
205202
}
206203

@@ -223,7 +220,9 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
223220
return Ty.subst(
224221
Builder.getModule(),
225222
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
226-
MakeAbstractConformanceForGenericType());
223+
MakeAbstractConformanceForGenericType(),
224+
CanGenericSignature(),
225+
SubstFlags::PreservePackExpansionLevel);
227226
}
228227
SILType getOpType(SILType Ty) {
229228
Ty = getTypeInClonedContext(Ty);
@@ -242,7 +241,8 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
242241

243242
return ty.subst(
244243
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
245-
MakeAbstractConformanceForGenericType()
244+
MakeAbstractConformanceForGenericType(),
245+
SubstFlags::PreservePackExpansionLevel
246246
)->getCanonicalType();
247247
}
248248

@@ -355,7 +355,8 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
355355
conformance.subst(ty,
356356
QueryTypeSubstitutionMapOrIdentity{
357357
LocalArchetypeSubs},
358-
MakeAbstractConformanceForGenericType());
358+
MakeAbstractConformanceForGenericType(),
359+
SubstFlags::PreservePackExpansionLevel);
359360
}
360361

361362
return asImpl().remapConformance(getASTTypeInClonedContext(ty),

lib/AST/SubstitutionMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ bool SubstitutionMap::hasArchetypes() const {
132132
return false;
133133
}
134134

135-
bool SubstitutionMap::hasOpenedExistential() const {
135+
bool SubstitutionMap::hasLocalArchetypes() const {
136136
for (Type replacementTy : getReplacementTypesBuffer()) {
137-
if (replacementTy && replacementTy->hasOpenedExistential())
137+
if (replacementTy && replacementTy->hasLocalArchetype())
138138
return true;
139139
}
140140
return false;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -emit-sil -O %s | %FileCheck %s
2+
3+
@_optimize(none)
4+
public func callee<T, each X>(_: T, _: repeat each X) {}
5+
6+
@_transparent
7+
public func caller<each X>(_ x: repeat each X) {
8+
repeat callee(each x, repeat each x)
9+
}
10+
11+
public func outerCaller<each X>(_ x: repeat each X) {
12+
caller(repeat each x)
13+
}
14+
15+
// CHECK-LABEL: sil @$s28variadic_generics_sil_cloner11outerCalleryyxxQpRvzlF : $@convention(thin) <each X> (@pack_guaranteed Pack{repeat each X}) -> () {
16+
// CHECK: [[CALLEE:%.*]] = function_ref @$s28variadic_generics_sil_cloner6calleeyyx_q_q_QptRv_r0_lF : $@convention(thin) <τ_0_0, each τ_0_1> (@in_guaranteed τ_0_0, @pack_guaranteed Pack{repeat each τ_0_1}) -> ()
17+
// CHECK: apply [[CALLEE]]<@pack_element("{{.*}}") each X, Pack{repeat each X}>(
18+
// CHECK: // end sil function '$s28variadic_generics_sil_cloner11outerCalleryyxxQpRvzlF'

0 commit comments

Comments
 (0)