Commit Graph

48274 Commits

Author SHA1 Message Date
Aidan Hall
88b2c1c056 Merge pull request #86846 from aidan-hall/disable-lifetime-indices
LifetimeDependence: Disable parameter indices in Swift lifetime dependence annotations
2026-02-06 22:34:52 +00:00
Hamish Knight
2ddadb6a0c Merge pull request #87028 from hamishknight/privy
[Sema] SE-0502: Enable `ExcludePrivateFromMemberwiseInit` by default
2026-02-06 21:40:03 +00:00
Alastair Houghton
e38c0652b6 Merge pull request #84906 from al45tair/eng/PR-101623384
[Backtracing] Add initial support for Windows.
2026-02-06 14:53:16 +00:00
Hamish Knight
bc65846be2 [Sema] SE-0502: Enable ExcludePrivateFromMemberwiseInit by default
Enable the feature by default, and add an experimental feature
`DeprecateCompatMemberwiseInit` to control the deprecation behavior
which was deferred from the proposal.
2026-02-06 11:50:40 +00:00
Kavon Farvardin
ae77ba81e3 Merge pull request #87013 from kavon/revert-84789
Back out #84789 after additional testing
2026-02-06 02:58:00 -08:00
Aidan Hall
63da6499eb LifetimeDependence: Disable indices in Swift lifetime dependencies
Lifetime indices are never necessary in Swift, they unnecessarily expose
implementation details, and they make lifetime annotations more error-prone,
since they may need to be updated if a function's parameter list changes.

The Swift Syntax parser also cannot handle lifetime annotations where the target
is an index. The main reason the C++ parser supports them is because it is also
used for SIL.
2026-02-06 10:27:01 +00: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
Alastair Houghton
ceaba82d6d [Backtracing] Updates after review.
Tweaked the comment in `Runtime/Config.h`.

Fixed a couple of incorrect ARM64 instruction mnemonics.  This still needs
testing on ARM64 Windows.

Fixed an out-of-date comment in `swift-backtrace`.

Use a macro in `Backtrace.cpp` to guarantee we don't overrun the buffer,
and in the process simplify the code slightly.

