Skip to content

Commit b08a6f5

Browse files
committed
[AST] Drop resilience expansion from TypeBase::getReferenceCounting().
We’re not using this parameter, and don’t expect to do so in the future, so remove it. Also fold away TypeBase::usesNativeReferenceCounting() and irgen::getReferenceCountingForType(), both of which are trivial.
1 parent 36dc43a commit b08a6f5

File tree

10 files changed

+18
-43
lines changed

10 files changed

+18
-43
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,9 @@ class alignas(1 << TypeAlignInBits) TypeBase {
841841
/// unknown-released.
842842
bool hasRetainablePointerRepresentation();
843843

844-
/// \brief Given that this type is a reference type, is it known to use
845-
/// Swift-native reference counting?
846-
bool usesNativeReferenceCounting(ResilienceExpansion resilience);
847-
848844
/// Given that this type is a reference type, which kind of reference
849845
/// counting does it use?
850-
ReferenceCounting getReferenceCounting(ResilienceExpansion resilience);
846+
ReferenceCounting getReferenceCounting();
851847

852848
/// Determines whether this type has a bridgeable object
853849
/// representation, i.e., whether it is always represented as a single

lib/AST/Type.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,13 +3994,10 @@ bool UnownedStorageType::isLoadable(ResilienceExpansion resilience) const {
39943994
auto ty = getReferentType();
39953995
if (auto underlyingTy = ty->getOptionalObjectType())
39963996
ty = underlyingTy;
3997-
return ty->usesNativeReferenceCounting(resilience);
3997+
return ty->getReferenceCounting() == ReferenceCounting::Native;
39983998
}
39993999

4000-
static ReferenceCounting getClassReferenceCounting(
4001-
ClassDecl *theClass,
4002-
ResilienceExpansion resilience) {
4003-
// TODO: Resilience? there might be some legal avenue of changing this.
4000+
static ReferenceCounting getClassReferenceCounting(ClassDecl *theClass) {
40044001
while (auto superclass = theClass->getSuperclassDecl()) {
40054002
theClass = superclass;
40064003
}
@@ -4010,8 +4007,7 @@ static ReferenceCounting getClassReferenceCounting(
40104007
: ReferenceCounting::Native;
40114008
}
40124009

4013-
ReferenceCounting TypeBase::getReferenceCounting(
4014-
ResilienceExpansion resilience) {
4010+
ReferenceCounting TypeBase::getReferenceCounting() {
40154011
CanType type = getCanonicalType();
40164012
ASTContext &ctx = type->getASTContext();
40174013

@@ -4037,20 +4033,17 @@ ReferenceCounting TypeBase::getReferenceCounting(
40374033
return ReferenceCounting::Unknown;
40384034

40394035
case TypeKind::Class:
4040-
return getClassReferenceCounting(cast<ClassType>(type)->getDecl(),
4041-
resilience);
4036+
return getClassReferenceCounting(cast<ClassType>(type)->getDecl());
40424037
case TypeKind::BoundGenericClass:
40434038
return getClassReferenceCounting(
4044-
cast<BoundGenericClassType>(type)->getDecl(),
4045-
resilience);
4039+
cast<BoundGenericClassType>(type)->getDecl());
40464040
case TypeKind::UnboundGeneric:
40474041
return getClassReferenceCounting(
4048-
cast<ClassDecl>(cast<UnboundGenericType>(type)->getDecl()),
4049-
resilience);
4042+
cast<ClassDecl>(cast<UnboundGenericType>(type)->getDecl()));
40504043

40514044
case TypeKind::DynamicSelf:
40524045
return cast<DynamicSelfType>(type).getSelfType()
4053-
->getReferenceCounting(resilience);
4046+
->getReferenceCounting();
40544047

40554048
case TypeKind::Archetype: {
40564049
auto archetype = cast<ArchetypeType>(type);
@@ -4059,7 +4052,7 @@ ReferenceCounting TypeBase::getReferenceCounting(
40594052
assert(archetype->requiresClass() ||
40604053
(layout && layout->isRefCounted()));
40614054
if (auto supertype = archetype->getSuperclass())
4062-
return supertype->getReferenceCounting(resilience);
4055+
return supertype->getReferenceCounting();
40634056
return ReferenceCounting::Unknown;
40644057
}
40654058

@@ -4068,7 +4061,7 @@ ReferenceCounting TypeBase::getReferenceCounting(
40684061
auto layout = type->getExistentialLayout();
40694062
assert(layout.requiresClass() && "Opaque existentials don't use refcounting");
40704063
if (auto superclass = layout.getSuperclass())
4071-
return superclass->getReferenceCounting(resilience);
4064+
return superclass->getReferenceCounting();
40724065
return ReferenceCounting::Unknown;
40734066
}
40744067

@@ -4106,10 +4099,6 @@ ReferenceCounting TypeBase::getReferenceCounting(
41064099
llvm_unreachable("Unhandled type kind!");
41074100
}
41084101

4109-
bool TypeBase::usesNativeReferenceCounting(ResilienceExpansion resilience) {
4110-
return getReferenceCounting(resilience) == ReferenceCounting::Native;
4111-
}
4112-
41134102
//
41144103
// SILBoxType implementation
41154104
//

lib/IRGen/GenArchetype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
287287
// representation.
288288
if (archetype->requiresClass() ||
289289
(layout && layout->isRefCounted())) {
290-
auto refcount = getReferenceCountingForType(IGM, CanType(archetype));
290+
auto refcount = archetype->getReferenceCounting();
291291

292292
llvm::PointerType *reprTy;
293293

lib/IRGen/GenClass.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@
6161
using namespace swift;
6262
using namespace irgen;
6363

64-
/// What reference counting mechanism does a class-like type have?
65-
ReferenceCounting irgen::getReferenceCountingForType(IRGenModule &IGM,
66-
CanType type) {
67-
return type->getReferenceCounting(ResilienceExpansion::Maximal);
68-
}
69-
7064
namespace {
7165
/// Layout information for class types.
7266
class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> {
@@ -2180,7 +2174,7 @@ const TypeInfo *
21802174
TypeConverter::convertClassType(CanType type, ClassDecl *D) {
21812175
llvm::StructType *ST = IGM.createNominalType(type);
21822176
llvm::PointerType *irType = ST->getPointerTo();
2183-
ReferenceCounting refcount = ::getReferenceCountingForType(IGM, type);
2177+
ReferenceCounting refcount = type->getReferenceCounting();
21842178

21852179
SpareBitVector spareBits;
21862180

lib/IRGen/GenClass.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ namespace irgen {
148148
StructLayout *getClassLayoutWithTailElems(IRGenModule &IGM, SILType classType,
149149
llvm::ArrayRef<SILType> tailTypes);
150150

151-
/// What reference counting mechanism does a class-like type use?
152-
ReferenceCounting getReferenceCountingForType(IRGenModule &IGM,
153-
CanType type);
154-
155151
ClassDecl *getRootClassForMetaclass(IRGenModule &IGM, ClassDecl *theClass);
156152

157153
/// Does the class metadata for the given class require dynamic

lib/IRGen/GenExistential.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ static const TypeInfo *createExistentialTypeInfo(IRGenModule &IGM, CanType T) {
13531353
if (layout.requiresClass()) {
13541354
// If we're not using the Objective-C runtime, we can use the
13551355
// native reference counting entry points.
1356-
ReferenceCounting refcounting = getReferenceCountingForType(IGM, T);
1356+
ReferenceCounting refcounting = T->getReferenceCounting();
13571357

13581358
llvm::PointerType *reprTy = nullptr;
13591359
if (auto superclass = layout.getSuperclass()) {

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,8 +2169,7 @@ namespace {
21692169

21702170
// Set a flag if the class uses Swift refcounting.
21712171
auto type = Target->getDeclaredType()->getCanonicalType();
2172-
if (getReferenceCountingForType(IGM, type)
2173-
== ReferenceCounting::Native) {
2172+
if (type->getReferenceCounting() == ReferenceCounting::Native) {
21742173
flags |= ClassFlags::UsesSwiftRefcounting;
21752174
}
21762175

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
341341

342342
if (auto CD = dyn_cast<ClassDecl>(NTD)) {
343343
auto type = CD->getDeclaredType()->getCanonicalType();
344-
auto RC = getReferenceCountingForType(IGM, type);
344+
auto RC = type->getReferenceCounting();
345345
if (RC == ReferenceCounting::ObjC)
346346
kind = FieldDescriptorKind::ObjCClass;
347347
else

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ namespace {
22682268
DynamicMetadataRequest request) {
22692269
// All class types have the same layout.
22702270
auto type = classDecl->getDeclaredType()->getCanonicalType();
2271-
switch (getReferenceCountingForType(IGF.IGM, type)) {
2271+
switch (type->getReferenceCounting()) {
22722272
case ReferenceCounting::Native:
22732273
return emitFromValueWitnessTable(IGF.IGM.Context.TheNativeObjectType);
22742274

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Builtins.h"
2323
#include "swift/AST/DiagnosticsSIL.h"
2424
#include "swift/AST/Module.h"
25+
#include "swift/AST/ReferenceCounting.h"
2526
#include "swift/SIL/SILArgument.h"
2627
#include "swift/SIL/SILUndef.h"
2728

@@ -366,7 +367,7 @@ static ManagedValue emitBuiltinCastToNativeObject(SILGenFunction &SGF,
366367
SGFContext C) {
367368
auto ty = args[0].getType().getASTType();
368369
(void)ty;
369-
assert(ty->usesNativeReferenceCounting(ResilienceExpansion::Maximal) &&
370+
assert(ty->getReferenceCounting() == ReferenceCounting::Native &&
370371
"Can only cast types that use native reference counting to native "
371372
"object");
372373
return emitBuiltinUnsafeCastToNativeObject(SGF, loc, substitutions,

0 commit comments

Comments
 (0)