Commit Graph

5276 Commits

Author SHA1 Message Date
Steven Wu
af6270ce6a Merge pull request #87208 from cachemeifyoucan/eng/PR-170007480
[ExplicitModule] Teach scanner emit loaded module trace
2026-02-19 15:25:59 -08:00
Erik Eckstein
ac072dad89 CrossModuleOptimization: correctly serialize value-type deinits
Serialize the module's SILMoveOnlyDeinit table. So that client modules can de-virtualize deinits.
So far this only worked for public non-copyable types.
This is especially important for embedded swift.

rdar://166051414
2026-02-19 09:59:07 +01:00
Steven Wu
7fdf642819 [ExplicitModule] Teach scanner emit loaded module trace
During explicit module build, teach dependency scanner to emit the
module trace file instead of each following compile job command. This
reduces the duplicated info, and allows supporting fully cached build
that only loads module from CAS thus cannot produce the path to the
original module file on disk.

rdar://170007480
2026-02-18 09:10:08 -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
Artem Chikin
f53ccd656d Merge pull request #86934 from artemcm/LiteralExpressionEnumRawValues
[Literal Expressions] Add support for literal expressions in enum raw values
2026-02-10 22:28:59 +00: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
Adrian Prantl
d02ee76447 Merge pull request #87099 from adrian-prantl/170007373
[LLDB] Add a missing nullptr check for ClangImporte
2026-02-10 08:13:46 -08:00
Anthony Latsis
85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Artem Chikin
1e5ba5fca8 [Literal Expressions] Add support for literal expressions in enum raw values
Modify relevant portions of the type-checker and parser to allow, when the 'LiteralExpressions' experimental feature is enabled, for arbitrary integer-typed expressions in enum raw value specifiers. These expressions will be type-checked and constant-folded into an integer literal expression, keeping the current interface of 'EnumElementDecl' consistent for clients.

Previously, 'EnumRawValuesRequest' had two different "modes" which were discerned based on typechecking stage (structural | interface), where the former had the request compute all raw values, both user-specified literal expressions and computing increment-derived values as well; the latter would also type-check the user-specified expressions and compute their types.
- With the need to have enum case raw values support arbitrary integer expressions, the request ('EnumRawValuesRequest') has been refactored and simplified to *always* both compute all case raw values and perform type-checking of user-specified raw value expressions. This is done in order to allow the AST-based constant-folding infrastructure ('ConstantFoldExpression' request) to run on the expressions. Constant folding is invoked during the evaluation of 'EnumRawValuesRequest' on all user-specified raw value expressions, in order to be able to compute subsequent increment values and ensure the expressions are foldable. If they are not, i.e. if constant folding fails, a relevant diagnostic will be emitted.
- 'EnumElementDecl' continues to store the raw value expression, which is no longer a 'LiteralExpr' but rather an 'Expr'; however, the getter ('getRawValueExpr') continues to return a 'LiteralExpr' by invoking the constant-folding request on the stored value, which is guaranteed to return a cached result from a prior invocation in 'EnumRawValuesRequest', assuming it succeeded.
- Furthermore, the 'structural' request kind was previously not cached, whereas now because the request must always do the complete type-checking work, it is always cached.

Resolves rdar://168005520
2026-02-10 09:43:07 +00:00
Adrian Prantl
a8392c24eb [LLDB] Add a missing nullptr check for ClangImporter
This is not a possible code path in the Swift compiler, but LLDB has error paths
where ClangImporter could be null, and it has (for testing mostly) a setting to
disable ClangImporter entirely. When importing a Module with a header dependency
this crashes LLDB.

rdar://170007373
2026-02-09 15:42:51 -08:00
John Hui
5bd319a59a [MemberLoading] Split storage and non-storage member loading
Doing so allows further granularity when lazily loading members.
2026-02-07 17:17:34 -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
Alexis Laferrière
395f1227d5 Merge pull request #86964 from xymus/deser-diag-member
Serialization: Raise a proper error on type members broken by invalid modularization
2026-02-05 16:33:27 -08:00
Alexis Laferrière
0ac40aada4 Serialization: Error on type members broken by invalid modularization
Extend support for proper errors on broken modularization to type
members, previously only top-level declarations were reported as error.
This change raises errors with relevant context if a type member is
referenced from a swiftmodule file but at reading the member is not
found or changed shape.

It doesn't report moves between modules like we do for top-level
declarations. This is less likely to happen at the member level as the
check is already applied at the top-level for the same reference. We may
still see such issues when using `SWIFT_NAME` to assign a top-level
declaration to a type from a different module.
2026-02-05 09:56:31 -08:00
Aidan Hall
fbb2da1526 Serialization: Add LifetimeDependenceInfo.isFromAnnotation to module format
The isFromAnnotation flag is set if and only if the lifetime originates from a
@lifetime or @_lifetime annotation in the source program.

