Commit Graph

28404 Commits

Author SHA1 Message Date
Michael Gottesman
9d59dbed17 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
2025-05-05 13:39:03 -07:00
Doug Gregor
1b5c9368a0 Make ConformanceIsolationRequest cache per-ProtocolConformance
This request was looking through to the root conformance, which could
mess with the caching bits. Sink the "is nonisolated conformance" bit
down into ProtocolConformance, and have the request for a non-root
conformance be defined in terms of the request for the root
conformance.
2025-05-05 11:08:55 -07:00
Doug Gregor
2e34549236 [SE-0470] Prohibit inference of isolated conformances with nonisolated witnesses
If all of the witnesses to a conformance are nonisolated, then infer that
conformance as nonisolated rather than global-actor-isolated. This is
only relevant when InferIsolatedConformances is enabled, and prevents
that inference to help maintain source compatibility.
2025-05-05 11:08:52 -07:00
Ludwig Hollmann
39aa950660 Update file header comments for headers in lib. 2025-05-04 22:26:26 +02:00
Pavel Yaskevich
ff790c6d01 Merge pull request #81176 from xedin/pre-enum-extensibility
[AST/Sema] Add `@preEnumExtensibility` attribute to downgrade warning…
2025-05-02 22:04:04 -07:00
Doug Gregor
c249357f16 Merge pull request #81249 from DougGregor/observation-nonisolated-conformances
[Observation] Create nonisolated conformances to Observable
2025-05-02 12:56:27 -07:00
Holly Borla
20e4413193 Merge pull request #80812 from jamieQ/invalid-isolated-any-conversion
[Sema]: ban @isolated(any) conversions to synchronous function types
2025-05-02 12:21:20 -07:00
Pavel Yaskevich
498430afaf [AST/Sema] Add @preEnumExtensibility attribute to downgrade warnings for extensible enums
Just like `@preconcurrency` for concurrency, this attribute is going
to allow exhaustiveness error downgrades for enums that were retroactively
marked as `@extensible`.
2025-05-02 09:07:22 -07:00
Doug Gregor
fed18d58dc [Observation] Create nonisolated conformances to Observable
This is needed to make default-main-actor mode work well with
Observable. Fixes rdar://150419628.
2025-05-01 22:01:41 -07:00
Pavel Yaskevich
11cf263347 Merge pull request #81231 from xedin/rdar-150397825
[Concurrency] Account for explicit `@concurrent` on closures
2025-05-01 09:03:23 -07:00
Pavel Yaskevich
31ff9b4335 Merge pull request #81219 from xedin/nonisolated-nonsending-inference-for-storage
[Concurrency] Allow `nonisolated(nonsending)` inference on properties…
2025-05-01 09:03:06 -07:00
Jamie
629e208970 [Sema]: ban @isolated(any) conversions to synchronous function types
per SE-0431, function conversions from an @isolated(any) function to a synchronous,
non-@isolated(any) function type should not be allowed. this adds a warning during
type checking to enforce this, which will be an error in a future major
language mode.
2025-05-01 07:19:03 -05:00
John Hui
c2f904caa4 Merge pull request #81188 from j-hui/fix-recursive-inheritance
[cxx-interop] Avoid unchecked recursion when importing C++ classes with circular inheritance
2025-05-01 02:00:46 -07:00
Pavel Yaskevich
ef65f26457 [Concurrency] Account for explicit @concurrent on closures
If closure is stated as `@concurrent` is has to be treated as
nonisolated.

Resolves: rdar://150397825
2025-04-30 20:25:32 -07:00
Slava Pestov
f5087c4944 Merge pull request #81202 from slavapestov/lookup-conformance-fn
AST: Change signature of LookupConformanceFn
2025-04-30 22:00:38 -04:00
Pavel Yaskevich
8a9bbd5114 [Concurrency] Allow nonisolated(nonsending) inference on properties with async getters
When `NonisolatedNonsendingByDefault` is enabled it should infer
`nonisolated(nonsending)` for both async functions and storage as
specified by the proposal.
2025-04-30 15:19:56 -07:00
John Hui
1f2107f357 [cxx-interop] Avoid unchecked recursion when importing C++ classes with circular inheritance
It is possible for a C++ class template to inherit from a specialization
of itself. Normally, these are imported to Swift as separate (unrelated)
types, but when symbolic import is enabled, unspecialized templates are
imported in place of their specializations, leading to circularly
inheriting classes to seemingly inherit from themselves.

This patch adds a check to guard against the most common case of
circular inheritance, when a class template directly inherits from
itself. This pattern appears in a recent version of libc++,
necessitating this patch. However, the solution here is imperfect as it
does not handle more complex/contrived circular inheritance patterns.

This patch also adds a test case exercising this pattern. The
-index-store-path flag causes swift-frontend to index the C++ module
with symbolic import enabled, without the fix in this patch, that test
triggers an assertion failure due to the circular reference (and can
infinitely recurse in the StorageVisitor when assertions are disabled).

rdar://148026461
2025-04-30 13:33:33 -07:00
Michael Gottesman
6e33329da5 Merge pull request #81193 from gottesmm/pr-5722431d23d74cb6adc74e1305c2b9e8b8d5159d
[concurrency] Fix an off by one error in generic handling in local capture checking code.
2025-04-30 13:05:11 -07:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Slava Pestov
2746a83109 Merge pull request #81181 from slavapestov/fix-issue-79763
AST: Fix existential erasure of long member types
2025-04-30 13:33:56 -04:00
Michael Gottesman
fb3c710212 [concurrency] Fix an off by one error in generic handling in local capture checking code.
Otherwise, we break memory safety by accessing a generic parameter that does not
exist resulting in undefined behavior.

rdar://150351351
2025-04-30 06:17:52 -07:00
Slava Pestov
6b4710ed22 Merge pull request #81142 from slavapestov/more-type-subst-cleanup
Clean up duplicated opened existential archetype handling in SIL and more
2025-04-30 02:42:57 -04:00
Slava Pestov
7b5b5e9602 Merge pull request #81171 from slavapestov/fix-issue-81036
AST: Use weighted reduction order for opaque return types
2025-04-30 01:53:29 -04:00
Slava Pestov
3c26321aa3 Merge pull request #81173 from slavapestov/unused-vars
Squash warnings
2025-04-30 01:48:33 -04:00
Slava Pestov
d2b0bf002a AST: Fix existential erasure of long member types
Suppose protocol P has a primary associated type A, and we have
a `any P<S>` value. We form the generalization signature <T>
with substitution map {T := S}, and the existential signature
<T, Self where T == Self.A>.

Now, if we call a protocol requirement that takes Self.A.A.A,
we see this is fixed concrete type, because the reduced type of
Self.A.A.A is T.A.A in the existential signature.

However, this type parameter is not formed from the
conformance requirements of the generalization signature
(there aren't any), so we cannot directly apply the outer
substitution map.

Instead, change the outer substitution conformance lookup
callback to check if the reduced type parameter is valid
in the generalization signature, and not just rooted in a
generic parameter of the generalization signature.

If it isn't, fall back to global conformance lookup.

A better fix would introduce new requirements into the
generalization signature to handle this, or store them
separately in the generic environment itself. But this is fine
for now.

- Fixes https://github.com/swiftlang/swift/issues/79763.
- Fixes rdar://problem/146111083.
2025-04-29 18:58:58 -04:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Slava Pestov
fa6ec5a4a8 Sema: Fix unused variable warning 2025-04-29 13:57:18 -04:00
Slava Pestov
8ab5ca2a7a Sema: Use weighted reduction order for opaque return types
If the opaque generic signature has a same-type requirement between
an outer type parameter and an opaque type parameter, the former
should always precede the latter in the type parameter order, even
if it is longer. Achieve this by giving the innermost generic
parameters a non-zero weight in the opaque generic signature.

Now, when we map a type parameter into an opaque generic environment,
we correctly decide if it is represented by a type parameter of the
outer generic signature, in which case we apply the outer substitution
map instead of instantiating an archetype.

The included test case demonstrates the issue; we declare an opaque
return type `some P<T.A.A>`, so the opaque generic signature has a
requirement `T.A.A == <<some P>>.A`. Previously, the reduced type of
`<<some P>>.A` was `<<some P>>.A`, so it remained opaque; now we
apply outer substitutions to `T.A.A`.

- Fixes https://github.com/swiftlang/swift/issues/81036.
- Fixes rdar://problem/149871931.
2025-04-29 13:55:31 -04:00
Slava Pestov
115ba5c54f AST: Factor out GenericTypeParamType::withDepth() 2025-04-29 13:55:29 -04:00
Pavel Yaskevich
085078dd8a [Feature] Rename Feature APIs from adoption to migration 2025-04-28 11:52:46 -07:00
Slava Pestov
cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
Pavel Yaskevich
22a3ec0ee3 Merge pull request #78601 from stzn/fix-sending-typecheck
[Sema]Skip Sendable conformance check when `sending` are added to parameters or return types of an actor-isolated function
2025-04-26 18:55:56 -07:00
Doug Gregor
771cb35c23 Merge pull request #81120 from DougGregor/unsafe-call-effects
[Strict memory safety] Provide argument-specific diagnostics for calls
2025-04-26 07:41:38 -07:00
Doug Gregor
1b94c3b3d6 Always emit "unsafe does not cover any unsafe constructs" warning
Check for unsafe constructs in all modes, so that we can emit the
"unsafe does not cover any unsafe constructs" warning consistently.
One does not need to write "unsafe" outside of strict memory safety
mode, but if you do... it needs to cover unsafe behavior.
2025-04-25 23:22:09 -07:00
Doug Gregor
60f7d20ed2 [Effects checking] Handle optional function types for dynamic @objc calls
We've been missing this case forever, but it hadn't come up until
we performed "unsafe" checking on calls.
2025-04-25 21:54:39 -07:00
Doug Gregor
81b68e567b [Strict memory safety] Temporarily disable warning about stray "unsafe" in _SwiftifyImport expansions
We need to improve on the macro so it doesn't generate unnecessary
"unsafe" expressions.
2025-04-25 21:54:29 -07:00
Doug Gregor
ee9487b86f [Strict memory safety] Provide argument-specific diagnostics for calls
Similar to what we do for 'throws' checking, perform argument-specific
checking for unsafe call arguments. This provides more detailed failures:

```
example.swift:18:3: warning: expression uses unsafe constructs but is not
marked with 'unsafe' [#StrictMemorySafety]
16 |   x.f(a: 0, b: 17, c: nil)
17 |
18 |   x.f(a: 0, b: 17, c: &i)
   |   |                   `- note: argument 'c' in call to instance
method 'f' has unsafe type 'UnsafePointer<Int>?'
   |   `- warning: expression uses unsafe constructs but is not marked
with 'unsafe' [#StrictMemorySafety]
19 |   unsafeF()
20 | }
```

It also means that we won't complain for `nil` or `Optional.none`
arguments passed to unsafe types, which eliminates some false
positives, and won't complain about unsafe result types when there is
a call---because we'd still get complaints later about the
actually-unsafe bit, which is using those results.

Fixes rdar://149629670.
2025-04-25 21:54:19 -07:00
Doug Gregor
0b264e2d55 [Effects] Keep track of whether we looked through a 'self' application
When we look through a "self" application while decomposing a function
call in effects checking, keep track of whether we did so. Use this to
ensure that we get the right parameter types when looking at the
"self" application vs. the outer call.

This has always been wrong, but the async/throws effects don't ever
matter for the innermost application (i.e., for `x.m`), so the
inconsistency didn't come up.
2025-04-25 16:02:34 -07:00
Allan Shortlidge
039974ad17 AST: Fix a typo in missingImportsForDefiningModule(). 2025-04-25 08:05:32 -07:00
Anthony Latsis
925b72eaec Merge pull request #76337 from DePasqualeOrg/grammar-compound-modifiers
Grammatical corrections for compound modifiers
2025-04-25 13:50:52 +01:00
Slava Pestov
27d96fc1c9 Merge pull request #80963 from slavapestov/fix-rdar149438520
Sema: Fix case where witness thrown error type is a subtype of a type parameter
2025-04-24 16:55:41 -04:00
Hamish Knight
1af98f7d26 Merge pull request #81025 from hamishknight/add-null-check
[Sema] Add missing null check for Type
2025-04-24 20:36:17 +01:00
Slava Pestov
2d8da4b49d Sema: Fix case where witness thrown error type is a subtype of a type parameter
In b30006837e, I changed the `if`
condition here to check for the absence of type variables as well
as type parameters. This is incorrect; the type variables come up
in ValueWitnessRequest, and the type parameters come up in
associated type inference. We want the matching to be more lax
in the former case.

Fixes rdar://149438520.
2025-04-24 12:28:56 -04:00
Anthony
c9b17383c8 Grammatical corrections for compound modifiers 2025-04-24 09:21:32 +02:00
Pavel Yaskevich
b484e9645d [Sema] ConstnessChecker: Look through function conversions while checking arguments
In strict concurrency mode some calls could reference a declaration that
is  wrapped in one or more function conversion expressions to apply
concurrency related attributes or erase them (such as `@Sendable` or
`@MainActor`). This shouldn't impact constness checking and the checker
should look through such conversions.

Resolves: rdar://148168219
2025-04-23 14:11:39 -07:00
Hamish Knight
54e0607091 [Sema] Add missing null check for Type
`getType` here can return a null type if the queried expression isn't
part of the solution, which can currently happen for code completion.
I'm working on a more principled fix for this, but until then this is
a low-risk fix that will unblock the stress tester and can be
cherry-picked to 6.2.

rdar://149759542
2025-04-23 12:58:28 +01:00
Allan Shortlidge
fe79c409ba Merge pull request #80972 from tshortli/member-import-visibility-cross-import-overlay
Sema: Improve MemberImportVisibility diagnostics for cross import overlays
2025-04-22 18:29:33 -07:00
stzn
55e8d5579f Change how to check null 2025-04-23 09:19:01 +09:00
stzn
c0e82eca51 Prevent casting null pointer 2025-04-22 20:55:50 +09:00
Allan Shortlidge
9e67cf00cf Sema: Improve MemberImportVisibility diagnostics for cross import overlays.
When `MemberImportVisibility` is enabled and a declaration from a cross import
overlay is diagnosed because it has not been imported, suggest imports of the
declaring and bystanding modules instead of the cross import overlay module
(which is an implementation detail).

Resolves rdar://149307959.
2025-04-21 16:51:39 -07:00