Commit Graph

2783 Commits

Author SHA1 Message Date
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
Kavon Farvardin c19889c6e7 Merge pull request #88976 from kavon/preinverse-generics-except-176395527
introduce @_preInverseGenerics(except:)
2026-05-15 04:43:33 -07:00
Aidan Hall 5149dbcd29 Lifetimes: Infer copy dependence kind on @noescape closures (#88879)
Follow-up to https://github.com/swiftlang/swift/pull/88733,
enabling the example in rdar://172511809 ([nonescapable] Allow a
nonescaping function to be a lifetime dependency source):

```swift
@_lifetime(body) // Inferred dependence kind: copy
func foo(body: () -> Span<Int>) { body() }
```

or

```swift
// Inferred: @_lifetime(copy body)
func foo(body: () -> Span<Int>) { body() }
```

Follow-up: Consider also disallowing borrow dependence on `@noescape`
closures.
<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

---------

Co-authored-by: Andrew Trick <atrick@apple.com>
2026-05-15 11:34:36 +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
Slava Pestov a2ed8c66c2 Merge pull request #88875 from slavapestov/fix-rdar152143989
Sema: Don't record bogus trail changes in salvage()
2026-05-08 15:37:53 -04:00
Slava Pestov 6db1fd00e9 Sema: Don't record bogus trail changes in salvage()
In salvage(), there is a point where we're done solving, but we haven't
yet torn down ConstraintSystem::solverState, so the trail is still
active.

It was possible to cause a change to be recorded, because of the
path compression we do in TypeVariableType::getRepresentative().

We have a similar situation where we don't want to do path compression
when we're looking up a type variable's representative in the middle
of undo(). Generalize the existing UndoActive flag to Closed, and set
it after solving in salvage() as well.

While we're here, clean up an existing place where we would check
isUndoActive() to not do that anymore, so now getRepresentative() is
the only place that checks the state of the trail.

A better cleanup would be to try to refactor or eliminate SolverState
entirely, but this fix is pretty clean.

Note that the test cases are somewhat random because the exact scenario
is hard to trigger; you need to set up an invalid expression where the
type variables are set up in just the right way so that path compression
kicks in.

- Fixes rdar://152143989.
- Fixes https://github.com/swiftlang/swift/issues/81801.
- Fixes https://github.com/swiftlang/swift/issues/84884.
2026-05-06 11:51:40 -04:00
Aidan Hall 6b80cf8b9d Merge pull request #88733 from aidan-hall/lifedep-closure-source
Make non-`@escaping` function types ~Escapable
2026-05-06 14:34:25 +01:00
Erik Eckstein 121c867c24 Sema: reword a confusing error message about @inline(always)
The old error message "cannot use '@inline(always)' together with '@usableFromInline'" does not tell the reason.
The new message "'@inline(always)' implies '@usableFromInline'; do not use both" makes this clear.

Also, remove an unused error message.

rdar://176028537
2026-05-04 19:07:24 +02:00
Pavel Yaskevich 4201e579be Merge pull request #88162 from CognitiveDisson/feat/scope-based-expression-type-checking-warnings
[Sema] Add scope-based analogues of -warn-long-expression-type-checking
2026-05-04 06:35:35 -07:00
Guillaume Lessard 2861d9e097 Merge pull request #88640 from glessard/rdar139816157-FullyInhabited-protocols 2026-05-01 10:07:53 -07:00
Aidan Hall c9940ba341 Lifetimes: ~Escapable function type tests 2026-04-30 16:30:46 +01:00
Aidan Hall fb2aa63295 Merge pull request #87217 from aidan-hall/lifedep-infer-closure-dependence
LifetimeDependence closure context dependence
2026-04-27 16:23:04 +01:00
Allan Shortlidge c0b5e6c7b8 AST: Add a NoUsage diagnostic group.
Adds every diagnostic in the legacy `no-usage` diagnostic category to a new
diagnostic group called NoUsage so that the diagnostics can participate in
diagnostic control mechanisms like `-Werror`.

Resolves rdar://160488389.
2026-04-24 16:56:48 -07:00
Aidan Hall eac68b5283 LifetimeDependence: Closure lifetimes tests 2026-04-24 16:14:25 +01:00
Guillaume Lessard c2c946af60 [test] parsing and errors for Convertible{To,From}Bytes 2026-04-24 05:11:24 -07:00
Allan Shortlidge 622a68601b AST: Add the InconsistentImportAccess diagnostic group. 2026-04-23 13:06:19 -07:00
Allan Shortlidge f9cbe0293c AST: Add the UnusedImportAccess diagnostic group.
Resolves rdar://147656067.
2026-04-23 13:05:57 -07:00
Allan Shortlidge 74b8a7fdd9 AST: Add the PackageModuleLoadedFromSDK diagnostic group.
Resolves rdar://175381846.
2026-04-23 12:46:34 -07:00
CognitiveDisson 575e69f90e [Sema] Add scope-based analogues of -warn-long-expression-type-checking 2026-04-23 10:46:03 +01:00
Pavel Yaskevich ae0c69face Merge pull request #88179 from broken-circle/feature/tuple-diagnostic
[Diagnostics] Coalesce large homogeneous tuples in diagnostics
2026-04-22 22:01:13 -07:00
Aviva f2c5bbc0af Merge pull request #88194 from a-viv-a/unavailable-conformance
[Sema] Diagnose retroactive conformance for unavailable conformance
2026-04-21 15:36:41 -07:00
Sam Pyankov 120c084079 Merge pull request #88341 from sepy97/IPIVerification
Sema: Enforce IPI library level for Swift modules
2026-04-15 15:16:03 -07:00
Saleem Abdulrasool 2b8ee6e5a2 test: disallow llvm-bcanalyzer and use new macro
This ensures that we use the correct llvm-bcanalyzer from the just built
compiler tools.
2026-04-13 16:22:02 -07:00
Sam Pyankov c6af01a5bc Sema: Enforce IPI library level for Swift modules
Diagnose public imports of IPI (non-distributable) modules from
API/SPI modules. Hidden imports (@_implementationOnly, internal,
package) and imports from other IPI/Other modules are allowed.

rdar://174257067
2026-04-10 13:11:33 -07:00
Aviva Ruben 14c1a98dfc [Sema] Tailor retroactive conformance diagnostic for unavailable conformances 2026-04-08 11:44:30 -07:00
Kathy Gray 0a82ff3446 Merge pull request #88032 from kathygray-pl/MissingPropertyRevert
[diagnostics] Partial reversion of member lookup impact
2026-04-08 19:15:53 +01:00
Alexis Laferrière 8d5d16a9f3 Merge branch 'main' into exportability-embedded-class-properties 2026-04-07 08:36:09 -07:00
Kathy Gray dca1ca55f6 [diagnostics] Partial reversion of member lookup impact
Changing the impact of member lookup diagnostic conflicted mismatched arguments
Reverting to avoid that ambiguity.
2026-04-07 11:39:34 +01:00
Erik Eckstein df8d87ee92 AST: add ProtocolDecl.isEligibleForFastCasting
This is true if this protocol is marked for fast casting, i.e. fast conformance lookup via the vtable of a conforming class.
Currently this is done with `@_semantics("fast_cast")`. However, in future we want to add a "real" attribute for this.
2026-04-03 07:49:34 +02:00
broken-circle ebc82848a6 Change compact tuple diagnostic message
Use a diagnostic message that cannot be mistaken for actual syntax.
2026-04-01 08:31:40 -07:00
broken-circle 0d42e6d62e [Diagnostics] Coalesce large homogeneous tuples in diagnostics
Homogeneous unlabeled tuples with many elements produce unwieldy type
names in diagnostics (e.g. C fixed-size arrays). Print them in compact
`(N of T)` form when there are 5+ elements, mirroring the style used
in `TypePrinter.visitInlineArrayType()` and SE-0483.

Add `PrintOptions.PrintHomogeneousTuplesCompactly`, enabled only in
diagnostic print paths. Type equality uses pointer comparison to avoid
coalescing differently-sugared types.
2026-03-29 16:34:12 -07:00
Meghana Gupta 3d3d476b6f Merge pull request #88107 from meg-gupta/enableborrow
Enable BorrowAndMutateAccessors by default
2026-03-27 12:43:02 -07:00
Meghana Gupta d6e220669f Enable BorrowAndMutateAccessors by default 2026-03-25 16:52:39 -07:00
CognitiveDisson 9bc81973e4 [Sema] Fix -debug-time-expression-type-checking producing no output 2026-03-25 18:28:50 +00:00
Allan Shortlidge 9a25399f81 Make StrictAccessControl an experimental feature.
It was originally introduced as an upcoming feature, but there isn't any
precedent for using upcoming features as a way to opt-in to type checking fixes
without an associated Swift Evolution proposal. Rather than using a "feature" to
control this behavior, it would probably be better to offer a way to use
`-Werror` to upgrade these warnings to errors.
2026-03-24 17:59:40 -07:00
Alexis Laferrière dd798e0079 Embedded: Accept and enforce @_implementationOnly class properties
When hiding dependencies in embedded mode there are special rules for
classes. Classes properties can safely reference the hidden
dependencies, however code referencing these properties must be marked
`@export(interface)`.