isFromAnnotation==false means that the lifetime dependence checker would infer
the same lifetime if the Swift type or decl was printed without an annotation
for that dependency. More specifically, it means that the depenence was inferred
by the lifetime dependence checker.

Some dependencies on imported C/C++ decls are "inferred", but they either
correspond to explicit lifetime information in the source (smart pointers,
lifetimebound attribute) or are likely to differ from what the dependence
checker would infer. As such, we set the flag to true for all of them.
2026-02-05 14:50:04 +00:00
Kavon Farvardin
eb7fe3c8a3 Reparenting: initial functionality 2026-02-03 16:39:19 -08:00
Kavon Farvardin
4a7cedcf1e Reparenting: introduce new attributes
A protocol that's been reparented declares it
by writing `@reparented` in its inheirtance clause
for each new parent. You can introduce a `@reparented`
parent to a pre-existing ABI-stable protocol's
inheritance hierarchy.

Only protocols declared to be  `@reparentable` can be
used to reparent other protocols. Adding or removing
the `@reparentable` attribute is ABI-breaking, as it
effects the type metadata layout. Thus, reparentable
protocols must be born as such to use them with
protocols that are already ABI-stable.

This set of changes does not include the actual
implementation of ABI-stable reparenting.
2026-02-03 16:39:19 -08:00
Alejandro Alonso
fe298fa51c Merge pull request #86836 from Azoy/borrow-serialization
[Serialization] Fix serialization of init_borrow_addr instruction
2026-01-28 08:48:00 -08:00
Alejandro Alonso
6c754561a9 Fix serialization of init_borrow_addr 2026-01-27 16:20:49 -08:00
Alexis Laferrière
fce039e841 Merge pull request #86794 from xymus/enable-recovery-from-broken-modules-by-default
Serialization: Enable recovery from broken modularization by default
2026-01-27 15:24:39 -08:00
Alexis Laferrière
231f43f162 Serialization: Limit modularization recovery to clang modules 2026-01-26 09:57:00 -08:00
Alexis Laferrière
be0b7595fe Serialization: Enable recovery from types moving between modules by default 2026-01-26 09:56:30 -08:00
Joe Groff
0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08:00
elsa
5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Joe Groff
2f02c7cda3 SIL: Introduce instructions for forming and dereferencing Builtin.Borrow.
Since after address lowering, `Borrow` can remain loadable with a known-
layout address-only referent, we need instructions that handle three
forms:

- borrow and referent are both loadable values
- borrow is a value, but referent is address-only
- borrow and referent are both address-only
2026-01-23 08:02:01 -08:00
Joe Groff
bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Elsa Keirouz
27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Erik Eckstein
18063707b5 Optimizer: enable complete OSSA lifetimes throughout the pass pipeline
This new OSSA invariant simplifies many optimizations because they don't have to take care of the corner case of incomplete lifetimes in dead-end blocks.

The implementation basically consists of these changes:
* add the lifetime completion utility
* add a flag in SILFunction which tells optimization that they need to run the lifetime completion utility
* let all optimizations complete lifetimes if necessary
* enable the ownership verifier to check complete lifetimes
2026-01-22 17:41:48 +01:00
Erik Eckstein
0f0aa0c17b Optimizer: require that there are no unreachable blocks and infinite loops in OSSA
These two new invariants eliminate corner cases which caused bugs if optimization didn't handle them.
Also, it will significantly simplify lifetime completion.

The implementation basically consists of these changes:
* add a flag in SILFunction which tells optimization if they need to take care of infinite loops
* add a utility to break infinite loops
* let all optimizations remove unreachable blocks and break infinite loops if necessary
* add verification to check the new SIL invariants

The new `breakIfniniteLoops` utility breaks infinite loops in the control flow by inserting an "artificial" loop exit to a new dead-end block with an `unreachable`.
It inserts a `cond_br` with a `builtin "infinite_loop_true_condition"`:
```
bb0:
  br bb1
bb1:
  br bb1              // back-end branch
```
->
```
bb0:
  br bb1
bb1:
  %1 = builtin "infinite_loop_true_condition"() // always true, but the compiler doesn't know
  cond_br %1, bb2, bb3
bb2:                  // new back-end block
  br bb1
bb3:                  // new dead-end block
  unreachable
```
2026-01-22 17:41:23 +01:00
Meghana Gupta
0f4790ac7d Update serialization/deserialization for the new OpaqueReadOwnership kinds 2026-01-20 10:33:28 -08:00
Michael Gottesman
56d6b60c36 Merge pull request #86312 from gottesmm/rdar166081666
[rbi] Convert Sendable immutable weak var captures to weak let to fix RegionIsolation checking
2026-01-17 11:38:12 -08:00
Michael Gottesman
5d0f2e3d5e [sil] Add [inferred-immutable] flag to alloc_box instruction
Introduce a new optional flag on the alloc_box SIL instruction to mark boxes as
inferred immutable, indicating that static analysis has proven they are never
written to despite having a mutable type.

