RequirementMachine: Improved modeling of concrete conformances #40425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduces a new symbol kind, the "concrete conformance symbol". This combines a concrete type with a protocol, and can appear in property rules, like so:
These rules are introduced by property map construction when the same key is known to have a concrete type requirement together with a conformance requirement. Together with the new rule, property map construction also adds a rewrite loop that relates the concrete type rule, the protocol conformance rule and the concrete conformance rule together:
The rewrite step
([concrete: C].[P] => [concrete: C : P])
does not correspond to a rewrite rule, but is rather a special new kindRewriteStep::ConcreteConformance
. It converts a pair of symbols, a concrete type symbol and a protocol symbol, into a concrete conformance symbol (or vice versa, when the step is inverted).Similarly for superclasses, there is a new
RewriteStep::SuperclassConformance
which converts([superclass: C].[P])
into[concrete: C : P]
.Note that in the new rewrite loop, the protocol conformance and concrete conformance rules appear in empty context, and the concrete type rule appears in context. This means the loop can be used to eliminate either the protocol conformance or the concrete conformance rules.
Concrete conformance symbols order before protocol conformance symbols, so a rule
T.[concrete: C : P] => T
orders beforeT.[P] => T
. This means generating conformances will prefer to mark the latter as redundant, if possible.Putting everything together, this means that given a signature like
The
T : Sequence
requirement will become redundant. The minimized rewrite system will also have the concrete conformance rule. Since there is no such thing as a "concrete conformance requirement" in generic signatures, these rules are just dropped for now.