[DNM] Protocol extensions with conformances? #25786
Closed
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.
Hi Apple,
Another speculative PR, this time exploring the feasibility of allowing conformances when declaring a protocol extension. The implementation is functional but at the stage where it could do with some guidance from someone who knows what they are doing. The new feature can be used to give behaviour to all nominals conforming to the protocol being extended. An example would be the following:
Thereafter strings could be converted to fixed width integers.
Most of the compiler mechanics required is already in place in the existing implementation of protocol extensions and this PR is largely based around a relatively minor change adapting the function
ConformanceLookupTable::addInheritedProtocols
which looks after implying the extension's conformance to any nationals conforming to the protocol being extended and tracking additional witness tables that need to be emitted. There is one limitation in that usage of nominals acquiring the new conformance must be in the same module as an extension of the protocol being extended. A test has been added to demonstrate what is possible. As this is additive all tests run fine.A toolchain is available for evaluation here
Resolves SR-11013.