Commit Graph

28352 Commits

Author SHA1 Message Date
Slava Pestov
f72260f85c Merge pull request #82586 from slavapestov/fix-issue-82160-6.2
[6.2] AST: Better cope with UnboundGenericType in TypeBase::getSuperclass()
2025-06-28 02:41:09 -04:00
Slava Pestov
68b9a52fc6 Merge pull request #82508 from slavapestov/warn-long-expression-type-checking-6.2
[6.2] Sema: Fix -warn-long-expression-type-checking when expression timer is disabled
2025-06-28 01:31:02 -04:00
Doug Gregor
b5cce1f694 [SE-0466] Don't infer @MainActor on types conforming to Sendable
When the default isolation is main-actor, don't infer @MainActor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
2025-06-27 15:14:26 -07:00
Slava Pestov
eabc8efb41 AST: Better cope with UnboundGenericType in TypeBase::getSuperclass()
Returning the unsubstituted superclass type is not correct,
because it may contain type parameters. Let's form a new
UnboundGenericType instead.

- Fixes https://github.com/swiftlang/swift/issues/82160.
- Fixes rdar://152989888.
2025-06-27 18:11:40 -04:00
Doug Gregor
2f6d21ebe6 "nonisolated deinit" does not have back-deployment constraints
Fixes rdar://150484159
2025-06-27 14:56:57 -07:00
Pavel Yaskevich
a381143495 [CSFix] Fix getConcurrencyFixBehavior to account for non-decl overloads
Adjust the downgrade check for static member references to
account for the fact that argument could come of a tuple or
some other reference that doesn't have a declaration associated
with it.

Resolves: rdar://153083848
(cherry picked from commit 3ae8d5680f)
2025-06-27 13:20:22 -07:00
Doug Gregor
3094c8cfa0 Merge pull request #82495 from DougGregor/effects-subst-parameter-packs-6.2
[6.2] [Effects] Ensure that we properly substitute function types in ByClosure checks
2025-06-25 21:27:14 -07:00
Slava Pestov
017be57e9b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:56 -04:00
Doug Gregor
e744e35086 Merge pull request #82384 from slavapestov/implied-isolated-conformance-6.2
[6.2] Sema: Expand isolated conformance inference to consider conformances to inherited protocols
2025-06-25 15:36:39 -07:00
Doug Gregor
283cb60664 [Effects] Ensure that we properly substitute function types in ByClosure checks
We weren't substituting generic arguments into function types. In the
presence of parameter packs, this could mean that the parameter and
argument lists no longer match up, which would cause the effects
checker to prematurely bail out after treating this as "invalid" code.
The overall effect is that we would not properly check for throwing
behavior in this case, allowing invalid code (as in the example) and
miscompiling valid code by not treating the call as throwing.

Fixes rdar://153926820.
2025-06-25 10:12:51 -07:00
Pavel Yaskevich
9220e686b5 Merge pull request #82470 from xedin/rdar-154202375-6.2
[6.2][Concurrency] Global actor isolated conformances are only allowed to …
2025-06-25 08:58:57 -07:00
Pavel Yaskevich
10bd67630f Merge pull request #82471 from xedin/rdar-154221449-6.2
[6.2][CSSimplify] Narrow down tuple wrapping for pack expansion matching
2025-06-25 08:58:45 -07:00
Pavel Yaskevich
36261876b6 Merge pull request #82459 from xedin/rdar-154010220-6.2
[6.2][CSSimplify] Prevent `missing call` fix from recording fixes while ma…
2025-06-24 20:51:17 -07:00
Pavel Yaskevich
767dbc0d78 [CSSimplify] Narrow down tuple wrapping for pack expansion matching
Follow-up for https://github.com/swiftlang/swift/pull/82326.

The optional injection is only viable is the wrapped type is
not yet resolved, otherwise it's safe to wrap the optional.

(cherry picked from commit 4804f2131b)
2025-06-24 17:27:28 -07:00
Pavel Yaskevich
574537fc8a [Concurrency] Global actor isolated conformances are only allowed to override nonisolated.
Follow-up for https://github.com/swiftlang/swift/pull/79893.

