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-12003] Anonymous func declarations #54438

Open
dan-zheng opened this issue Jan 9, 2020 · 1 comment
Open

[SR-12003] Anonymous func declarations #54438

dan-zheng opened this issue Jan 9, 2020 · 1 comment

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-12003
Radar rdar://problem/58455446
Original Reporter @dan-zheng
Type New Feature
Additional Detail from JIRA
Votes 1
Component/s
Labels New Feature
Assignee None
Priority Medium

md5: 3dc3cab5f8f6574b634f38be788d67e5

relates to:

  • SR-13688 Require @derivative functions to have same access level as original declaration

Issue Description:

Implement anonymous func declarations.

Anonymous func declarations are useful for defining functions that intentionally cannot be referenced directly but that serve some other purpose.

Use cases:

// 1. `@dynamicReplacement(for:)`: dynamic replacement functions.
dynamic func foo(_ x: Float) -> Float { x }

@_dynamicReplacement(for: foo)
func _(x: Float) -> Float { x + 1 }
// 2. `@derivative` and `@transpose`: derivative and transpose registration.
// `func _` helps avoid exposing derivative and transpose functions as public APIs.
public func bar(_ x: Float) -> Float { x }

// Publicly registered derivative. Derivative function itself is not exposed, however.
@derivative(of: bar)
public func _(_ x: Float) -> (value: Float, differential: (Float) -> Float) {
  (x, { dx in dx })
}

// Publicly registered transpose. Transpose function itself is not exposed, however.
@transpose(of: bar)
public func _(_ v: Float) -> Float { v }

Todo: pitch to Swift Evolution.

@beccadax
Copy link
Contributor

beccadax commented Jan 9, 2020

@swift-ci create

@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
Projects
None yet
Development

No branches or pull requests

2 participants