Skip to content

Commit b994bf3

Browse files
committedOct 12, 2020
Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a generic function in a library. The following definition provides a pre-specialized entry point for `genericFunc(_:)` for the parameter type `Int` that clients of the library can call. ``` @_specialize(exported: true, where T == Int) public func genericFunc<T>(_ t: T) { ... } ``` Pre-specializations of internal `@inlinable` functions are allowed. ``` @usableFromInline internal struct GenericThing<T> { @_specialize(exported: true, where T == Int) @inlinable internal func genericMethod(_ t: T) { } } ``` There is syntax to pre-specialize a method from a different module. ``` import ModuleDefiningGenericFunc @_specialize(exported: true, target: genericFunc(_:), where T == Double) func prespecialize_genericFunc(_ t: T) { fatalError("dont call") } ``` Specially marked extensions allow for pre-specialization of internal methods accross module boundries (respecting `@inlinable` and `@usableFromInline`). ``` import ModuleDefiningGenericThing public struct Something {} @_specializeExtension extension GenericThing { @_specialize(exported: true, target: genericMethod(_:), where T == Something) func prespecialize_genericMethod(_ t: T) { fatalError("dont call") } } ``` rdar://64993425
1 parent be38df8 commit b994bf3

File tree

85 files changed

+1978
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1978
-332
lines changed
 

‎docs/ABI/Mangling.rst

+1
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ Function Specializations
995995
::
996996

997997
specialization ::= type '_' type* 'Tg' SPEC-INFO // Generic re-abstracted specialization
998+
specialization ::= type '_' type* 'Ts' SPEC-INFO // Generic re-abstracted prespecialization
998999
specialization ::= type '_' type* 'TG' SPEC-INFO // Generic not re-abstracted specialization
9991000
specialization ::= type '_' type* 'Ti' SPEC-INFO // Inlined function with generic substitutions.
10001001

‎include/swift/AST/Attr.def

+5
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ SIMPLE_DECL_ATTR(globalActor, GlobalActor,
584584
APIStableToAdd | APIBreakingToRemove,
585585
104)
586586

587+
SIMPLE_DECL_ATTR(_specializeExtension, SpecializeExtension,
588+
OnExtension | UserInaccessible |
589+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
590+
105)
591+
587592
#undef TYPE_ATTR
588593
#undef DECL_ATTR_ALIAS
589594
#undef CONTEXTUAL_DECL_ATTR_ALIAS

0 commit comments

Comments
 (0)