We previously added a check to report implicit code without the requited
`@export(interface)`. However explicit references from user written code
wasn't fully checked, only explicit references to the imported type or
the type's services would be reported, not references to the property
itself.

We patch that hole here by introducing new requirements and a new layer
of check specific to class properies in embedded mode.

---

Class properties referencing a hidden dependency must be marked
`@_implementationOnly`. This adds on top of the requirement for the
class itself to have an explicit `@export(interface) deinit`.

This allows to report references from user written code using existing
diagnostics.
2026-03-24 13:18:23 -07:00
Alexis Laferrière 88241abcc7 Merge pull request #87992 from xymus/exportability-embedded-init
Embedded: Check exportability of default inits and arguments in embedded mode
2026-03-24 10:03:22 -07:00
Aidan Hall c4d32f901d Merge pull request #87281 from aidan-hall/lifedep-protocol-check
Require compatible lifetimes in protocol conformance checking and function type matching
2026-03-24 14:16:56 +00:00
Alexis Laferrière 516677aa77 Embedded: Consider default arguments as implicitly inlinable
Check the code of default arguments for references to restricted
dependencies in embedded mode.
2026-03-23 10:49:17 -07:00
Alexis Laferrière 0b4827c775 Embedded: Check exportability of implicit inits in classes
Without library-evolution we can be more permissive about references to
hidden dependencies from classes properties. However, lifting these
checks broke other checks on properties. Here we fix this hole and
ensure that while we allow references from stored properties we still
checking implicit initializers.

rdar://173011223
2026-03-23 10:49:17 -07:00
Pavel Yaskevich f59eb04ac9 Merge pull request #87974 from xedin/rdar-119695934
[Frontend] SE-0518: Turn `TildeSendable` into a language feature
2026-03-23 09:32:25 -07:00
Xi Ge c42e274a70 [Sema] Allow @_originallyDefinedIn with unavailable platforms
@_spi_available is rewritten to @available(platform, unavailable) in public swiftinterfaces, causing the @_originallyDefinedIn validity check to spuriously fire for missing introductory OS versions. We should accept explicit unconditional unavailability as sufficient availability annotation.

rdar://172856603
2026-03-20 14:34:58 -07:00
Pavel Yaskevich de8b2fb22c [Frontend] SE-0518: Turn TildeSendable into a language feature
The proposal has been accepted and `~Sendable` doesn't require
an explicitly enabled experimental flag.
2026-03-20 10:27:12 -07:00
Alexis Laferrière a97152468e Merge pull request #87582 from xymus/exportability-embedded-deinit
Embedded:  Require a deinit in classes with properties referencing a hidden dependency
2026-03-20 10:04:12 -07:00
Aidan Hall 11429fc6ba LifetimeDependence: Lifetime subtyping tests
- Function type matching
- Protocol conformance
2026-03-20 14:42:15 +00:00
Slava Pestov ca72d2d276 Sema: Remove unused TypeOperation cases 2026-03-17 13:41:19 -04:00
Alexis Laferrière 569ec1c06f Sema: Custom note with fixit for required init in classes 2026-03-12 09:59:59 -07:00
Alexis Laferrière 7c1b4802c8 Sema: Require classes to have a deinit for references non Embedded
Even without library-evolution, we allow references to hidden
dependencies from class properties as long as the class is not marked
open. In embedded, references from functions are only accepted when
marked `@export(interface)` as it can't be inlined in clients.

Combine both requirements to protect the implicitly generated destructor
as well. Add a requirement for classes with such a property to
explicitly declare a `@export(interface)` deinit. Otherwise that deinit
may be inlined in clients and cause a deserialization failure.

rdar://170855491
2026-03-12 09:59:59 -07:00
Alexis Laferrière 74f82aadba Sema: Custom text for error on references to IOI from open classes in NLE 2026-03-12 09:59:59 -07:00
elsa 70e82cf6f6 Merge pull request #87716 from elsakeirouz/add-borrowing-for-loop-tests
Fix BorrowingSequence availability check and add BorrowingForLoop tests
2026-03-11 12:41:46 +00:00