Commit Graph

1299 Commits

Author SHA1 Message Date
Becca Royal-Gordon ef1470baed Don’t print module selectors in more cases
There were a number of cases where Swift would emit module selectors into module interface files that it was subsequently unable to parse because the compiler at least temporarily represented them as dependent member types. Modify the carve-out so that if *any* of a type’s parents are generic parameters or archetypes, we don’t print a module selector on it.

Fixes rdar://166180424.
2025-12-19 13:33:35 -08:00
Meghana Gupta 4089775de8 Fix swiftinterface printing of accessors and inferred lifetime dependencies when Lifetimes feature is enabled 2025-12-09 14:59:41 -08:00
Pavel Yaskevich b6291e680d Merge pull request #85736 from xedin/rdar-122963120
[ASTPrinter] Print a fully resolved type for an outermost property wr…
2025-12-02 11:54:53 -08:00
Pavel Yaskevich 4b33db0a84 Merge pull request #85605 from xedin/tilde-sendable-cond-conformances
[Concurrency] Allow conditionally conforming to `Sendable` when confo…
2025-12-01 21:53:25 -08:00
Pavel Yaskevich 5b665a8426 [ASTPrinter] Print a fully resolved type for an outermost property wrapper in swift interfaces
The type of an outermost property wrapper should be printed together
with (inferred) generic arguments because otherwise if a any wrapper
in the chain has generic parameters that are not involved in
`wrappedValue:` argument it won't be impossible to infer them while
type-checking the interface file where it appears.

Resolves: rdar://122963120
2025-11-28 22:00:14 -08:00
Sam Pyankov 7c8766fac8 Merge pull request #85571 from sepy97/desugar-inherited-ParaProtoType
ModuleInterface: Avoid printing generic arguments of a ParameterizedProtocolType in inheritance clause
2025-11-20 18:29:52 -08:00
Pavel Yaskevich d868e68cd2 [Concurrency] Allow conditionally conforming to Sendable when conformance is suppressed
For consistency with invertible protocols using `~Sendable` should
only prohibit use of unconditional extensions.

For example:

```swift
struct G<T>: ~Sendable {}
```

The following (unconditional) extension is rejected:

```
extension G: Sendable {} // error: cannot both conform to and suppress conformance to 'Sendable'
```

But conditional on `T` is accepted:

```
extension G: Sendable where T: Sendable {} // Ok!
```
2025-11-19 16:46:29 -08:00
Sam Pyankov 480b64ef50 ModuleInterface: Avoid printing generic arguments of a ParameterizedProtocolType in inheritance clause
When emitting module interfaces, parameterized protocols in inheritance clauses were being printed with generic arguments (public struct T: Fancy<Float64>), causing errors with protocol conformance verification.
The fix strip ParameterizedProtocolType to its base protocol type when printing inherited types, producing the correct inheritance clause.

Resolves: rdar://161925627
2025-11-19 10:27:15 -08:00
Arnold Schwaighofer 91991bfd47 Silence Misc/verify-swift-feature-testing.test-sh failure 2025-11-07 10:46:33 -08:00
Arnold Schwaighofer 9795f65145 Change tests to also test that this feature is available per default 2025-11-07 10:10:47 -08:00
Becca Royal-Gordon 2504beeccc Merge pull request #85043 from beccadax/mod-squad-interface
[SE-0491] Conditionally emit module selectors into swiftinterfaces
2025-11-03 19:08:09 -08:00
Artem Chikin 164d3ae5a8 Merge pull request #85010 from artemcm/AlwaysRebuildExplicitInterface
[Explicit Module Builds] Always rebuild the target module in explicit `-compile-module-from-interface` builds.
2025-10-31 21:24:18 -04:00
Becca Royal-Gordon 9454c0aaa4 Emit module selectors in swiftinterfaces
This support is currently opt-in and can be disabled by a blocklist.
2025-10-31 16:48:06 -07:00
Alexis Laferrière 94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Artem Chikin 4cdbcb8645 [Explicit Module Builds] Always rebuild the target module in explicit -compile-module-from-interface builds.
We have long switched to delegate the checking of whether a module is up-to-date to the build system (SwiftDriver) and stopped serializing file dependencies for interface-built binary modules.

