Skip to content
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

[SR-11128] Protocol stubs include __consuming and __owned #53524

Open
beccadax opened this issue Jul 14, 2019 · 7 comments
Open

[SR-11128] Protocol stubs include __consuming and __owned #53524

beccadax opened this issue Jul 14, 2019 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@beccadax
Copy link
Contributor

Previous ID SR-11128
Radar None
Original Reporter @beccadax
Type Bug
Environment

Reproduced in Xcode 11 beta 3 and Swift Development Snapshot 2019-07-11 (a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: b4e61ffcb5ec292d8f0f34fef152663e

Issue Description:

When Swift offers to apply protocol stubs in Xcode, the fix-it produced may include the __consuming and __owned modifiers, which are not currently a supported part of the language and are not intended to be used in most conformances even once they are officially added.

Steps To Reproduce:
Although this is a compiler bug, the printed form of compiler diagnostics doesn't display fix-its in sufficient detail to easily demonstrate it. It's most easily reproduced in an Xcode with an appropriate toolchain:

1. Create a new Xcode project with this code in a Swift source file:

struct MyType: Hashable {
  typealias Element = Int
}
extension MyType: SetAlgebra {}

2. Build it.
3. Click the error badge on the extension line, then click the “Fix” button to apply the fix-it.

Results:
Some of the stubbed declarations include __consuming and/or __owned modifiers, such as:

__consuming func union(_ other: __owned MyType) -> MyType

I would not expect Swift to suggest these modifiers, since they aren’t officially part of the language. Instead I would expect it to drop these keywords:

func union(_ other: MyType) -> MyType

Even after we fully support move-only types, I would expect the protocol stubs for a non-move-only conformance to remove unnecessary move-only–related modifiers so that users don't need to worry about this complexity.

@beccadax
Copy link
Contributor Author

In later work on my project, I realized that mutating is not treated as compatible with __consuming in copyable (i.e. currently all) types. This seems…less than ideal.

@belkadan
Copy link
Contributor

Can you file a separate bug for "mutating implementations should satisfy consuming requirements"?

I think there's a Radar for the protocol stubs one, too.

@beccadax
Copy link
Contributor Author

We talked and we don't actually think mutating methods should satisfy __consuming requirements; however, dropping __consuming should be (and is) supported. So the bug here is merely that the compiler should drop these attributes if you aren't conforming a move-only type.

@theblixguy
Copy link
Collaborator

Just to clarify, do we always want to drop __consuming and __owned when printing stubs or only when the type is not move-only? Also, since only functions can have the __consuming attribute (correct me if I am wrong), should we add a check before printing it?

@belkadan
Copy link
Contributor

We don't have any such thing as "move-only types" yet. And I think you meant "only structs and enums" rather than "only functions", right?

@theblixguy
Copy link
Collaborator

I meant functions, because if you add **consuming ** to anything other than a func then the compiler throws an error: "__consuming may only be used on 'func' declarations" (unless I am doing something wrong!). To fix this, I was thinking of setting SkipUnderscoredKeywords=true in printRequirementStub().

@belkadan
Copy link
Contributor

The point of protocol stubs is to match what was written in a protocol's requirements, though. If someone put __consuming on a non-function in a protocol, they already would have gotten an error.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants