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

Opaque parameters #40993

Merged
merged 7 commits into from
Jan 27, 2022
Merged

Opaque parameters #40993

merged 7 commits into from
Jan 27, 2022

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jan 25, 2022

Implement function parameters of the form some P be synthesizing an
implicit generic parameter whose requirements come from the opaque
type. We then map the opaque type back to the generic parameter, and
print as the opaque type. This allows us to write functions with
implicit generic parameters:

func f(_: some Collection) { }

which is equivalent to:

func f<T: Collection>(_: T) { }

where T is an otherwise-unused generic parameter name.

All of this is behind the experimental frontend flag
-enable-experimental-opaque-parameters.

Tracked via rdar://86032821

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@slavapestov
Copy link
Contributor

Awesome!

func f<T: Collection>(_: some T) { }

That some shouldn't be there right?

@DougGregor
Copy link
Member Author

That some shouldn't be there right?

Right, thanks

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - 10d75b30739a760a7aedde49ba717edd0539280f

Install command
tar zxf swift-PR-40993-790-ubuntu16.04.tar.gz
More info

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - 842ab9d8ff3138bde08faf7e6545c5ecec776fde

Install command
tar zxf swift-PR-40993-795-ubuntu16.04.tar.gz
More info

@swift-ci
Copy link
Contributor

macOS Toolchain
Download Toolchain
Git Sha - 842ab9d8ff3138bde08faf7e6545c5ecec776fde

Install command
tar -zxf swift-PR-40993-1311-osx.tar.gz --directory ~/

Implement function parameters of the form `some P` be synthesizing an
implicit generic parameter whose requirements come from the opaque
type. We then map the opaque type back to the generic parameter, and
print as the opaque type. This allows us to write functions with
implicit generic parameters:

```swift
func f(_: some Collection) { }
```

which is equivalent to:

```swift
func f<T: Collection>(_: some T) { }
```

where `T` is an otherwise-unused generic parameter name.

All of this is behind the experimental frontend flag
`-enable-experimental-opaque-parameters`.
When printing the generic parameters and requirements clauses of
declarations that involve opaque parameters, suppress the implicit
generic parameters created by the opaque parameters as well as the
generic requirements that involve said parameters.
That way, they can be used with Swift interfaces.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 20.04)
Download Toolchain
Git Sha - 66e12e8

Install command
tar zxf swift-PR-40993-796-ubuntu20.04.tar.gz
More info

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 20.04)
Download Toolchain
Git Sha - 49bc1ed

Install command
tar zxf swift-PR-40993-798-ubuntu20.04.tar.gz
More info

@DougGregor DougGregor merged commit 05f2c49 into swiftlang:main Jan 27, 2022
@DougGregor DougGregor deleted the opaque-parameters branch January 27, 2022 17:19
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.

3 participants