Resolves rdar://162881032
2025-10-20 14:13:37 -07:00
Joe Groff 25af94495c Merge pull request #84975 from jckarter/cant-discard-in-inlinable-code
Sema: `discard self` should not be allowed in inlinable methods of non-frozen types.
2025-10-20 08:28:38 -07:00
Rintaro Ishizaki 13e17870cc Merge pull request #84972 from rintaro/accessor-disambiguation-rdar140943107
[ASTPrinter/Parse] Disambiguate accessor block in .swiftinterface
2025-10-17 18:40:56 -07:00
Joe Groff 6f2811110d Sema: discard self should not be allowed in inlinable methods of non-frozen types.
`discard self` requires knowledge of the internal layout of the type in order to clean
up its fields while bypassing its public `deinit`. Inlinable code can get copied into
and run from outside of the defining module, so this is impossible to implement.
Fixes rdar://160815058.
2025-10-17 16:14:58 -07:00
Rintaro Ishizaki 6a1604ba09 [ASTPrinter/Parse] Disambiguate accessor block in .swiftinterface
.swiftinterface sometimes prints a pattern binding initializer and the
accessor block. However the parser doesn't expect such constructs and
the disambiguation from trailing closures would be fragile. To make it
reliable, introduce a disambiguation marker `@_accessorBlock` .
`ASTPrinter` prints it right after `{` only if 1) The accessor block is
for a pattern binding declaration, 2) the decl has an initializer
printed, and 3) the non-observer accessor block is being printed. In the
parser, if the block after an initializer starts with
`{ @_accessorBlock`, it's always parsed as an accessor block instead of
a trailing closure.

rdar://140943107
2025-10-16 22:16:29 -07:00
Henrik G. Olsson 2fceb9a41d Merge pull request #84863 from ramonasuncion/test-moduleinterface-replace-find
[Test][ModuleInterface] Replace find with find_files utility
2025-10-15 23:30:37 -07:00
Henrik G. Olsson 81f1e75b4f Merge pull request #84843 from hnrklssn/filecheck-sanitize-tmp-dir
[Utils] Sanitize %t with PathSanitizingFileCheck
2025-10-15 15:43:58 -07:00
Ramon Asuncion f99260cfa7 [Test][ModuleInterface] Replace find with find_files utility 2025-10-13 10:49:09 -07:00
Henrik G. Olsson bc6a034a94 Update ModuleInterface/ModuleCache/SDKDependencies.swift (NFC)
This one `DEPCHANGE-DAG: SDKDependencies.swift` used to match because
the expansion of the `%t` temp dir contained the substring
"SDKDependencies.swift", but this is now sanitized to `TMP_DIR`.
2025-10-12 23:09:10 -07:00
Henrik G. Olsson 9e2a18d401 fix tests with TMP_DIR 2025-10-12 16:01:30 -07:00
Pavel Yaskevich 93961aa5a2 [AST] Implement printing suppression for ~Sendable 2025-10-09 13:45:55 -07:00
Henrik G. Olsson cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Arnold Schwaighofer 3447bd1b31 Change implementation to infer @inlinable semantics from @inline(always) on public declarations 2025-09-30 08:36:32 -07:00
Arnold Schwaighofer 25a071efc8 Add experimental feature @inline(always)
The intent for `@inline(always)` is to act as an optimization control.
The user can rely on inlining to happen or the compiler will emit an error
message.

Because function values can be dynamic (closures, protocol/class lookup)
this guarantee can only be upheld for direct function references.

In cases where the optimizer can resolve dynamic function values the
attribute shall be respected.

rdar://148608854
2025-09-30 08:36:26 -07:00
eeckstein a1e5a06c9e Merge pull request #84530 from eeckstein/remove-enable-oss-module-option
Remove the `-enable-ossa-modules` option
2025-09-27 07:35:40 +02:00
Alexis Laferrière 4c7a313de7 Merge pull request #84488 from xymus/c-impl-in-swiftinterfaces
ModuleInterface: Don't print `@c @implementation` functions
2025-09-26 16:09:34 -07:00
Slava Pestov be52ed20d5 Merge pull request #84469 from slavapestov/fix-opaque-return-attr-crash
Sema: Fix crash with invalid @_opaqueReturnTypeOf attribute
2025-09-26 18:36:09 -04:00
Erik Eckstein 2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Allan Shortlidge fba664c082 Revert "Frontend: Require explicit language mode when emitting swiftinterfaces."
This reverts commit 9067051c29.
2025-09-25 08:02:18 -07:00
Slava Pestov ffc501cbd3 Sema: Fix crash with invalid @_opaqueReturnTypeOf attribute
If we demangle the name but we can't resolve the opaque return
declaration, we would dereference a null pointer and crash.

