Skip to content

Commit 00b46f3

Browse files
committed
[Gardening] De-RST TransparentAttr
1 parent 309f864 commit 00b46f3

4 files changed

+77
-81
lines changed

docs/LibraryEvolution.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ any future use of the function must take this into account.
210210
Although they are not a supported feature for arbitrary libraries at this time,
211211
public `transparent`_ functions are implicitly marked ``@inlinable``.
212212

213-
.. _transparent: https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst
213+
.. _transparent: https://github.com/apple/swift/blob/master/docs/TransparentAttr.md
214214

215215

216216
Restrictions on Inlinable Functions

docs/StandardLibraryProgrammersManual.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let theBits = unsafeBitCast(&x, ...)
180180

181181
Should only be used if necessary. This has the effect of forcing inlining to occur before any dataflow analyses take place. Unless you specifically need this behavior, use `@_inline(__always)` or some other mechanism. Its primary purpose is to force the compiler's static checks to peer into the body for diagnostic purposes.
182182

183-
Use of this attribute imposes limitations on what can be in the body. For more details, refer to the [documentation](https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst).
183+
Use of this attribute imposes limitations on what can be in the body. For more details, refer to the [documentation](https://github.com/apple/swift/blob/master/docs/TransparentAttr.md).
184184

185185
#### `@unsafe_no_objc_tagged_pointer`
186186

docs/TransparentAttr.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
`@_transparent`
2+
=================
3+
4+
Semantically, `@_transparent` means something like "treat this operation as
5+
if it were a primitive operation". The name is meant to imply that both the
6+
compiler and the compiled program will "see through" the operation to its
7+
implementation.
8+
9+
This has several consequences:
10+
11+
- Any calls to a function marked `@_transparent` MUST be inlined prior to
12+
doing dataflow-related diagnostics, even under `-Onone`. This may be
13+
necessary to *catch* dataflow errors.
14+
15+
- Because of this, a `@_transparent` function is implicitly inlinable, in
16+
that changing its implementation most likely will not affect callers in
17+
existing compiled binaries.
18+
19+
- Because of this, a public or `@usableFromInline` `@_transparent` function
20+
MUST only reference public symbols, and MUST not be optimized based on
21+
knowledge of the module it's in. [The former is caught by checks in Sema.]
22+
23+
- Debug info SHOULD skip over the inlined operations when single-stepping
24+
through the calling function.
25+
26+
This is all that `@_transparent` means.
27+
28+
29+
When should you use `@_transparent`?
30+
--------------------------------------
31+
32+
- Does the implementation of this function ever have to change? Then you can't
33+
allow it to be inlined.
34+
35+
- Does the implementation need to call private things---either true-`private`
36+
functions, or `internal` functions that might go away in the next release?
37+
Then you can't allow it to be inlined.
38+
39+
- Is it okay if the function is *not* inlined? You'd just prefer that it were?
40+
Then you should use `@inlinable`, rather than `@_transparent`. (If you
41+
really need this, you can add `@inline(__always)` as well.)
42+
43+
- Is it a problem if the function is inlined even under `-Onone`? Then you're
44+
really in the previous case. Trust the compiler.
45+
46+
- Is it a problem if you can't step through the function that's been inlined?
47+
Then you don't want `@_transparent`; you just want `@inline(__always)`
48+
(and probably `@inlinable` as well, for cross-module inlining).
49+
50+
- Is it okay if the inlining happens after all the dataflow diagnostics? Then
51+
you don't want `@_transparent`; you just want `@inline(__always)`.
52+
53+
If you made it this far, it sounds like `@_transparent` is the right choice.
54+
55+
56+
Interaction with other annotations
57+
----------------------------------
58+
59+
- As mentioned above, putting `@_transparent` on a function that is
60+
`public` or `@usableFromInline` exposes its body to other modules. It is
61+
not necessary to additionally include `@inlinable`.
62+
63+
- Unlike `@inlinable`, however, `@_transparent` does not imply
64+
`@usableFromInline`. It is possible to have functions marked
65+
`@_transparent` that are only meant for use within the current module or
66+
even the current file.
67+
68+
69+
Current implementation limitations
70+
----------------------------------
71+
72+
- When compiling in non-single-frontend mode, no SIL is generated for any
73+
functions but those in the primary file (for each frontend invocation),
74+
including `@inline(__always)` and `@_transparent` functions, which means
75+
they will not be inlined. This is semantically a bug. rdar://problem/15366167

docs/TransparentAttr.rst

-79
This file was deleted.

0 commit comments

Comments
 (0)