Skip to content

Commit c1201a5

Browse files
committed
Sema: Less eager computation of protocol extension signatures in associated type inference
We only need the generic signature if the extended nominal is concrete. In the protocol extension case, we're using getSelfBoundsFromWhereClause(), which only needs to perform name lookup.
1 parent 2481503 commit c1201a5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,22 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
207207
if (extendedNominal == nullptr)
208208
return true;
209209

210-
// FIXME: The extension may not have a generic signature set up yet as
211-
// resolving signatures may trigger associated type inference. This cycle
212-
// is now detectable and we should look into untangling it
213-
// - see rdar://55263708
214-
if (!extension->hasComputedGenericSignature())
215-
return true;
216-
217-
// Retrieve the generic signature of the extension.
218-
const auto extensionSig = extension->getGenericSignature();
219-
220210
auto *proto = dyn_cast<ProtocolDecl>(extendedNominal);
221211

222212
// If the extension is bound to the nominal the conformance is
223213
// declared on, it is viable for inference when its conditional
224214
// requirements are satisfied by those of the conformance context.
225215
if (!proto) {
216+
// FIXME: The extension may not have a generic signature set up yet as
217+
// resolving signatures may trigger associated type inference. This cycle
218+
// is now detectable and we should look into untangling it
219+
// - see rdar://55263708
220+
if (!extension->hasComputedGenericSignature())
221+
return true;
222+
223+
// Retrieve the generic signature of the extension.
224+
const auto extensionSig = extension->getGenericSignature();
225+
226226
// Extensions of non-generic nominals are always viable for inference.
227227
if (!extensionSig)
228228
return true;
@@ -261,9 +261,6 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
261261
return true;
262262
};
263263

264-
auto typeInContext =
265-
conformance->getDeclContext()->mapTypeIntoContext(conformance->getType());
266-
267264
for (auto witness :
268265
checker.lookupValueWitnesses(req, /*ignoringNames=*/nullptr)) {
269266
LLVM_DEBUG(llvm::dbgs() << "Inferring associated types from decl:\n";
@@ -319,6 +316,10 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
319316
if (!associatedTypesAreSameEquivalenceClass(dmt->getAssocType(),
320317
result.first))
321318
return false;
319+
320+
auto typeInContext =
321+
conformance->getDeclContext()->mapTypeIntoContext(conformance->getType());
322+
322323
if (!dmt->getBase()->isEqual(typeInContext))
323324
return false;
324325

0 commit comments

Comments
 (0)