@@ -343,49 +343,6 @@ used. *NOTE* The standard library is a special case. Definitions in
343
343
the standard library are visible in all modules and available for
344
344
specialization.
345
345
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
-
389
346
The cost of large Swift values
390
347
==============================
391
348
@@ -586,6 +543,15 @@ protocols as class-only protocols to get better runtime performance.
586
543
.. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
587
544
588
545
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.
589
555
590
556
Footnotes
591
557
=========
0 commit comments