Skip to content

Commit 2146a5a

Browse files
committed
AST: Remove some usages of SubstFlags::PreservePackExpansionLevel
1 parent 61f4d6f commit 2146a5a

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
196196
// If we found a type containing a local archetype, substitute
197197
// open existentials throughout the substitution map.
198198
Subs = Subs.subst(QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
199-
MakeAbstractConformanceForGenericType(),
200-
SubstFlags::PreservePackExpansionLevel);
199+
MakeAbstractConformanceForGenericType());
201200
}
202201
}
203202

@@ -221,8 +220,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
221220
Builder.getModule(),
222221
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
223222
MakeAbstractConformanceForGenericType(),
224-
CanGenericSignature(),
225-
SubstFlags::PreservePackExpansionLevel);
223+
CanGenericSignature());
226224
}
227225
SILType getOpType(SILType Ty) {
228226
Ty = getTypeInClonedContext(Ty);
@@ -241,8 +239,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
241239

242240
return ty.subst(
243241
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
244-
MakeAbstractConformanceForGenericType(),
245-
SubstFlags::PreservePackExpansionLevel
242+
MakeAbstractConformanceForGenericType()
246243
)->getCanonicalType();
247244
}
248245

@@ -355,8 +352,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
355352
conformance.subst(ty,
356353
QueryTypeSubstitutionMapOrIdentity{
357354
LocalArchetypeSubs},
358-
MakeAbstractConformanceForGenericType(),
359-
SubstFlags::PreservePackExpansionLevel);
355+
MakeAbstractConformanceForGenericType());
360356
}
361357

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

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,14 @@ std::string ASTMangler::mangleAutoDiffGeneratedDeclaration(
653653
static Type getTypeForDWARFMangling(Type t) {
654654
return t.subst(
655655
[](SubstitutableType *t) -> Type {
656-
if (isa<GenericTypeParamType>(t))
657-
return t->getCanonicalType();
658-
return t;
656+
if (isa<GenericTypeParamType>(t) &&
657+
cast<GenericTypeParamType>(t)->isParameterPack()) {
658+
return PackType::getSingletonPackExpansion(t->getCanonicalType());
659+
}
660+
return t->getCanonicalType();
659661
},
660662
MakeAbstractConformanceForGenericType(),
661-
SubstFlags::AllowLoweredTypes |
662-
SubstFlags::PreservePackExpansionLevel);
663+
SubstFlags::AllowLoweredTypes);
663664
}
664665

665666
std::string ASTMangler::mangleTypeForDebugger(Type Ty, GenericSignature sig) {

lib/AST/RequirementEnvironment.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ RequirementEnvironment::RequirementEnvironment(
4343
auto concreteType = conformanceDC->getSelfInterfaceType();
4444
auto conformanceSig = conformanceDC->getGenericSignatureOfContext();
4545

46+
auto conformanceToWitnessThunkGenericParamFn = [&](GenericTypeParamType *genericParam)
47+
-> GenericTypeParamType * {
48+
return GenericTypeParamType::get(genericParam->isParameterPack(),
49+
genericParam->getDepth() + (covariantSelf ? 1 : 0),
50+
genericParam->getIndex(), ctx);
51+
};
52+
4653
// This is a substitution function from the generic parameters of the
4754
// conforming type to the witness thunk environment.
4855
//
@@ -53,25 +60,20 @@ RequirementEnvironment::RequirementEnvironment(
5360
// This is a raw function rather than a substitution map because we need to
5461
// keep generic parameters as generic, even if the conformanceSig (the best
5562
// way to create the substitution map) equates them to concrete types.
56-
auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) {
63+
auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) -> Type {
5764
auto *genericParam = cast<GenericTypeParamType>(type);
58-
if (covariantSelf) {
59-
return GenericTypeParamType::get(genericParam->isParameterPack(),
60-
genericParam->getDepth() + 1,
61-
genericParam->getIndex(), ctx);
62-
}
65+
auto t = conformanceToWitnessThunkGenericParamFn(genericParam);
66+
if (t->isParameterPack())
67+
return PackType::getSingletonPackExpansion(t);
6368

64-
return GenericTypeParamType::get(genericParam->isParameterPack(),
65-
genericParam->getDepth(),
66-
genericParam->getIndex(), ctx);
69+
return t;
6770
};
6871
auto conformanceToWitnessThunkConformanceFn =
6972
MakeAbstractConformanceForGenericType();
7073

7174
auto substConcreteType = concreteType.subst(
7275
conformanceToWitnessThunkTypeFn,
73-
conformanceToWitnessThunkConformanceFn,
74-
SubstFlags::PreservePackExpansionLevel);
76+
conformanceToWitnessThunkConformanceFn);
7577

7678
// Calculate the depth at which the requirement's generic parameters
7779
// appear in the witness thunk signature.
@@ -168,9 +170,8 @@ RequirementEnvironment::RequirementEnvironment(
168170
// Now, add all generic parameters from the conforming type.
169171
if (conformanceSig) {
170172
for (auto param : conformanceSig.getGenericParams()) {
171-
auto substParam = Type(param).subst(conformanceToWitnessThunkTypeFn,
172-
conformanceToWitnessThunkConformanceFn);
173-
genericParamTypes.push_back(substParam->castTo<GenericTypeParamType>());
173+
auto substParam = conformanceToWitnessThunkGenericParamFn(param);
174+
genericParamTypes.push_back(substParam);
174175
}
175176
}
176177

lib/AST/TypeSubstitution.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ QueryTypeSubstitutionMapOrIdentity::operator()(SubstitutableType *type) const {
5555
auto known = substitutions.find(key);
5656
if (known != substitutions.end() && known->second)
5757
return known->second;
58-
58+
59+
if (isa<PackArchetypeType>(type) ||
60+
(isa<GenericTypeParamType>(type) &&
61+
cast<GenericTypeParamType>(type)->isParameterPack())) {
62+
return PackType::getSingletonPackExpansion(type);
63+
}
64+
5965
return type;
6066
}
6167

0 commit comments

Comments
 (0)