Skip to content

Commit 999dbec

Browse files
authored
Merge pull request #64464 from rjmccall/pack-argument-reabstraction
A myriad of fixes, including the reabstraction of pack argument values
2 parents e087759 + cd3765c commit 999dbec

File tree

9 files changed

+598
-258
lines changed

9 files changed

+598
-258
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ class AbstractionPattern {
915915
// don't want to try to unique by Clang node.
916916
//
917917
// Even if we support Clang nodes someday, we *cannot* cache
918-
// by the open-coded patterns like Tuple and PackExpansion.
918+
// by the open-coded patterns like Tuple.
919919
return getKind() == Kind::Type || getKind() == Kind::Opaque
920920
|| getKind() == Kind::Discard;
921921
}
@@ -980,7 +980,8 @@ class AbstractionPattern {
980980
case Kind::Type:
981981
case Kind::ClangType:
982982
case Kind::Discard: {
983-
return getType()->isParameterPack();
983+
auto ty = getType();
984+
return isa<PackArchetypeType>(ty) || ty->isParameterPack();
984985
}
985986
default:
986987
return false;
@@ -1470,6 +1471,18 @@ class AbstractionPattern {
14701471
AbstractionPattern getPackExpansionComponentType(CanType substType) const;
14711472
AbstractionPattern getPackExpansionComponentType(bool isExpansion) const;
14721473

1474+
/// Given that the value being abstracted is a metatype type, return
1475+
/// the abstraction pattern for its instance type.
1476+
AbstractionPattern getMetatypeInstanceType() const;
1477+
1478+
/// Given that the value being abstracted is a dynamic self type, return
1479+
/// the abstraction pattern for its self type.
1480+
AbstractionPattern getDynamicSelfSelfType() const;
1481+
1482+
/// Given that the value being abstracted is a parameterized protocol
1483+
/// type, return the abstraction pattern for one of its argument types.
1484+
AbstractionPattern getParameterizedProtocolArgType(unsigned i) const;
1485+
14731486
/// Given that the value being abstracted is a function, return the
14741487
/// abstraction pattern for its result type.
14751488
AbstractionPattern getFunctionResultType() const;

lib/AST/SubstitutionMap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ SubstitutionMap SubstitutionMap::subst(TypeSubstitutionFn subs,
458458
continue;
459459
}
460460
newSubs.push_back(type.subst(subs, conformances, options));
461+
assert(type->is<PackType>() == newSubs.back()->is<PackType>() &&
462+
"substitution changed the pack-ness of a replacement type");
461463
}
462464

463465
SmallVector<ProtocolConformanceRef, 4> newConformances;

lib/AST/Type.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5311,28 +5311,16 @@ case TypeKind::Id:
53115311
case TypeKind::SILFunction: {
53125312
auto fnTy = cast<SILFunctionType>(base);
53135313
bool changed = false;
5314-
auto hasTypeErasedGenericClassType = [](Type ty) -> bool {
5315-
return ty.findIf([](Type subType) -> bool {
5316-
if (subType->isTypeErasedGenericClassType())
5317-
return true;
5318-
else
5319-
return false;
5320-
});
5321-
};
53225314
auto updateSubs = [&](SubstitutionMap &subs) -> bool {
5323-
// This interface isn't suitable for updating the substitution map in a
5324-
// substituted SILFunctionType.
5325-
// TODO(SILFunctionType): Is it suitable for any SILFunctionType??
5315+
// This interface isn't suitable for doing most transformations on
5316+
// a substituted SILFunctionType, but it's too hard to come up with
5317+
// an assertion that meaningfully captures what restrictions are in
5318+
// place. Generally the restriction that you can't naively substitute
5319+
// a SILFunctionType using AST mechanisms will have to be good enough.
53265320
SmallVector<Type, 4> newReplacements;
53275321
for (Type type : subs.getReplacementTypes()) {
53285322
auto transformed =
53295323
type.transformWithPosition(TypePosition::Invariant, fn);
5330-
assert((type->isEqual(transformed) ||
5331-
(type->hasTypeParameter() && transformed->hasTypeParameter()) ||
5332-
(hasTypeErasedGenericClassType(type) &&
5333-
hasTypeErasedGenericClassType(transformed))) &&
5334-
"Substituted SILFunctionType can't be transformed into a "
5335-
"concrete type");
53365324
newReplacements.push_back(transformed->getCanonicalType());
53375325
if (!type->isEqual(transformed))
53385326
changed = true;

0 commit comments

Comments
 (0)