[Accepted with modification] SE-0068: Expanding Swift Self to class members and value types


(Chris Lattner) #1

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md

The review of SE-0068: "Expanding Swift Self to class members and value types" ran from April 20...25, 2016. A subset of the proposal has been *accepted*:

This proposal had light discussion in the community review process, but the core team heavily debated it. It includes two pieces:

1. Expanding the existing support for Self to work in value types, and in the bodies of classes.

2. Replacing the x.dynamicType expression with x.Self, a purely syntactic change that eliminates the “dynamicType” keyword.

The core team has accepted the first half for this proposal. This allows the use of “Self” as shorthand for referring to the containing type (in the case of structs, enums, and final class) or the dynamic type (in the case of non-final classes). Most of the discussion in the core team centered around whether people familiar with the former behavior would be surprised by the (more general) behavior when using it in a class, but they came to agree that this is actually a simple and general model, and a helpful point of consistency.

In contrast, there are still a number of concerns with rebranding x.dynamicType as x.Self. This may (or may not) be the right ultimate direction to go, but it should be split out of this proposal. There is another outstanding proposal that would eliminate the “Type.self” syntax as being necessary, and the core team would like to resolve that discussion before tackling x.dynamicType.

Thank you to Erica Sadun for proposing this! I filed SR-1340 to track implementation work for this, this would be a great starter project for someone interested in getting involved in the Swift compiler.

-Chris Lattner
Review Manager