More than one global actor isolated conformance at any level
creates a clash and conforming type should be inferred as `nonisolated`.

Resolves: rdar://154202375
(cherry picked from commit 2e1fe444a6)
2025-06-24 17:23:03 -07:00
Meghana Gupta
1d1f9b063f Merge pull request #82431 from meg-gupta/lifetimeenumcp
[6.2] Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads
2025-06-24 11:06:27 -07:00
Pavel Yaskevich
39a7138a0c [CSSimplify] Prevent missing call fix from recording fixes while matching types
We need to be very careful while matching types to test whether a
fix is applicable or not to avoid adding extraneous fixes and failing
the path early. This is a temporary workaround, the real fix would
be to let `matchTypes` to propagate `TMF_ApplyingFixes` down.

Resolves: rdar://154010220
Resolves: https://github.com/swiftlang/swift/issues/82397
(cherry picked from commit 7ecb1fd1db)
2025-06-24 09:49:02 -07:00
Pavel Yaskevich
67449c91e4 Merge pull request #82432 from xedin/nonisolated_nonsending-fixes-6.2
[6.2][Concurrency] A few `nonisolated(nonsending)` fixes
2025-06-24 09:12:45 -07:00
Doug Gregor
c251897278 Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
'@preconcurrency' imports open up memory safety holes with respect to
Sendable, which are diagnosed under strict memory safety + strict
concurrency checking. Allow one to write '@unsafe' on those imports to
silence the diagnostic about it.
2025-06-23 19:12:24 -07:00
Pavel Yaskevich
61c480f852 [Concurrency] References to nonisolated(nonsending) properties don't leave caller's isolation
Make sure that referencing `nonisolated(nonsending)` properties,
especially through a witness is as not treated as leaving the
isolation domain of the caller.

Resolves: rdar://153922620
(cherry picked from commit 35a41ab9cf)
2025-06-23 13:58:18 -07:00
Pavel Yaskevich
c68a17b8c4 [Concurrency] Don't infer nonisolated(nonsending) on synchronous witnesses
If the requirement is `nonisolated(nonsending)` but witness is
synchronous, prevent actor isolation inference from requirements
because this isolation only applies to asynchronous declarations
at the moment.

Resolves: rdar://153680826
(cherry picked from commit a964282275)
2025-06-23 13:58:07 -07:00
Meghana Gupta
3e359e4774 Support lifetime dependence inference on enum elements 2025-06-23 13:48:57 -07:00
Slava Pestov
f9a6432ffd Sema: Expand isolated conformance inference to consider conformances to inherited protocols
Otherwise, if PDerived inherits from P and P's requirements are
witnessed by @MainActor-isolated members, we fail to infer
@MainActor isolation on the conformance to PDerived.

- Fixes https://github.com/swiftlang/swift/issues/82222.
- Fixes rdar://153219831.
2025-06-23 15:19:55 -04:00
Michael Gottesman
25c2359cca Merge pull request #82379 from gottesmm/release/6.2-152522631
[6.2][sema] Work around a double curry thunk actor isolation inference bug that is a knock on effect of ced96aa5cd.
2025-06-20 20:41:59 -07:00
Michael Gottesman
845e1bcd14 [sema] Work around a double curry thunk actor isolation inference bug that is a knock on effect of ced96aa5cd.
Specifically, there is currently a bug in TypeCheckConcurrency.cpp where we do
not visit autoclosures. This causes us to never set the autoclosure's
ActorIsolation field like all other closures. For a long time we were able to
get away with this just by relying on the isolation of the decl context of the
autoclosure... but with the introduction of nonisolated(nonsending), we found
cases where the generated single curry autoclosure would necessarily be
different than its decl context (e.x.: a synchronous outer curry thunk that is
nonisolated that returns an inner curry thunk that is
nonisolated(nonsending)). This problem caused us to hit asserts later in the
compiler since the inner closure was actually nonisolated(nonsending), but we
were thinking that it should have been concurrent.

