Skip to content

SE-0460: Introduce @specialized attribute #81714

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 1 commit into from
May 28, 2025

Conversation

aschwaighofer
Copy link
Contributor

Implements SE-0460 -- the non-underscored version of @specialized.

It allows to specify "internal" (not abi affecting) specializations.

Quoting from the proposal:

A new attribute, @specialized, will allow the author of a function to cause the compiler to generate specializations of that function. In the body of the unspecialized version, the types are first checked to see if they are of one of the specialized types. If they are, the specialized version will be called.

So in our example above:

extension Sequence where Element: BinaryInteger {
  @specialized(where Self == [Int])
  func sum() -> Double {
    reduce(0) { $0 + Double($1) }
  }
}

A specialized version of [Int].sum will be generated in the same way as if it had been specialized for a callsite. And inside the unspecialized generic code, the additional check-and-redispatch logic will be inserted at the start of the function.

rdar://150033316

@aschwaighofer
Copy link
Contributor Author

test with swiftlang/swift-syntax#3082

@swift-ci test

@aschwaighofer
Copy link
Contributor Author

@swift-ci test

@aschwaighofer
Copy link
Contributor Author

test with swiftlang/swift-syntax#3082

@swift-ci test

Implements SE-0460 -- the non-underscored version of @specialized.

It allows to specify "internal" (not abi affecting) specializations.

rdar://150033316
@aschwaighofer
Copy link
Contributor Author

test with swiftlang/swift-syntax#3082

@swift-ci test

1 similar comment
@aschwaighofer
Copy link
Contributor Author

test with swiftlang/swift-syntax#3082

@swift-ci test

@aschwaighofer aschwaighofer merged commit 7ac5516 into swiftlang:main May 28, 2025
5 checks passed
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.

1 participant