Commit Graph

1251 Commits

Author SHA1 Message Date
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
Allan Shortlidge 457debcf4d ModuleInterface: Fix availability attributes on synthesized conformances.
Adjust the algorithm that collects the availability attributes for synthesized
conformances to ensure it skips attributes from parent declarations that are
superceded by attributes in nested declarations, even when the domains of those
attributes do not match exactly.
2026-03-03 17:14:45 -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
Allan Shortlidge bee3eb843b ModuleInterface: Handle custom availability domains for synthesized conformances.
When gathering availability attributes to print in a .swiftinterface for
synthesized conformances to inherited protocols, don't assume availabilty
attributes always have a platform kind.

Resolves rdar://170361240.
2026-02-28 17:56:41 -08:00
Allan Shortlidge 864c08f5ef Merge pull request #87501 from tshortli/require-language-mode-in-interface
Frontend: Require explicit language mode when emitting swiftinterfaces
2026-02-25 21:35:05 -08:00
Sam Pyankov 87421450a5 Merge pull request #87434 from sepy97/transitive_import_check
ASTPrinter: Filter inherited constructors from restricted modules
2026-02-25 20:50:23 -08:00
Allan Shortlidge 1ca0d87e2b Frontend: Require explicit language mode when emitting swiftinterfaces.
If a .swiftinterface file does not include an explicit `-language-mode` option
(or its predecessor `-swift-version`) and needs to be built as a dependency of a
client compilation, then the invocation to build the module from interface
would end up inheriting the language mode that the client code is built with.
This can result in spurious type checking diagnostics or even mis-compilation.
To ensure that a module interface is always built using the language mode that
its source code was originally built with, require an explicit `-language-mode`
option when emitting swiftinterface files.

In #84307 this diagnostic was downgraded to a warning. The failures it caused
in PR testing should now be resolved.

This is a re-attempt of https://github.com/swiftlang/swift/pull/84327.

Resolves rdar://145168219.
2026-02-25 12:42:02 -08:00
Sam Pyankov 2aeaf2cd89 ASTPrinter: Filter inherited constructors from restricted modules
Skip printing inherited constructors defined in modules that are not
publicly imported.
This prevents interface verification errors where types are used but
their modules aren't in the import list.

rdar://168101765
2026-02-25 11:36:32 -08:00
Ryan Mansfield f07c1a1b82 Merge pull request #87284 from rjmansfield/se-0441-alias-swap
Swap the alias relationship between -language-mode and -swift-version.
2026-02-20 18:14:44 -05:00
Becca Royal-Gordon 1f008fb0d0 [ModuleInterface] Enable module selectors by default
And update tests to use them.

This commit depends on fixes in swiftlang/swift PRs #86905, #87129, and #87130.

Fixes rdar://169749886.
2026-02-20 00:35:23 -08:00
Ryan Mansfield ae78773ad8 Swap the alias relationship between -language-mode and -swift-version.
As specified in SE-0441, -language-mode should appear in help output
while -swift-version should be the hidden alias.

Related to swiftlang/swift-driver#1894
2026-02-18 16:06:08 -05:00
Aidan Hall 229eccb899 Merge pull request #87183 from aidan-hall/lifedep-borrow-print
LifetimeDependence: Fix mutable borrow printing
2026-02-16 10:12:35 +00:00
Becca Royal-Gordon 3dc9fba08e Merge pull request #87128 from beccadax/mod-squad-dissociated
[ModuleInterface] Fix associated type selectors more
2026-02-12 23:04:55 -08:00
Aidan Hall a8c5a0cc92 LifetimeDependence: Fix mutable borrow printing
Use the '&' specifier for inout scoped dependence sources, since this is the
only kind of borrowed dependence they can have.
2026-02-12 17:29:56 +00:00
Andrew Trick 0867ca8ec4 Merge pull request #87101 from atrick/lifedep-inout-immortal
Support @_lifetime(immortal) to suppress inout default dependency
2026-02-12 09:09:31 -08:00
Pavel Yaskevich 88c0b0adcb Merge pull request #87096 from xedin/rdar-166159992
[ASTPrinter] Print `Sendable` conformance for package types in swift …
2026-02-11 12:20:03 -08:00
Andrew Trick b7e2186f7d Support @_lifetime(immortal) to suppress inout default dependency
Non-Escapable 'inout' arguments have a default self-dependency, regardless of
any other annotations.  For example:

    @_lifetime(dest: copy source)
    /* DEFAULT: @_lifetime(dest: copy dest, copy source) */
    func foo<T: ~Escapable>(dest: inout T, source: T)

An immortal lifetime specifier now suppresses that default. For example:

    @_lifetime(dest: immortal, copy source)
    /* DEFAULT: @_lifetime(dest: copy source) */
    func foo<T: ~Escapable>(dest: inout T, source: T)

