Skip to content

Commit 76ec591

Browse files
committed
AST: hasOpenedExistentialWithRoot() => hasLocalArchetypeFromEnvironment()
1 parent 28078d6 commit 76ec591

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
752752
return getRecursiveProperties().hasParameterizedExistential();
753753
}
754754

755-
/// Determine whether the type involves the given opened existential
756-
/// archetype.
757-
bool hasOpenedExistentialWithRoot(const OpenedArchetypeType *root) const;
755+
/// Determine whether the type involves a local archetype from the given
756+
/// environment.
757+
bool hasLocalArchetypeFromEnvironment(GenericEnvironment *env) const;
758758

759759
/// Determine whether the type involves an opaque type.
760760
bool hasOpaqueArchetype() const {

lib/AST/Type.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,14 @@ bool TypeBase::isSpecialized() {
520520
return false;
521521
}
522522

523-
bool TypeBase::hasOpenedExistentialWithRoot(
524-
const OpenedArchetypeType *root) const {
525-
assert(root->isRoot() && "Expected a root archetype");
526-
527-
if (!hasOpenedExistential())
523+
bool TypeBase::hasLocalArchetypeFromEnvironment(
524+
GenericEnvironment *env) const {
525+
if (!hasLocalArchetype())
528526
return false;
529527

530528
return getCanonicalType().findIf([&](Type type) -> bool {
531-
auto *opened = dyn_cast<OpenedArchetypeType>(type.getPointer());
532-
if (!opened)
533-
return false;
534-
535-
return opened->getRoot() == root;
529+
auto *local = dyn_cast<LocalArchetypeType>(type.getPointer());
530+
return local && local->getGenericEnvironment() == env;
536531
});
537532
}
538533

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,9 @@ static bool canReplaceCopiedArg(FullApplySite Apply, SILValue Arg,
947947
static bool applyInvolvesOpenedArchetypeWithRoot(FullApplySite Apply,
948948
OpenedArchetypeType *RootOA,
949949
unsigned SkipArgIdx) {
950-
if (Apply.getType().getASTType()->hasOpenedExistentialWithRoot(RootOA)) {
950+
auto *env = RootOA->getGenericEnvironment();
951+
952+
if (Apply.getType().getASTType()->hasLocalArchetypeFromEnvironment(env)) {
951953
return true;
952954
}
953955

@@ -958,7 +960,7 @@ static bool applyInvolvesOpenedArchetypeWithRoot(FullApplySite Apply,
958960
if (Apply.getArgument(Idx)
959961
->getType()
960962
.getASTType()
961-
->hasOpenedExistentialWithRoot(RootOA)) {
963+
->hasLocalArchetypeFromEnvironment(env)) {
962964
return true;
963965
}
964966
}

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,10 @@ namespace {
956956
// If we had a return type of 'Self', erase it.
957957
Type resultTy;
958958
resultTy = cs.getType(result);
959-
if (resultTy->hasOpenedExistentialWithRoot(record.Archetype)) {
959+
960+
auto *env = record.Archetype->getGenericEnvironment();
961+
962+
if (resultTy->hasLocalArchetypeFromEnvironment(env)) {
960963
Type erasedTy = constraints::typeEraseOpenedArchetypesWithRoot(
961964
resultTy, record.Archetype);
962965
auto range = result->getSourceRange();

0 commit comments

Comments
 (0)