Speculative fix for rdar://161067984.
2025-09-24 10:02:32 -04:00
Alexis Laferrière 0eaab86219 ModuleInterface: Don't print @c @implementation functions
We don't need to print the `@c @implementation` functions in
swiftinterfaces as clients need only to see the original declaration in
the C header. Don't print `@objc @implementation` functions either, but
still print simple `@c` and `@objc` functions.
2025-09-23 16:41:34 -07:00
Konrad Malawski 3b3c36457a [Distributed] fix missing availability annotation
resolves rdar://161100405
2025-09-23 15:56:05 +09:00
Konrad `ktoso` Malawski 6f4c26f29a Merge pull request #84384 from ktoso/wip-distributed-red-conf 2025-09-22 21:00:26 +09:00
Alexis Laferrière 97002e1ee0 Merge pull request #84373 from xymus/le-import-warn
Sema: Limit errors on LE importing non-LE modules to SDK modules
2025-09-19 16:34:48 -07:00
Konrad Malawski 7affd14c24 fix assertions in other test 2025-09-19 15:44:11 +09:00
Konrad Malawski 1ea4e914e3 Simplify the check; conforming to (Distributed)Actor is not right in any case 2025-09-19 10:50:23 +09:00
Konrad Malawski d73b907d66 [Distributed] Avoid redundant conformance to DistributedActor in interface files
Forgetting to handle DistributedActor next to Actor strikes again:
Actors are special that their conformance is implicit and needs not be
printed in swift interface files.

an actor's Actor conformance was filtered out, however the same logic
needs to be applied to DistributedActor, as otherwise there can be
redundant conformance errors when validating module interface files.

Resolves rdar://160252579
2025-09-19 09:01:23 +09:00
Alexis Laferrière 8b38d29333 Sema: Limit error on LE importing non-LE modules to SDK modules
Limit reporting as an error imports of a non-library-evolution module
from a library-evolution enabled module to sources that are part of the
SDK. The error also requires having enabled `InternalImportsByDefault`.
This should help prevent SDK breaking regressions while loosening the
restriction elsewhere.

Framework owners can enable `-library-level api` or `spi` to get this
check as an error, along with more sanity checks.

Other cases remain as a warning. We should look to silence it in some
cases or offer a flag to do so.

rdar://160414667
2025-09-18 11:31:36 -07:00
Allan Shortlidge c78725359b Merge pull request #84327 from tshortli/really-require-swift-version-in-module-interfaces
Frontend: Require explicit language mode when emitting swiftinterfaces
2025-09-16 15:57:26 -07:00
Allan Shortlidge 01d458b7a3 Merge pull request #84311 from tshortli/preconcurrency-import-in-swiftinterface
ModuleInterface: Print imports with @preconcurrency in swiftinterface files
2025-09-16 13:09:48 -07:00
Allan Shortlidge 9067051c29 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 https://github.com/swiftlang/swift/pull/84307 this diagnostic was downgraded
to a warning. The failures it caused in PR testing should now be resolved.

Resolves rdar://145168219.
2025-09-16 10:25:14 -07:00
Allan Shortlidge 4841bcffa1 ModuleInterface: Print imports with @preconcurrency in swiftinterface files.
When a module has been imported `@preconcurrency` in source, when it is printed
in a `swiftinterface` file it should be printed along with the attribute to
ensure that type checking of the module's public declarations behaves
consistently.

This fix is a little unsatisfying because it adds another a linear scan over
all imports in the source for each printed import. This should be improved, but
it can be done later.

Resolves rdar://136857313.
2025-09-15 17:33:13 -07:00
Allan Shortlidge e2c8235a2c Frontend: Temporarily downgrade 'error_module_interface_requires_language_mode'.
Downgrade the new error in https://github.com/swiftlang/swift/pull/84244 to a
warning.

The PR smoke test build is using a different build system that is failing to
pass `-swift-version` arguments when building various stdlib modules. That
needs to be fixed, but for now we also need to unblock CI.
2025-09-15 14:10:24 -07:00
Allan Shortlidge cfe9f90347 Merge pull request #84244 from tshortli/require-swift-version-in-module-interfaces
Frontend: Require `-language-mode` option when emitting swiftinterfaces
2025-09-15 10:08:23 -07:00
Slava Pestov 87cbb7d2d0 AST: New way of printing @_opaqueReturnTypeOf when parameter packs are involved
This is the ASTPrinter change to go with the Sema change.
We now print @_opaqueReturnTypeOf using the new nested
syntax when parameter packs are involved.

Fixes rdar://problem/151171381.
2025-09-12 15:43:30 -04:00
Slava Pestov af78807313 Sema: Generalize @_opaqueReturnTypeOf syntax to correctly handle parameter packs
We now allow the dummy identifier to be a qualified reference, so
that we can reconstruct generic parameter lists from multiple levels:

    @_opaqueReturnTypeOf(...) __.<OuterArgs...>.__<InnerArgs...>

This fixes an ambiguity with parameter packs, where flattening the
packs from multiple levels of nested types no longer produced an
unambiguous result.

To maintain backward compatibility, we still accept the old "flat"
form when no parameter packs are present.
2025-09-12 15:43:30 -04:00