Skip to content

Commit db7ee5f

Browse files
authored
Merge pull request #36059 from xedin/nfc-remove-argument-info-collector
[ConstraintSystem] NFC: Remove `ArgumentInfoCollector` which was part…
2 parents dcc1292 + 1eb4788 commit db7ee5f

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
@@ -4906,61 +4906,6 @@ class ConstraintSystem {
49064906
return getExpressionTooComplex(solutionMemory);
49074907
}
49084908

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

lib/Sema/CSSolver.cpp

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

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

0 commit comments

Comments
 (0)