Commit Graph

1299 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
Aidan Hall 5149dbcd29 Lifetimes: Infer copy dependence kind on @noescape closures (#88879)
Follow-up to https://github.com/swiftlang/swift/pull/88733,
enabling the example in rdar://172511809 ([nonescapable] Allow a
nonescaping function to be a lifetime dependency source):

```swift
@_lifetime(body) // Inferred dependence kind: copy
func foo(body: () -> Span<Int>) { body() }
```

or

```swift
// Inferred: @_lifetime(copy body)
func foo(body: () -> Span<Int>) { body() }
```

Follow-up: Consider also disallowing borrow dependence on `@noescape`
closures.
<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

---------

Co-authored-by: Andrew Trick <atrick@apple.com>
2026-05-15 11:34:36 +01: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
Dario Rexin 2ff89dc880 Merge pull request #89069 from drexin/wip-166720900
[AST] Print movesAsLike if present on @_rawLayout
2026-05-14 17:21:11 -07:00
Pavel Yaskevich 1e1fa735f5 Merge pull request #89122 from xedin/rdar-176978806
[TypeChecker] PropertyWrappers: When setting projected value setter a…
2026-05-14 15:42:44 -07:00
Dario Rexin e653441d08 [AST] Print movesAsLike if present on @_rawLayout
rdar://166720900

A missing movesAsLike on the attribute in an interface file will cause miscompiles.
2026-05-14 11:16:26 -07:00
Pavel Yaskevich c296d3fb47 [TypeChecker] PropertyWrappers: When setting projected value setter access account for projectedValue setter
Previously, the synthesis set the access of the setter of a newly
synthesized projected value property to match that of the parent
property setter, but `projectedValue` of the property wrapper could
be less accessible than that and the synthesis needs to account
for that. Otherwise, the interface file might get a setter printed
even though it's not part of the ABI.

Resolves: rdar://176978806
2026-05-14 09:47:35 -07:00
Allan Shortlidge c2c8470dac ModuleInterface: Remove warning about types shadowing modules.
Now that module selectors (SE-0491) are used by default when printing
.swiftinterface files, the following warning is unnecessary:

```
public struct <name> shadows module <name>, which may cause failures...
```

Remove the implementation of the warning entirely. Technically, we could keep
diagnosing the issue when use of module selectors in .swiftinterface files is
disabled via the `-disable-module-selectors-in-module-interface` flag, but on
balance it does not seem worth it since we don't anticipate any uses of that
flag aside from temporarily working around compiler bugs.

Resolves rdar://176476640.
2026-05-13 10:39:19 -07: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 52c306636b AST: Print the override keyword when appropriate in package swiftinterfaces.
If a decl written in source has `override` because it overrides a `package`
decl, then the `override` keyword should be printed in the
`.package.swiftinterface` since the overridden decl is visible.

Resolves rdar://158178648.
2026-05-05 08:10:10 -07:00
Allan Shortlidge 17c12affb8 tests: Expand MemberImportVisibility tests for conformances.
Add test cases for various edge cases related to conformances with
MemberImportVisibility enabled. Missing imports that break conformances should
be diagnosed, but those diagnostics should not prevent certain accepted
conformances from continuing to be accepted.

Tests only, NFC.
2026-04-30 06:30:05 -07:00
Allan Shortlidge cf62cdb9de Revert "Sema: Skip MemberImportVisibility diags for conformances in swiftinterfaces."
This reverts commit 091d1dad64.
2026-04-30 05:27:36 -07:00
Allan Shortlidge 3a66e7d63b Revert "Sema: Skip MemberImportVisibility diagnostics for self-witnessing requirements."
This reverts commit 7f419bcb56.
2026-04-30 05:26:59 -07:00
Artem Chikin 00001b93e4 [Source Warning Control] Exclude @diagnose from textual module interfaces
The @diagnose attribute only affects local diagnostic behavior within a declaration's body and has no API or ABI impact. It should not appear in .swiftinterface files, and should not cause declarations to be wrapped in #if $SourceWarningControl feature guards.
2026-04-29 10:39:29 +01:00
Allan Shortlidge 7f419bcb56 Sema: Skip MemberImportVisibility diagnostics for self-witnessing requirements.
When a requirement witnesses itself that indicates that no witness was found
and the conformance checker is treating the witness as "opaque". The visibility
of the requirement should not be diagnosed.

Follow up to https://github.com/swiftlang/swift/pull/88616.

Resolves rdar://175691719.
2026-04-27 14:36:10 -07:00
Aidan Hall fb2aa63295 Merge pull request #87217 from aidan-hall/lifedep-infer-closure-dependence
LifetimeDependence closure context dependence
2026-04-27 16:23:04 +01:00
Allan Shortlidge c6e37097c7 Merge pull request #88639 from tshortli/import-warning-groups
Add diagnostic group names to several import-related warnings
2026-04-24 11:32:11 -07:00
Aidan Hall eac68b5283 LifetimeDependence: Closure lifetimes tests 2026-04-24 16:14:25 +01:00
Kavon Farvardin ffedccb3f3 Merge pull request #88307 from kavon/supp-assoc-types-enable
Enable SE-503 (SuppressedAssociatedTypesWithDefaults)
2026-04-23 18:59:14 -07:00
Allan Shortlidge de35fbd4ff AST: Add the UnsupportedScopedImport diagnostic group. 2026-04-23 15:28:09 -07:00
Kavon Farvardin 1ce7a67529 Test: client/library mis-match of SuppAssocTypes
Ensures that people can workaround issues in light of SE-503,
for people using libraries that adopted the old experimental
SuppressedAssociatedTypes.
2026-04-22 22:11:42 -07:00
Allan Shortlidge 091d1dad64 Sema: Skip MemberImportVisibility diags for conformances in swiftinterfaces.
Conformance checking in swiftinterfaces is lenient and can recover from missing
witnesses by assuming that the protocol witness table will have an entry for
the requirement at runtime. As a result, diagnosing missing imports for
witnesses here could break source compatibility for existing interface files
and must be skipped. This fixes a regression introduced by
https://github.com/swiftlang/swift/pull/88470.

Resolves rdar://175215763.
2026-04-22 16:28:55 -07:00
Tim Kientzle c46cabde95 Merge pull request #88504 from tbkka/tbkka-yielding-in-swiftinterface
Write `yielding` accessor names to swiftinterface files
2026-04-19 13:35:54 -07:00
Doug Gregor d31c82ce95 Merge pull request #88446 from DougGregor/code-generation-model
Aggressive CMO can force the serialization of the bodies of `@export(interface)` functions
2026-04-16 10:01:08 -07:00
Allan Shortlidge 902f13a132 AST: Add group IDs to diags for module interface option obsoletion..
Makes it possible for users of `-warnings-as-errors` to control the behavior of
warnings about the obsoletion of module interface emission options.

Resolves rdar://174787052.
2026-04-15 13:08:31 -07:00
Doug Gregor f2eb7cb1a8 [SIL] Model @export(interface) and @export(implementation) on SIL functions
The `@export(interface)` and `@export(implementation)` attributes
SE-0497 are queried directly on AST nodes in several places within the
SIL pipeline. However, they don't persist when SIL functions are
serialized, meaning that clients of the original module might make
different assumptions about the availability of a given function's
definition.

Represent these attributes in a SIL function (as an optional
CodeGenerationModel), (de-)serialize them into the module, and add a
textual representation as SIL function attributes `[export_interface]`
and `[export_implementation]`.
2026-04-15 13:04:10 -07:00
Tim Kientzle c85ebdaed5 Write yielding accessor names to swiftinterface files
Back in January, I updated the swiftinterface _reading_ code to accept either
`read`/`modify` or `yielding borrow`/`yielding mutate`.  That update has been
around for long enough that we can now switch over the swiftinterface _writing_
code to emit the standard final `yielding borrow`/`yielding mutate` spellings.

Interface files written with the old spellings will continue to be
accepted for some time (likely a year or more).
2026-04-15 12:34:46 -07:00
Saleem Abdulrasool 2b8ee6e5a2 test: disallow llvm-bcanalyzer and use new macro
This ensures that we use the correct llvm-bcanalyzer from the just built
compiler tools.
2026-04-13 16:22:02 -07:00
Kavon Farvardin f608fc03ef Reparenting: even more feature guarding improvements
The only known condfail scenario is inheriting from
a protocol P that inherits from a reparentable one R.

