Skip to content

[ABI] Rework protocol descriptor metadata. #18163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 24, 2018

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jul 24, 2018

Reimplement protocol descriptors for Swift protocols as a kind of
context descriptor, dropping the Objective-C protocol compatibility
layout. The new protocol descriptors have several advantages over the
current implementation:

  • They drop all of the unused fields required for layout-compatibility
    with Objective-C protocols.
  • They encode the full requirement signature of the protocol. This
    maintains more information about the protocol itself, including
    (e.g.) correctly encoding superclass requirements.
  • They fit within the general scheme of context descriptors, rather than
    being their own thing, which allows us to share more code with
    nominal type descriptors.
  • They only use relative pointers, so they’re smaller and can be placed
    in read-only memory
  • They store simple names rather than weird backward-compatible _Tt
    mangled names.

Implements rdar://problem/38815359.

…overlap.

As a small step toward splitting apart the Swift and Objective-C protocol
descriptors, eliminate most places where we rely on a shared representation.
Introduce TargetObjCProtocolPrefix, which describes just enough of the
Objective-C runtime’s Protocol structure to extract the name without
having to call Objective-C’s protocol_getName().
When reading the protocol metadata from existential type metadata,
check the “isObjC” bit and handle the reading of the Objective-C
protocol name (using TargetObjCProtocolPrefix) separately from the reading the name of a Swift protocol (using TargetProtocolDescriptor).
More preparation for separating the layout of these two entities.
Reimplement protocol descriptors for Swift protocols as a kind of
context descriptor, dropping the Objective-C protocol compatibility
layout. The new protocol descriptors have several advantages over the
current implementation:

* They drop all of the unused fields required for layout-compatibility
  with Objective-C protocols.
* They encode the full requirement signature of the protocol. This
  maintains more information about the protocol itself, including
  (e.g.) correctly encoding superclass requirements.
* They fit within the general scheme of context descriptors, rather than
  being their own thing, which allows us to share more code with
  nominal type descriptors.
* They only use relative pointers, so they’re smaller and can be placed
  in read-only memory

 Implements rdar://problem/38815359.
@DougGregor DougGregor force-pushed the protocol-context-descriptor branch from cc92895 to a54a6d8 Compare July 24, 2018 05:13
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

From the macOS testing:

02:07:18 Could not update commit status of the Pull Request on GitHub.
02:07:18 java.net.NoRouteToHostException: No route to host (Host unreachable)

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

Rather than storing a mangled name in a Swift protocol descriptor,
which encodes information that is redundant with the context of the
protocol, store an unmangled name as in nominal type descriptors. Update
the various places where this name is used to extract the demangle
tree from the context descriptors.
These were used to encode the “inherited protocols” for Objective-C
Protocol structures. These are no longer a part of either Swift protocol
descriptors or the part of Objective-C Protocol structures that the
Swift runtime inspects.
@DougGregor
Copy link
Member Author

@swift-ci please test macOS

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a54a6d8

…ects.

Protocols are never generic, so don't inherit from
TrailingGenericContextObjects. Instead, directly use
swift::ABI::TrailingObjects. Since protocols are never generic, this
doesn't actually affect layout at all; it's cleanup.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit cf501b4 into swiftlang:master Jul 24, 2018
@DougGregor DougGregor deleted the protocol-context-descriptor branch July 25, 2018 00:02
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.

2 participants