Skip to content

Commit b83da60

Browse files
authored
Merge pull request #18264 from DougGregor/assoc-type-inference-recursion
[Associated type inference] Eliminate unnecessary recursion on error.
2 parents a9ebaef + 00f51a0 commit b83da60

File tree

3 files changed

+7
-30
lines changed

3 files changed

+7
-30
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,8 +2158,7 @@ bool ConformanceChecker::checkObjCTypeErasedGenerics(
21582158

21592159
void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
21602160
Type type,
2161-
TypeDecl *typeDecl,
2162-
bool performRedeclarationCheck) {
2161+
TypeDecl *typeDecl) {
21632162

21642163
// If we already recoded this type witness, there's nothing to do.
21652164
if (Conformance->hasTypeWitness(assocType)) {
@@ -2210,26 +2209,6 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
22102209
}
22112210
} else {
22122211
// If there was no type declaration, synthesize one.
2213-
2214-
// If we're just setting an error, double-check that nobody has
2215-
// introduced a type declaration since we deduced one. This can
2216-
// happen when type-checking a different conformance deduces a
2217-
// different type witness with the same name. For non-error cases,
2218-
// the caller handles this.
2219-
if (performRedeclarationCheck && type->hasError()) {
2220-
switch (resolveTypeWitnessViaLookup(assocType)) {
2221-
case ResolveWitnessResult::Success:
2222-
case ResolveWitnessResult::ExplicitFailed:
2223-
// A type witness has shown up, and will have been
2224-
// recorded. There is nothing more to do.
2225-
return;
2226-
2227-
case ResolveWitnessResult::Missing:
2228-
// The type witness is still missing: create a new one.
2229-
break;
2230-
}
2231-
}
2232-
22332212
auto aliasDecl = new (TC.Context) TypeAliasDecl(SourceLoc(),
22342213
SourceLoc(),
22352214
assocType->getName(),
@@ -2294,8 +2273,7 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
22942273
auto overriddenRootConformance =
22952274
overriddenConformance->getConcrete()->getRootNormalConformance();
22962275
ConformanceChecker(TC, overriddenRootConformance, GlobalMissingWitnesses)
2297-
.recordTypeWitness(overridden, type, typeDecl,
2298-
/*performRedeclarationCheck=*/true);
2276+
.recordTypeWitness(overridden, type, typeDecl);
22992277
}
23002278
}
23012279

@@ -3197,12 +3175,12 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
31973175
auto interfaceType = viable.front().MemberType;
31983176
if (interfaceType->hasArchetype())
31993177
interfaceType = interfaceType->mapTypeOutOfContext();
3200-
recordTypeWitness(assocType, interfaceType, viable.front().Member, true);
3178+
recordTypeWitness(assocType, interfaceType, viable.front().Member);
32013179
return ResolveWitnessResult::Success;
32023180
}
32033181

32043182
// Record an error.
3205-
recordTypeWitness(assocType, ErrorType::get(TC.Context), nullptr, false);
3183+
recordTypeWitness(assocType, ErrorType::get(TC.Context), nullptr);
32063184

32073185
// If we had multiple viable types, diagnose the ambiguity.
32083186
if (!viable.empty()) {

lib/Sema/TypeCheckProtocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class ConformanceChecker : public WitnessChecker {
564564
///
565565
/// \param typeDecl The decl the witness type came from; can be null.
566566
void recordTypeWitness(AssociatedTypeDecl *assocType, Type type,
567-
TypeDecl *typeDecl, bool performRedeclarationCheck);
567+
TypeDecl *typeDecl);
568568

569569
/// Enforce restrictions on non-final classes witnessing requirements
570570
/// involving the protocol 'Self' type.

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,8 +1979,7 @@ void ConformanceChecker::resolveTypeWitnesses() {
19791979
if (auto inferred = inference.solve(*this)) {
19801980
for (const auto &inferredWitness : *inferred) {
19811981
recordTypeWitness(inferredWitness.first, inferredWitness.second,
1982-
/*typeDecl=*/nullptr,
1983-
/*performRedeclarationCheck=*/true);
1982+
/*typeDecl=*/nullptr);
19841983
}
19851984

19861985
ensureRequirementsAreSatisfied(/*failUnsubstituted=*/false);
@@ -1997,7 +1996,7 @@ void ConformanceChecker::resolveTypeWitnesses() {
19971996
if (Conformance->hasTypeWitness(assocType))
19981997
continue;
19991998

2000-
recordTypeWitness(assocType, ErrorType::get(TC.Context), nullptr, true);
1999+
recordTypeWitness(assocType, ErrorType::get(TC.Context), nullptr);
20012000
}
20022001
}
20032002

0 commit comments

Comments
 (0)