Skip to content

Commit 1eb4788

Browse files
committed
[ConstraintSystem] NFC: Remove ArgumentInfoCollector which was part of designated operator work
1 parent cd724d4 commit 1eb4788

File tree

2 files changed

+0
-279
lines changed

2 files changed

+0
-279
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4905,61 +4905,6 @@ class ConstraintSystem {
49054905
return getExpressionTooComplex(solutionMemory);
49064906
}
49074907

4908-
// Utility class that can collect information about the type of an
4909-
// argument in an apply.
4910-
//
4911-
// For example, when given a type variable type that represents the
4912-
// argument of a function call, it will walk the constraint graph
4913-
// finding any concrete types that are reachable through various
4914-
// subtype constraints and will also collect all the literal types
4915-
// conformed to by the types it finds on the walk.
4916-
//
4917-
// This makes it possible to get an idea of the kinds of literals
4918-
// and types of arguments that are used in the subexpression rooted
4919-
// in this argument, which we can then use to make better choices
4920-
// for how we partition the operators in a disjunction (in order to
4921-
// avoid visiting all the options).
4922-
class ArgumentInfoCollector {
4923-
ConstraintSystem &CS;
4924-
llvm::SetVector<Type> Types;
4925-
llvm::SetVector<ProtocolDecl *> LiteralProtocols;
4926-
4927-
void addType(Type ty) {
4928-
assert(!ty->is<TypeVariableType>());
4929-
Types.insert(ty);
4930-
}
4931-
4932-
void addLiteralProtocol(ProtocolDecl *proto) {
4933-
LiteralProtocols.insert(proto);
4934-
}
4935-
4936-
void walk(Type argType);
4937-
void minimizeLiteralProtocols();
4938-
4939-
public:
4940-
ArgumentInfoCollector(ConstraintSystem &cs, FunctionType *fnTy) : CS(cs) {
4941-
for (auto &param : fnTy->getParams())
4942-
walk(param.getPlainType());
4943-
4944-
minimizeLiteralProtocols();
4945-
}
4946-
4947-
ArgumentInfoCollector(ConstraintSystem &cs, AnyFunctionType::Param param)
4948-
: CS(cs) {
4949-
walk(param.getPlainType());
4950-
minimizeLiteralProtocols();
4951-
}
4952-
4953-
const llvm::SetVector<Type> &getTypes() const { return Types; }
4954-
const llvm::SetVector<ProtocolDecl *> &getLiteralProtocols() const {
4955-
return LiteralProtocols;
4956-
}
4957-
4958-
SWIFT_DEBUG_DUMP;
4959-
};
4960-
4961-
bool haveTypeInformationForAllArguments(FunctionType *fnType);
4962-
49634908
typedef std::function<bool(unsigned index, Constraint *)> ConstraintMatcher;
49644909
typedef std::function<void(ArrayRef<Constraint *>, ConstraintMatcher)>
49654910
ConstraintMatchLoop;

lib/Sema/CSSolver.cpp

Lines changed: 0 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,230 +1611,6 @@ static Constraint *selectBestBindingDisjunction(
16111611
return firstBindDisjunction;
16121612
}
16131613