This is necessary because there is otherwise no other way to suppress the
default lifetime.

Fixes rdar://170016708 ([nonescapable] Support @_lifetime(immortal) to suppress
the usual inout default self-dependency)
2026-02-11 05:55:26 -08:00
Becca Royal-Gordon b0bd6c711c Merge pull request #86905 from beccadax/mod-squad-not-for-export-2 2026-02-11 02:28:08 -08:00
Becca Royal-Gordon 31ef4d00e0 [ModuleInterface] Fix associated type selectors more
Qualification has discovered a complicated test case where the module interface printer incorrectly adds module selectors to nested types that don’t support them. Tweak module interface printing to omit the module selector in more situations.

Fixes rdar://169720990.
2026-02-10 16:43:21 -08:00
Becca Royal-Gordon cbad1d8a18 Tweak export_as behavior with submodules
In #86859, I modified the way `export_as` names are used in private module interfaces so that the `export_as` name is used when that module has been imported. This turns out to be slightly too aggressive in a specific scenario where a submodule of the export_as module imports a submodule of the real module—the compiler ends up using the export name even though the resulting lookup won’t actually work.

Modify the logic for deciding whether to use an exported module name so that it not only checks whether the export_as module has been loaded, but also whether the specific module or submodule the declaration belongs to is (possibly transitively) imported by that module.

Fixes rdar://167874630 (harder).
2026-02-10 15:49:47 -08:00
Kavon Farvardin 0a74877ec3 Merge pull request #87119 from kavon/supp-assoc-interfaces-2
SuppAssocDefaults: extra mangling test coverage
2026-02-10 14:13:42 -08:00
Anthony Latsis 4cdd2955a9 Merge pull request #86956 from swiftlang/jepa-main
Basic: Introduce a safe, structured representation for language modes
2026-02-10 21:03:03 +00:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Kavon Farvardin d49ebd5a58 Merge pull request #87066 from kavon/supp-assoc-interfaces
SuppressedAssociatedTypesWithDefaults: swiftinterface and mangling support
2026-02-10 03:04:16 -08:00
Kavon Farvardin 1c8b03557c SuppAssocDefaults: extra mangling test coverage 2026-02-09 17:16:47 -08:00
Kavon Farvardin b2e698ec41 SuppAssocDefaults: update getRequirementsWithInverses
Given that we implicitly expanded Copyable & Escapable
conformance requirements for suppressed primary associated
types, we now need this function to do the opposite;
filtering Copyable & Escapable requirements on such primary
associated types and adding inverses if those requirements
are missing.

This function plays a crucial role in emitting the interface
files accurately for functions and types, in addition to
how we mangle generic signatures into function symbols.

The mangling for generic signatures under the -WithDefaults version of
suppressed associated types goes like this:

- primary associated type T.A has an inverse `Rj` or `RJ` mangled
  into the generic signature if it lacks the conformance, or
  nothing is mangled into it.

- non-primary associated type T.B has either a `T.B: Copyable`
  requirement mangled into it, or nothing is mangled into it.

For the legacy SuppressedAssociatedTypes feature, where there's no
defaults, it uses the "non-primary assocated type" mangling strategy
for all generic signatures.
2026-02-09 16:10:00 -08:00
Pavel Yaskevich 824c6dc926 [ASTPrinter] Print Sendable conformance for package types in swift interfaces
If printing is for a package interface, let's add derived/implied `Sendable`
conformance to avoid having to infer it while type-checking the interface
file later. Such inference is not always possible, because i.e. a package
declaration can have private storage that won't be printed in a package
interface file and attempting inference would produce an invalid result.

Resolves: rdar://166159992
2026-02-09 14:38:12 -08:00
Andrew Trick e9312d3d10 Merge pull request #87055 from atrick/lifedep-inout-defaults
Tweak lifetime dependencies for 'inout' parameters
2026-02-09 08:40:45 -08:00
Kavon Farvardin 3021f32c9b Merge pull request #87048 from kavon/retro-refinement-3
Reparenting: second batch of fixes
2026-02-06 19:04:04 -08:00
Andrew Trick d4b0c713d4 Tweak lifetime dependencies for 'inout' parameters
Assume a default dependency for all 'inout' parameters regardless of the
presence of an explicit annotation.

Default to `@lifetime(inoutArg: copy inoutArg)` even if an explicit annotation
exists.

This way API authors do not need to make the inout dependency explicit when they
probably always want that and don't normally need to write it.

Now:
```
@_lifetime(a: copy b)
func foo(a: inout T, b: T)
```

implies:
```
@_lifetime(a: copy a, copy b)
func foo(a: inout T, b: T)
```

Fixes rdar://169835235 (Always default inout dependencies)
2026-02-06 16:11:26 -08:00
Kavon Farvardin 58ad64d3f4 Reparenting: fix interface emission
The `@reparented` was missing and a typealias
was being synthesized unexpectedly, creating
an issue when typechecking the interface later.

