You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/StandardLibraryProgrammersManual.md
+58-39
Original file line number
Diff line number
Diff line change
@@ -7,56 +7,37 @@ TODO: Should this subsume or link to [StdlibRationales.rst](https://github.com/a
7
7
TODO: Should this subsume or link to [AccessControlInStdlib.rst](https://github.com/apple/swift/blob/master/docs/AccessControlInStdlib.rst)
8
8
9
9
10
-
## (Meta): List of wants and TODOs for this guide
11
-
12
-
1. Library Organization
13
-
1. What files are where
14
-
1. Brief about CMakeLists
15
-
1. Brief about GroupInfo.json
16
-
1. What tests are where
17
-
1. Furthermore, should there be a split between whitebox tests and blackbox tests?
18
-
1. What benchmarks are where
19
-
1. Furthermore, should there be benchmarks, microbenchmarks, and nanobenchmarks (aka whitebox microbenchmarks)?
20
-
1. What SPIs exist, where, and who uses them
21
-
1. Explain test/Prototypes, and how to use that for rapid (relatively speaking) prototyping
22
-
1. Library Concepts
23
-
1. Protocol hierarchy
24
-
1. Customization hooks
25
-
1. Use of classes, COW implementation, buffers, etc
26
-
1. Compatibility, `@available`, etc.
27
-
1. Resilience, ABI stability, `@inlinable`, `@usableFromInline`, etc
28
-
1. Strings and ICU
29
-
1. Lifetimes
30
-
1. withExtendedLifetime, withUnsafe...,
31
-
1. Shims and stubs
32
-
1. Coding Standards
33
-
1. High level concerns
34
-
1. Best practices
35
-
1. Formatting
36
-
1. Internals
37
-
1.`@inline(__always)` and `@inline(never)`
38
-
1.`@semantics(...)`
39
-
1. Builtins
40
-
1. Builtin.addressof, _isUnique, etc
41
-
1. Dirty hacks
42
-
1. Why all the underscores and extra protocols?
43
-
1. How does the `...` ranges work?
44
-
1. Frequently Encountered Issues
45
-
46
-
47
10
## Coding style
48
11
49
-
- The stdlib currently has a hard line length limit of 80 characters.
12
+
- The stdlib currently has a hard line length limit of 80 characters.
50
13
51
14
To break long lines, please closely follow the indentation conventions you see in the existing codebase. (FIXME: Describe.)
52
15
53
16
- All entities that aren't public API must include at least one underscored component in their fully qualified names. This includes symbols that are technically declared public but that aren't considered part of the public stdlib API, as well as `@usableFromInline internal`, plain `internal` and `[file]private` types and members.
54
17
55
18
The underscored component need not be the last. For example, `Swift.Dictionary._worble()` is a good name for an internal helper method, but so is `Swift._NativeDictionary.worble()` -- the `_NativeDictionary` type already has the underscore.
56
19
57
-
Initializers don't have a dedicated name we can put the underscore on; instead, we add the underscore on the first argument label:`init(_value: Int)`. If the initializer doesn't have any parameters, then we add a dummy parameter of type Void with an underscored label: for example, `UnsafeBufferPointer.init(_empty: ())`.
20
+
Initializers don't have a dedicated name on which we can put the underscore; instead, we add the underscore on the first argument label, adding one if necessary: e.g., `init(_ value: Int)` may become`init(_value: Int)`. If the initializer doesn't have any parameters, then we add a dummy parameter of type Void with an underscored label: for example, `UnsafeBufferPointer.init(_empty: ())`.
58
21
59
22
This rule ensures we don't accidentally clutter the public namespace with `@usableFromInline` things (which could prevent us from choosing the best names for new public API), and it also makes it easy to see at a glance if a piece of stdlib code uses any non-public entities.
23
+
24
+
- We prefer to explicitly spell out all access modifiers in the stdlib codebase. (I.e., we type `internal` even if it's the implicit default.) Additionally, we put the access level on each individual entry point rather than inheriting them from the extension they are in:
25
+
26
+
```swift
27
+
publicextensionString {
28
+
// 😢👎
29
+
funcblanch() { ... }
30
+
funcroast() { ... }
31
+
}
32
+
33
+
extensionString {
34
+
// 😊👍
35
+
publicfuncroast() { ... }
36
+
publicfuncroast() { ... }
37
+
}
38
+
```
39
+
40
+
This makes it trivial to identify the access level of every definition without having to scan the context it appears in.
60
41
61
42
## Internals
62
43
@@ -261,3 +242,41 @@ Clicking around a little bit, we can find `lib/swift/iphonesimulator/i386/libswi
261
242
Going further, for various reasons the standard library has lots of warnings. This is actively being addressed, but fixing all of them may require language features, etc. In the mean time, let’s suppress warnings in our build so that we just see the errors. `ninja -nv lib/swift/iphonesimulator/i386/libswiftCore.dylib` will show us the actual commands ninja will issue to build the i386 stdlib. (You’ll notice that an incremental build here is merely 3 commands as opposed to ~150for `swift-stdlib-iphonesimulator-i386`).
262
243
263
244
Copy the invocation that has ` -o <build-path>/swift-macosx-x86_64/stdlib/public/core/iphonesimulator/i386/Swift.o`, so that we can perform the actual call to swiftc ourselves. Tack on `-suppress-warnings` at the end, and now we have the command to just build `Swift.o` for i386 while only displaying the actual errors.
245
+
246
+
## (Meta): List of wants and TODOs for this guide
247
+
248
+
1. Library Organization
249
+
1. What files are where
250
+
1. Brief about CMakeLists
251
+
1. Brief about GroupInfo.json
252
+
1. What tests are where
253
+
1. Furthermore, should there be a split between whitebox tests and blackbox tests?
254
+
1. What benchmarks are where
255
+
1. Furthermore, should there be benchmarks, microbenchmarks, and nanobenchmarks (aka whitebox microbenchmarks)?
256
+
1. What SPIs exist, where, and who uses them
257
+
1. Explain test/Prototypes, and how to use that forrapid (relatively speaking) prototyping
258
+
1. Library Concepts
259
+
1. Protocol hierarchy
260
+
1. Customization hooks
261
+
1. Use of classes, COW implementation, buffers, etc
262
+
1. Compatibility, `@available`, etc.
263
+
1. Resilience, ABI stability, `@inlinable`, `@usableFromInline`, etc
0 commit comments