Commit Graph

2084 Commits

Author SHA1 Message Date
Kavon Farvardin c19889c6e7 Merge pull request #88976 from kavon/preinverse-generics-except-176395527
introduce @_preInverseGenerics(except:)
2026-05-15 04:43:33 -07:00
Kavon Farvardin 19119ad88a introduce @_preInverseGenerics(except:)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
2026-05-14 18:27:00 -07:00
Allan Shortlidge fb7c8816a5 AST: Fix availability scopes for if #unavailable else branches.
When an `if #unavalable` statement also includes a secondary (non-availability)
condition, the availability scope for the else branch should not be refined.
The else branch can be reached because the secondary condition failed, in which
case the availability condition may not hold.

Resolves rdar://165863221.
2026-05-14 16:41:36 -07:00
Allan Shortlidge 86bfcafb92 tests: Move regression test case for GH issue #64694 to appropriate file. 2026-05-14 16:28:15 -07:00
Slava Pestov 40cb62fb54 Merge pull request #88480 from slavapestov/additional-dynamicmemberlookup-args-v2
[Sema] Support additional args in @dynamicMemberLookup subscripts 2.0
2026-05-11 17:56:52 -04:00
Artem Chikin e1b0e520b3 Merge pull request #88950 from artemcm/DefaultSourceWarningControl
[SourceWarningControl] Promote `@diagnose` attribute to a default language feature
2026-05-11 17:03:04 +01:00
Allan Shortlidge 18e4fd76b5 Merge pull request #88886 from tshortli/improve-use-any-apple-os-diags
Sema: Improve `UseAnyAppleOSAvailability` diagnostics
2026-05-08 14:41:40 -07:00
Slava Pestov 25e3f47a1c Sema: Tweak @dynamicMemberLookup diagnostics
Make sure we diagnose something if we had an invalid subscript,
but don't diagnose an error in the case we used to emit an
access control warning.
2026-05-08 15:46:20 -04:00
Slava Pestov fa2448b4ff Sema: Migrate dynamic member lookup to use matchCallArguments() 2026-05-08 15:46:18 -04:00
Itai Ferber 18eda1a855 Add non-magic default arg to tests
Expand `Magic` unit test to include non-magic default arg to confirm it
also works as expected at runtime.
2026-05-08 15:46:18 -04:00
Itai Ferber ea785dcef9 Improve @dynamicMemberLookup diagnostics
Instead of producing a single error (with notes) for most
`@dynamicMemberLookup` failures, introduce individual errors with
fix-its.
2026-05-08 15:46:17 -04:00
Slava Pestov 092bbe120a Sema: Fix cross-module dynamic member subscripts 2026-05-08 15:46:17 -04:00
Slava Pestov b062b8a285 Convert SubscriptDecl @dynamicMemberLookup checking to request
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
2026-05-08 15:46:17 -04:00
Itai Ferber 21ef3952d7 Add unit tests for multi-arg @dynamicMemberLookup subscripts 2026-05-08 15:46:17 -04:00
Artem Chikin 740800dd21 [SourceWarningControl] Promote '@diagnose' attribute to a default language feature
No longer experimental as of approval of SE-0522.

Resolves rdar://176535491
2026-05-08 09:59:11 +01:00
Artem Chikin a7bbffd953 Merge pull request #88205 from artemcm/DiagnoseAttr
[Source Warning Control] Rename `@warn` to `@diagnose` & prevent printing it in Textual Interfaces
2026-05-07 16:52:22 +01:00
Allan Shortlidge cea706a03f AST: Improve InFlightDiagnostic::fixItRemove() heuristics.
If the fix-it would remove a range that is followed by a newline and the
remaining text on the line is empty or all whitespace then remove the entire
line. This produces better results when a fix-it removes an attribute that is
written on a line by itself.
2026-05-06 11:03:30 -07:00
Aidan Hall c9940ba341 Lifetimes: ~Escapable function type tests 2026-04-30 16:30:46 +01:00
Artem Chikin 866371d73e [Source Warning Control] Rename '@warn' to '@diagnose'
Resolves rdar://173774670
2026-04-29 10:39:25 +01:00
Kavon Farvardin 58c1cfeea6 Sema: require UnderscoreOwned to use @_owned
If we don't require that experimental feature to be enabled,
users might accidentally publish swiftinterface files using
the attribute, without telling compilers that in order to
consume the swiftinterface file, they need UnderscoreOwned
enabled.

It's a valuable thing to make an error as people may be
publishing interfaces that are hiding the computed property
always.

resolves rdar://174880934
2026-04-16 13:46:58 -07:00
Allan Shortlidge 9a25399f81 Make StrictAccessControl an experimental feature.
It was originally introduced as an upcoming feature, but there isn't any
precedent for using upcoming features as a way to opt-in to type checking fixes
without an associated Swift Evolution proposal. Rather than using a "feature" to
control this behavior, it would probably be better to offer a way to use
`-Werror` to upgrade these warnings to errors.
2026-03-24 17:59:40 -07:00
Artem Chikin 47d904ea1f [Test][Source Warning Control] Add peer macro test 2026-03-24 10:17:03 +00:00
Artem Chikin 6caabab5c1 [Source Warning Control] Add test for '@warn' in combination with property wrapper attribute 2026-03-20 10:12:09 +00:00
Artem Chikin 4aeaa732ac Revert "[Diagnostics] Allow lexically-escalated warning groups to 'escape' the '-suppress-warnings' compiler flag."
This reverts commit 96e7f2587d.
2026-03-20 10:12:09 +00:00
Artem Chikin 350aa9d6a3 [Source Warning Control] Add test for '@warn' on a macro expansion 2026-03-20 10:12:09 +00:00
Artem Chikin 126bed7b1e [Source Warning Control] Support '@warn' on macro declarations 2026-03-20 10:12:08 +00:00
Artem Chikin e047f9b371 [Source Warning Control] Support '@warn' on typealias and associated type declarations 2026-03-20 10:12:08 +00:00
Artem Chikin 324ed8df28 [Source Warning Control] Support '@warn' on enum elements 2026-03-20 10:12:06 +00:00
Aviva b07c3fc0e8 Merge pull request #87838 from a-viv-a/improve-alias-attribute-diagnostic 2026-03-18 00:25:07 -07:00
Aviva Ruben 4b9faeb5aa [Sema] Downgrade unused attr following used attr to warning
This commit downgrades unused attrs that follow used attrs to warnings,
since this code was previously silently accepted.
2026-03-17 11:34:01 -07:00
Aviva Ruben 21c0dadbf7 [Sema] Tailor diagnostic for attributes on aliases
Tailor a diagnostic and fix for attributes on aliases, to suggest
moving them to the definition and adding preconcurrency if necessary or
inlining the alias so attribute can be applied.
2026-03-17 11:34:01 -07:00
Aviva Ruben 71a4f93594 [Sema] Fix unclaimed iteration ignoring attrs after claimed attr
Fixes rdar://152866923. This logic bug in iteration lead us to
accept Sendable on aliases without actually applying it in some cases.
diagnoseUnclaimed was only incrementing i when the attr was not
claimed. This led to a bug where a claimed attr followed by an unclaimed
attr would not be detected, leading code like `@escaping @Sendable`
on a type alias to be accepted, without @Sendable being represented
on the type, when we intended to diagnose it and bail. Code downstream
behaves like no sendable annotation has been applied.
2026-03-16 18:19:05 -07:00
Allan Shortlidge 8dee947aa3 AST: Relax availability checking for decls in unavailable contexts.
Loosen availability checking to allow references to a decl that is unavailable
in a broader platform context in contexts which are unavailable in a more
specific platform context. For example, `@available(macOS, unavailable)` decls
should be allowed in `@available(macOSApplicationExtension, unavailable)`
contexts. This enhancement, which has always been desirable but wasn't high
priority, became more important with the introduction of `anyAppleOS`. Some
library authors may replace platform-specific availability annotations with
`anyAppleOS` availability and without this behavior change those attribute
updates would be source breaking.

Test updates assisted by claude.
2026-03-16 14:49:09 -07:00
Allan Shortlidge 7473e5c502 test: Add regression tests for anyAppleOS and @backDeployed. 2026-03-16 11:08:07 -07:00
Doug Gregor 321c8690df Only complain about "swift_" symbols defined outside the standard library
Specifically, don't warn about C standard library symbols that the
compiler happens to know about, like "free".

Fixes #87239 / rdar://170390023.
2026-03-11 10:16:39 -07:00
Artem Chikin 5cd1ac311b Merge pull request #87621 from artemcm/WarnEscalateSuppression
[Diagnostics] Allow lexically-escalated warning groups to 'escape' the '-suppress-warnings' compiler flag.
2026-03-10 13:12:21 +00:00
Artem Chikin 1ba5ae1058 Merge pull request #87646 from artemcm/GuardSyntacticWarningsOnFeature
[Diagnostics] Guard the user-controlled behavior warning logic behind experimental feature
2026-03-10 09:32:13 +00:00
Artem Chikin 8b395b3280 [Diagnostics] Guard the user-controlled behavior warning logic behind experimental feature
`-enable-experimental-feature SourceWarningControl` guards the actual *use* of `@warn` attribute, but it did not guard this logic which queries it, which is meant to be general in the absense of the attribute as well.

We are seeing some unintended compile time performance implications from this logic, so for now guard it behind the same experimental feature flag.

Related to rdar://171506799
2026-03-09 12:17:15 +00:00
Allan Shortlidge 3087b935ab AST: Refactor availability version remapping.
Implement version remapping without assuming the remap is to the target domain
of compilation.
2026-03-03 06:12:38 -08:00
Allan Shortlidge 5e094d03a3 Merge pull request #87522 from tshortli/embedded-concurrency-availability 2026-03-03 05:46:36 -08:00
Allan Shortlidge 9724348f86 AST: Allow anyAppleOS availability without an experimental feature.
Resolves rdar://170988964.
2026-03-02 14:05:39 -08:00
Allan Shortlidge c7ce5a8aed Parse: Allow availability macros to contain empty expansions.
In some cases, it's useful to allow an availability macro to expand to an empty
availability specification list. Allow developers to express this using macros
that are defined to exactly the string `*`, while continuing to reject `*` in
availability macros that contain other entries.
2026-03-02 12:14:29 -08:00
Artem Chikin 96e7f2587d [Diagnostics] Allow lexically-escalated warning groups to 'escape' the '-suppress-warnings' compiler flag.
While '-suppress-warnings' does not fit into the overall model established with command-line controls (-Werror, -Wwarning) and declaration lexical scope controls (@warn), when users specify:
```swift
@warn(DiagGroupID, as: error)
```
They are explicitly opting in to treat certain diagnostic categories as build-halting error conditions and as such they should not longer be silenced by the '-suppress-warnings' flag.
2026-03-02 16:42:11 +00:00
AbdAlRahman Gad 7b427485fc nit: show attribute name 2026-02-24 06:46:06 +02:00
AbdAlRahman Gad ad3151b7ac nit: small improvement 2026-02-24 00:53:30 +02:00
AbdAlRahman Gad 0e3e848c8f [Sema] Improve diagnostics for duplicate global actor attributes
Add a note diagnostic that points to the source location of each
conflicting global actor attribute when a declaration has more than one.
2026-02-23 07:28:48 +02:00
Ian Anderson fc628a8bfb [test][NFC] Add more keys to test SDKSettings files
Every time DarwinSDKInfo reads a new key out of SDKSettings, a boatload of test SDKSettings files need to be updated across several repositories and forks and branches. It’s tedious to be careful to update those with real values so that the tests are properly regression testing older SDKs. It’s important to be careful so that the tests are accurate, e.g. to prevent the scenario where DarwinSDKInfo starts reading a new key out of SDKSettings and assumes that it’s always available everywhere, when in reality it was only added a few releases ago and will break with older SDKs. If the test SDKSettings files continue to be updated ad hoc, it’s going to be really easy to copy/paste a default value everywhere, and then clients will see incorrect behaviors with the real SDKs, or even compiler crashes if the key is unconditionally read. Preemptively add all of the maybe-possibly-compiler relevant keys to the test SDKSettings files from the real SDKs so that the test files are an accurate representation and shouldn't need to be touched in the future. Where the test SDKSettings have intentionally doctored data, add a Comments key explaining what is changed from the real SDK, and alter the SDK name with a tag indicating the change.

rdar://168700857
2026-01-23 02:19:36 -08:00
Sam Pyankov a0dc22e819 Merge pull request #86392 from sepy97/strict_access_check_errors
Stricter access control enforcement
2026-01-13 15:45:16 -08:00
Tim Kientzle adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00
Sam Pyankov b0eee67a7b Emit an errors instead of warnings access control violations that should be fixed in the future when StrictAccessControl upcoming feature is enabled 2026-01-08 14:24:35 -08:00