Skip to content

Commit c2057c3

Browse files
committed
Revert "Sema: Change associated type inference handling of generic parameters"
This reverts commit fe7631c.
1 parent fe7631c commit c2057c3

File tree

2 files changed

+27
-46
lines changed

2 files changed

+27
-46
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ class AssociatedTypeInference {
980980

981981
/// Infer associated type witnesses for the given associated type.
982982
InferredAssociatedTypesByWitnesses inferTypeWitnessesViaAssociatedType(
983+
const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
983984
AssociatedTypeDecl *assocType);
984985

985986
/// Infer associated type witnesses for all relevant value requirements.
@@ -1678,7 +1679,8 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
16781679
if (assocTypes.count(assocType) == 0)
16791680
continue;
16801681

1681-
auto reqInferred = inferTypeWitnessesViaAssociatedType(assocType);
1682+
auto reqInferred = inferTypeWitnessesViaAssociatedType(assocTypes,
1683+
assocType);
16821684
if (!reqInferred.empty())
16831685
result.push_back({req, std::move(reqInferred)});
16841686

@@ -1826,12 +1828,10 @@ static Type removeSelfParam(ValueDecl *value, Type type) {
18261828

18271829
InferredAssociatedTypesByWitnesses
18281830
AssociatedTypeInference::inferTypeWitnessesViaAssociatedType(
1831+
const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
18291832
AssociatedTypeDecl *assocType) {
18301833
InferredAssociatedTypesByWitnesses result;
18311834

1832-
LLVM_DEBUG(llvm::dbgs() << "Considering associated type:\n";
1833-
assocType->dump(llvm::dbgs()));
1834-
18351835
// Check if this associated type is actually fixed to a fully concrete type by
18361836
// a same-type requirement in a protocol that our conforming type conforms to.
18371837
//
@@ -1856,34 +1856,6 @@ AssociatedTypeInference::inferTypeWitnessesViaAssociatedType(
18561856
}
18571857
}
18581858

1859-
// Look for a generic parameter with the same name as this associated type.
1860-
if (ctx.LangOpts.EnableExperimentalAssociatedTypeInference) {
1861-
// Ignore the generic parameters for AsyncIteratorProtocol.Failure and
1862-
// AsyncSequence.Failure.
1863-
if (!isAsyncIteratorProtocolFailure(assocType)) {
1864-
if (auto genericSig = dc->getGenericSignatureOfContext()) {
1865-
for (auto *gp : genericSig.getInnermostGenericParams()) {
1866-
// Packs cannot witness associated type requirements.
1867-
if (gp->isParameterPack())
1868-
continue;
1869-
1870-
if (gp->getName() == assocType->getName()) {
1871-
auto witnessType = dc->mapTypeIntoContext(gp);
1872-
1873-
// Add this result.
1874-
InferredAssociatedTypesByWitness inferred;
1875-
inferred.Witness = gp->getDecl();
1876-
inferred.Inferred.push_back({assocType, witnessType});
1877-
result.push_back(std::move(inferred));
1878-
1879-
LLVM_DEBUG(llvm::dbgs() << "Candidate generic parameter:\n";
1880-
gp->dump(llvm::dbgs()));
1881-
}
1882-
}
1883-
}
1884-
}
1885-
}
1886-
18871859
// Form the default name _Default_Foo.
18881860
DeclNameRef defaultName;
18891861
{
@@ -2468,6 +2440,29 @@ AssociatedTypeInference::computeAbstractTypeWitness(
24682440
void AssociatedTypeInference::collectAbstractTypeWitnesses(
24692441
TypeWitnessSystem &system,
24702442
ArrayRef<AssociatedTypeDecl *> unresolvedAssocTypes) const {
2443+
// Look for suitably-named generic parameters first, before we go digging
2444+
// through same-type requirements of protocols.
2445+
if (auto genericSig = dc->getGenericSignatureOfContext()) {
2446+
for (auto *const assocType : unresolvedAssocTypes) {
2447+
// Ignore the generic parameters for AsyncIteratorProtocol.Failure and
2448+
// AsyncSequence.Failure.
2449+
if (isAsyncIteratorProtocolFailure(assocType))
2450+
continue;
2451+
2452+
for (auto *gp : genericSig.getInnermostGenericParams()) {
2453+
// Packs cannot witness associated type requirements.
2454+
if (gp->isParameterPack())
2455+
continue;
2456+
2457+
if (gp->getName() == assocType->getName()) {
2458+
system.addTypeWitness(assocType->getName(),
2459+
dc->mapTypeIntoContext(gp),
2460+
/*preferred=*/true);
2461+
}
2462+
}
2463+
}
2464+
}
2465+
24712466
auto considerProtocolRequirements = [&](ProtocolDecl *conformedProto) {
24722467
// FIXME: The RequirementMachine will assert on re-entrant construction.
24732468
// We should find a more principled way of breaking this cycle.

test/decl/protocol/req/rdar122587432.swift

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)