Skip to content

Conversation

DougGregor
Copy link
Member

Implement diagnostics in the type checker for more of the Embedded Swift language restrictions in the type checker. They are all introduced as warnings in the same diagnostic group (EmbeddedRestrictions), which also documents the restrictions. Take existing diagnostics in SIL and put them in the same diagnostic group. Diagnostics introduced include:

  • Casting to an existential
  • Defining non-final generic functions in a class
  • Calling generic functions on an existential

This is tracked by rdar://119383905

…propriate group

Embedded Swift must defer some of the diagnostics about its
restrictions to late in the optimization pipeline, because some
source-level constructs (such as metatypes) are allowed in specific
cases that cannot be diagnosed in the type checker.

Put these diagnostics into the same EmbeddedRestrictions diagnostic
group as the type checker diagnostics, because that's the central
point at which we can direct folks to more information about the
restrictions in Embedded Swift.

Addresses rdar://119383905.
…ecker

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.
Generic methods declared in protocols (and extensions thereof) cannot
be used on existential values, because there is no way to specialize
them for all potential types. Diagnose such cases in Embedded Swift
mode and via `-Wwarning EmbeddedRestrictions`.

This adds a bunch more warnings to the standard library that we'll
need to clean up, probably by `#if`'ing more code out.

Part of rdar://119383905.
… methods to a warning

The existing SIL-level diagnostic for this check only triggers when
the type is actually used, while the type-checker version is more
eager. Stage in the stricter check as a warning and we'll clamp down
on things later.
Embedded Swift doesn't have protocol conformance metadata, so it cannot
handle dynamic casts to existentials (nor should it).

Another part of rdar://119383905.
@DougGregor DougGregor force-pushed the embedded-swift-restrictions branch from 5ce4274 to 11976c5 Compare September 18, 2025 17:05
@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 Windows

@DougGregor DougGregor merged commit 3e981b7 into swiftlang:main Sep 19, 2025
3 checks passed
@DougGregor DougGregor deleted the embedded-swift-restrictions branch September 19, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant