Skip to content

Commit fa193fa

Browse files
committed
[embedded] Update UserManual.md and EmbeddedSwiftStatus.md with some additional information
1 parent d82b836 commit fa193fa

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

docs/EmbeddedSwift/EmbeddedSwiftStatus.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ For an introduction and motivation into Embedded Swift, please see "[A Vision fo
1010

1111
This status table describes which of the following standard library features can be used in Embedded Swift:
1212

13-
| **Swift Standard Library Feature** | **Currently Supported In Embedded Swift** |
14-
|---------------------------------------------|-----------------------------------------------------|
13+
| **Swift Standard Library Feature** | **Currently Supported In Embedded Swift?** |
14+
|------------------------------------------------------------|-----------------------------------------------------|
1515
| Array (dynamic heap-allocated container) | Yes |
1616
| Array slices | Yes |
1717
| assert, precondition, fatalError | Partial, only StaticStrings can be used as a failure message |
@@ -46,6 +46,10 @@ This status table describes which of the following standard library features can
4646

4747
This status table describes which of the following Swift features can be used in Embedded Swift:
4848

49-
| **Swift Feature** | **Currently Supported In Embedded Swift** |
50-
|---------------------------------------------|-----------------------------------------------------|
51-
| Swift Concurrency | Partial, experimental (basics of actors and tasks work in single-threaded concurrency mode) |
49+
| **Swift Feature** | **Currently Supported In Embedded Swift?** |
50+
|------------------------------------------------------------|-----------------------------------------------------|
51+
| Swift Concurrency | Partial, experimental (basics of actors and tasks work in single-threaded concurrency mode) |
52+
| C interop | Yes |
53+
| C++ interop | Yes |
54+
| ObjC interop | No, intentionally unsupported long-term |
55+
| Library Evolution | No, intentionally unsupported long-term |

docs/EmbeddedSwift/UserManual.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ Segment __TEXT: 16384
9898
...
9999
```
100100

101+
## Conditionalizing compilation for Embedded Swift
102+
103+
It's often useful to have source code be compilable under both regular Swift and Embedded Swift. The following syntax is available for that (but note that as the rest of Embedded Swift, it's experimental, subject to change and not considered source stable):
104+
105+
```swift
106+
func sayHello() {
107+
#if hasFeature(Embedded)
108+
print("I'm Embedded Swift")
109+
#else
110+
print("I'm regular Swift")
111+
#endif
112+
}
113+
```
114+
115+
Additionally, you can also use an attribute (also experimental, and not source stable) to make entire functions, types and other declarations unavailable in Embedded Swift. This can be particularly useful to explicitly mark your own code (and also entire types and conformances) that relies on features unavailable in Embedded Swift, e.g. existentials or strings -- it is explicitly allowed to use those in unavailable contexts:
116+
117+
```swift
118+
@_unavailableInEmbedded
119+
func useAnExistential(_: Any) { ... }
120+
121+
@_unavailableInEmbedded
122+
extension MyStruct: CustomStringConvertible {
123+
var description: String { return "..." }
124+
}
125+
```
126+
101127
## Embedded Swift is a subset of Swift
102128

103129
Embedded Swift is a subset of the Swift language, and some features are not available in Embedded Swift, however features are available, including: Generics, protocols, enums with associated values, tuples, optionals, classes (instances are allocated on the heap and refcounted just like in regular Swift), inheritance, runtime polymorphism, arrays (heap-allocated copy-on-write just like in regular Swift) and many more.
@@ -119,7 +145,7 @@ Traditional library build and use model of Swift is that library code is compile
119145

120146
The library model in Embedded Swift works slightly differently: All Swift source code of a library is promoted into being inlineable and visible to client builds (this is necessary for generic code, and beneficial for optimizations for non-generic code), and ends up serialized into the .swiftmodule, the interface of the library. Therefore, the compiled code of a library is never needed, and doesn't even need to be produced. For example:
121147

122-
```
148+
```bash
123149
# Build the library, only as a .swiftmomodule. Notice that we never build the .o or .a for the library.
124150
$ swiftc -target <target> -enable-experimental-feature Embedded -wmo \
125151
a.swift b.swift -module-name MyLibrary -emit-module -emit-module-path ./MyLibrary.swiftmodule

0 commit comments

Comments
 (0)