Skip to content

Commit b597f6b

Browse files
committed
Consolidate get(Opaque|Opened)TypeArchetypeProperties into archetypeProperties()
1 parent ada0ceb commit b597f6b

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

include/swift/AST/Types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6556,6 +6556,14 @@ class ArchetypeType : public SubstitutableType,
65566556
}
65576557

65586558
public:
6559+
/// Compute the recursive type properties for an archtype, merging the
6560+
/// given properties with those derived from the other arguments.
6561+
static RecursiveTypeProperties archetypeProperties(
6562+
RecursiveTypeProperties properties,
6563+
ArrayRef<ProtocolDecl *> conformsTo,
6564+
Type superclass,
6565+
SubstitutionMap subs);
6566+
65596567
/// Retrieve the name of this archetype.
65606568
Identifier getName() const;
65616569

lib/AST/ASTContext.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5419,20 +5419,13 @@ DependentMemberType *DependentMemberType::get(Type base,
54195419
return known;
54205420
}
54215421

5422-
/// Compute the recursive type properties of an opaque type archetype.
5423-
static RecursiveTypeProperties getOpaqueTypeArchetypeProperties(
5424-
SubstitutionMap subs) {
5425-
RecursiveTypeProperties properties =
5426-
RecursiveTypeProperties::HasOpaqueArchetype;
5427-
properties |= subs.getRecursiveProperties();
5428-
return properties;
5429-
}
5430-
54315422
OpaqueTypeArchetypeType *OpaqueTypeArchetypeType::getNew(
54325423
GenericEnvironment *environment, Type interfaceType,
54335424
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
54345425
LayoutConstraint layout) {
5435-
auto properties = getOpaqueTypeArchetypeProperties(
5426+
auto properties = archetypeProperties(
5427+
RecursiveTypeProperties::HasOpaqueArchetype,
5428+
conformsTo, superclass,
54365429
environment->getOuterSubstitutions());
54375430
auto arena = getArena(properties);
54385431
auto size = OpaqueTypeArchetypeType::totalSizeToAlloc<
@@ -5451,19 +5444,12 @@ Type OpaqueTypeArchetypeType::get(
54515444
return env->getOrCreateArchetypeFromInterfaceType(interfaceType);
54525445
}
54535446

5454-
/// Compute the recursive type properties of an opened existential archetype.
5455-
static RecursiveTypeProperties getOpenedArchetypeProperties(SubstitutionMap subs) {
5456-
RecursiveTypeProperties properties =
5457-
RecursiveTypeProperties::HasOpenedExistential;
5458-
properties |= subs.getRecursiveProperties();
5459-
return properties;
5460-
}
5461-
54625447
CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
54635448
GenericEnvironment *environment, Type interfaceType,
54645449
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
54655450
LayoutConstraint layout) {
5466-
auto properties = getOpenedArchetypeProperties(
5451+
auto properties = archetypeProperties(
5452+
RecursiveTypeProperties::HasOpenedExistential, conformsTo, superclass,
54675453
environment->getOuterSubstitutions());
54685454
auto arena = getArena(properties);
54695455
auto size = OpenedArchetypeType::totalSizeToAlloc<
@@ -5658,7 +5644,8 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
56585644

56595645
auto &ctx = opaque->getASTContext();
56605646

5661-
auto properties = getOpaqueTypeArchetypeProperties(subs);
5647+
auto properties = ArchetypeType::archetypeProperties(
5648+
RecursiveTypeProperties::HasOpaqueArchetype, { }, Type(), subs);
56625649
auto arena = getArena(properties);
56635650
auto &environments
56645651
= ctx.getImpl().getArena(arena).OpaqueArchetypeEnvironments;
@@ -5706,7 +5693,11 @@ GenericEnvironment::forOpenedExistential(
57065693

57075694
auto &ctx = existential->getASTContext();
57085695

5709-
auto properties = getOpenedArchetypeProperties(subs);
5696+
auto layout = existential->getExistentialLayout();
5697+
auto properties = ArchetypeType::archetypeProperties(
5698+
RecursiveTypeProperties::HasOpenedExistential,
5699+
layout.getProtocols(), layout.getSuperclass(), subs);
5700+
57105701
auto arena = getArena(properties);
57115702

57125703
auto key = std::make_pair(subs, uuid);

lib/AST/Type.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,11 +3494,14 @@ std::string ArchetypeType::getFullName() const {
34943494
}
34953495

34963496
/// Determine the recursive type properties for an archetype.
3497-
static RecursiveTypeProperties archetypeProperties(
3497+
RecursiveTypeProperties ArchetypeType::archetypeProperties(
34983498
RecursiveTypeProperties properties,
34993499
ArrayRef<ProtocolDecl *> conformsTo,
3500-
Type superclass
3500+
Type superclass,
3501+
SubstitutionMap subs
35013502
) {
3503+
properties |= subs.getRecursiveProperties();
3504+
35023505
for (auto proto : conformsTo) {
35033506
if (proto->isUnsafe()) {
35043507
properties |= RecursiveTypeProperties::IsUnsafe;
@@ -3538,7 +3541,7 @@ PrimaryArchetypeType::getNew(const ASTContext &Ctx,
35383541

35393542
RecursiveTypeProperties Properties = archetypeProperties(
35403543
RecursiveTypeProperties::HasPrimaryArchetype,
3541-
ConformsTo, Superclass);
3544+
ConformsTo, Superclass, SubstitutionMap());
35423545
assert(!Properties.hasTypeVariable());
35433546

35443547
auto arena = AllocationArena::Permanent;
@@ -3611,7 +3614,7 @@ PackArchetypeType::get(const ASTContext &Ctx,
36113614
RecursiveTypeProperties properties = archetypeProperties(
36123615
(RecursiveTypeProperties::HasPrimaryArchetype |
36133616
RecursiveTypeProperties::HasPackArchetype),
3614-
ConformsTo, Superclass);
3617+
ConformsTo, Superclass, SubstitutionMap());
36153618
assert(!properties.hasTypeVariable());
36163619

36173620
auto arena = AllocationArena::Permanent;

0 commit comments

Comments
 (0)