-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Allow Copyable Types To Elide Ownership Conventions #16999
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
Conversation
@swift-ci please smoke test |
Does this work with retroactive conformances too? |
Changing (non-defaulted) ownership conventions is an ABI-incompatible change. |
You can still thunk in the witness (for copyable types), though. These annotations in a protocol requirement shouldn't be a source-affecting change for any copyable type witnesses. |
I’ll add a test for the thunking then. I’ve got to clean up the commit log anyways. |
I’m not sure I like this. Confirming to a protocol should not change the types of witnesses. Instead, the witness thunk should handle convention changes. |
@slavapestov Yeah, now that you mention it, that's more the model I had in mind too. Trying to push the convention attributes onto witnessing declarations could also lead to ABI breaks at a distance if you add a protocol conformance. |
The witnesses shouldn't be allowed to break the interface of their parents. Especially when we have moveonly contexts, the ability to e.g.
Retroactive modelling is a known ABI break but wouldn't it be less of a concern now that we're mangling conventions in? If you tried to swap a binary framework that changed conventions you should get linker errors. |
For copyable types, though, there is no difference in the user interface. The ABI is an implementation detail.
The ABI break seems gratuitous in this case. If a library wants to make a public type conform to a new protocol, it should be allowed to without breaking ABI. |
69d6267
to
335212a
Compare
For those that are watching this thread/go digging for it in the future: There was a misunderstanding here. Witnesses to protocol requirements in a copyable context may elide ownership requirements. We will not change the calling convention of the witness and must thunk to it. If the author of the witness cares about the behavior of the witness thunk - say for performance purposes - they must make sure that they explicitly annotate with the requirement's very same ownership conventions. Otherwise, we are at liberty to copy or borrow. In a future moveonly context, these concerns are allayed by the fact that we simply won't allow ownership convention changes in witness thunks by virtue of Sema rejecting the protocol conformance. |
335212a
to
10f25c1
Compare
Allow witnesses to protocols in a copyable context to elide explicit ownership conventions. This allows clients like the standard library to standardize on one ownership convention without an ABI or API breaking change in 3rd party code. In the future, moveonly contexts must disallow this default behavior else the witness thunks could silently transfer ownership. rdar://40774922 protocol P { __consuming func implicit(x: __shared String) __consuming func explicit(x: __owned String) __consuming func mismatch(x: __shared String) } class C : P { // C.implicit(x:) takes self and x '@guaranteed' thru the witness thunk func implicit(x: String) {} // C.explicit(x:) takes self and x @owned with no convention changes __consuming func explicit(x: __owned String) {} // Would inherit __consuming, but x has been spelled __owned so the requirement match fails. func mismatch(x: __owned String) {} }
10f25c1
to
9bd02e1
Compare
@swift-ci please smoke test |
⛵️ |
Allow witnesses to protocols in a copyable context to elide explicit
ownership conventions. This allows clients like the standard library to
standardize on one ownership convention without an ABI or API breaking
change in 3rd party code.
In the future, moveonly contexts must disallow this default behavior
else the witness thunks could silently transfer ownership.
rdar://40774922