Skip to content

Commit aa81ce3

Browse files
committed
AST: Use new form of getOpenedExistentialSignature() in getMinimalCanonicalType()
1 parent 2fbf2f6 commit aa81ce3

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
587587
/// Canonical protocol composition types are minimized only to a certain
588588
/// degree to preserve ABI compatibility. This routine enables performing
589589
/// slower, but stricter minimization at need (e.g. redeclaration checking).
590-
CanType getMinimalCanonicalType(const DeclContext *useDC) const;
590+
CanType getMinimalCanonicalType() const;
591591

592592
/// Reconstitute type sugar, e.g., for array types, dictionary
593593
/// types, optionals, etc.
@@ -6139,7 +6139,7 @@ class ProtocolCompositionType final : public TypeBase,
61396139
/// Canonical protocol composition types are minimized only to a certain
61406140
/// degree to preserve ABI compatibility. This routine enables performing
61416141
/// slower, but stricter minimization at need (e.g. redeclaration checking).
6142-
CanType getMinimalCanonicalType(const DeclContext *useDC) const;
6142+
CanType getMinimalCanonicalType() const;
61436143

61446144
/// Retrieve the set of members composed to create this type.
61456145
///

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
36363636
/*topLevelFunction=*/true, isMethod,
36373637
/*isInitializer=*/isa<ConstructorDecl>(afd),
36383638
getNumCurryLevels())
3639-
->getMinimalCanonicalType(afd);
3639+
->getMinimalCanonicalType();
36403640
}
36413641

36423642
if (isa<AbstractStorageDecl>(this)) {
@@ -3652,7 +3652,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
36523652
/*topLevelFunction=*/true,
36533653
/*isMethod=*/false,
36543654
/*isInitializer=*/false, getNumCurryLevels())
3655-
->getMinimalCanonicalType(cast<SubscriptDecl>(this));
3655+
->getMinimalCanonicalType();
36563656
}
36573657

36583658
// We want to curry the default signature type with the 'self' type of the
@@ -3667,7 +3667,7 @@ CanType ValueDecl::getOverloadSignatureType() const {
36673667
auto mappedType = mapSignatureFunctionType(
36683668
getASTContext(), getInterfaceType(), /*topLevelFunction=*/false,
36693669
/*isMethod=*/false, /*isInitializer=*/false, getNumCurryLevels());
3670-
return mappedType->getMinimalCanonicalType(getDeclContext());
3670+
return mappedType->getMinimalCanonicalType();
36713671
}
36723672

36733673
// Note: If you add more cases to this function, you should update the

lib/AST/Type.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,9 @@ CanType TypeBase::getReducedType(GenericSignature sig) {
18361836
return sig.getReducedType(this);
18371837
}
18381838

1839-
CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
1840-
const auto MinimalTy = getCanonicalType().transformRec([useDC](TypeBase *Ty) -> std::optional<Type> {
1839+
CanType TypeBase::getMinimalCanonicalType() const {
1840+
const auto MinimalTy = getCanonicalType().transformRec(
1841+
[](TypeBase *Ty) -> std::optional<Type> {
18411842
const CanType CanTy = CanType(Ty);
18421843

18431844
if (const auto ET = dyn_cast<ExistentialType>(CanTy)) {
@@ -1847,7 +1848,7 @@ CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
18471848
return CanTy;
18481849
}
18491850

1850-
const auto MinimalTy = PCT->getMinimalCanonicalType(useDC);
1851+
const auto MinimalTy = PCT->getMinimalCanonicalType();
18511852
if (MinimalTy->getClassOrBoundGenericClass()) {
18521853
return MinimalTy;
18531854
}
@@ -1861,7 +1862,7 @@ CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
18611862
return CanTy;
18621863
}
18631864

1864-
const auto MinimalTy = PCT->getMinimalCanonicalType(useDC);
1865+
const auto MinimalTy = PCT->getMinimalCanonicalType();
18651866
if (MinimalTy->getClassOrBoundGenericClass()) {
18661867
return MetatypeType::get(MinimalTy);
18671868
}
@@ -1870,7 +1871,7 @@ CanType TypeBase::getMinimalCanonicalType(const DeclContext *useDC) const {
18701871
}
18711872

18721873
if (const auto Composition = dyn_cast<ProtocolCompositionType>(CanTy)) {
1873-
return Composition->getMinimalCanonicalType(useDC);
1874+
return Composition->getMinimalCanonicalType();
18741875
}
18751876

18761877
return std::nullopt;
@@ -3795,21 +3796,15 @@ Type ProtocolCompositionType::get(const ASTContext &C,
37953796
return build(C, CanTypes, Inverses, HasExplicitAnyObject);
37963797
}
37973798

3798-
CanType ProtocolCompositionType::getMinimalCanonicalType(
3799-
const DeclContext *useDC) const {
3799+
CanType ProtocolCompositionType::getMinimalCanonicalType() const {
38003800
auto &Ctx = getASTContext();
38013801

3802-
// Use generic signature minimization: the requirements of the signature will
3803-
// represent the minimal composition.
3804-
auto parentSig = useDC->getGenericSignatureOfContext();
3805-
auto existentialSig =
3806-
Ctx.getOpenedExistentialSignature(getCanonicalType(), parentSig);
3807-
auto selfTy =
3808-
OpenedArchetypeType::getSelfInterfaceTypeFromContext(parentSig, Ctx);
3809-
return existentialSig->getUpperBound(selfTy,
3810-
/*forExistentialSelf=*/true,
3811-
/*includeParameterizedProtocols=*/true)
3812-
->getCanonicalType();
3802+
auto existentialSig = Ctx.getOpenedExistentialSignature(getCanonicalType());
3803+
auto result = existentialSig.OpenedSig->getUpperBound(
3804+
existentialSig.SelfType,
3805+
/*forExistentialSelf=*/true,
3806+
/*includeParameterizedProtocols=*/true);
3807+
return result.subst(existentialSig.Generalization)->getCanonicalType();
38133808
}
38143809

38153810
ClangTypeInfo AnyFunctionType::getClangTypeInfo() const {

0 commit comments

Comments
 (0)