Commit Graph

24107 Commits

Author SHA1 Message Date
Doug Gregor 7d48e98f5e Replace the DeferredCodeGen feature with CodeGenerationModel=<model>
The default code generation model for Embedded Swift is "inlinable".
DeferredCodeGen made the default code generation model
"implementation", and there was no spelling for "interface".

Introduce the experimental feature CodeGenerationModel=<model>, which
can be any of those three options. The default remains "inlinable", but
one can now specify "implementation" (which keeps most everything in
SIL) or "interface" (which only keeps the generic things in SIL). The
"interface" mode is more like non-embedded Swift for non-generic
declarations, emitting them into the IR (only) but not SIL. Generic
declarations would remain in SIL.

Implements rdar://172433062.
2026-05-20 08:35:13 -07:00
Doug Gregor 14bc0baecf Introduce the notion of an "effective" code generation model
The code generation model for a particular declaration or conformance
can be defined explicitly with `@export(interface)`,
`@export(implementation)`, or `@inlinable` (for declarations),
indicating where the definition will occur.

Embedded Swift also has some limitations on what can be emitted into
IR. For example, a generic function cannot be `@export(interface)`
because Embedded Swift does not support unspecialized generics.

Compute the effective code generation model based on what was
explicitly specified, the limitations of the model, and the default
code generation model for the given module, which defaults to
"inlinable" but can be made "implementation" by the DeferredCodeGen
feature. Use the effective code generation model for IR- and SIL-level
determinations of linkage and where to emit symbols.
[WIP] Start computing and using the "effective" code generation model

FIXUP linkage of the alias symbol
2026-05-20 08:35:11 -07:00
Xi Ge e562a4b6c1 Merge pull request #89227 from nkcsgexi/hide-types-on-emit 2026-05-18 19:19:49 -07:00
Slava Pestov e33a43aa3e Merge pull request #89167 from slavapestov/clean-up-variadic-parameter-requirement-check
Sema: Fix crash when declaring an old-style variadic parameter with nonescaping type
2026-05-18 22:19:08 -04:00
Xi Ge 886f856f7e [Serialization] Substitute HiddenType for hidden stored-property types when emitting binary modules
The substitution is driven by a canonical type to mangled name table on ASTContext,
populated by exportability checking at the same site where the corresponding
diagnostics are suppressed. After this change, the module emitter and module
loader see hidden types differently: the emitter still sees the real types
defined in the bridging header, while the loader sees only a mangled name
wrapped in a HiddenType placeholder.
2026-05-18 12:48:59 -07:00
Slava Pestov f05d1cab32 Sema: Fix crash when declaring an old-style variadic parameter with nonescaping type
This is not supported for the same reason you can't have a noncopyable
variadic parameter, but the code was hard-coded to check for copyability
only.

Generalize this to apply the generic signature for Array via the
common code path, and add a custom note to explain why those requirements
are checked in the first place.

Cleaning this up also fixed some fuzzer crashes.

Reported on the forums:
https://forums.swift.org/t/variadic-escapable-arguments-crash-the-compiler/86727/2
2026-05-18 10:49:23 -04:00
Jamie 2be7db49ed [docs][NFC]: improve GlobalActorAttributeRequest doc comment 2026-05-17 15:41:15 -05:00
Xi Ge 0e96664855 Merge pull request #89177 from nkcsgexi/serialize-hidden-type-layout 2026-05-16 06:20:06 -07:00
Michael Gottesman de8ffa5c96 Merge pull request #88936 from gottesmm/pr-8c09d3b5dc72a3bf501f3feea39e69b786040836
[diagnostic] Convert swift-diagnostics-assert-on-{error,warning} from llvm::cl::opt globals to Swift frontend flags
2026-05-15 17:26:01 -07:00
Hamish Knight 16742ae9fa Merge pull request #89126 from hamishknight/try-fix
[Sema] Fix missing async sequence `for` loop throwing diagnostic
2026-05-15 20:54:06 +01:00
Guillaume Lessard 5317cef640 Merge pull request #89161 from glessard/no-effect-in-effect-marker
Move 4 warnings to new UnnecessaryEffectMarker group
2026-05-15 12:26:50 -07:00
elsa 83d4291709 CSE Optimizer Pass rewrite (#88248)
Resolves rdar://173862129
2026-05-15 19:11:10 +01:00
Xi Ge 7972ea36ee Merge remote-tracking branch 'origin/main' into serialize-hidden-type-layout 2026-05-15 10:12:20 -07:00
Xi Ge 00897a0efb [Serialization] Add precomputed layout table for hidden types
Add the module-format machinery that lets a Swift library record the
physical layout of hidden types (currently limited to C types imported via internal bridging header).
into binary modules, so downstream consumers can pull the layouts of these hidden types without
loading the internal dependency.

To test this, this change also added a frontend action to print hidden types' layouts
from both the module under compilation and all the modules being imported.
2026-05-15 10:07:19 -07:00
Kavon Farvardin c19889c6e7 Merge pull request #88976 from kavon/preinverse-generics-except-176395527
introduce @_preInverseGenerics(except:)
2026-05-15 04:43:33 -07:00
Guillaume Lessard c55c4d740b [Sema] move 4 warnings to new UnnecessaryEffectMarker group
The “no unsafe operations occur within ‘unsafe’ expression” diagnostic was not part of any warning group.
The new group also includes the matching “try” and “await” warnings.
2026-05-15 02:21:00 -07:00
Aidan Hall 7a870dc1e3 Merge pull request #89053 from aidan-hall/lifedep-partial-apply-result-lifetimes
Lifetimes: Replace deps on partial_apply parameters with 'captures'
2026-05-15 10:15:34 +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
Michael Gottesman c36f842bed [diagnostic] Convert diagnostics-assert-on-{error,warning} and sil-region-isolation-assert-on-unknown-pattern from llvm::cl::opt globals to Swift frontend flags, and add -diagnostics-assert-on-group
llvm::cl::opt flags are compiled out in non-asserts builds, making these
debug flags unavailable in an important category of use cases — debugging
a release compiler in lldb. By promoting them to Swift frontend flags stored
in DiagnosticOptions/SILOptions, they are available in all build
configurations.

The three existing flags are migrated:
  -diagnostics-assert-on-error
  -diagnostics-assert-on-warning
  -sil-region-isolation-assert-on-unknown-pattern
    (backing field renamed to AbortOnUnknownRegionIsolationPatternError)

A new flag is added:
  -diagnostics-assert-on-group <group>
    Traps when any diagnostic belonging to the named group is emitted,
    allowing targeted breakpoints on a single diagnostic group rather than
    all errors or all warnings.

The assert-on-{error,warning,group} flags are intentionally kept separate
from the normal diagnostic suppression/escalation machinery so that they
remain useful while other diagnostics are also being emitted.

Tests are added for all four flags.
2026-05-14 17:36:08 -07:00
Egor Zhdan 227346870c Merge pull request #89074 from egorzhdan/egorzhdan/swift-name-this
[cxx-interop] Do not allow `swift_name` to add a method to a different struct
2026-05-14 18:18:17 +01:00
Hamish Knight bbef9e16b8 [Sema] Fix missing async sequence for loop throwing diagnostic
The diagnostic for an async sequence `for` loop missing a `try` got
accidentally dropped during the `for` loop desugaring rework. Restore
it here.

rdar://177062849
2026-05-14 12:55:50 +01:00
Egor Zhdan e27c9fc5f0 [cxx-interop] Do not allow swift_name to add a method to a different struct
If a C++ method is not static, let's not allow changing its parent struct type to a different type, since the implicit `this` parameter would have an incompatible type.

This fixes an assertion that would previously fire for this scenario.

rdar://161208348
2026-05-13 18:55:29 +01: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
Aidan Hall 280eed8b7d Lifetimes: Replace deps on partial_apply parameters with 'captures' 2026-05-13 15:48:23 +01:00
Xi Ge 4f60cc6e6e Merge pull request #89057 from nkcsgexi/hidden-type 2026-05-13 06:38:57 -07:00
Artem Chikin b74a131b20 Merge pull request #89049 from artemcm/FixDiagnoseBinarySerialization
[Source Warning Control] Ensure we do not attempt to serialize `@diagnose` attributes
2026-05-13 14:17:39 +01:00
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Artem Chikin 68bd6ba1d1 [Source Warning Control] Ensure we do not attempt to serialize @diagnose attributes
It is already not printed into textual interfaces and we forgot to also ensure it never gets serialized into binary modules

Resolves rdar://176893559
2026-05-12 18:59:42 +01:00
Artem Chikin 2a01c35e53 Merge pull request #88952 from artemcm/ImprovedLiteralExpressions
[Literal Expressions] Improvements to semantics to address feedback
2026-05-12 10:48:56 +01:00
Karoy Lorentey 285fd54fde Merge pull request #88900 from lorentey/bump-swift-version
Bump Swift version to 6.5
2026-05-11 18:28:56 -07:00
Pavel Yaskevich 7cf861b9e5 Merge pull request #88811 from xedin/optimize-nonisolated-nonsending-emission
[Concurrency] SILGen: Emit special closures that behave like `nonisolated(nonsending)`
2026-05-11 16:53:05 -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
Doug Gregor 86febb3a3e Merge pull request #88979 from DougGregor/export-interface-types-and-conformances
[Embedded] Extend @export(interface) to non-generic types and protocol conformances
2026-05-11 11:25:10 -07: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
Doug Gregor 7c3b534eab Diagnose @export(interface) on generic types in embedded swift 2026-05-10 15:34:30 -07:00
Gábor Horváth 33ae606011 Merge pull request #88964 from Xazax-hun/trivial-move-only-type
[cxx-interop] Never copy trivial move-only C++ types
2026-05-10 10:52:05 +01:00
Xi Ge 74362dae21 Merge pull request #88972 from nkcsgexi/struct-layout-all
Frontend: Add computeAbstractStructLayout for full struct layout computation
2026-05-08 22:44:49 -07:00
Doug Gregor f6f379daab [Embedded] Extend @export(interface) to protocol conformances
Protocol conformances normally have shared linkage in Embedded Swift.
However, allow the use of @export(interface) on conformances (by way
of their enclosing nominal type or extension), which will emit the
witness tables for those conformances as strong symbols in the owning
module, and references to these symbols from other modules.
2026-05-08 16:25:46 -07:00
Aidan Hall d966ce12ef Merge pull request #88768 from aidan-hall/lifedep-refactored-print
Unified lifetime printing for Swift, SIL and AST dumps
2026-05-08 22:24:00 +01:00
Doug Gregor 09dd9db3e1 [Embedded] Extend @export(interface) to non-generic types
@export(interface) makes it so that Embedded Swift will emit a strong
definition of a symbol in its defining module, and use that symbol in
other modules. Extend this notion to non-generic types, where we will
emit a strong definition for the full type metadata, and let it be
referenced from other modules rather than the lazy, shared emission.

Implements rdar://176392354.
2026-05-08 14:23:21 -07:00
Xi Ge 1c15202f8a Frontend: Add computeAbstractStructLayout for full struct layout computation
Computes per-field abstract layout (offset, size, alignment, mangled name,
bitwiseCopyable, isOpaque) for structs with both Clang-imported and Swift-native fields.

This API will be used from the library-side to serialize layout information to binary modules.
2026-05-08 14:10:06 -07:00
Slava Pestov 1f269ebcf0 AST: Remove SubscriptDecl field from DynamicMemberLookupSubscriptEligibility 2026-05-08 15:46:20 -04:00
Slava Pestov 6b84857d6f AST: Remove useDC parameter from getDynamicMemberLookupKind() 2026-05-08 15:46:20 -04:00
Slava Pestov 29768061ef Sema: Remove useDC parameter from DynamicMemberLookupSubscriptRequest 2026-05-08 15:46:18 -04:00
Slava Pestov 4926234b54 Sema: Remove SubscriptDecl::isValidDynamicMemberLookupSubscript() 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 f448191d34 Support additional args in @dynamicMemberLookup subscripts
Adds support for `SubscriptDecl`s to fulfill `@dynamicMemberLookup`
requirements if they have additional arguments after `dynamicMember:` so
long as those arguments have default values, or are variadic.

This allows exposing values like `#function`, `#fileID`, `#line`, etc.
to dynamic member lookup.
2026-05-08 15:46:17 -04:00
Itai Ferber c191d4994c Cache SubscriptDecl @dynamicMemberLookup eligibility
`SubscriptDecl`s may get checked multiple times for eligibility in
fulfilling `@dynamicMemberLookup` requirements; since the checks are
non-trivial and the result doesn't change, this eligibility can be
cached in the decl's `Bits`.
2026-05-08 15:46:17 -04:00