1614-
// For a given type, collect any concrete types or literal
1615-
// conformances we can reach by walking the constraint graph starting
1616-
// from this point.
1617-
//
1618-
// For example, if the type is a type variable, we'll walk back
1619-
// through the constraints mentioning this type variable and find what
1620-
// types are converted to this type along with what literals are
1621-
// conformed-to by this type.
1622-
void ConstraintSystem::ArgumentInfoCollector::walk(Type argType) {
1623-
llvm::SmallSet<TypeVariableType *, 4> visited;
1624-
llvm::SmallVector<Type, 4> worklist;
1625-
worklist.push_back(argType);
1626-
1627-
while (!worklist.empty()) {
1628-
auto itemTy = worklist.pop_back_val()->getRValueType();
1629-
1630-
if (!itemTy->is<TypeVariableType>()) {
1631-
addType(itemTy);
1632-
continue;
1633-
}
1634-
1635-
auto tyvar = itemTy->castTo<TypeVariableType>();
1636-
if (auto fixedTy = CS.getFixedType(tyvar)) {
1637-
addType(fixedTy);
1638-
continue;
1639-
}
1640-
1641-
auto *rep = CS.getRepresentative(tyvar);
1642-
1643-
// FIXME: This can happen when we have two type variables that are
1644-
// subtypes of each other. We would ideally merge those type
1645-
// variables somewhere.
1646-
if (visited.count(rep))
1647-
continue;
1648-
1649-
visited.insert(rep);
1650-
1651-
auto constraints = CS.getConstraintGraph().gatherConstraints(
1652-
rep, ConstraintGraph::GatheringKind::EquivalenceClass);
1653-
1654-
for (auto *constraint : constraints) {
1655-
switch (constraint->getKind()) {
1656-
case ConstraintKind::LiteralConformsTo:
1657-
addLiteralProtocol(constraint->getProtocol());
1658-
break;
1659-
1660-
case ConstraintKind::Bind:
1661-
case ConstraintKind::Equal: {
1662-
auto firstTy = constraint->getFirstType();
1663-
auto secondTy = constraint->getSecondType();
1664-
if (firstTy->is<TypeVariableType>()) {
1665-
auto otherRep =
1666-
CS.getRepresentative(firstTy->castTo<TypeVariableType>());
1667-
if (otherRep->isEqual(rep))
1668-
worklist.push_back(secondTy);
1669-
}
1670-
if (secondTy->is<TypeVariableType>()) {
1671-
auto otherRep =
1672-
CS.getRepresentative(secondTy->castTo<TypeVariableType>());
1673-
if (otherRep->isEqual(rep))
1674-
worklist.push_back(firstTy);
1675-
}
1676-
break;
1677-
}
1678-
1679-
case ConstraintKind::Subtype:
1680-
case ConstraintKind::OperatorArgumentConversion:
1681-
case ConstraintKind::ArgumentConversion:
1682-
case ConstraintKind::Conversion:
1683-
case ConstraintKind::BridgingConversion:
1684-
case ConstraintKind::BindParam:
1685-
case ConstraintKind::OpaqueUnderlyingType: {
1686-
auto secondTy = constraint->getSecondType();
1687-
if (secondTy->is<TypeVariableType>()) {
1688-
auto otherRep =
1689-
CS.getRepresentative(secondTy->castTo<TypeVariableType>());
1690-
if (otherRep->isEqual(rep))
1691-
worklist.push_back(constraint->getFirstType());
1692-
}
1693-
break;
1694-
}
1695-
1696-
case ConstraintKind::DynamicTypeOf:
1697-
case ConstraintKind::EscapableFunctionOf: {
1698-
auto firstTy = constraint->getFirstType();
1699-
if (firstTy->is<TypeVariableType>()) {
1700-
auto otherRep =
1701-
CS.getRepresentative(firstTy->castTo<TypeVariableType>());
1702-
if (otherRep->isEqual(rep))
1703-
worklist.push_back(constraint->getSecondType());
1704-
}
1705-
break;
1706-
}
1707-
1708-
case ConstraintKind::OptionalObject: {
1709-
// Get the underlying object type.
1710-
auto secondTy = constraint->getSecondType();
1711-
if (secondTy->is<TypeVariableType>()) {
1712-
auto otherRep =
1713-
CS.getRepresentative(secondTy->castTo<TypeVariableType>());
1714-
if (otherRep->isEqual(rep)) {
1715-
// See if we can actually determine what the underlying
1716-
// type is.
1717-
Type fixedTy;
1718-
auto firstTy = constraint->getFirstType();
1719-
if (!firstTy->is<TypeVariableType>()) {
1720-
fixedTy = firstTy;
1721-
} else {
1722-
fixedTy = CS.getFixedType(firstTy->castTo<TypeVariableType>());
1723-
}
1724-
if (fixedTy && fixedTy->getOptionalObjectType())
1725-
worklist.push_back(fixedTy->getOptionalObjectType());
1726-
}
1727-
}
1728-
break;
1729-
}
1730-
1731-
case ConstraintKind::KeyPathApplication:
1732-
case ConstraintKind::KeyPath: {
1733-
auto firstTy = constraint->getFirstType();
1734-
if (firstTy->is<TypeVariableType>()) {
1735-
auto otherRep =
1736-
CS.getRepresentative(firstTy->castTo<TypeVariableType>());
1737-
if (otherRep->isEqual(rep))
1738-
worklist.push_back(constraint->getThirdType());
1739-
}
1740-
break;
1741-
}
1742-
1743-
case ConstraintKind::BindToPointerType:
1744-
case ConstraintKind::ValueMember:
1745-
case ConstraintKind::ValueWitness:
1746-
case ConstraintKind::UnresolvedValueMember:
1747-
case ConstraintKind::Disjunction:
1748-
case ConstraintKind::CheckedCast:
1749-
case ConstraintKind::OpenedExistentialOf:
1750-
case ConstraintKind::ApplicableFunction:
1751-
case ConstraintKind::DynamicCallableApplicableFunction:
1752-
case ConstraintKind::BindOverload:
1753-
case ConstraintKind::FunctionInput:
1754-
case ConstraintKind::FunctionResult:
1755-
case ConstraintKind::SelfObjectOfProtocol:
1756-
case ConstraintKind::ConformsTo:
1757-
case ConstraintKind::Defaultable:
1758-
case ConstraintKind::OneWayEqual:
1759-
case ConstraintKind::OneWayBindParam:
1760-
case ConstraintKind::DefaultClosureType:
1761-
break;
1762-
}
1763-
}
1764-
}
1765-
}
1766-
1767-
void ConstraintSystem::ArgumentInfoCollector::minimizeLiteralProtocols() {
1768-
if (LiteralProtocols.size() <= 1)
1769-
return;
1770-
1771-
llvm::SmallVector<std::pair<ProtocolDecl *, Type>, 2> candidates;
1772-
llvm::SmallVector<ProtocolDecl *, 2> skippedProtocols;
1773-
1774-
for (auto *protocol : LiteralProtocols) {
1775-
if (auto defaultType = TypeChecker::getDefaultType(protocol, CS.DC)) {
1776-
candidates.push_back({protocol, defaultType});
1777-
continue;
1778-
}
1779-
1780-
// Looks like argument expected to conform to something like
1781-
// `ExpressibleByNilLiteral` which doesn't have a default
1782-
// type and as a result can't participate in minimalization.
1783-
skippedProtocols.push_back(protocol);
1784-
}
1785-
1786-
if (candidates.size() <= 1)
1787-
return;
1788-
1789-
unsigned result = 0;
1790-
for (unsigned i = 1, n = candidates.size(); i != n; ++i) {
1791-
const auto &candidate = candidates[i];
1792-
1793-
auto first =
1794-
TypeChecker::conformsToProtocol(candidate.second, candidates[result].first,
1795-
CS.DC);
1796-
auto second =
1797-
TypeChecker::conformsToProtocol(candidates[result].second, candidate.first,
1798-
CS.DC);
1799-
if (first.isInvalid() == second.isInvalid())
1800-
return;
1801-
1802-
if (!first.isInvalid())
1803-
result = i;
1804-
}
1805-
1806-
LiteralProtocols.clear();
1807-
LiteralProtocols.insert(candidates[result].first);
1808-
LiteralProtocols.insert(skippedProtocols.begin(), skippedProtocols.end());
1809-
}
1810-
1811-
void ConstraintSystem::ArgumentInfoCollector::dump() const {
1812-
auto &log = llvm::errs();
1813-
log << "types:\n";
1814-
for (auto type : Types)
1815-
type->print(log);
1816-
log << "\n";
1817-
1818-
log << "literal protocols:\n";
1819-
for (auto *proto : LiteralProtocols)
1820-
proto->print(log);
1821-
log << "\n";
1822-
}
1823-
1824-
// Check to see if we know something about the types of all arguments
1825-
// in the given function type.
1826-
bool ConstraintSystem::haveTypeInformationForAllArguments(
1827-
FunctionType *fnType) {
1828-
llvm::SetVector<Constraint *> literalConformsTo;
1829-
return llvm::all_of(fnType->getParams(),
1830-
[&](AnyFunctionType::Param param) -> bool {
1831-
ArgumentInfoCollector argInfo(*this, param);
1832-
auto countFacts = argInfo.getTypes().size() +
1833-
argInfo.getLiteralProtocols().size();
1834-
return countFacts > 0;
1835-
});
1836-
}
1837-
18381614
Optional<std::pair<Constraint *, unsigned>>
18391615
ConstraintSystem::findConstraintThroughOptionals(
18401616
TypeVariableType *typeVar, OptionalWrappingDirection optionalDirection,

0 commit comments

Comments
 (0)