Skip to content

AST: Remove some unnecessary getCanonicalType() calls #8044

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 13, 2017
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
16 changes: 0 additions & 16 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ class CanType : public Type {
bool isActuallyCanonicalOrNull() const;

static bool isReferenceTypeImpl(CanType type, bool functionsCount);
static bool isExistentialTypeImpl(CanType type);
static bool isAnyExistentialTypeImpl(CanType type);
static bool isExistentialTypeImpl(CanType type,
SmallVectorImpl<ProtocolDecl*> &protocols);
static bool isAnyExistentialTypeImpl(CanType type,
Expand Down Expand Up @@ -392,21 +390,11 @@ class CanType : public Type {
return isReferenceTypeImpl(*this, /*functions count*/ false);
}

/// Is this type existential?
bool isExistentialType() const {
return isExistentialTypeImpl(*this);
}

/// Is this type existential?
bool isExistentialType(SmallVectorImpl<ProtocolDecl *> &protocols) {
return isExistentialTypeImpl(*this, protocols);
}

/// Is this type an existential or an existential metatype?
bool isAnyExistentialType() const {
return isAnyExistentialTypeImpl(*this);
}

/// Is this type an existential or an existential metatype?
bool isAnyExistentialType(SmallVectorImpl<ProtocolDecl *> &protocols) {
return isAnyExistentialTypeImpl(*this, protocols);
Expand All @@ -424,11 +412,7 @@ class CanType : public Type {
return isObjCExistentialTypeImpl(*this);
}

ClassDecl *getClassOrBoundGenericClass() const; // in Types.h
StructDecl *getStructOrBoundGenericStruct() const; // in Types.h
EnumDecl *getEnumOrBoundGenericEnum() const; // in Types.h
NominalTypeDecl *getNominalOrBoundGenericNominal() const; // in Types.h
CanType getNominalParent() const; // in Types.h
NominalTypeDecl *getAnyNominal() const;
GenericTypeDecl *getAnyGeneric() const;

Expand Down
67 changes: 14 additions & 53 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4383,46 +4383,29 @@ inline GenericTypeParamType *TypeBase::getRootGenericParam() {
}

inline bool TypeBase::isExistentialType() {
return getCanonicalType().isExistentialType();
return is<ProtocolType>() || is<ProtocolCompositionType>();
}

inline bool TypeBase::isAnyExistentialType() {
return getCanonicalType().isAnyExistentialType();
}

inline bool CanType::isExistentialTypeImpl(CanType type) {
return isa<ProtocolType>(type) || isa<ProtocolCompositionType>(type);
}

inline bool CanType::isAnyExistentialTypeImpl(CanType type) {
return isExistentialTypeImpl(type) || isa<ExistentialMetatypeType>(type);
return isExistentialType() || is<ExistentialMetatypeType>();
}

inline bool TypeBase::isClassExistentialType() {
CanType T = getCanonicalType();
if (auto pt = dyn_cast<ProtocolType>(T))
if (auto pt = getAs<ProtocolType>())
return pt->requiresClass();
if (auto pct = dyn_cast<ProtocolCompositionType>(T))
if (auto pct = getAs<ProtocolCompositionType>())
return pct->requiresClass();
return false;
}

inline bool TypeBase::isOpenedExistential() {
if (!hasOpenedExistential())
return false;

CanType T = getCanonicalType();
if (auto archetype = dyn_cast<ArchetypeType>(T))
if (auto archetype = getAs<ArchetypeType>())
return !archetype->getOpenedExistentialType().isNull();
return false;
}

inline bool TypeBase::isOpenedExistentialWithError() {
if (!hasOpenedExistential())
return false;

CanType T = getCanonicalType();
if (auto archetype = dyn_cast<ArchetypeType>(T)) {
if (auto archetype = getAs<ArchetypeType>()) {
auto openedExistentialType = archetype->getOpenedExistentialType();
return (!openedExistentialType.isNull() &&
openedExistentialType->isExistentialWithError());
Expand All @@ -4431,42 +4414,30 @@ inline bool TypeBase::isOpenedExistentialWithError() {
}

inline ClassDecl *TypeBase::getClassOrBoundGenericClass() {
return getCanonicalType().getClassOrBoundGenericClass();
}

inline ClassDecl *CanType::getClassOrBoundGenericClass() const {
if (auto classTy = dyn_cast<ClassType>(*this))
if (auto classTy = getAs<ClassType>())
return classTy->getDecl();

if (auto boundTy = dyn_cast<BoundGenericClassType>(*this))
if (auto boundTy = getAs<BoundGenericClassType>())
return boundTy->getDecl();

return nullptr;
}

inline StructDecl *TypeBase::getStructOrBoundGenericStruct() {
return getCanonicalType().getStructOrBoundGenericStruct();
}

inline StructDecl *CanType::getStructOrBoundGenericStruct() const {
if (auto structTy = dyn_cast<StructType>(*this))
if (auto structTy = getAs<StructType>())
return structTy->getDecl();

if (auto boundTy = dyn_cast<BoundGenericStructType>(*this))
if (auto boundTy = getAs<BoundGenericStructType>())
return boundTy->getDecl();

return nullptr;
}

inline EnumDecl *TypeBase::getEnumOrBoundGenericEnum() {
return getCanonicalType().getEnumOrBoundGenericEnum();
}

inline EnumDecl *CanType::getEnumOrBoundGenericEnum() const {
if (auto enumTy = dyn_cast<EnumType>(*this))
if (auto enumTy = getAs<EnumType>())
return enumTy->getDecl();

if (auto boundTy = dyn_cast<BoundGenericEnumType>(*this))
if (auto boundTy = getAs<BoundGenericEnumType>())
return boundTy->getDecl();

return nullptr;
Expand Down Expand Up @@ -4504,10 +4475,8 @@ inline GenericTypeDecl *TypeBase::getAnyGeneric() {
return getCanonicalType().getAnyGeneric();
}



inline bool TypeBase::isBuiltinIntegerType(unsigned n) {
if (auto intTy = dyn_cast<BuiltinIntegerType>(getCanonicalType()))
if (auto intTy = getAs<BuiltinIntegerType>())
return intTy->getWidth().isFixedWidth()
&& intTy->getWidth().getFixedWidth() == n;
return false;
Expand Down Expand Up @@ -4564,20 +4533,12 @@ inline CanType CanType::getLValueOrInOutObjectTypeImpl(CanType type) {
return type;
}

inline CanType CanType::getNominalParent() const {
if (auto classType = dyn_cast<NominalType>(*this)) {
return classType.getParent();
} else {
return cast<BoundGenericType>(*this).getParent();
}
}

inline bool TypeBase::mayHaveSuperclass() {
if (getClassOrBoundGenericClass())
return true;

if (auto archetype = getAs<ArchetypeType>())
return (bool)archetype->requiresClass();
return archetype->requiresClass();

return is<DynamicSelfType>();
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4158,7 +4158,7 @@ class InitExistentialMetatypeInst final
exType = exMetatype.getInstanceType();
concreteType = cast<MetatypeType>(concreteType).getInstanceType();
}
assert(exType.isExistentialType());
assert(exType->isExistentialType());
return concreteType;
}

Expand Down
12 changes: 6 additions & 6 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,22 @@ class SILType {
/// Retrieve the ClassDecl for a type that maps to a Swift class or
/// bound generic class type.
ClassDecl *getClassOrBoundGenericClass() const {
return getSwiftRValueType().getClassOrBoundGenericClass();
return getSwiftRValueType()->getClassOrBoundGenericClass();
}
/// Retrieve the StructDecl for a type that maps to a Swift struct or
/// bound generic struct type.
StructDecl *getStructOrBoundGenericStruct() const {
return getSwiftRValueType().getStructOrBoundGenericStruct();
return getSwiftRValueType()->getStructOrBoundGenericStruct();
}
/// Retrieve the EnumDecl for a type that maps to a Swift enum or
/// bound generic enum type.
EnumDecl *getEnumOrBoundGenericEnum() const {
return getSwiftRValueType().getEnumOrBoundGenericEnum();
return getSwiftRValueType()->getEnumOrBoundGenericEnum();
}
/// Retrieve the NominalTypeDecl for a type that maps to a Swift
/// nominal or bound generic nominal type.
NominalTypeDecl *getNominalOrBoundGenericNominal() const {
return getSwiftRValueType().getNominalOrBoundGenericNominal();
return getSwiftRValueType()->getNominalOrBoundGenericNominal();
}

/// True if the type is an address type.
Expand Down Expand Up @@ -284,11 +284,11 @@ class SILType {
}
/// Returns true if the referenced type is an existential type.
bool isExistentialType() const {
return getSwiftRValueType().isExistentialType();
return getSwiftRValueType()->isExistentialType();
}
/// Returns true if the referenced type is any kind of existential type.
bool isAnyExistentialType() const {
return getSwiftRValueType().isAnyExistentialType();
return getSwiftRValueType()->isAnyExistentialType();
}
/// Returns true if the referenced type is a class existential type.
bool isClassExistentialType() const {
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ bool CanType::isExistentialTypeImpl(CanType type,
return true;
}

assert(!type.isExistentialType());
return false;
}

Expand All @@ -263,7 +262,7 @@ bool TypeBase::isObjCExistentialType() {
}

bool CanType::isObjCExistentialTypeImpl(CanType type) {
if (!type.isExistentialType()) return false;
if (!type->isExistentialType()) return false;

SmallVector<ProtocolDecl *, 4> protocols;
type.getAnyExistentialTypeProtocols(protocols);
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CategoryInitializerVisitor
classMetadata = llvm::ConstantExpr::getBitCast(classMetadata,
IGM.ObjCClassPtrTy);
metaclassMetadata = IGM.getAddrOfMetaclassObject(
origTy.getClassOrBoundGenericClass(),
origTy->getClassOrBoundGenericClass(),
NotForDefinition);
metaclassMetadata = llvm::ConstantExpr::getBitCast(metaclassMetadata,
IGM.ObjCClassPtrTy);
Expand Down
16 changes: 8 additions & 8 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static llvm::Value *emitNominalMetadataRef(IRGenFunction &IGF,


bool irgen::hasKnownSwiftMetadata(IRGenModule &IGM, CanType type) {
if (ClassDecl *theClass = type.getClassOrBoundGenericClass()) {
if (ClassDecl *theClass = type->getClassOrBoundGenericClass()) {
return hasKnownSwiftMetadata(IGM, theClass);
}

Expand Down Expand Up @@ -3667,7 +3667,7 @@ namespace {
}

void addParentMetadataRef(ClassDecl *forClass, Type classType) {
CanType parentType = classType->getCanonicalType().getNominalParent();
CanType parentType = classType->getNominalParent()->getCanonicalType();

if (auto metadata =
tryEmitConstantTypeMetadataRef(IGM, parentType,
Expand Down Expand Up @@ -3781,7 +3781,7 @@ namespace {
}

void addParentMetadataRef(ClassDecl *forClass, Type classType) {
CanType parentType = classType->getCanonicalType().getNominalParent();
CanType parentType = classType->getNominalParent()->getCanonicalType();
this->addFillOp(parentType, None, /*relative*/ false);
B.addNullPointer(IGM.TypeMetadataPtrTy);
}
Expand Down Expand Up @@ -4487,7 +4487,7 @@ llvm::Value *irgen::emitHeapMetadataRefForHeapObject(IRGenFunction &IGF,
llvm::Value *object,
CanType objectType,
bool suppressCast) {
ClassDecl *theClass = objectType.getClassOrBoundGenericClass();
ClassDecl *theClass = objectType->getClassOrBoundGenericClass();
if (theClass && isKnownNotTaggedPointer(IGF.IGM, theClass))
return emitLoadOfHeapMetadataRef(IGF, object,
getIsaEncodingForType(IGF.IGM, objectType),
Expand Down Expand Up @@ -5226,8 +5226,8 @@ namespace {
Size AddressPoint = Size::invalid();

bool computeUnfilledParent() {
if (auto parentType = asImpl().getTargetType().getNominalParent()) {
return !tryEmitConstantTypeMetadataRef(IGM, parentType,
if (auto parentType = asImpl().getTargetType()->getNominalParent()) {
return !tryEmitConstantTypeMetadataRef(IGM, parentType->getCanonicalType(),
SymbolReferenceKind::Absolute);
}
return false;
Expand Down Expand Up @@ -5364,7 +5364,7 @@ namespace {
}
void emitInitialization(IRGenFunction &IGF, llvm::Value *metadata) {
if (HasUnfilledParent) {
auto parentType = getTargetType().getNominalParent();
auto parentType = getTargetType()->getNominalParent()->getCanonicalType();
auto parentMetadata = IGF.emitTypeMetadataRef(parentType);

int index = ValueTypeParentIndex;
Expand Down Expand Up @@ -5410,7 +5410,7 @@ namespace {
}
void emitInitialization(IRGenFunction &IGF, llvm::Value *metadata) {
if (HasUnfilledParent) {
auto parentType = getTargetType().getNominalParent();
auto parentType = getTargetType()->getNominalParent()->getCanonicalType();
auto parentMetadata = IGF.emitTypeMetadataRef(parentType);

int index = ValueTypeParentIndex;
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static void emitSuperArgument(IRGenFunction &IGF, bool isInstanceMethod,
} else {
ClassDecl *searchClassDecl =
searchClass.castTo<MetatypeType>().getInstanceType()
.getClassOrBoundGenericClass();
->getClassOrBoundGenericClass();
searchValue = IGF.IGM.getAddrOfMetaclassObject(searchClassDecl,
NotForDefinition);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void EmitPolymorphicParameters::bindExtraSource(const MetadataSource &source,
auto selfTy = FnType->getSelfInstanceType();
CanType argTy = getTypeInContext(selfTy);
setTypeMetadataName(IGF.IGM, metadata, argTy);
auto *CD = selfTy.getClassOrBoundGenericClass();
auto *CD = selfTy->getClassOrBoundGenericClass();
// The self metadata here corresponds to the conforming type.
// For an inheritable conformance, that may be a subclass of the static
// type, and so the self metadata will be inexact. Currently, all
Expand Down
Loading