Skip to content

Commit

Permalink
IRGen: Kill classifyTypeSize(), NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
slavapestov committed Nov 15, 2015
1 parent c469b20 commit f3d5345
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 123 deletions.
108 changes: 0 additions & 108 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,114 +1924,6 @@ bool IRGenModule::isPOD(SILType type, ResilienceScope scope) {
}


namespace {
struct ClassifyTypeSize : CanTypeVisitor<ClassifyTypeSize, ObjectSize> {
IRGenModule &IGM;
ResilienceScope Scope;
ClassifyTypeSize(IRGenModule &IGM, ResilienceScope scope)
: IGM(IGM), Scope(scope) {}

#define ALWAYS(KIND, RESULT) \
ObjectSize visit##KIND##Type(KIND##Type *t) { return ObjectSize::RESULT; }

ALWAYS(Builtin, Fixed)
ALWAYS(SILFunction, Fixed)
ALWAYS(Class, Fixed)
ALWAYS(BoundGenericClass, Fixed)
ALWAYS(Protocol, Fixed)
ALWAYS(ProtocolComposition, Fixed)
ALWAYS(LValue, Dependent)
#undef ALWAYS

ObjectSize visitArchetypeType(CanArchetypeType archetype) {
if (archetype->requiresClass())
return ObjectSize::Fixed;
return ObjectSize::Dependent;
}

ObjectSize visitTupleType(CanTupleType tuple) {
ObjectSize result = ObjectSize::Fixed;
for (auto eltType : tuple.getElementTypes()) {
result = std::max(result, visit(eltType));
}
return result;
}

ObjectSize visitStructType(CanStructType type) {
if (type->getDecl()->getGenericParamsOfContext())
return visitGenericStructType(type, type->getDecl());
if (IGM.isResilient(type->getDecl(), Scope))
return ObjectSize::Resilient;
return ObjectSize::Fixed;
}

ObjectSize visitBoundGenericStructType(CanBoundGenericStructType type) {
return visitGenericStructType(type, type->getDecl());
}

ObjectSize visitGenericStructType(CanType type, StructDecl *D) {
assert(D->getGenericParamsOfContext());

// If a generic struct is resilient, we have to assume that any
// unknown fields might be dependently-sized.
if (IGM.isResilient(D, Scope))
return ObjectSize::Dependent;

auto structType = SILType::getPrimitiveAddressType(type);

ObjectSize result = ObjectSize::Fixed;
for (auto field : D->getStoredProperties()) {
auto fieldType = structType.getFieldType(field, *IGM.SILMod);
result = std::max(result, visitSILType(fieldType));
}
return result;
}

ObjectSize visitEnumType(CanEnumType type) {
if (type->getDecl()->getGenericParamsOfContext())
return visitGenericEnumType(type, type->getDecl());
if (IGM.isResilient(type->getDecl(), Scope))
return ObjectSize::Resilient;
return ObjectSize::Fixed;
}

ObjectSize visitBoundGenericEnumType(CanBoundGenericEnumType type) {
return visitGenericEnumType(type, type->getDecl());
}

ObjectSize visitGenericEnumType(CanType type, EnumDecl *D) {
assert(D->getGenericParamsOfContext());

// If a generic enum is resilient, we have to assume that any
// unknown elements might be dependently-sized.
if (IGM.isResilient(D, Scope))
return ObjectSize::Dependent;

auto enumType = SILType::getPrimitiveAddressType(type);

ObjectSize result = ObjectSize::Fixed;
for (auto elt : D->getAllElements()) {
if (!elt->hasArgumentType()) continue;
auto eltType = enumType.getEnumElementType(elt, *IGM.SILMod);
result = std::max(result, visitSILType(eltType));
}
return result;
}

ObjectSize visitType(CanType type) {
return ObjectSize::Fixed;
}

ObjectSize visitSILType(SILType type) {
return visit(type.getSwiftRValueType());
}
};
}

ObjectSize IRGenModule::classifyTypeSize(SILType type, ResilienceScope scope) {
return ClassifyTypeSize(*this, scope).visitSILType(type);
}

SpareBitVector IRGenModule::getSpareBitsForType(llvm::Type *scalarTy, Size size) {
auto it = SpareBitsForTypes.find(scalarTy);
if (it != SpareBitsForTypes.end())
Expand Down
14 changes: 0 additions & 14 deletions lib/IRGen/IRGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ enum class ResilienceScope {
Universal
};

/// Whether an object is fixed in size or not. This answer is always
/// relative to some resilience scope.
enum class ObjectSize : uint8_t {
/// The object's size is fixed in the resilience scope.
Fixed,

/// The object's size is unknown in the resilience domain, but it is
/// not dependent.
Resilient,

/// The object's size is dependent on a generic parameter.
Dependent
};

/// Destructor variants.
enum class DestructorKind : uint8_t {
/// A deallocating destructor destroys the object and deallocates
Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ class IRGenModule {
llvm::PointerType *isSingleIndirectValue(SILType T);
llvm::PointerType *requiresIndirectResult(SILType T);
bool isPOD(SILType type, ResilienceScope scope);
ObjectSize classifyTypeSize(SILType type, ResilienceScope scope);
clang::CanQual<clang::Type> getClangType(CanType type);
clang::CanQual<clang::Type> getClangType(SILType type);
clang::CanQual<clang::Type> getClangType(SILParameterInfo param);
Expand Down

0 comments on commit f3d5345

Please sign in to comment.