Commit Graph

49051 Commits

Author SHA1 Message Date
Doug Gregor 92dcbd17c6 [SIL] Explicitly keep the code generation model in SILGlobalVariable
Just like we do with SILFunction, allow a code generation model to be
specified on a SILGlobalVariable and maintain that through the printed
and serialized forms.
2026-05-20 08:35:22 -07:00
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
Argyrios Kyrtzidis 81f4ef3ef7 Merge pull request #89143 from akyrtzi/akyrtzi/pr/cas-input-index-stored-in-result
[CAS] Store the input index along the compiler results
2026-05-20 06:25:33 -07:00
Argyrios Kyrtzidis 429416cabd [CAS] Store the input index along the compiler results
This allows replaying the cached compiler results from an upstream CAS,
if we know the key, without needing access to the caching key input CAS tree.
2026-05-19 11:09:35 -07:00
Aidan Hall 0a5bb082de Merge pull request #89123 from aidan-hall/pack-opt-nothrow
PackSpecialization: Handle error result separately, propagate apply nothrow & async flags
2026-05-19 17:13:06 +01: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
Pavel Yaskevich 6ceb787a93 Merge pull request #89200 from jamieQ/global-actor-req-docs
[docs][NFC]: improve GlobalActorAttributeRequest doc comment
2026-05-18 15:03:51 -07: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
Emil Pedersen c0cc0827de Merge pull request #89071 from Snowy1803/debug-bb
[DebugInfo] Supplement debug values with Debug Basic Blocks
2026-05-18 17:32:35 +01: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
Ben Cohen ad8a8f7cc8 SILOptimizer: add FunctionConvention.formalResults; use it in PackSpecialization
The C++ `SILFunctionType` exposes both `getResults()` (formal results only)
and `getResultsWithError()` (formal + error). The Swift mirror previously
only had `results`, bridging to the with-error variant. Add `formalResults`
for the formal-only view, matching the C++ split.

Switch PackSpecialization's three result-iteration sites to `formalResults`.
The bridged `createSpecializedFunctionDeclaration` preserves the error
result on its own, so iterating with-error included it twice in the new
function's signature.

Also forward the original apply's `nothrow`/`noasync` flags to the
specialized apply, required for SIL verification of a plain apply calling
a function with an error result.
2026-05-18 14:45:26 +01:00
Jamie 2be7db49ed [docs][NFC]: improve GlobalActorAttributeRequest doc comment 2026-05-17 15:41:15 -05:00
Emil Pedersen aa4de7a348 [DebugInfo] Add getOrCreateDebugReconstructionBlock function
This function is used by passes and salvages to facilitate adding
instructions to reconstruction blocks, even if no block exists on the
debug value yet.
2026-05-16 18:23:44 +01: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
Mike Ash 0dfb02dd29 Merge pull request #88612 from mikeash/remote-mirror-macho-parse-fix
[Reflection] Fix incorrect count and segment matching in ReflectionContext mach-o parsing.
2026-05-15 14:42:05 -04:00
Mike Ash d2cd2e5521 Merge pull request #88628 from mikeash/remote-mirror-field-descriptor-size-fix
[Reflection] Fix overrun when reading field records of nonstandard size.
2026-05-15 14:37:29 -04:00
elsa 83d4291709 CSE Optimizer Pass rewrite (#88248)
Resolves rdar://173862129
2026-05-15 19:11:10 +01:00
Mike Ash 0ad96e4d5b Merge pull request #89140 from mikeash/env-vars-types-namespace
[Runtime] Group environment variable types into a types namespace.
2026-05-15 13:55:05 -04:00
Emil Pedersen f807825e33 [SILVerifier] Add full verification of debug basic block content
Additionally, remove debug scopes from debug reconstruction basic block
instructions.
2026-05-15 18:32:46 +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
Mike Ash acb09e2f87 Merge pull request #88935 from mikeash/remote-mirror-variadic-generic
[Reflection] Support parameter packs in generic substitutions.
2026-05-15 12:35:24 -04:00
Emil Pedersen b563de2da4 [DebugInfo] Rename debug basic blocks to reconstruction blocks 2026-05-15 16:42:53 +01: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
Kavon Farvardin ceb302c7aa NFC: further constexpr-ize InvertibleProtocolSet
I'd like `InvertibleProtocolSet::allKnown()` to be evaluated
at compile-time.
2026-05-14 18:26:19 -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
Mike Ash 23fac72075 Merge pull request #88933 from mikeash/remote-mirror-inline-array
[Reflection] Support inspection of InlineArray.
2026-05-14 19:53:11 -04:00
Mike Ash f7745f2094 [Runtime] Group environment variable types into a types namespace.
Rather than attempt to use standard C++ type names, create a namespace specifically for environment variable types and require vars to use a type from that namespace. This avoids the annoying collision between this `string` and `std::string`, and makes everything a bit more consistent. Rename the types a bit to be more appropriate for this context: boolean, uint8, and uint32, instead of bool, uint8_t, and uint32_t.
2026-05-14 15:16:17 -04: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
Allan Shortlidge 2d30b6d99b Merge pull request #89109 from tshortli/remove-warning-for-type-shadowing-module
ModuleInterface: Remove warning about types shadowing modules
2026-05-13 21:23:51 -07:00
John Hui 5541237829 Merge pull request #88903 from j-hui/reenable-clangimporter-cacheing
[cxx-interop] Bring back ClangImporter request caching
2026-05-13 15:28:12 -07: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
Emil Pedersen 93e511e372 [DebugInfo] Fix moving debug basic blocks between functions
Assisted-by: Claude
2026-05-13 16:03:53 +01:00
Emil Pedersen 07d542e6f9 [DebugInfo] Implement SILCloner support for debug basic blocks
Assisted-by: Claude
2026-05-13 16:03:53 +01:00
Emil Pedersen cbb439941e [DebugInfo] Add SIL support for debug basic blocks
Assisted-by: Claude
2026-05-13 16:03:38 +01: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
Artem Chikin 0c9d6e0507 Merge pull request #88464 from artemcm/NoSharedSourceMgrDepScan
[DependencyScan] Give each scanning worker its own SourceManager
2026-05-13 09:22:20 +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