Skip to content

AST: rename OpenArchetypeType -> ExistentialArchetypeType #79917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Generics/chapters/types.tex
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ \section{Source Code Reference}\label{typesourceref}
\item \texttt{ArchetypeType}, and its three subclasses:
\begin{itemize}
\item \texttt{PrimaryArchetypeType},
\item \texttt{OpenedArchetypeType},
\item \texttt{ExistentialArchetypeType},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn’t have to update this, but thanks! There’s a whole unfinished chapter on existential types I’ll get around to finishing some day…

\item \texttt{OpaqueArchetypeType}.
\end{itemize}
\item The abstract types:
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/ASTBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ bool BridgedASTType::hasLocalArchetype() const {
}

bool BridgedASTType::isExistentialArchetype() const {
return unbridged()->is<swift::OpenedArchetypeType>();
return unbridged()->is<swift::ExistentialArchetypeType>();
}

bool BridgedASTType::isExistentialArchetypeWithError() const {
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace swift {
class ValueDecl;
class Decl;
class DeclRefExpr;
class OpenedArchetypeType;
class ExistentialArchetypeType;
class ParamDecl;
class Pattern;
class SubscriptDecl;
Expand Down Expand Up @@ -3013,7 +3013,7 @@ class OpenExistentialExpr : public Expr {

/// Retrieve the opened archetype, which can only be referenced
/// within this expression's subexpression.
OpenedArchetypeType *getOpenedArchetype() const;
ExistentialArchetypeType *getOpenedArchetype() const;

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::OpenExistential;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/GenericEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ASTContext;
class GenericTypeParamType;
class OpaqueTypeDecl;
class ElementArchetypeType;
class OpenedArchetypeType;
class ExistentialArchetypeType;
class PackArchetypeType;
class PackExpansionType;
class SILModule;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class TypeMatcher {
}
}

// FIXME: Once OpenedArchetypeType stores substitutions, do something
// FIXME: Once ExistentialArchetypeType stores substitutions, do something
// similar to the above.

if (firstArchetype->isEqual(secondType))
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ ABSTRACT_TYPE(Substitutable, Type)
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
ABSTRACT_TYPE(LocalArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(OpenedArchetype, LocalArchetypeType)
ALWAYS_CANONICAL_TYPE(ExistentialArchetype, LocalArchetypeType)
ALWAYS_CANONICAL_TYPE(ElementArchetype, LocalArchetypeType)
TYPE_RANGE(LocalArchetype, OpenedArchetype, ElementArchetype)
TYPE_RANGE(LocalArchetype, ExistentialArchetype, ElementArchetype)
ALWAYS_CANONICAL_TYPE(PackArchetype, ArchetypeType)
TYPE_RANGE(Archetype, PrimaryArchetype, PackArchetype)
TYPE(GenericTypeParam, SubstitutableType)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TypeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ case TypeKind::Id:
newSubMap);
}

case TypeKind::OpenedArchetype: {
case TypeKind::ExistentialArchetype: {
auto *local = cast<LocalArchetypeType>(base);
if (auto result = asDerived().transformLocalArchetypeType(local, pos))
return *result;
Expand Down
25 changes: 14 additions & 11 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GenericSignatureBuilder;
class Identifier;
class InOutType;
class OpaqueTypeDecl;
class OpenedArchetypeType;
class ExistentialArchetypeType;
class PackExpansionType;
class PackType;
enum class ParamSpecifier : uint8_t;
Expand Down Expand Up @@ -114,6 +114,9 @@ enum class TypeKind : uint8_t {
#define TYPE_RANGE(Id, FirstId, LastId) \
First_##Id##Type = FirstId, Last_##Id##Type = LastId,
#include "swift/AST/TypeNodes.def"
// For backward compatibility in LLDB sources.
// TODO: remove this once OpenedArchetype is renamed in LLDB sources.
OpenedArchetype = ExistentialArchetype
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also update lldb at the same time and do a cross-repo test

};

enum : unsigned {
Expand Down Expand Up @@ -6971,16 +6974,16 @@ class LocalArchetypeType : public ArchetypeType {

public:
static bool classof(const TypeBase *type) {
return type->getKind() == TypeKind::OpenedArchetype ||
return type->getKind() == TypeKind::ExistentialArchetype ||
type->getKind() == TypeKind::ElementArchetype;
}
};
BEGIN_CAN_TYPE_WRAPPER(LocalArchetypeType, ArchetypeType)
END_CAN_TYPE_WRAPPER(LocalArchetypeType, ArchetypeType)

/// An archetype that represents the dynamic type of an opened existential.
class OpenedArchetypeType final : public LocalArchetypeType,
private ArchetypeTrailingObjects<OpenedArchetypeType>
class ExistentialArchetypeType final : public LocalArchetypeType,
private ArchetypeTrailingObjects<ExistentialArchetypeType>
{
friend TrailingObjects;
friend ArchetypeType;
Expand All @@ -6991,7 +6994,7 @@ class OpenedArchetypeType final : public LocalArchetypeType,
///
/// This is only invoked by the generic environment when mapping the
/// interface type into context.
static CanTypeWrapper<OpenedArchetypeType>
static CanTypeWrapper<ExistentialArchetypeType>
getNew(GenericEnvironment *environment, Type interfaceType,
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
LayoutConstraint layout);
Expand All @@ -7001,7 +7004,7 @@ class OpenedArchetypeType final : public LocalArchetypeType,
/// of an existential value.
///
/// \param existential The existential type to open.
static CanTypeWrapper<OpenedArchetypeType> get(CanType existential);
static CanTypeWrapper<ExistentialArchetypeType> get(CanType existential);

/// Create a new archetype that represents the opened type
/// of an existential value.
Expand All @@ -7014,18 +7017,18 @@ class OpenedArchetypeType final : public LocalArchetypeType,
static Type getAny(Type existential);

static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::OpenedArchetype;
return T->getKind() == TypeKind::ExistentialArchetype;
}

private:
OpenedArchetypeType(GenericEnvironment *environment, Type interfaceType,
ExistentialArchetypeType(GenericEnvironment *environment, Type interfaceType,
ArrayRef<ProtocolDecl *> conformsTo,
Type superclass,
LayoutConstraint layout,
RecursiveTypeProperties properties);
};
BEGIN_CAN_TYPE_WRAPPER(OpenedArchetypeType, LocalArchetypeType)
END_CAN_TYPE_WRAPPER(OpenedArchetypeType, LocalArchetypeType)
BEGIN_CAN_TYPE_WRAPPER(ExistentialArchetypeType, LocalArchetypeType)
END_CAN_TYPE_WRAPPER(ExistentialArchetypeType, LocalArchetypeType)

/// A wrapper around a shape type to use in ArchetypeTrailingObjects
/// for PackArchetypeType.
Expand Down Expand Up @@ -7111,7 +7114,7 @@ const Type *ArchetypeType::getSubclassTrailingObjects() const {
if (auto opaqueTy = dyn_cast<OpaqueTypeArchetypeType>(this)) {
return opaqueTy->getTrailingObjects<Type>();
}
if (auto openedTy = dyn_cast<OpenedArchetypeType>(this)) {
if (auto openedTy = dyn_cast<ExistentialArchetypeType>(this)) {
return openedTy->getTrailingObjects<Type>();
}
if (auto childTy = dyn_cast<PackArchetypeType>(this)) {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
return numScalarElements == 1;
}

void remapRootOpenedType(CanOpenedArchetypeType archetypeTy) {
void remapRootOpenedType(CanExistentialArchetypeType archetypeTy) {
auto *origEnv = archetypeTy->getGenericEnvironment();

auto genericSig = origEnv->getGenericSignature();
Expand Down
12 changes: 6 additions & 6 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7773,7 +7773,7 @@ class OpenExistentialAddrInst

OpenedExistentialAccess getAccessKind() const { return ForAccess; }

CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand All @@ -7794,7 +7794,7 @@ class OpenExistentialValueInst
ValueOwnershipKind forwardingOwnershipKind);

public:
CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand All @@ -7815,7 +7815,7 @@ class OpenExistentialRefInst
ValueOwnershipKind forwardingOwnershipKind);

public:
CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand All @@ -7837,7 +7837,7 @@ class OpenExistentialMetatypeInst
SILType ty);

public:
CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand All @@ -7858,7 +7858,7 @@ class OpenExistentialBoxInst
SILType ty);

public:
CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand All @@ -7879,7 +7879,7 @@ class OpenExistentialBoxValueInst
ValueOwnershipKind forwardingOwnershipKind);

public:
CanOpenedArchetypeType getDefinedOpenedArchetype() const {
CanExistentialArchetypeType getDefinedOpenedArchetype() const {
const auto archetype = getOpenedArchetypeOf(getType().getASTType());
assert(archetype && archetype->isRoot() &&
"Type should be a root opened archetype");
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace swift {
/// recursively check any children of this type, because
/// this is the task of the type visitor invoking it.
/// \returns The found opened archetype or empty type otherwise.
CanOpenedArchetypeType getOpenedArchetypeOf(CanType Ty);
CanExistentialArchetypeType getOpenedArchetypeOf(CanType Ty);
CanLocalArchetypeType getLocalArchetypeOf(CanType Ty);

/// How an existential type container is represented.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Differentiation/Thunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SILOptFunctionBuilder;
class SILModule;
class SILLocation;
class SILValue;
class OpenedArchetypeType;
class ExistentialArchetypeType;
class GenericEnvironment;
class SubstitutionMap;
class ArchetypeType;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Utils/Existential.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace swift {
/// When successful, ConcreteExistentialInfo can be used to determine the
/// concrete type of the opened existential.
struct OpenedArchetypeInfo {
OpenedArchetypeType *OpenedArchetype = nullptr;
ExistentialArchetypeType *OpenedArchetype = nullptr;
// The opened value.
SingleValueInstruction *OpenedArchetypeValue;
// The existential value.
Expand Down
8 changes: 4 additions & 4 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ class Solution {
llvm::DenseMap<ConstraintLocator *, ArrayRef<OpenedType>> OpenedTypes;

/// The opened existential type for a given locator.
llvm::DenseMap<ConstraintLocator *, OpenedArchetypeType *>
llvm::DenseMap<ConstraintLocator *, ExistentialArchetypeType *>
OpenedExistentialTypes;

llvm::DenseMap<PackExpansionType *, TypeVariableType *>
Expand Down Expand Up @@ -2420,7 +2420,7 @@ class ConstraintSystem {

/// A mapping from constraint locators to the opened existential archetype
/// used for the 'self' of an existential type.
llvm::SmallDenseMap<ConstraintLocator *, OpenedArchetypeType *, 4>
llvm::SmallDenseMap<ConstraintLocator *, ExistentialArchetypeType *, 4>
OpenedExistentialTypes;

llvm::SmallDenseMap<PackExpansionType *, TypeVariableType *, 4>
Expand Down Expand Up @@ -3380,12 +3380,12 @@ class ConstraintSystem {
/// Open the given existential type or existential metatype, recording the
/// opened archetype in the constraint system and returning both the opened
/// type and opened archetype.
std::pair<Type, OpenedArchetypeType *>
std::pair<Type, ExistentialArchetypeType *>
openAnyExistentialType(Type type, ConstraintLocator *locator);

/// Update OpenedExistentials and record a change in the trail.
void recordOpenedExistentialType(ConstraintLocator *locator,
OpenedArchetypeType *opened);
ExistentialArchetypeType *opened);

/// Retrieve the generic environment for the opened element of a given pack
/// expansion, or \c nullptr if no environment was recorded yet.
Expand Down
18 changes: 9 additions & 9 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5601,55 +5601,55 @@ Type OpaqueTypeArchetypeType::get(
return env->getOrCreateArchetypeFromInterfaceType(interfaceType);
}

CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
CanTypeWrapper<ExistentialArchetypeType> ExistentialArchetypeType::getNew(
GenericEnvironment *environment, Type interfaceType,
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
LayoutConstraint layout) {
auto properties = archetypeProperties(
RecursiveTypeProperties::HasOpenedExistential, conformsTo, superclass,
environment->getOuterSubstitutions());
auto arena = getArena(properties);
auto size = OpenedArchetypeType::totalSizeToAlloc<
auto size = ExistentialArchetypeType::totalSizeToAlloc<
ProtocolDecl *, Type, LayoutConstraint>(
conformsTo.size(),
superclass ? 1 : 0,
layout ? 1 : 0);

ASTContext &ctx = interfaceType->getASTContext();
void *mem = ctx.Allocate(size, alignof(OpenedArchetypeType), arena);
void *mem = ctx.Allocate(size, alignof(ExistentialArchetypeType), arena);

return CanOpenedArchetypeType(::new (mem) OpenedArchetypeType(
return CanExistentialArchetypeType(::new (mem) ExistentialArchetypeType(
environment, interfaceType, conformsTo, superclass, layout,
properties));
}

CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential) {
CanExistentialArchetypeType ExistentialArchetypeType::get(CanType existential) {
auto &ctx = existential->getASTContext();
auto existentialSig = ctx.getOpenedExistentialSignature(existential);

auto *genericEnv = GenericEnvironment::forOpenedExistential(
existentialSig.OpenedSig, existentialSig.Shape,
existentialSig.Generalization, UUID::fromTime());

return cast<OpenedArchetypeType>(
return cast<ExistentialArchetypeType>(
genericEnv->mapTypeIntoContext(existentialSig.SelfType)
->getCanonicalType());
}

Type OpenedArchetypeType::getAny(Type existential) {
Type ExistentialArchetypeType::getAny(Type existential) {
assert(existential->isAnyExistentialType());

if (auto metatypeTy = existential->getAs<ExistentialMetatypeType>()) {
auto instanceTy = metatypeTy->getExistentialInstanceType();
auto openedInstanceTy = OpenedArchetypeType::getAny(instanceTy);
auto openedInstanceTy = ExistentialArchetypeType::getAny(instanceTy);
if (metatypeTy->hasRepresentation()) {
return MetatypeType::get(openedInstanceTy,
metatypeTy->getRepresentation());
}
return MetatypeType::get(openedInstanceTy);
}

return OpenedArchetypeType::get(existential->getCanonicalType());
return ExistentialArchetypeType::get(existential->getCanonicalType());
}

void SubstitutionMap::Storage::Profile(
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6105,8 +6105,8 @@ namespace {

printFoot();
}
void visitOpenedArchetypeType(OpenedArchetypeType *T, Label label) {
printArchetypeCommon(T, "opened_archetype_type", label);
void visitExistentialArchetypeType(ExistentialArchetypeType *T, Label label) {
printArchetypeCommon(T, "existential_archetype_type", label);

auto *env = T->getGenericEnvironment();
printFieldQuoted(env->getOpenedExistentialUUID(),
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ std::string ASTMangler::mangleKeyPathGetterThunkHelper(
// FIXME: This seems wrong. We used to just mangle opened archetypes as
// their interface type. Let's make that explicit now.
sub = sub.transformRec([](Type t) -> std::optional<Type> {
if (auto *openedExistential = t->getAs<OpenedArchetypeType>()) {
if (auto *openedExistential = t->getAs<ExistentialArchetypeType>()) {
auto &ctx = openedExistential->getASTContext();
return GenericTypeParamType::getType(0, 0, ctx);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ std::string ASTMangler::mangleKeyPathSetterThunkHelper(
// FIXME: This seems wrong. We used to just mangle opened archetypes as
// their interface type. Let's make that explicit now.
sub = sub.transformRec([](Type t) -> std::optional<Type> {
if (auto *openedExistential = t->getAs<OpenedArchetypeType>()) {
if (auto *openedExistential = t->getAs<ExistentialArchetypeType>()) {
auto &ctx = openedExistential->getASTContext();
return GenericTypeParamType::getType(0, 0, ctx);
}
Expand Down Expand Up @@ -1675,7 +1675,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
case TypeKind::PrimaryArchetype:
case TypeKind::PackArchetype:
case TypeKind::ElementArchetype:
case TypeKind::OpenedArchetype:
case TypeKind::ExistentialArchetype:
llvm::errs() << "Cannot mangle free-standing archetype: ";
tybase->dump(llvm::errs());
abort();
Expand Down
Loading