To work around this problem, I changed the type checker in
ced96aa5cd to explicitly set the isolation of
single curry thunk autoclosures when it generates them. The reason why we did
this is that it made it so that we did not have to have a potential large source
break in 6.2 by changing TypeCheckConcurrency.cpp to visit all autoclosures it
has not been visiting.

This caused a follow on issue where since we were now inferring the inner
autoclosure to have the correct isolation, in cases where we were creating a
double curry thunk for an access to a global actor isolated field of a
non-Sendable non-global actor isolated nominal type, we would have the outer
curry thunk have unspecified isolation instead of main actor isolation. An
example of this is the following:

```swift
class A {
  var block:  @MainActor () -> Void = {}
}

class B {
  let a = A()

  func d() {
    a.block = c // Error! Passing task isolated 'self' to @MainActor closure.
  }

  @MainActor
  func c() {}
}
```

This was unintentional. To work around this, this commit changes the type
checker to explicitly set the double curry thunk isolation to the correct value
when the type checker generates the double curry thunk in the same manner as it
does for single curry thunks and validates that if we do set the value to
something explicitly that it has the same value as the single curry thunk.

rdar://152522631
(cherry picked from commit c28490b527)
2025-06-20 11:05:24 -07:00
Pavel Yaskevich
cb9925d556 [CSSimplify] VariadicGenerics: Don't attempt to wrap optional into one-element tuple
If we have a tuple with unresolved pack expansion on one side
and an optional type on the other, prevent `matchTypes` from
wrapping optional into a one-element tuple because the matching
should be handled as part of the optional injection.

Resolves: rdar://152940244
(cherry picked from commit 6cfbafd968)
2025-06-20 00:15:07 -07:00
Hamish Knight
8f66e610df Merge pull request #82340 from hamishknight/record-opened-6.2 2025-06-19 08:19:06 +01:00
Hamish Knight
612f7b213c Merge pull request #82319 from hamishknight/keyed-6.2
[6.2] [Sema] Tighten up function call check in `resolveKeyPathExpr`
2025-06-18 18:24:30 +01:00
Pavel Yaskevich
3d1c592456 Merge pull request #82324 from xedin/SE-0449-fixes-6.2
[6.2][Concurrency] SE-0449: Fix a few issues related to `nonisolated` type declarations
2025-06-18 09:14:07 -07:00
Hamish Knight
4d654b271f [CS] Distinguish locators for generic args in addSpecializationConstraint
Make sure we give each argument a different locator to ensure we
can correctly record any opened types.

rdar://153674889
2025-06-18 16:21:45 +01:00
Pavel Yaskevich
06d1224aec [Concurrency] SE-0449: nonisolated on a type should prevent isolation inference from protocol requirements
If a `nonisolated` type conforms to a global-isolated protocol
the witnesses to the protocol requirements should infer the
isolation from the protocol but instead be `nonisolated`.

Resolves: rdar://145519840
(cherry picked from commit e50acbf3d5)
2025-06-17 15:29:18 -07:00
Pavel Yaskevich
7d0e2b51fd [Concurrency] SE-0449: Implied conformances to nonisolated protocols make witnesses nonisolated
Even if the requirement is stated on an isolated protocol if the
conformance is implied by a nonisolated one all of the requirements
and witnesses should be nonisolated.

(cherry picked from commit 06be7bda39)
2025-06-17 15:29:18 -07:00
Sima Nerush
a0b0a0704d [Concurrency] Make sure to still infer global actor if the conformance kind is explicit.
(cherry picked from commit 7e42a19187)
2025-06-17 15:29:18 -07:00
Sima Nerush
0ed6c1cf41 [Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances.
(cherry picked from commit 4fca62a771)
2025-06-17 15:29:18 -07:00
Hamish Knight
f95eb6bf48 [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:55 +01:00
Hamish Knight
61e0326b7f [Sema] Add null check in createMemberwiseInitParameter
The property wrapper initializer info may be null if e.g we had a
request cycle, just use the property's interface type in that case.

rdar://82899428
2025-06-17 17:31:24 +01:00
Pavel Yaskevich
cd83345651 [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate $ prefixed declarations
These are special declarations that are synthesized by the compiler
or a macro and warnings about them are non-actionable.

(cherry picked from commit 17976c7775)
2025-06-16 13:44:02 -07:00
Pavel Yaskevich
93c955c4f9 [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate swift-testing test cases
The execution of these functions is controlled by the testing
framework and it's okay if their behavior changes when the feature
flag is enabled.

Resolves: rdar://152687527
(cherry picked from commit f2f5d234dc)
2025-06-16 13:44:02 -07:00
Slava Pestov
acb53d2050 Merge pull request #82132 from slavapestov/bind-extensions-macro-6.2
[6.2] Sema: Don't expand macros when binding extensions
2025-06-14 12:14:10 -04:00
Hamish Knight
c1db12a0d4 Merge pull request #82239 from hamishknight/cod-cycle-6.2
[6.2] [Sema] Scale back CodingKeys hack in `TypeChecker::lookupUnqualifiedType`
2025-06-14 12:54:54 +01:00
Slava Pestov
a10cc92bf7 Sema: Try to bind extensions without expanding macros
Macro expansion can call typeCheckExpr(), which performs qualified
lookups. So if we expand macros while binding extensions, these
qualified lookups can fail because they cannot find members of
extensions that have not been bound yet.

To fix this, try binding extensions without performing macro
expansion first. If any extensions remain at the end, we fall back
to the old behavior, and try to bind them again, this time
performing macro expansion.

Fixes rdar://149798059.
2025-06-13 16:00:16 -04:00
Slava Pestov
15f968f269 AST: Call setExtendedNominal() instead of cacheOutput(ExtendedNominalRequest...) 2025-06-13 16:00:16 -04:00
Hamish Knight
9ba1da9a51 [Sema] Scale back CodingKeys hack in TypeChecker::lookupUnqualifiedType
I previously added this hack to match the logic in
`TypeChecker::lookupUnqualified`, but it turns out that can introduce
request cycles for cases where `CodingKeys` is used in a generic
requirement for one of `Codable`'s potential value witnesses. Scale
back the hack such that it's only done when we get an initial empty
lookup result, ensuring we maintain source compatibility. Both these
lookup hacks should go away once we properly handle CodingKeys 
synthesis.

rdar://153096639
2025-06-13 19:56:02 +01:00
Pavel Yaskevich
c17d370158 Merge pull request #82219 from xedin/rdar-152687353-6.2
[6.2][Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
2025-06-13 09:14:47 -07:00
Hamish Knight
19bc18f064 Merge pull request #82152 from hamishknight/fix-nested-arenas-6.2 2025-06-13 08:01:57 +01:00
Pavel Yaskevich
c0984d2bf5 [Concurrency] NonisolatedNonsendingByDefault/NFC: Move 'same module' check higher
This is a follow-up to https://github.com/swiftlang/swift/pull/82173
which moves the check higher to make it an early exist.

(cherry picked from commit f0502c2257)
2025-06-12 10:42:32 -07:00
Pavel Yaskevich
20e086cdc7 [Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
Prevent migration from handling declarations that come from a
module different from the current one, this is primarily a
problem for swiftinterfaces that can get rebuilt when the module
is imported by a model that has migration mode enabled.

Resolves: rdar://152687353
(cherry picked from commit bcd6caaea4)
2025-06-12 10:19:46 -07:00
Pavel Yaskevich
36f376f50c [TypeChecker] Remove @_inheritActorContext effect from synchronous types
The compiler would previously accept use of `@_inheritActorContext`
on a parameter with a synchronous function type which wasn't marked
as `@isolated(any)`. That is incorrect because in such cases the
attribute has no effect and furthermore would prevent Sendable
and isolation checking.

Uses like that are currently diagnosed by the type-checker but we
need to go one step further and remove the effect in such case to
prevent invalid uses.

Resolves: rdar://143581268
(cherry picked from commit dbe19b6d5f)
2025-06-12 08:54:12 -07:00
Meghana Gupta
58b714b968 Introduce a new suppressible experimental feature to guard @_lifetime 2025-06-11 08:03:40 -07:00
Meghana Gupta
a9b831788d Update spelling for representing lifetime dependencies to @_lifetime 2025-06-11 08:03:39 -07:00