Skip to content

Commit 06ef7bc

Browse files
committed
Add a Future Directions section on handling unsafe code in macro expansions.
1 parent a3947c8 commit 06ef7bc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

proposals/0458-strict-memory-safety.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ We have several options here:
511511
if case unsafe .rawOffsetIntoGlobalArray(let offset) = weirdAddress { ... }
512512
```
513513

514+
### Handling unsafe code in macro expansions
515+
516+
A macro can expand to any code. If the macro-expanded code contains uses of unsafe constructs not properly covered by `@safe`, `@unsafe`, or an `unsafe` expression within the macro, then strict safety checking will diagnose those safety issues within the macro expansion. In this case, the client of the macro does not have any way to suppress diagnostics within the macro expansion itself without modifying the implementation of the macro.
517+
518+
There are a number of possible approaches that one could use for suppression. The `unsafe` expression could be made to apply to everything in the macro expansion, which would also require some spelling for attached attributes and other places where expressions aren't permitted. Alternatively, Swift could introduce a general syntax for suppressing a class of warnings within a block of code, and that could be used to surround the macro expansion.
519+
520+
Note that both of these approaches trade away some of the benefits of the strict safety mode for the convenience of suppressing safety-related diagnostics.
521+
514522
## Alternatives considered
515523

516524
### Prohibiting unsafe conformances and overrides entirely
@@ -735,6 +743,7 @@ We could introduce an optional `message` argument to the `@unsafe` attribute, wh
735743
* 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.
736744
* 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.
737745
* Add an Alternatives Considered section on prohibiting unsafe conformances and overrides.
746+
* Add a Future Directions section on handling unsafe code in macro expansions.
738747

739748
## Acknowledgments
740749

0 commit comments

Comments
 (0)