Commit Graph

2682 Commits

Author SHA1 Message Date
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
6aa55785f0 LifetimeDependence: Tests for function type attribute
Includes:
- rdar://166912068 test case
- Nested type SIL tests
- rdar://160894371 test
- Many more
2026-02-05 14:50:44 +00: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
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
Andrew Trick
d07f031929 Updates tests for lifetime diagnostic:
error: cannot copy the lifetime of an Escapable type
    note: use '@_lifetime(borrow arg)' instead
2026-01-30 11:07:37 -08:00
Meghana Gupta
a210ab1050 [NFC] Add borrow accessor test with lazy 2026-01-29 15:45:17 -08:00
Meghana Gupta
3520123564 [NFC] Add borrow/mutate accessor test with observers 2026-01-29 15:45:17 -08:00
Meghana Gupta
4e0098583d Update for borrow/mutate accessors with ownership modifiers 2026-01-29 15:45:16 -08:00
Erik Eckstein
9d0b6c8417 RedundantLoadElimination: fix a complexity problem when replacing a huge amount of loads with a common value
As RedundantLoadElimination processing the loads in reverse control flow order, the replaced loads might accumulate quite a lot of users.
This happens if the are many loads from the same location in a row.
To void quadratic complexity in `uses.replaceAll`, we swap both load instructions and move the uses from the `existingLoad` (which usually has a small number of uses) to this load - and delete the `existingLoad`.

This came up in the Sema/large_int_array.swift.gyb test, which tests a 64k large Int array.
With this fix, the compile time gets down from 3 minutes to 5 seconds.
I also changed the test:
* run the compiler with the timeout script to detect build time regressions
* re-enabled the SIL verifier because the problem there is already fixed (https://github.com/swiftlang/swift/pull/86781)
* run the compiler with -O to also test the whole optimizer pipeline and not only the mandatory pipeline
* assigned the array to a real variable (instead of `_`) to not let the optimizer remove the whole array too early
* run the compiler with and without `-parse-as-library` because this makes a huge difference how the global array is being generated
2026-01-28 17:54:37 +01: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
Alexis Laferrière
c8f99af698 Merge pull request #86335 from xymus/exportability-nle-warn
Sema: Enable exportability checks in non-library-evolution mode as warnings by default
2026-01-22 09:47:52 -08:00
Alexis Laferrière
974e61d45a Sema: Loosen exportability checking for non-publicly imported types
This one is specific. Allow extensions to define public members to
package types implicitly exporting their memory layout when imported
non-publicly.

Enabling exportability checks for non-library-evolution by default as a
warning triggered marking such types as implicitly exported to clients.
This in turn enabled erroring on the extensions in clients when imported
non-publicly. This error would be source breaking and shouldn't be
required in such a context. We may even consider lifting this
restriction entierly, even for public types imported non-public.
2026-01-21 11:30:36 -08:00
Alexis Laferrière
8ab9047cbf Sema: Downgrade more exportability diags to warning by default
Centralize the logic downgrading diagnostics to warning for newly
introduced exportability checks along with the one silencing the errors.
Update client sites to the new API and to uniformly apply the downgrade
to warning behavior.

Diagnostics about typealiases and conformances are now properly
downgraded to warnings if not opt-in.
2026-01-20 13:55:11 -08:00
Meghana Gupta
319aeec985 [NFC] Update borrow/mutate requirement test with yielding borrow and yielding mutate 2026-01-20 11:44:12 -08:00
Meghana Gupta
0195dbb760 Rename checkWitnessForRequirement to checkWitnessAccessor and move some more accessor checking there 2026-01-20 11:44:11 -08:00
Meghana Gupta
a3261aa31d Add diagnostic when conforming a borrow/mutate requirement without a stored property or borrow/mutate accessor 2026-01-20 11:44:10 -08: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
Alexis Laferrière
5cc4c788aa Sema: Update warning on @_implementationOnly import
Invite users of `@_implementationsOnly` imports from modules without
library-evolution to adopt `CheckImplementationOnly`. Use the existing warning
on the import statement. Adopting that feature reports unsafe references to
implementation-only imported types as errors and silences the warning on
the import.
2026-01-06 15:12:47 -08:00
Alexis Laferrière
2c59e8c659 Sema: Check exportability in non-library-evolution as warnings by default
Always enable checking for references to `@_implementationOnly` imports
even without library-evolution enabled but downgrade errors to warnings
by default. Clients should enable them as errors by adopting
`CheckImplementationOnly`.
2026-01-06 15:11:50 -08:00
Hamish Knight
5d7ece7b7f [test] Move extension_binding_multi.swift 2026-01-06 15:34:00 +00:00
Tim Kientzle
104dba920b [SE-0474] Implement yielding borrow and yielding mutate syntax
This does not rename all the internal variables, functions, and types
whose names were based on the old syntax.

I think it adds new syntax support everywhere it's needed while
retaining enough of the old syntax support that early adopters will
see nice deprecation messages guiding them to the new syntax.
2026-01-03 15:07:10 -08:00
Alexis Laferrière
7924c73f20 Merge pull request #86154 from xymus/exportability-nle-more
Sema: Extend exportability checking for non-library-evolution to more reasons
2025-12-22 13:58:44 -08:00
Alexis Laferrière
cd253e7748 Sema: Add diagnostics specific to enum associated values 2025-12-19 15:13:25 -08:00
Alexis Laferrière
8b55b25b34 Sema: Add diagnostic for implicitly public inheritance 2025-12-19 15:13:25 -08:00
Alexis Laferrière
80149d627a Sema: Always allow on @_implementationOnly on types 2025-12-19 11:26:06 -08:00
Meghana Gupta
5c4ce2f942 Merge pull request #86023 from meg-gupta/miscborrowfixes
Minor fixes to borrow accessors
2025-12-16 20:03:19 -08:00
Andrew Trick
edfe1a1e47 Merge pull request #85998 from atrick/lifedep-sametype
[lifetimes] add same-type default lifetime inference
2025-12-16 11:01:09 -08:00
Slava Pestov
ea587322dc Sema: New StrictAccessControl upcoming feature
Some access control holes were unconditionally downgraded to warnings, and
others were conditional on Swift 6 language mode. Let's hang them off an
upcoming feature instead.
2025-12-15 18:02:52 -05:00
Andrew Trick
6aaf9034ae [lifetimes] add same-type default lifetime inference
Infer @lifetime(result: copy arg) for every (result: R, arg: A) pair
such that R == A and 'arg' is not 'inout'.
2025-12-12 21:21:09 -08:00
Meghana Gupta
20b23d631c Diagnose borrow/mutate accessors in enums
We don't have support for borrowing switch on Copyable types.
It is supported for ~Copyable types, but the return expression emission for borrow accessors is not yet implemented.
Diagnose instead of crashing the compiler.
2025-12-12 11:38:37 -08:00
Kathy Gray
472937e57d Merge pull request #85591 from kathygray-pl/kathy/diagnosticProperty
[Diagnostics] Increase possibility for missed property diagnostic
2025-12-12 16:09:12 +00:00
Chris Williams
fe0191c62c [CSSimplify] Parameter pack wrapping logic incorrectly considers tuple LValueTypes to not be tuples (#85962)
In #65125 (and beyond) `matchTypes`, has logic to attempt to wrap an
incoming parameter in a tuple under certain conditions that might help
with type expansion.

In the case the incoming type was backed by a `var`, it would be wrapped
by an `LValueType` then be subsequently mis-diagnosed as not-a-tuple.

More details in #85924 , this this is also the cause of (and fix for)
#85837 as well...
2025-12-11 22:29:42 -08:00
Ben Cohen
9dd9e96e1d Allow Hashable: ~Copyable (#85748)
Builds on #85746 which covers Equatable.
2025-12-11 14:47:36 -08:00
Kathy Gray
fde49b8847 Diagnostics : Increase possibility for missed property diagnostic
Impact for an unknown property access was frequently higher than other options
on ambiguous selections, by 3 to 5 points, causing fix selections that were
farther away and frequently noted to be in accurate. This commit lowers the
impact to be in a similar range to other fixes and this causes property accesses
to be selected more proprotionaly.

In the existing test suite, this changed the diagnostic only in the case of
protocol composition, which was also discovered to be a flawed binding lookup.

Tests added for the property lookup, tests updated for protocol composition
(Including correcting a likely error in a test specification)
2025-12-11 16:08:22 +00:00
Alexis Laferrière
85d522e4c2 Merge pull request #85917 from xymus/exportability-nle-classes
Sema: Allow non-open class properties to reference hidden dependencies in non-library-evolution mode
2025-12-09 13:36:01 -08:00
Alexis Laferrière
1fd44e67a2 Sema: Allow refs to hidden dependencies in prorperties of non-open classes
We now report properties referencing types imported from
implementation-only dependencies in non-library-evolution mode as the
memory layouts of structs and enums may be exposed to clients. Here we
exempt non-open classes from this check as clients hold pointers to
classes which hides the class internal memory layouts. Keep forbidding
it for open classes in order to error early, a client trying to subclass
an open class with such a reference from their property would already
see an error about members not deserializable.
2025-12-08 16:39:16 -08:00
Pavel Yaskevich
df3aa1e011 Merge pull request #85879 from xedin/add-supression-note-to-explicit-sendable-warning
[Diagnostics] TildeSendable: Suggest `Sendable` suppression in explic…
2025-12-08 13:29:25 -08:00
Alexis Laferrière
de9148e6f1 Merge pull request #85868 from xymus/exportability-nle-split
Sema: Distinguish implicitly visible memory layouts from the typical `@frozen` ones
2025-12-08 13:29:16 -08:00
Pavel Yaskevich
f0fd506745 [Diagnostics] TildeSendable: Suggest Sendable suppression in explicit Senable warning
Add a note to missing explicit `Sendable` conformance warning
(produced by `-Wwarning ExplicitSendable`) and a fix-it with
a suggestion to suppress `Senable` conformance  via `~Sendable`.
2025-12-05 17:20:55 -08:00
Alexis Laferrière
e3571eb833 Sema: Allow SPI references from implicitly public layouts 2025-12-05 17:13:52 -08:00
Alexis Laferrière
8e04430498 Sema: Differentiate the reason for implictly public memory layouts 2025-12-05 09:25:37 -08:00
Alexis Laferrière
627b8f9915 Sema: Test @frozen struct in hidden-memory-layout.swift 2025-12-04 14:12:31 -08:00
Pavel Yaskevich
a724f4c7d3 Merge pull request #85828 from xedin/tilde-sendable-with-inheritance-and-isolation
[Concurrency] TildeSendable: Fix handling of isolated types and inherited conformances
2025-12-04 09:26:40 -08:00
Pavel Yaskevich
42f6455055 [Concurrency] TildeSendable: Disallow Sendable suppression on actor declarations 2025-12-03 16:40:31 -08:00
Pavel Yaskevich
84d775e098 [Concurrency] TildeSendable: Account for inherited conformances
This helps to properly detect and account for derived conformances
to `Sendable` protocol that come from parent classes.
2025-12-03 16:40:31 -08:00
Pavel Yaskevich
d8860bc349 [Concurrency] TildeSendable: Lift the check up to cover isolated types
If a type is suppressing `~Sendable` global-actor isolation shouldn't
make it `Sendable` and the compiler should diagnose cases were `Sendable`
comes from an isolated protocol.
2025-12-03 16:40:00 -08:00
Ben Cohen
fbb420f38d Allow Equatable: ~Copyable (#85746)
Under review
[here](https://forums.swift.org/t/se-0499-support-copyable-escapable-in-simple-standard-library-protocols/83297).
Multi-part version of #85079.
2025-12-03 05:45:38 -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
Henrik G. Olsson
2211824798 Merge pull request #85468 from hnrklssn/revert-dedup-clang-module-imports
Revert "Sema: Prefer the submodule import for access-levels diagnostics"
2025-11-20 10:22:45 -08:00