We already guard P if it mentions R in its inheritance clause.
So older compilers will simply report that "P" is missing in the
interface, which is a better error message than virally guarding
everything mentioning P. It's an ABI break anyway to do that
without introducing a `@reparented` extension, which needs a guard.

In theory, older compilers shouldn't have too much go wrong if they
were to ignore `@reparentable`, though the RequirementMachine and
witness tables will look different.

rdar://174263176
2026-04-08 10:48:40 -07:00
Allan Shortlidge 102581b597 ModuleInterface: Handle more synthesized conformance availability corner cases.
As a follow up to https://github.com/swiftlang/swift/pull/87832, continue
adjusting the algorithm for computing synthesized conformance availability.
When an outer declaration is `unavailable` in a more specific platform domain
and the inner declaration is `introduced:` in a less specific domain, the inner
declaration attribute does not override the outer declaration attribute.
Unavailability and introduction on separate axes of availability.

Resolves rdar://173724423.
2026-03-30 17:42:39 -07:00
Meghana Gupta 3d3d476b6f Merge pull request #88107 from meg-gupta/enableborrow
Enable BorrowAndMutateAccessors by default
2026-03-27 12:43:02 -07:00
Allan Shortlidge 141ac3fd5d Merge pull request #88079 from tshortli/unowned-executor-availability
Sema: Removed inferred availability from `unownedExecutor` synthesis
2026-03-25 19:06:59 -07:00
Meghana Gupta d6e220669f Enable BorrowAndMutateAccessors by default 2026-03-25 16:52:39 -07:00
Allan Shortlidge 9d2d1a3316 Sema: Removed inferred availability from unownedExecutor synthesis.
The compiler synthesizes an `unownedExecutor` property for every `actor` type.
It was also synthesizing availability attributes for this property by
intersecting the availability of the actor type and the `UnownedExecutor` type.
This may have been necessary early in the development of Swift Concurrency but
now it amounts to little more than a convoluted procedure that must result in
repeating the availability of the actor on one of its properties (the property
can never be less available than the actor itself).
2026-03-25 04:54:25 -07:00
Allan Shortlidge 945f95f8d4 ModuleInterface: Improve availability inference for synthesized conformances.
When printing `.swiftinterface` files, implicit conformances may need to be
printed with inferred availability attributes. The existing algorithm for
determining which availability attributes to print needed a few updates to
better handle `anyAppleOS` availability attributes:

- `@available(anyAppleOS, ...)` attributes attached to a nested declaration
  should take priority over platform-specific `@available` attributes on outer
  declarations.
- At the same time, `@available(anyAppleOS, ...)` attributes attached to the
  _same_ declaration as a platform-specific `@available` attribute should not
  take priority. Instead, both attributes should be included in the inferred
  set.
2026-03-25 04:51:42 -07:00
Steven Wu 12f8d9c6c9 [TEST] Switch to use new swift-driver when running tests
Default to use new swift-driver to run lit tests as legacy swift driver
is deprecated for a long time. The lit tests for legacy drivers are also
disable when running new swift-driver.

Tests that relies on legacy swift driver (for example, tests merge
module) can be enabled on conditions `legacy_swift_driver`. Fix and
split up some existing tests that relies on legacy driver.
2026-03-23 09:48:45 -07:00
Pavel Yaskevich de8b2fb22c [Frontend] SE-0518: Turn TildeSendable into a language feature
The proposal has been accepted and `~Sendable` doesn't require
an explicitly enabled experimental flag.
2026-03-20 10:27:12 -07:00
Steven Wu 3ba1ba45d4 Merge pull request #87892 from cachemeifyoucan/eng/PR-172693314
[DependencyScan] Propagate module library level through dependency scanner for CAS builds
2026-03-18 09:08:27 -07:00
Aviva Ruben 2f58b7c57a [Sema] Preserve type alias sugar when removing escaping
This change fixes rdar://172417385 and #45125 by using transformRec
to set no escape, instead of casting which drops sugar. This affects
how interfaces are printed, and could theoretically cause issues with
printing private aliases into public interfaces. Motivated by needing
to be able to diagnose issues with attributes on aliases; without this
change, the alias sugar is sometimes lost.
2026-03-17 11:33:58 -07:00
Steven Wu 34d52cfe1a [DependencyScan] Propagate module library level through dependency scanner for CAS builds
Compute and propagate the library level (api/spi/ipi) of each module
dependency through the dependency scanner so that the compiler can
correctly enforce private module import diagnostics in CAS mode, where
path-based SPI detection fails because CAS abstracts file paths to
content IDs.

Swift modules:
- Detect library level from the module interface path using
  libraryLevelFromPath() during scanning, for both textual (.swiftinterface)
  and binary (.swiftmodule) Swift modules.

Clang modules:
- Expose ModuleMapIsPrivate from clang::Module in ModuleDeps via the
  dependency scanning infrastructure.
- Set library level for clang modules in bridgeClangModuleDependency()
  using ModuleMapIsPrivate (catches module.private.modulemap in any
  SDK location) and libraryLevelFromPath() on the module map file
  (catches modules under PrivateFrameworks directories).

The library level is:
- Stored in ModuleDependencyInfo and serialized in the module dependency
  cache (format version bumped to v8).
- Exposed through the swiftscan C API via a new
  swiftscan_module_info_get_library_level() function (API minor version
  bumped to 3).
- Emitted in the dependency scanner JSON output as "libraryLevel" for
  all module kinds (Swift textual, Swift binary, Clang, and main module).
- Parsed from the explicit module map JSON by ExplicitModuleMapParser
  for both Swift (ExplicitSwiftModuleInputInfo) and Clang
  (ExplicitClangModuleInputInfo) modules.
- Looked up in ModuleLibraryLevelRequest via
  ASTContext::getExplicitModuleLibraryLevel(name, isClang), which
  consults the appropriate map (Swift or Clang) based on module kind.

rdar://172693314

Assisted-By: Claude
2026-03-17 11:04:18 -07:00
Allan Shortlidge c875d52cdd Merge pull request #87821 from tshortli/reorder-platform-kinds
AST: Reorder platforms in `PlatformKinds.def`
2026-03-12 10:37:33 -07:00
Allan Shortlidge 9cfdb17d7e AST: Reorder platforms in PlatformKinds.def.
This allows stable sorting of availability domains to result in an order that
looks more natural when printed in swiftinterface files.
2026-03-12 01:50:31 -07:00
Kavon Farvardin 8f8b782531 Merge branch 'main' into se427-techdebt 2026-03-11 10:00:18 -07:00
Kavon Farvardin e5b2ead0d7 Sema: remove SE427NoInferenceOnExtension
The feature was added only to avoid a reverse-condfail
in the initial bring-up of noncopyable generics.

Nearly 2 years have passed since the last time I tried
to remove this old technical debt [1] and had to revert
it due to outdated build bots [2]. Hoping that won't be
a problem this time.

[1] 5b2f2cbfcf
[2] https://github.com/swiftlang/swift/pull/75267

resolves rdar://131560183
2026-03-11 09:57:47 -07:00
Allan Shortlidge bac99b6d63 Merge pull request #87779 from tshortli/revert-87670
Revert "ModuleInterface: Fix availability attributes on synthesized conformances
2026-03-11 06:00:50 -07:00
Kavon Farvardin 745cc5a4b0 Merge pull request #87791 from kavon/polish-suppassoc 2026-03-11 01:20:19 -07:00
Kavon Farvardin fe50668d0e SuppAssocTypes: add deprecation warning of legacy version
We need to start moving people over to using the version of
suppressed associated types that has the officially accepted
behavior according to SE-503, and that is via
`SuppressedAssociatedTypesWithDefaults`.

To allow for time to migrate to the new version, I'm introducing
the deprecation message as a warning for now.

This set of changes also moves most of the test suite over to using
the officially accepted version.

rdar://172231663
2026-03-10 17:08:10 -07:00
Allan Shortlidge a2a120daab Revert "ModuleInterface: Fix availability attributes on synthesized conformances."
This reverts commit 457debcf4d.

Resolves rdar://172144339.
2026-03-10 14:27:11 -07:00
Rintaro Ishizaki f8911bc257 [ASTPrinter] Disambiguation marker for simple-stored var accessor block
Previously, the `@_accessorBlock` disambiguation attribute was only
emitted for observed variables. But We need `@_accessorBlock`
disambiguation marker for simple stored properties with non-public
setters in `@frozen` types too.

rdar://171819084
2026-03-05 14:14:41 -08:00