Skip to content

Commit a23d1fa

Browse files
committed
AST: Remove TypeBase::isSpelledLike()
1 parent 47e2390 commit a23d1fa

File tree

2 files changed

+3
-146
lines changed

2 files changed

+3
-146
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ class alignas(1 << TypeAlignInBits) TypeBase {
415415
}
416416

417417
/// isEqual - Return true if these two types are equal, ignoring sugar.
418+
///
419+
/// To compare sugar, check for pointer equality of the underlying TypeBase *
420+
/// values, obtained by calling getPointer().
418421
bool isEqual(Type Other);
419422

420-
/// isSpelledLike - Return true if these two types share a sugared spelling.
421-
bool isSpelledLike(Type Other);
422-
423423
/// getDesugaredType - If this type is a sugared type, remove all levels of
424424
/// sugar until we get down to a non-sugar type.
425425
TypeBase *getDesugaredType();

lib/AST/Type.cpp

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,149 +1435,6 @@ const llvm::fltSemantics &BuiltinFloatType::getAPFloatSemantics() const {
14351435
llvm::report_fatal_error("Unknown FP semantics");
14361436
}
14371437

1438-
bool TypeBase::isSpelledLike(Type other) {
1439-
TypeBase *me = this;
1440-
TypeBase *them = other.getPointer();
1441-
1442-
if (me == them)
1443-
return true;
1444-
1445-
if (me->getKind() != them->getKind())
1446-
return false;
1447-
1448-
switch (me->getKind()) {
1449-
#define ALWAYS_CANONICAL_TYPE(id, parent) case TypeKind::id:
1450-
#define UNCHECKED_TYPE(id, parent) case TypeKind::id:
1451-
#define TYPE(id, parent)
1452-
#include "swift/AST/TypeNodes.def"
1453-
case TypeKind::Error:
1454-
case TypeKind::Enum:
1455-
case TypeKind::Struct:
1456-
case TypeKind::Class:
1457-
case TypeKind::Protocol:
1458-
case TypeKind::NameAlias:
1459-
case TypeKind::GenericTypeParam:
1460-
case TypeKind::DependentMember:
1461-
case TypeKind::DynamicSelf:
1462-
return false;
1463-
1464-
case TypeKind::BoundGenericClass:
1465-
case TypeKind::BoundGenericEnum:
1466-
case TypeKind::BoundGenericStruct: {
1467-
auto bgMe = cast<BoundGenericType>(me);
1468-
auto bgThem = cast<BoundGenericType>(them);
1469-
if (bgMe->getDecl() != bgThem->getDecl())
1470-
return false;
1471-
if (bgMe->getGenericArgs().size() != bgThem->getGenericArgs().size())
1472-
return false;
1473-
for (size_t i = 0, sz = bgMe->getGenericArgs().size(); i < sz; ++i)
1474-
if (!bgMe->getGenericArgs()[i]->isSpelledLike(bgThem->getGenericArgs()[i]))
1475-
return false;
1476-
return true;
1477-
}
1478-
1479-
case TypeKind::Tuple: {
1480-
auto tMe = cast<TupleType>(me);
1481-
auto tThem = cast<TupleType>(them);
1482-
if (tMe->getNumElements() != tThem->getNumElements())
1483-
return false;
1484-
for (size_t i = 0, sz = tMe->getNumElements(); i < sz; ++i) {
1485-
auto &myField = tMe->getElement(i), &theirField = tThem->getElement(i);
1486-
if (myField.getName() != theirField.getName())
1487-
return false;
1488-
1489-
if (myField.isVararg() != theirField.isVararg())
1490-
return false;
1491-
if (!myField.getType()->isSpelledLike(theirField.getType()))
1492-
return false;
1493-
}
1494-
return true;
1495-
}
1496-
1497-
case TypeKind::SILFunction:
1498-
case TypeKind::SILBlockStorage:
1499-
case TypeKind::SILBox:
1500-
case TypeKind::SILToken:
1501-
case TypeKind::GenericFunction: {
1502-
// Polymorphic function types should never be explicitly spelled.
1503-
return false;
1504-
}
1505-
1506-
// TODO: change this to is same ExtInfo.
1507-
case TypeKind::Function: {
1508-
auto fMe = cast<FunctionType>(me);
1509-
auto fThem = cast<FunctionType>(them);
1510-
if (fMe->isAutoClosure() != fThem->isAutoClosure())
1511-
return false;
1512-
if (fMe->getRepresentation() != fThem->getRepresentation())
1513-
return false;
1514-
if (!fMe->getInput()->isSpelledLike(fThem->getInput()))
1515-
return false;
1516-
if (!fMe->getResult()->isSpelledLike(fThem->getResult()))
1517-
return false;
1518-
return true;
1519-
}
1520-
1521-
case TypeKind::LValue: {
1522-
auto lMe = cast<LValueType>(me);
1523-
auto lThem = cast<LValueType>(them);
1524-
return lMe->getObjectType()->isSpelledLike(lThem->getObjectType());
1525-
}
1526-
case TypeKind::InOut: {
1527-
auto lMe = cast<InOutType>(me);
1528-
auto lThem = cast<InOutType>(them);
1529-
return lMe->getObjectType()->isSpelledLike(lThem->getObjectType());
1530-
}
1531-
case TypeKind::ProtocolComposition: {
1532-
auto pMe = cast<ProtocolCompositionType>(me);
1533-
auto pThem = cast<ProtocolCompositionType>(them);
1534-
if (pMe->getMembers().size() != pThem->getMembers().size())
1535-
return false;
1536-
for (size_t i = 0, sz = pMe->getMembers().size(); i < sz; ++i)
1537-
if (!pMe->getMembers()[i]->isSpelledLike(pThem->getMembers()[i]))
1538-
return false;
1539-
return true;
1540-
}
1541-
case TypeKind::ExistentialMetatype: {
1542-
auto mMe = cast<ExistentialMetatypeType>(me);
1543-
auto mThem = cast<ExistentialMetatypeType>(them);
1544-
return mMe->getInstanceType()->isSpelledLike(mThem->getInstanceType());
1545-
}
1546-
case TypeKind::Metatype: {
1547-
auto mMe = cast<MetatypeType>(me);
1548-
auto mThem = cast<MetatypeType>(them);
1549-
return mMe->getInstanceType()->isSpelledLike(mThem->getInstanceType());
1550-
}
1551-
case TypeKind::Paren: {
1552-
auto pMe = cast<ParenType>(me);
1553-
auto pThem = cast<ParenType>(them);
1554-
return pMe->getUnderlyingType()->isSpelledLike(pThem->getUnderlyingType());
1555-
}
1556-
case TypeKind::ArraySlice:
1557-
case TypeKind::Optional:
1558-
case TypeKind::ImplicitlyUnwrappedOptional: {
1559-
auto aMe = cast<SyntaxSugarType>(me);
1560-
auto aThem = cast<SyntaxSugarType>(them);
1561-
return aMe->getBaseType()->isSpelledLike(aThem->getBaseType());
1562-
}
1563-
case TypeKind::Dictionary: {
1564-
auto aMe = cast<DictionaryType>(me);
1565-
auto aThem = cast<DictionaryType>(them);
1566-
return aMe->getKeyType()->isSpelledLike(aThem->getKeyType()) &&
1567-
aMe->getValueType()->isSpelledLike(aThem->getValueType());
1568-
}
1569-
case TypeKind::UnownedStorage:
1570-
case TypeKind::UnmanagedStorage:
1571-
case TypeKind::WeakStorage: {
1572-
auto rMe = cast<ReferenceStorageType>(me);
1573-
auto rThem = cast<ReferenceStorageType>(them);
1574-
return rMe->getReferentType()->isSpelledLike(rThem->getReferentType());
1575-
}
1576-
}
1577-
1578-
llvm_unreachable("Unknown type kind");
1579-
}
1580-
15811438
bool TypeBase::mayHaveSuperclass() {
15821439
if (getClassOrBoundGenericClass())
15831440
return true;

0 commit comments

Comments
 (0)