Trying to grok the ABI documents, w.r.t. strong typedefs


(Daryle Walker) #1

I’m trying to understand two of the ABI documents, <https://github.com/apple/swift/blob/master/docs/ABI.rst> and <https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md>, with respect to a strong type-alias idea I just posted:

retype IDENTIFIER: IMPLEMENTATION-TYPE (“,” PROTOCOL)* {
// New methods and computed properties
// Maybe type-level stored properties
// Optionally export symbols from the original type to this one
}

I think we would need a new ABI entry for re-types. I think the implementation type would have to be a value type (structs, enums, tuples, and possibly someday fixed-sized arrays); I couldn’t get how to make a retype work with a class’s witness information block (which are customized to fit Objective-C compatibility) and what would it mean to shadow something that is a pointer to the real information anyway. This also means that retypes are always value types themselves.

Looking at the ABI Stability Manifesto:

* A retype has the same data layout as its implementation type. It has the same trivial and bitwise-movable status as its implementation type.
* The value metadata for a retype needs a pointer to its implementation type’s value metadata. I don’t know if a retype should share its witness table with the implementation type, or have a separate table that has a pointer to the original’s table.

Looking at the ABI doc:

* A retype has the same layout as its implementation type.
* The common metadata layout of the type metadata has a new kind value for retypes.
* In addition to the common metadata layout, a retype’s metadata has a nominal type descriptor, a reference to the parent metadata record, a reference to the implementation type’s metadata record, then possibly a generic parameter vector.
* The nominal type descriptor needs a new kind for retypes. I’m not sure if it needs any field/case/payload data.
* I don’t know if new mangling operators are needed for retypes, or if they can reuse their implementation type’s codes.

Other:

* I guess methods and computed property getters & setters of a type are listed with the general functions, with some marker of where the “self” pointer is. New methods of a retype would need new function entries, but I don’t know if exported methods would just reuse the implementation type’s method entry, or would new functions be created that just forward to the implementation type’s versions.

···


Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com