rdar://101623384
2026-02-06 08:53:16 +00:00
Hiroshi Yamauchi
36be4d294e Remove Clang CASFS (#86973) 2026-02-05 19:32:08 -08: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
Slava Pestov
1b717b37d3 Merge pull request #86993 from slavapestov/move-code-around-in-solver
Sema: Move some code around
2026-02-05 16:16:20 -05:00
Kavon Farvardin
d5f9a1eeeb Revert "Merge pull request #84789 from nickolas-pohilets/mpokhylets/fix-82618"
This reverts commit b633bd37ac, reversing
changes made to b27bb64b03.
2026-02-05 11:34:59 -08:00
Artem Chikin
e168a84355 Merge pull request #86980 from jamieQ/fix-diag-control-bug
[Diagnostics]: restore unknown warning group behavior
2026-02-05 18:59:27 +00: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
a366c4765a [AST] Print function type LifetimeDependenceInfo using parameter labels
We fall back to indices when labels are not available, but labels are
preferable, because they readable, stable, and preferred by the lifetime
dependencies proposal.
2026-02-05 14:50:39 +00:00
Aidan Hall
7b9db38984 LifetimeDependence: Support function types
To a function type's lifetimes, a base version of the type is first created with
no lifetime dependence info. This is then passed to the dependence checker, and
the resulting dependencies are added to it.

It would be possible to do this analysis by passing just the parameter list and
result type (which are available before the type is created), but this approach
lets us avoid dealing with a header inclusion cycle between Types.h, ExtInfo.h,
and LifetimeDependence.h, since it does not require AnyFunctionType::Param to be
defined in LifetimeDependence.h.
2026-02-05 14:50:27 +00:00
Aidan Hall
e401b1a720 [AST] Support multiple of the same attribute per type 2026-02-05 14:50:21 +00:00
Aidan Hall
805d8e9e26 Add language feature ClosureLifetimes 2026-02-05 14:50:14 +00:00
Aidan Hall
b2c79211af Types: + AnyFunctionType::hasExplicitLifetimeDependencies 2026-02-05 14:50:14 +00: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
Slava Pestov
9036602aa1 Sema: Split off BindingProducer.h/.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov
78e9329184 Sema: Move OpenUnboundGenericType to CSGen.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov
b1e1cba094 Sema: Remove unused OverloadSetCounter 2026-02-05 09:19:01 -05:00
Slava Pestov
cfb6e2db30 Sema: Move InputMatcher from ConstraintSystem.h to CSRanking.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov
7cd06a5088 Sema: Split off TypeVariableType.h/.cpp 2026-02-05 09:19:01 -05:00
Michael Gottesman
f03a540e4f Merge pull request #86985 from gottesmm/pr-c993a1a690bdf75d09085e1ab2edbd7d264ea7af
[rbi] Fix logic around tracking of Sendable/non-Sendable field projections from Sendable/non-Sendable values
2026-02-04 14:21:58 -08:00
Ian Anderson
6f9919edc1 Merge pull request #86906 from ian-twilightcoder/firmware-os
[Triple] Support the new target triple "os" for firmware
2026-02-04 12:15:56 -08:00
Michael Gottesman
82fa88a855 [rbi] Fix logic around tracking of Sendable/non-Sendable field projections from Sendable/non-Sendable values
Previously, region-based isolation was not diagnosing cases where a non-Sendable
value projected from a Sendable base that was MainActor isolated. For example:

```swift
@MainActor
struct MainActorBox {
  var value: NonSendableKlass?

  mutating func take() -> sending NonSendableKlass {
    if let value {
      self.value = nil
      return value // Should warn: main actor-isolated value cannot be 'sending'
    } else {
      preconditionFailure("Consumed twice")
    }
  }
}
```

This was caused by two issues:

1. A logic bug in `AddressBaseComputingVisitor::visitAll` where we overwrote an
   already-found Sendable value when recursing. The visitor should only record
   the first Sendable value found, not subsequent ones. This caused us to
   incorrectly return the `@MainActor` `MainActorBox` as the base instead of
   emitting a require for the projected value.

2. struct_element_addr being transparent unconditionally causing us to not even
   emit a require at all.

This commit has two parts:

1. I fixed the first two issues by fixing the logic bug and by making
   struct_element_addr only transparent if its operand and result are
   non-Sendable. I added logic that we have used in other such cases to handle
   non-Sendable operand/Sendable result as well as Sendable operand and
   non-Sendable result. I then added the same support for tuple_element_addr and
   unchecked_take_enum_data_addr since they suffered from a similar problem.

2. Adding the logic to handle variants where the operand was non-Sendable and
   the result was Sendable, caused a bunch of tests to break so I had to fix
   that.

To fix the broken test cases, I had to make the compiler smarter about how it
was inserting this require. To do this:

1. I checked if the access base of the projection was actually immutable or if
   we are an alloc_stack that there was a prefix path in the projection path of
   immutable projections that end in the alloc_stack. In such a case, we know
   that we do not need to require that the operand is available in the current
   isolation domain since we will never write to that piece of memory and once
   we have loaded the result from memory, we know that the value is Sendable so
   nothing bad can happen.

2. If the access base of the projection was mutable, I used the same logic that
   we used for alloc_box that were non-Sendable that stored a Sendable thing by
   changing operand to be a `require [mutable_base_of_sending]` on the result of
   the projection instead of requiring the projection's operand. This ensures
   that we handled important flow sensitive cases.

rdar://169626088
2026-02-04 09:33:58 -08:00
Hamish Knight
746f011cd0 Merge pull request #77063 from jamieQ/jquadri/warn-weak-to-strong-capture
[Sema]: diagnose implicit strong captures of weak capture list entries
2026-02-04 14:55:58 +00:00
Jamie
94eab75e86 [Diagnostics]: restore unknown warning group behavior 2026-02-04 08:15:49 -06:00
Slava Pestov
437589d1b6 Merge pull request #86950 from slavapestov/remove-more-solver-hacks
Sema: Add flag to disable more solver performance hacks
2026-02-04 08:13:31 -05:00
Kavon Farvardin
1b70c2a3b3 Merge pull request #86736 from kavon/retro-refinement
Protocol Reparenting (part 1)
2026-02-04 03:14:00 -08:00
Meghana Gupta
27bd05b70b Merge pull request #86948 from meg-gupta/trivialresultconv
Fixes for borrow accessors
2026-02-04 01:15:37 -08:00
Slava Pestov
1b918ded02 Merge pull request #86163 from youngbash88/fix-54030
[Sema] Move anonymous closure argument check from parser to semantic analysis
2026-02-04 02:03:50 -05:00
Michael Gottesman
52a33beec0 Merge pull request #86946 from gottesmm/pr-fb033d6ec27597054d09c768a52a3a97dd3d81e0
[rbi] Use indirect assignment for stores to no-alias destinations to fix a common data race hole
2026-02-03 21:21:43 -08:00
Michael Gottesman
20630cd2fd Merge pull request #86966 from gottesmm/pr-b19b102e8bb8a370516f94d39651a12bebfc635c
Refactor AddressWalker to use OperandWorklist instead of rolling its own OperandWorklist.
2026-02-03 21:15:35 -08:00
Kavon Farvardin
006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00
Kavon Farvardin
ed65f8bb55 Mangling: support Self in associated conformance descriptor
For reparenting, we rely on a default associated conformance witness accessor
to build the witness table for 'Self: NewParent' at runtime. This means that
when mangling the symbol for such a descriptor, we need support for there
being no associated type at all; it's just tau_0_0 aka Self as the subject.

This patch extends _default_ associated conformance witness accessor mangling
to support a GenericTypeParamType for the subject, as the non-default accessors
already quietly did have support; see `mangleAssociatedConformanceDescriptor`.
It was quiet in the sense that there was no demangling support for it, nor
documentation about it either. So I've brought both kinds of witness accessor
manglings up-to-par, without extending the `assoc-type-name` grammar itself.
2026-02-03 16:39:19 -08: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
Doug Gregor
c88519a83b Reject @isolated(any) when we don't have the concurrency library
IRGen crashes on @isolated(any) functions if the Actor protocol isn't
available. It's safer to reject in the type checker in these cases.

Fixes rdar://165090740.
2026-02-03 16:14:38 -08:00
Jamie
f9e41569f1 [Sema]: diagnose implicit strong captures of weak capture list items
Add a diagnostic for when a weak or unowned capture list item binds a
referent that is implicitly strongly captured in an outer escaping
closure.
2026-02-03 16:21:20 -06:00
Slava Pestov
9623b85b7b Parse: Remove last remnants of 'operator designated types' 2026-02-03 16:34:10 -05:00
Slava Pestov
2e60d29973 Sema: Add -solver-{disable,enable}-performance-hacks flags 2026-02-03 16:34:10 -05:00
Slava Pestov
061958f970 Sema: Eagerly filter out protocol extension operators
This optimizes for the case where we have a disjunction that contains an
operator defined in a protocol, and a protocol defined in a protocol
extension, and furthermore, the protocol extension operator's type is a
refinement of the protocol requirement operator's type.

In this case, there are three possibilities:

- Either the operator requirement is witnessed by a concrete operator
  in the conforming type, in which case the solution involving the
  protocol extension operator is going to be worse, so we can skip this
  choice.

- Otherwise, the protocol requirement operator is witnessed by the same
  protocol extension operator that we skipped, in which case we will find
  the same solution if we just pick the protocol requirement operator
  anyway.

- The only other possibility is that the protocol requirement operator
  is witnessed by a protocol extension operator, but also, a more
  refined protocol extension operator exists. However, it appears that in
  this case, solution ranking _also_ picks the solution involving the
  protocol requirement operator, as the new test case demonstrates.

Thus, we gain nothing by considering these protocol extension operators.
Skip them when forming the disjunction.
2026-02-03 16:34:09 -05:00
Ian Anderson
69fa949c01 [Triple] Support the new target triple "os" for firmware
Add support for the new Firmware llvm::Triple::OSType, and make a swift::DarwinPlatformKind to go with it.

rdar://165361368
2026-02-03 13:02:44 -08:00
Michael Gottesman
d04cdeba56 Refactor AddressWalker to use OperandWorklist instead of rolling its own OperandWorklist.
Just saw this as I working in the area.
2026-02-03 12:03:39 -08:00
Alastair Houghton
3463b1e145 [Backtracing] Disable backtracing for 32-bit Windows.
Right now, the backtracer won't work on 32-bit Windows because we
aren't properly dealing with the `stdcall` calling convention on
the Win32 API calls.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
d13988bd5f [Backtracing][Windows] Initial Windows support.
This doesn't have a working symbolicator yet, but it does build and
it can obtain a basic backtrace.

It also doesn't include a working `swift-backtrace` program yet.

rdar://101623384
2026-02-03 18:23:29 +00:00
Michael Gottesman
192344076f [rbi] Use translateSILAssignIndirect for stores to no-alias destinations
For stores to unaliased, non-aggregate-projected destinations, switch from
translateSILAssignDirect(destValue, src) to translateSILAssignIndirect(dest, src).
This passes the Operand* rather than just the SILValue, enabling proper tracking
of the destination address in region analysis.

First in a series migrating instruction handlers to indirect assignment.

NOTE: I originally thought that pack_element_set would also have this property,
but alloc_pack today is always assumed to be to be MayAlias and thus we emit a
merge. I think this is fine since one can never actually assign over a pack
variable like one can other things (that is I think they are generally just used
for marshalling and the like). If I am wrong, I can just fix it later.

rdar://156024613
https://github.com/swiftlang/swift/issues/83121
2026-02-03 09:00:27 -08:00