@@ -592,6 +592,46 @@ autorelease in the callee.
592592 importer only imports non-native methods and types as ``throws ``
593593 when it is possible to do this automatically.
594594
595+ - SIL function types may provide a pattern signature and substitutions
596+ to express that values of the type use a particular generic abstraction
597+ pattern. Both must be provided together. If a pattern signature is
598+ present, the component types (parameters, yields, and results) must be
599+ expressed in terms of the generic parameters of that signature.
600+ The pattern substitutions should be expressed in terms of the generic
601+ parameters of the overall generic signature, if any, or else
602+ the enclosing generic context, if any.
603+
604+ A pattern signature follows the ``@substituted `` attribute, which
605+ must be the final attribute preceding the function type. Pattern
606+ substitutions follow the function type, preceded by the ``for ``
607+ keyword. For example::
608+
609+ @substituted <T: Collection> (@in T) -> @out T.Element for Array<Int>
610+
611+ The low-level representation of a value of this type may not match
612+ the representation of a value of the substituted-through version of it::
613+
614+ (@in Array<Int>) -> @out Int
615+
616+ Substitution differences at the outermost level of a function value
617+ may be adjusted using the ``convert_function `` instruction. Note that
618+ this only works at the outermost level and not in nested positions.
619+ For example, a function which takes a parameter of the first type above
620+ cannot be converted by ``convert_function `` to a function which takes
621+ a parameter of the second type; such a conversion must be done with a
622+ thunk.
623+
624+ Type substitution on a function type with a pattern signature and
625+ substitutions only substitutes into the substitutions; the component
626+ types are preserved with their exact original structure.
627+
628+ - In the implementation, a SIL function type may also carry substitutions
629+ for its generic signature. This is a convenience for working with
630+ applied generic types and is not generally a formal part of the SIL
631+ language; in particular, values should not have such types. Such a
632+ type behaves like a non-generic type, as if the substitutions were
633+ actually applied to the underlying function type.
634+
595635Coroutine Types
596636```````````````
597637
@@ -815,7 +855,8 @@ Functions
815855::
816856
817857 decl ::= sil-function
818- sil-function ::= 'sil' sil-linkage? sil-function-name ':' sil-type
858+ sil-function ::= 'sil' sil-linkage? sil-function-attribute+
859+ sil-function-name ':' sil-type
819860 '{' sil-basic-block+ '}'
820861 sil-function-name ::= '@' [A-Za-z_0-9]+
821862
@@ -827,6 +868,134 @@ The ``sil`` syntax declares the function's name and SIL type, and
827868defines the body of the function inside braces. The declared type must
828869be a function type, which may be generic.
829870
871+
872+ Function Attributes
873+ ```````````````````
874+ ::
875+
876+ sil-function-attribute ::= '[canonical]'
877+
878+ The function is in canonical SIL even if the module is still in raw SIL.
879+ ::
880+
881+ sil-function-attribute ::= '[ossa]'
882+
883+ The function is in OSSA (ownership SSA) form.
884+ ::
885+
886+ sil-function-attribute ::= '[transparent]'
887+
888+ Transparent functions are always inlined and don't keep their source
889+ information when inlined.
890+ ::
891+
892+ sil-function-attribute ::= '[' sil-function-thunk ']'
893+ sil-function-thunk ::= 'thunk'
894+ sil-function-thunk ::= 'signature_optimized_thunk'
895+ sil-function-thunk ::= 'reabstraction_thunk'
896+
897+ The function is a compiler generated thunk.
898+ ::
899+
900+ sil-function-attribute ::= '[dynamically_replacable]'
901+
902+ The function can be replaced at runtime with a different implementation.
903+ Optimizations must not assume anything about such a function, even if the SIL
904+ of the function body is available.
905+ ::
906+
907+ sil-function-attribute ::= '[dynamic_replacement_for' identifier ']'
908+ sil-function-attribute ::= '[objc_replacement_for' identifier ']'
909+
910+ Specifies for which function this function is a replacement.
911+ ::
912+
913+ sil-function-attribute ::= '[exact_self_class]'
914+
915+ The function is a designated initializers, where it is known that the static
916+ type being allocated is the type of the class that defines the designated
917+ initializer.
918+ ::
919+
920+ sil-function-attribute ::= '[without_actually_escaping]'
921+
922+ The function is a thunk for closures which are not actually escaping.
923+ ::
924+
925+ sil-function-attribute ::= '[' sil-function-purpose ']'
926+ sil-function-purpose ::= 'global_init'
927+
928+ The implied semantics are:
929+
930+ - side-effects can occur any time before the first invocation.
931+ - all calls to the same ``global_init `` function have the same side-effects.
932+ - any operation that may observe the initializer's side-effects must be
933+ preceded by a call to the initializer.
934+
935+ This is currently true if the function is an addressor that was lazily
936+ generated from a global variable access. Note that the initialization
937+ function itself does not need this attribute. It is private and only
938+ called within the addressor.
939+ ::
940+
941+ sil-function-attribute ::= '[weak_imported]'
942+
943+ Cross-module references to this function should always use weak linking.
944+ ::
945+
946+ sil-function-attribute ::= '[available' sil-version-tuple ']'
947+ sil-version-tuple ::= [0-9]+ ('.' [0-9]+)*
948+
949+ The minimal OS-version where the function is available.
950+ ::
951+
952+ sil-function-attribute ::= '[' sil-function-inlining ']'
953+ sil-function-inlining ::= 'never'
954+
955+ The function is never inlined.
956+ ::
957+
958+ sil-function-inlining ::= 'always'
959+
960+ The function is always inlined, even in a ``Onone `` build.
961+ ::
962+
963+ sil-function-attribute ::= '[' sil-function-optimization ']'
964+ sil-function-inlining ::= 'Onone'
965+ sil-function-inlining ::= 'Ospeed'
966+ sil-function-inlining ::= 'Osize'
967+
968+ The function is optimized according to this attribute, overriding the setting
969+ from the command line.
970+ ::
971+
972+ sil-function-attribute ::= '[' sil-function-effects ']'
973+ sil-function-effects ::= 'readonly'
974+ sil-function-effects ::= 'readnone'
975+ sil-function-effects ::= 'readwrite'
976+ sil-function-effects ::= 'releasenone'
977+
978+ The specified memory effects of the function.
979+ ::
980+
981+ sil-function-attribute ::= '[_semantics "' [A-Za-z._0-9]+ '"]'
982+
983+ The specified high-level semantics of the function. The optimizer can use this
984+ information to perform high-level optimizations before such functions are
985+ inlined. For example, ``Array `` operations are annotated with semantic
986+ attributes to let the optimizer perform redundant bounds check elimination and
987+ similar optimizations.
988+ ::
989+
990+ sil-function-attribute ::= '[_specialize "' [A-Za-z._0-9]+ '"]'
991+
992+ Specifies for which types specialized code should be generated.
993+ ::
994+
995+ sil-function-attribute ::= '[clang "' identifier '"]'
996+
997+ The clang node owner.
998+
830999Basic Blocks
8311000~~~~~~~~~~~~
8321001::
0 commit comments