RequirementMachine: Conditional requirement inference

If a type parameter is subject to both a conformance requirement
and a concrete type requirement, the concrete type might conform
conditionally.

In this case, introduce new requirements to satisfy the conditional
conformance.

Since this can add new hitherto-unseen protocols to the rewrite
system, restrict this feature to top-level generic signatures, and
not protocol requirement signatures. Allowing this to occur in
protocol requirement signatures would change the connectivity of
the protocol dependency graph (and hence the connected components)
during completion, which would be a major complication in the
design. The GSB already enforces this restriction.

I changed the existing conditional_requirement_inference.swift test
to run with -requirement-machine-inferred-signatures=verify. Since
one of the test cases there triggers an unrelated bug in the
Requirement Machine, I split it off into a new file named
conditional_requirement_inference_2.swift which still runs with
the GSB. Once the bug is fixed I'll merge the files again.
This commit is contained in:
Slava Pestov
2022-01-22 00:20:27 -05:00
parent 75dfab00b9
commit eb9f12109e
7 changed files with 176 additions and 57 deletions

View File

@@ -264,6 +264,10 @@ private:
ProtocolConformance *concrete,
AssociatedTypeDecl *assocType) const;
void inferConditionalRequirements(
ProtocolConformance *concrete,
ArrayRef<Term> substitutions) const;
MutableTerm computeConstraintTermForTypeWitness(
Term key, RequirementKind requirementKind,
CanType concreteType, CanType typeWitness,
@@ -284,4 +288,4 @@ private:
} // end namespace swift
#endif
#endif