Skip to content

Commit 4b98fb5

Browse files
committed
docs: Overhaul the documentation for SIL
With a focus on updating the documentation of Ownership SSA. The main changes are: * Created a new directory `docs/SIL` and moved all SIL-related files into this directory. * Converted `rst` files to markdown. * Extracted sections from `SIL.md` which go into very much detail - including the instruction reference - into separate files: `Types.md`, `Ownership.md`, `FunctionAttributes.md`, `Instructions.md`. Those files are referenced from `SIL.md` at the relevant places. * Rewrote and updated the OSSA part in `SIL.md` * Removed a few sections, which are not relevant anymore, like "Value dependency" (which is replaced by ownership concepts). * Fixed and improved a lot of small things.
1 parent 44481f8 commit 4b98fb5

12 files changed

+9347
-9243
lines changed

docs/SIL.rst

Lines changed: 0 additions & 9201 deletions
This file was deleted.
File renamed without changes.

docs/SIL/FunctionAttributes.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Function Attributes
2+
3+
This document is a reference guide for SIL function attributes. For an overview
4+
of SIL and OSSA see the [SIL](SIL.md) document.
5+
6+
### Canonical SIL stage override
7+
8+
```
9+
sil-function-attribute ::= '[canonical]'
10+
```
11+
12+
The function is in canonical SIL even if the module is still in raw SIL.
13+
14+
### Ownership SSA
15+
16+
```
17+
sil-function-attribute ::= '[ossa]'
18+
```
19+
20+
The function is in OSSA (ownership SSA) form.
21+
22+
### Transparent functions
23+
24+
```
25+
sil-function-attribute ::= '[transparent]'
26+
```
27+
28+
Transparent functions are always inlined and don't keep their source
29+
information when inlined.
30+
31+
### Thunks
32+
33+
```
34+
sil-function-attribute ::= '[' sil-function-thunk ']'
35+
sil-function-thunk ::= 'thunk'
36+
sil-function-thunk ::= 'signature_optimized_thunk'
37+
sil-function-thunk ::= 'reabstraction_thunk'
38+
sil-function-thunk ::= 'back_deployed_thunk'
39+
```
40+
41+
The function is a compiler generated thunk.
42+
43+
```
44+
sil-function-attribute ::= '[without_actually_escaping]'
45+
```
46+
47+
The function is a thunk for closures which are not actually escaping.
48+
49+
### Dynamically replaceable functions
50+
51+
```
52+
sil-function-attribute ::= '[dynamically_replacable]'
53+
```
54+
55+
The function can be replaced at runtime with a different implementation.
56+
Optimizations must not assume anything about such a function, even if
57+
the SIL of the function body is available.
58+
59+
```
60+
sil-function-attribute ::= '[dynamic_replacement_for' identifier ']'
61+
sil-function-attribute ::= '[objc_replacement_for' identifier ']'
62+
```
63+
64+
Specifies for which function this function is a replacement.
65+
66+
### exact_self_class
67+
68+
```
69+
sil-function-attribute ::= '[exact_self_class]'
70+
```
71+
72+
The function is a designated initializers, where it is known that the
73+
static type being allocated is the type of the class that defines the
74+
designated initializer.
75+
76+
### Global variable initialization
77+
78+
```
79+
sil-function-attribute ::= '[' sil-function-purpose ']'
80+
sil-function-purpose ::= 'global_init'
81+
```
82+
83+
A `global_init` function is used to access a global variable which needs to be
84+
initialized the first time the accessor is called. The implied semantics of a
85+
`global_init` function are:
86+
87+
- side-effects can occur any time before the first invocation.
88+
- all calls to the same `global_init` function have the same
89+
side-effects.
90+
- any operation that may observe the initializer's side-effects
91+
must be preceded by a call to the initializer.
92+
93+
This is currently true if the function is an addressor that was lazily
94+
generated from a global variable access. Note that the initialization
95+
function itself does not need this attribute. It is private and only
96+
called within the addressor.
97+
98+
```
99+
sil-function-purpose ::= 'global_init_once_fn'
100+
```
101+
102+
The actual initialization function for a global, which is called once by its
103+
corresponding `global_init` function.
104+
105+
```
106+
sil-function-purpose ::= 'lazy_getter'
107+
```
108+
109+
The function is a getter of a lazy property for which the backing storage is an
110+
`Optional` of the property's type. The getter contains a top-level
111+
[`switch_enum`](Instructions.md#switch_enum) (or
112+
[`switch_enum_addr`](Instructions.md#switch_enum_addr)), which tests if the
113+
lazy property is already computed. In the `None`-case, the property is computed
114+
and stored to the backing storage of the property.
115+
116+
After the first call of a lazy property getter, it is guaranteed that
117+
the property is computed and consecutive calls always execute the
118+
`Some`-case of the top-level [`switch_enum`](Instructions.md#switch_enum).
119+
120+
### Weakly imported functions
121+
122+
```
123+
sil-function-attribute ::= '[weak_imported]'
124+
```
125+
126+
Cross-module references to this function should always use weak linking.
127+
128+
### Stack protection
129+
130+
```
131+
sil-function-attribute ::= '[stack_protection]'
132+
```
133+
134+
Stack protectors are inserted into this function to detect stack related
135+
buffer overflows.
136+
137+
### Availability
138+
139+
```
140+
sil-function-attribute ::= '[available' sil-version-tuple ']'
141+
sil-version-tuple ::= [0-9]+ ('.' [0-9]+)*
142+
```
143+
144+
The minimal OS-version where the function is available.
145+
146+
### Function inlining control
147+
148+
```
149+
sil-function-attribute ::= '[' sil-function-inlining ']'
150+
sil-function-inlining ::= 'noinline'
151+
```
152+
153+
The function is never inlined.
154+
155+
```
156+
sil-function-inlining ::= 'always_inline'
157+
```
158+
159+
The function is always inlined.
160+
161+
### Optimization modes
162+
163+
```
164+
sil-function-attribute ::= '[' sil-function-optimization ']'
165+
sil-function-inlining ::= 'Onone'
166+
sil-function-inlining ::= 'Ospeed'
167+
sil-function-inlining ::= 'Osize'
168+
```
169+
170+
The function is optimized according to this attribute, overriding the
171+
setting from the command line.
172+
173+
```
174+
sil-function-attribute ::= '[' sil-function-effects ']'
175+
sil-function-effects ::= 'readonly'
176+
sil-function-effects ::= 'readnone'
177+
sil-function-effects ::= 'readwrite'
178+
sil-function-effects ::= 'releasenone'
179+
```
180+
181+
The specified memory effects of the function.
182+
183+
### Semantic attributes
184+
185+
```
186+
sil-function-attribute ::= '[_semantics "' [A-Za-z._0-9]+ '"]'
187+
```
188+
189+
The specified high-level semantics of the function. The optimizer can
190+
use this information to perform high-level optimizations before such
191+
functions are inlined. For example, `Array` operations are annotated
192+
with semantic attributes to let the optimizer perform redundant bounds
193+
check elimination and similar optimizations.
194+
195+
### Pre-specialization
196+
197+
```
198+
sil-function-attribute ::= '[_specialize "' [A-Za-z._0-9]+ '"]'
199+
```
200+
201+
Specifies for which types specialized code should be generated.
202+
203+
### Clang node owner
204+
205+
```
206+
sil-function-attribute ::= '[clang "' identifier '"]'
207+
```
208+
209+
The clang node owner.
210+
211+
### Performance constraints
212+
213+
```
214+
sil-function-attribute ::= '[' performance-constraint ']'
215+
performance-constraint :: 'no_locks'
216+
performance-constraint :: 'no_allocation'
217+
```
218+
219+
Specifies the performance constraints for the function, which defines
220+
which type of runtime functions are allowed to be called from the
221+
function.
222+
223+
```
224+
sil-function-attribute ::= '[perf_constraint]'
225+
```
226+
227+
Specifies that the optimizer and IRGen must not add runtime calls which
228+
are not in the function originally. This attribute is set for functions
229+
with performance constraints or functions which are called from
230+
functions with performance constraints.

0 commit comments

Comments
 (0)