Skip to content

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Sep 14, 2025

Untyped throws depends on existentials (any Error), and is therefore not available in Embedded Swift. Introduce a diagnostic that diagnoses any use of untyped throws, suggesting that one use typed throws instead.

Make this an opt-in diagnostic enabled with -Wwarning EmbeddedRestrictions, whether in Embedded Swift or not, using the "default ignore" flag on these new warnings. Document this new diagnostic group, and put the existing Embedded Swift error about weak/unowned references in it as well.

When this diagnostic is enabled but we aren't in Embedded Swift, check for compiler conditionals like #if hasFeature(Embedded) and suppress the diagnostic if the code we're checking will not be compiled when building as Embedded Swift. For example, if it's in a #if !hasFeature(Embedded) block.

Part of the general push to have the type checker identify code that will not compile as Embedded Swift earlier, rdar://133874555.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Windows

Untyped throws depends on existentials (`any Error`), and is therefore
not available in Embedded Swift. Introduce a diagnostic that diagnoses
any use of untyped throws, suggesting that one use typed throws
instead.

Make this an opt-in diagnostic enabled with `-Wwarning
EmbeddedRestrictions`, whether in Embedded Swift or not, using the
"default ignore" flag on these new warnings. Document this new
diagnostic group, and put the existing Embedded Swift error about
weak/unowned references in it as well.

Part of the general push to have the type checker identify code that
will not compile as Embedded Swift earlier, rdar://133874555.
@DougGregor DougGregor force-pushed the embedded-swift-untyped-throws-restriction branch from edf7f36 to 95d3550 Compare September 15, 2025 04:49
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please clean smoke test

…led as Embedded

When emitting diagnostics for the Embedded Swift restrictions outside
of Embedded Swift mode, consider `#if $Embedded` and `#if
hasFeature(Embedded)` configurations. If the code where we would emit
the diagnostic would be disabled in Embedded Swift by one of those
checks, don't emit the diagnostic. This helps code that can compile
either with Embedded or regular Swift stay within the restrictions on
Embedded Swift.
@DougGregor DougGregor force-pushed the embedded-swift-untyped-throws-restriction branch from 72bb532 to 865c643 Compare September 15, 2025 14:10
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 01873c9 into swiftlang:main Sep 15, 2025
3 checks passed
@DougGregor DougGregor deleted the embedded-swift-untyped-throws-restriction branch September 15, 2025 19:55
@rauhul rauhul added the embedded Embedded Swift label Sep 15, 2025
@DougGregor
Copy link
Member Author

Note: this specific thing was also tracked by rdar://121205043, silly me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

embedded Embedded Swift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants