Skip to content

Commit df6e927

Browse files
committed
Documentation: move the @_specialize discussion into
proposals/UnsupportedOptimizationAttributes.rst.
1 parent 0725bc9 commit df6e927

File tree

3 files changed

+74
-43
lines changed

3 files changed

+74
-43
lines changed

docs/OptimizationTips.rst

+9-43
Original file line numberDiff line numberDiff line change
@@ -343,49 +343,6 @@ used. *NOTE* The standard library is a special case. Definitions in
343343
the standard library are visible in all modules and available for
344344
specialization.
345345

346-
Advice: Use @_specialize to direct the compiler to specialize generics
347-
----------------------------------------------------------------------
348-
349-
The compiler only automatically specializes generic code if the call
350-
site and the callee function are located in the same module. However,
351-
the programmer can provide hints to the compiler in the form of
352-
@_specialize attributes. For details see
353-
:ref:`generics-specialization`.
354-
355-
This attribute instructs the compiler to specialize on the specified
356-
concrete type list. The compiler inserts type checks and dispatches
357-
from the generic function to the specialized variant. In the following
358-
example, injecting the @_specialize attribute speeds up the code by
359-
about 10 times.
360-
361-
::
362-
363-
/// ---------------
364-
/// Framework.swift
365-
366-
public protocol Pingable { func ping() -> Self }
367-
public protocol Playable { func play() }
368-
369-
extension Int : Pingable {
370-
public func ping() -> Int { return self + 1 }
371-
}
372-
373-
public class Game<T : Pingable> : Playable {
374-
var t : T
375-
376-
public init (_ v : T) {t = v}
377-
378-
@_specialize(Int)
379-
public func play() {
380-
for _ in 0...100_000_000 { t = t.ping() }
381-
}
382-
}
383-
384-
/// -----------------
385-
/// Application.swift
386-
387-
Game(10).play
388-
389346
The cost of large Swift values
390347
==============================
391348

@@ -586,6 +543,15 @@ protocols as class-only protocols to get better runtime performance.
586543
.. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
587544
588545
546+
Unsupported Optimization Attributes
547+
===================================
548+
549+
Some underscored type attributes function as optimizer directives. Developers
550+
are welcome to experiment with these attributes and send back bug reports and
551+
other feedback, including meta bug reports on the following incomplete
552+
documentation: :ref:`UnsupportedOptimizationAttributes`. These attributes are
553+
not supported language features. They have not been reviewed by Swift Evolution
554+
and are likely to change between compiler releases.
589555

590556
Footnotes
591557
=========

docs/TransparentAttr.rst

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ This has several consequences:
2828
This is all that ``@_transparent`` means.
2929

3030

31+
.. _transparent-attribute:
32+
3133
When should you use ``@_transparent``?
3234
--------------------------------------
3335

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
:orphan:
2+
3+
.. _UnsupportedOptimizationAttributes:
4+
5+
===================================
6+
Unsupported Optimization Attributes
7+
===================================
8+
9+
The following attributes are experimental optimizer directives. The attribute
10+
names are underscored because they are internal compiler directives. These are
11+
not supported language features, have not gone through the Swift Evolution
12+
process, and future versions of the compiler are likely to drop support,
13+
requiring manual intervention of the source maintainer.
14+
15+
@inline(__always)
16+
-----------------
17+
18+
Force inlining (at least at -O for now). See the discussion in
19+
:ref:`transparent-attribute`.
20+
21+
@_specialize directs the compiler to specialize generics
22+
--------------------------------------------------------
23+
24+
The compiler only automatically specializes generic code if the call
25+
site and the callee function are located in the same module. However,
26+
the programmer can provide hints to the compiler in the form of
27+
@_specialize attributes. For details see
28+
:ref:`generics-specialization`.
29+
30+
This attribute instructs the compiler to specialize on the specified
31+
concrete type list. The compiler inserts type checks and dispatches
32+
from the generic function to the specialized variant. In the following
33+
example, injecting the @_specialize attribute speeds up the code by
34+
about 10 times.
35+
36+
::
37+
38+
/// ---------------
39+
/// Framework.swift
40+
41+
public protocol Pingable { func ping() -> Self }
42+
public protocol Playable { func play() }
43+
44+
extension Int : Pingable {
45+
public func ping() -> Int { return self + 1 }
46+
}
47+
48+
public class Game<T : Pingable> : Playable {
49+
var t : T
50+
51+
public init (_ v : T) {t = v}
52+
53+
@_specialize(Int)
54+
public func play() {
55+
for _ in 0...100_000_000 { t = t.ping() }
56+
}
57+
}
58+
59+
/// -----------------
60+
/// Application.swift
61+
62+
Game(10).play
63+

0 commit comments

Comments
 (0)