There's no fundamental reason why typealiases
cannot be supported to say the same thing as
the same-type requirement, but I think the
same-type requirement is always needed to be
written on the extension, one way or another.

For now I've chosen to only go with an
explicitly-written same-type requirement.
2026-02-06 13:23:22 -08:00
Aidan Hall e98a7a6bf8 Merge pull request #86842 from aidan-hall/just-func-type-lifetimes-try-print
LifetimeDependence: Support function types
2026-02-06 10:09:25 +00:00
Ian Anderson 4d89b9b0a5 Merge pull request #86945 from ian-twilightcoder/case-sensitive-test-fix
[test][NFC] ModuleInterface/canonicalized-os-version.swift fails on a case sensitive file system
2026-02-05 20:26:29 -08:00
Pavel Yaskevich 527ab6386a Merge pull request #86967 from xedin/rdar-164077275
[Concurrency] A few fixes for default isolation inference
2026-02-05 15:31:10 -08:00
Ian Anderson 61b0472662 [test][NFC] ModuleInterface/canonicalized-os-version.swift fails on a case sensitive file system
Fix a typo in the test
2026-02-05 15:29:45 -08:00
Aidan Hall 6aa55785f0 LifetimeDependence: Tests for function type attribute
Includes:
- rdar://166912068 test case
- Nested type SIL tests
- rdar://160894371 test
- Many more
2026-02-05 14:50:44 +00:00
Meghana Gupta 657fa172bc Fix ASTPrinting of borrow/mutate protocol requirements 2026-02-04 07:16:32 -08:00
Meghana Gupta a3a3134037 Guard borrow/mutate accessors in swiftinterface files 2026-02-04 07:16:28 -08:00
Pavel Yaskevich 9b8e53c0a1 [Concurrency] Check whether @preconcurrency is supported before adding it
Don't trasfer "preconcurrency" from isolation onto a declaration if
the declaration doesn't support it. This is especially important for
`MainActor` by default mode where each `@MainActor` injection site
gets marked as `@preconcurrency` implicitly in pre-6 language modes.

Resolves: https://github.com/swiftlang/swift/issues/85564
2026-02-03 10:29:59 -08:00
Becca Royal-Gordon fce99b3173 Merge pull request #86859 from beccadax/mod-squad-not-for-export 2026-01-29 09:02:50 -08:00
Becca Royal-Gordon 71986c6559 Merge pull request #86862 from beccadax/mod-squad-aka-workaround 2026-01-29 09:02:00 -08:00
Sam Pyankov 1c2cb16a6a ASTPrinter: skip printing incompatible attributes in swiftinterface
Attributes that can not appear on declaration should not be printed in textual interface
rdar://164975727
2026-01-28 15:48:21 -08:00
Becca Royal-Gordon d8f38cfa71 [ModuleInterface] Disable aliasing with selectors
When both `-alias-module-names-in-module-interface` and `-enable-module-selectors-in-module-interface` are turned on, the compiler now disables the former with a warning. Eliminates workaround hacks that should no longer be necessary.

Fixes rdar://problem/169132519.
2026-01-28 15:47:52 -08:00
Becca Royal-Gordon f02b2f1532 Use export_as name in some private swiftinterfaces
Previously, if a declaration belonged to a module with an `export_as` attribute, Swift always used the exported module name in the public module interface and the real module name in the private module interface. However, this is only a rough approximation of the behavior we really want, which is to use the real name in module interfaces that might be imported by dependencies of the exported name.

Change this logic so that public interfaces always use the exported name, and private interfaces use the exported name *only* if a module with that name has been loaded. This should make it so that if you’re building the `export_as` module or anything that imports it, you use the exported name; otherwise you use the real name.

Fixes rdar://167874630.
2026-01-28 14:28:14 -08:00
Becca Royal-Gordon a68d8176a8 [NFC] Tweak export_as test
Duplicated set of commands, FileCheck use pattern that produces suboptimal diagnostics.
2026-01-28 14:26:10 -08:00
Sam Pyankov 139c325d76 Merge pull request #86323 from slavapestov/fix-ppt-type-witness-conflict-crash
Sema: Fix crash when parameterized protocol types define conflicting type witnesses
2026-01-14 09:51:03 -08:00
Slava Pestov 38a9d8389d Sema: Fix crash when parameterized protocol types define conflicting type witnesses 2026-01-13 15:52:44 -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
Doug Gregor 3f00643d13 [Module interface printing] Print @c as @_cdecl for older compilers
Add a feature just for the purpose of suppressing it. Print the check
as `hasAttribute(c)` so this feature can be temporary.

Fixes rdar://167546897 .
2026-01-05 09:47:19 -08:00