The flag is preserved through serialization/deserialization and properly printed/parsed in textual SIL format.

I am doing this to prepare for treating these boxes as being Sendable when they
contain a sendable weak reference.
2026-01-16 09:09:47 -08:00
Michael Gottesman
581cfcd7b6 [sil] Add @inferredImmutable flag to SILFunctionArgument for captured boxes
Introduce a new optional inferred-immutable flag on SILFunctionArgument to mark
closure-captured box parameters that are never written to despite being mutable.

This flag will enable in future commits:

- Marking captured mutable boxes as immutable when interprocedural analysis
  proves they are never modified
- Treating these captures as Sendable when they contain Sendable types
- Improving region-based isolation analysis for concurrent code

This complements the inferred-immutable flag on alloc_box by allowing
immutability information to flow through closure boundaries.
2026-01-16 08:22:21 -08:00
Gabor Horvath
6eb4d5b915 [cxx-interop] Fix crash deserializing some Clang function types
When a function type refers to a Swift declaration we get a crash during
deserialization. This patch prevents serializing the problematic clang
function types to avoid this crash.

rdar://166359524
2026-01-14 15:39:58 +00: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
Hamish Knight
7c36833439 Merge pull request #86311 from hamishknight/ext-fix
Avoid loading serialized extensions for nominals in SourceFile
2026-01-08 21:38:06 +00:00
Hamish Knight
777b4c3ca2 Merge pull request #86304 from hamishknight/at-request
[Serialization] Ensure semantic attributes are serialized
2026-01-08 04:14:44 +00:00
Hamish Knight
4e950e3591 Avoid loading serialized extensions for nominals in SourceFile
Looking up serialized extensions for a nested nominal type requires
computing its mangled name, which may kick semantic requests. Ensure
we don't do this for nominals in parsed SourceFiles such that we
don't end up kicking this during extension binding.
2026-01-06 15:34:33 +00:00
Hamish Knight
9cf65afc16 [Serialization] Ensure semantic attributes are serialized
Make sure we serialize `getSemanticAttrs` since for lazy type-checking
we may not yet have computed e.g actor isolation.

rdar://162100120
2026-01-05 23:33:42 +00:00
Tim Kientzle
8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Adrian Prantl
bacb12131f [Serialization] Return a nullptr instead of crashing
We got LLDB crash logs where `importer` is dereferenced. In the same crash log
the parent frame correctly checks for nullptr, so this would fix the immediate
crash. In LLDB it is not guaranteed that a ClangImporter is installed at all
times.
Ideally this function should be converted to return `llvm::Expected<ModuleDecl &>`.

rdar://166224928
2025-12-19 17:02:17 -08:00
Artem Chikin
828813c7e4 Merge pull request #85036 from artemcm/AddSupportForWarnAttr
Add support for a declaration attribute `@warn` for source-level warning group behavior control
2025-12-14 19:14:36 -08:00
Artem Chikin
e593fd97a0 Add parsing for a declaration attribute '@warn' for source-level warning group behavior control 2025-12-12 10:14:14 -08:00
Alexis Laferrière
175d0ba8e6 Serialization: Minor improvements to the error on conformance mismatch
Clarify the sources of information when a conformance reference in a
swiftmodule doesn't match with the requirements seen by the reader.
2025-12-10 15:08:03 -08:00
Hamish Knight
302e803b2f [AST] Store original lazy VarDecl for backing storage
Store the original VarDecl in the same map we use for tracking the
original wrapper var for property wrappers. This will allow us to
use the same logic to determine the original var for both.
2025-12-08 23:22:35 +00:00
Anthony Latsis
153dd02cd8 Merge pull request #85833 from swiftlang/jepa-main
[NFC] "SwiftVersion" → "LanguageMode" in `DiagnosticEngine::warnUntilSwiftVersion`, etc.
2025-12-05 09:34:30 +00:00
Anthony Latsis
88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Doug Gregor
e888395a26 Fix typo in deserialization error name 2025-12-02 12:12:52 -08:00
Doug Gregor
e624915ed9 [Custom availability] Serialize custom domains described on the command line
When a custom domain is described on the command line, there is no
backing declaration for it. Serialize such custom domains by
identifier and look them up globally at the point of deserialization.
When that fails, warn and drop the annotation.

This is all a stopgap until we have a way to spell custom availability
domains in the Swift language itself.
2025-12-02 12:12:50 -08:00
Michael Gottesman
29229a9410 [sil] Add basic SIL support for alloc_stack [non_nested].
This means I just added the flag and added support for
cloning/printing/serializing the bit on alloc_stack.
2025-11-21 11:21:14 -08:00