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
[Embedded] Diagnose non-final generic methods in class in the type checker
Move the diagnostic about non-final generic methods in classes up to
the type checker, so that it is available to `-Wwarning
EmbeddedRestrictions` and earlier in the pipeline. The SIL version of
this is still available as a backstop.
Yet another part of rdar://133874555.
func f<U>(value:U){} // expected-nonembedded-warning{{generic instance method 'f(value:)' in a class must be 'final' in Embedded Swift}}
75
+
// expected-embedded-error@-1{{generic instance method 'f(value:)' in a class must be 'final' in Embedded Swift}}
76
+
func g(){}
77
+
classfunc h()where T:P{} // expected-nonembedded-warning{{generic class method 'h()' in a class must be 'final' in Embedded Swift}}
78
+
// expected-embedded-error@-1{{generic class method 'h()' in a class must be 'final' in Embedded Swift}}
79
+
80
+
init<U>(value:U){} // okay, can be directly called
81
+
82
+
requiredinit(){} // non-generic is okay
83
+
84
+
requiredinit<V>(something:V){} // expected-nonembedded-warning{{generic initializer 'init(something:)' in a class cannot be 'required' in Embedded Swift}}
85
+
// expected-embedded-error@-1{{generic initializer 'init(something:)' in a class cannot be 'required' in Embedded Swift}}
# Embedded Swift language restrictions (EmbeddedRestrictions)
2
2
3
-
Embedded Swift is a compilation model of Swift that can produce extremely small binaries without external dependencies, suitable for restricted environments including embedded (microcontrollers) and baremetal setups (no operating system at all), and low-level environments (firmware, kernels, device drivers, low-level components of userspace OS runtimes). While the vast majority of Swift language features are available in Embedded Swift, there are some language features that require the full Swift standard library and runtime, which are not available in Embedded Swift.
3
+
Embedded Swift is a subset of the Swift language that compiles to smaller binaries that do not rely on the Swift runtime. Embedded Swift produces some restrictions on the use of the Swift language to eliminate the runtime dependency, which are captured by the `EmbeddedRestrictions` diagnostic group.
4
4
5
-
Diagnostics in the `EmbeddedRestrictions` group describe those language features that cannot be used in Embedded Swift. For example, Embedded Swift uses a simplified reference-counting model that does not support `weak` or `unowned` references. The following will produce a diagnostic in Embedded Swift:
5
+
The Embedded Swift compilation model can produce extremely small binaries without external dependencies, suitable for restricted environments including embedded (microcontrollers) and baremetal setups (no operating system at all), and low-level environments (firmware, kernels, device drivers, low-level components of userspace OS runtimes). While the vast majority of Swift language features are available in Embedded Swift, there are some language features that require the full Swift standard library and runtime, which are not available in Embedded Swift.
6
+
7
+
Diagnostics in the `EmbeddedRestrictions` group describe those language features that cannot be used in Embedded Swift. These include:
8
+
9
+
*`weak` and `unowned` references, because Embedded Swift uses a simplified reference-counting model that cannot support them. For example:
6
10
7
11
class Node {
8
12
weak var parent: Node? // error: attribute 'weak' cannot be used in Embedded Swift
9
13
}
10
14
15
+
* Non-final generic methods in a class, which are prohibited because they cannot be specialized for every possible call site. For example:
16
+
17
+
class MyGenericClass<T> {
18
+
func f<U>(value: U) { } // warning: generic instance method 'f(value:)' in a class must be 'final' in Embedded Swift
19
+
20
+
func g() { } // okay, not generic relative to the class itself
21
+
22
+
class func h() where T: P { } // warning: generic class method 'h()' in a class must be 'final' in Embedded Swift
23
+
}
24
+
11
25
## See Also
12
26
13
27
-[A Vision for Embedded Swift](https://github.com/swiftlang/swift-evolution/blob/main/visions/embedded-swift.md)
0 commit comments