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: proposals/0458-strict-memory-safety.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -331,6 +331,35 @@ There are a number of compiler flags that intentionally disable some safety-rela
331
331
*`-strict-concurrency=` for anything other than "complete", because the memory safety model requires strict concurrency to eliminate thread safety issues.
332
332
*`-disable-access-control`, which allows one to break invariants of a type that can lead to memory-safety issues, such as breaking the invariant of `Range` that the lower bound not exceed the upper bound.
333
333
334
+
### Types with unsafe storage
335
+
336
+
Types that wrap unsafe types will often encapsulate the unsafe behavior to provide safe interfaces. However, this requires deliberate design and implementation, potentially involving adding specific preconditions. When strict safety checking is enabled, a type whose storage is unsafe will be diagnosed as involving unsafe code. This diagnostic can be suppressed by marking the type as `@safe` or `@unsafe`, in the same manner as any other declaration that has unsafe types or conformances in its signature:
337
+
338
+
```swift
339
+
// @safe is required to suppress a diagnostic about the 'buffer' property's use
* Any stored instance property (for `actor`, `class`, and `struct` types) or associated value (for cases of `enum` types) have a type that involves an unsafe type or conformance.
361
+
* Any stored instance property uses one of the unsafe language features (such as `unowned(unsafe)`).
362
+
334
363
### Unsafe overrides
335
364
336
365
Overriding a safe method within an `@unsafe` one could introduce unsafety, so it will produce a diagnostic in the strict safety mode:
@@ -704,6 +733,7 @@ We could introduce an optional `message` argument to the `@unsafe` attribute, wh
704
733
705
734
***Revision 2 (following first review)**
706
735
* Specified that variables of unsafe type passed in to uses of `@safe` declarations (e.g., calls, property accesses) are not diagnosed as themselves being unsafe. This makes means that expressions like `unsafeBufferePointer.count` will be considered safe.
736
+
* Require types whose storage involves an unsafe type or conformance to be marked as `@safe` or `@unsafe`, much like other declarations that have unsafe types or conformances in their signature.
707
737
* Add an Alternatives Considered section on prohibiting unsafe conformances and overrides.
0 commit comments