Skip to content

Conversation

johnno1962
Copy link
Contributor

@johnno1962 johnno1962 commented Jun 26, 2019

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:

extension FixedWidthInteger: ExpressibleByUnicodeScalarLiteral {
    public init(unicodeScalarLiteral value: Unicode.Scalar) {
      self = Self(value.value)
    }
}

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.

@johnno1962 johnno1962 changed the title Protocol extensions with conformances? DNM Protocol extensions with conformances? Jun 28, 2019
@johnno1962
Copy link
Contributor Author

There are seemingly irresolvable issues with this idea if you use it across files. See the JIRA

@johnno1962 johnno1962 closed this Jun 28, 2019
@johnno1962 johnno1962 reopened this Jun 30, 2019
@johnno1962 johnno1962 force-pushed the proto-inherit-proto branch 2 times, most recently from 82a0959 to 6b1ee6e Compare June 30, 2019 16:57
@johnno1962 johnno1962 force-pushed the proto-inherit-proto branch from 6b1ee6e to 88eea42 Compare June 30, 2019 20:23
@johnno1962 johnno1962 changed the title DNM Protocol extensions with conformances? [DNM] Protocol extensions with conformances? Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant