Commit Graph

28382 Commits

Author SHA1 Message Date
Hamish Knight
4c6e06fed3 [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 21:19:45 +01:00
Hamish Knight
13118899cd NFC: Constify GenericTypeParamDeclGetValueTypeRequest's parameter 2025-07-02 21:19:45 +01:00
Slava Pestov
14a27751e2 Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
This was added in #80220 to fix a related issue with captures of packs,
but it's even better to sink this down into diagnoseNonSendableTypes(),
so that we can handle packs in parameter position as well.

- Fixes https://github.com/swiftlang/swift/issues/82614.
- Fixes rdar://problem/154649522.
2025-07-02 15:26:13 -04:00
Pavel Yaskevich
b353f717f5 [Concurency] Allow declarations with @isolated(any) parameters be marked as @concurrent/nonisolated(nonsending)
It's shouldn't be possible to use these attributes directly on
the function type that is `@isolated(any)` as per SE-0461 proposal
but it shouldn't preclude declarations that have parameters with
`@isolated(any)` from using them.

Resolves: rdar://154754939
(cherry picked from commit a522448e90)
2025-07-02 11:50:22 -07:00
Anthony Latsis
6ddd1c95f3 Merge pull request #82664 from swiftlang/jepa2-6.2
[6.2] Sema: Fix the insertion location for conformances attributes
2025-07-02 16:51:55 +01:00
Doug Gregor
d98ab48611 Merge pull request #82670 from DougGregor/isolated-deinit-main-actor-mode-6.2
[6.2] [SE-0466] Infer isolated deinit in main-actor-by-default mode
2025-07-02 07:42:06 -07:00
Egor Zhdan
fc0c350c56 Merge pull request #82688 from swiftlang/egorzhdan/6.2-void-begin-crash
🍒[cxx-interop] Do not crash for `void begin()`
2025-07-02 14:45:11 +01:00
Doug Gregor
7d10f95f6a Merge pull request #82662 from DougGregor/back-deploy-main-actor-isolated-deinit-6.2
[6.2] [SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-02 00:13:47 -07:00
Pavel Yaskevich
1c501e8242 Merge pull request #82675 from xedin/rdar-153646123-6.2
[6.2][Concurrency] Forego Sendable checking if conversion doesn't change t…
2025-07-01 14:19:05 -07:00
John McCall
eff0845360 Merge pull request #82613 from rjmccall/local-function-isolation-fixes-6.2
[6.2] Local function isolation fixes
2025-07-01 13:34:16 -04:00
Egor Zhdan
1a4176041e [cxx-interop] Do not crash for void begin()
When importing C++ methods, Swift always assumes that methods named `begin()` and `end()` are unsafe, since these methods commonly return iterator types that are inherently unsafe in Swift.

Some additional logic in Sema tries to diagnose usages of `.begin()` and `.end()` from Swift and suggest safe alternatives. That logic had a null pointer dereference bug.

rdar://153814676 / resolves https://github.com/swiftlang/swift/issues/82361
(cherry picked from commit 883ff18adb)
2025-07-01 17:38:30 +01:00
Pavel Yaskevich
3263327653 [Concurrency] Forego Sendable checking if conversion doesn't change the global actor
`FunctionConversionExpr` is allowed to modify different attributes
of a type, sometimes it could strip `@Sendable` but keep the same
global actor attribute in place, that needs to be handled explicitly
before performing Sendable checking because in this case there is
going to be no isolation context change for arguments or results.

Resolves: rdar://153646123
(cherry picked from commit 053199eb12)
2025-07-01 00:21:07 -07:00
Doug Gregor
d9bc9a2238 Merge pull request #82655 from DougGregor/isolated-conformances-collection-literals-6.2
[6.2] [SE-0470] Check uses of isolated conformances in collection literals
2025-07-01 00:20:27 -07:00
Pavel Yaskevich
c1d96d6b7b Merge pull request #82647 from xedin/rdar-148076903-6.2
[6.2][Concurrency] Fix a crash caused by misuse of `isolated` modifier
2025-07-01 00:02:07 -07:00
Konrad `ktoso` Malawski
0eb6263b6d [6.2][Concurrency] Remove experimental @Task macro (#82622) 2025-06-30 23:02:12 -07:00
Doug Gregor
f711ecc29b [SE-0466] Infer isolated deinit in main-actor-by-default mode
Now that main-actor-isolated deinit can be back-deployed, enable
inference of isolated deinit within main-actor-by-default mode.

Implements rdar://154729369.
2025-06-30 22:04:32 -07:00
Anthony Latsis
c1ed83e95f Fix use-after-free through diagnostic argument 2025-07-01 02:58:59 +01:00
Anthony Latsis
1f28a04d29 Sema: Fix the insertion location for conformances attributes 2025-07-01 02:58:48 +01:00
Doug Gregor
dc27da053c [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:40:00 -07:00
Doug Gregor
96583f1c6c [SE-0470] Check uses of isolated conformances in collection literals
Fixes rdar://151646584.
2025-06-30 16:08:17 -07:00
Pavel Yaskevich
a651d020d8 [Concurrency] Fix a crash caused by misuse of isolated modifier
Adjust isolation checking to handle misused `isolated` attribute
and let attribute checker property diagnose it.

Resolves: rdar://148076903
Resolves: https://github.com/swiftlang/swift/issues/80363
(cherry picked from commit 358067917e)
2025-06-30 13:09:32 -07:00
Hamish Knight
c74b7a5e75 Merge pull request #82617 from hamishknight/solve-escape-6.2
[6.2] [CS] Fix a couple of use-after-frees
2025-06-30 20:10:39 +01:00
Pavel Yaskevich
44a43df76b Merge pull request #82580 from xedin/rdar-153083848-6.2
[6.2][CSFix] Fix `getConcurrencyFixBehavior` to account for non-decl overloads
2025-06-30 10:11:02 -07:00
Hamish Knight
f72c443ea6 [CS] Downgrade an assert for 6.2 2025-06-30 10:38:26 +01:00
Hamish Knight
dbc9dae27f [CS] Use the resolved type in NonOptionalUnwrapFailure::diagnoseAsError
Diagnostics can outlive the ConstraintSystem itself if we have a
diagnostic transaction for e.g `typeCheckParameterDefault`, make sure
we don't try to use a solver-allocated type as an argument.
2025-06-30 10:34:18 +01:00
Hamish Knight
2acacc9a74 [CS] Avoid escaping solver-allocated types in computeSubstitutions
Make sure we call `simplifyType` for the opened type bindings to
ensure holes get converted to UnresolvedType.

rdar://154553285
2025-06-30 10:34:18 +01:00
John McCall
06dec05473 Fix a bunch of bugs with the isolation of local funcs. Since we
use local funcs to implement `defer`, this also fixes several
bugs with that feature, such as it breaking in nonisolated
functions when a default isolation is in effect in the source file.

Change how we compute isolation of local funcs. The rule here is
supposed to be that non-`@Sendable` local funcs are isolated the
same as their enclosing context. Unlike closure expressions, this
is unconditional: in instance-isolated functions, the isolation
does not depend on whether `self` is captured. But the computation
was wrong: it didn't translate global actor isolation between
contexts, it didn't turn parameter isolation into capture isolation,
and it fell through for several other kinds of parent isolation,
causing the compiler to try to apply default isolation instead.
I've extracted the logic from the closure expression path into a
common function and used it for both paths.

The capture computation logic was forcing a capture of the
enclosing isolation in local funcs, but only for async functions.
Presumably this was conditional because async functions need the
isolation for actor hops, but sync functions don't really need it.
However, this was causing crashes with `-enable-actor-data-race-checks`.
(I didn't investigate whether it also failed with the similar
assertion we do with preconcurrency.) For now, I've switched this
to capture the isolated instance unconditionally. If we need to
be more conservative by either only capturing when data-race checks
are enabled or disabling the checks when the isolation isn't captured,
we can look into that.

Fix a bug in capture isolation checking. We were ignoring captures
of nonisolated declarations in order to implement the rule that
permits `nonisolated(unsafe)` variables to be captured in
non-sendable closures. This check needs to only apply to variables!
The isolation of a local func has nothing to do with its sendability
as a capture.

That fix exposed a problem where we were being unnecessarily
restrictive with generic local func declarations because we didn't
consider them to have sendable type. This was true even if the
genericity was purely from being declared in a generic context,
but it doesn't matter, they ought to be sendable regardless.

Finally, fix a handful of bugs where global actor types were not
remapped properly in SILGen.
2025-06-30 01:48:48 -04:00
John McCall
00463df058 [NFC] Encapsulate the parameter index of an ActorIsolation 2025-06-30 01:48:37 -04:00
Doug Gregor
2f838823ee Merge pull request #82590 from DougGregor/no-main-actor-when-conforming-to-sendable-6.2
[6.2] [SE-0466 experimental amendment] Don't infer @mainactor on types conforming to Sendable
2025-06-28 05:57:50 -07:00
Doug Gregor
997a252da4 Merge pull request #82585 from DougGregor/nonisolated-deinit-availability-6.2
"nonisolated deinit" does not have back-deployment constraints
2025-06-28 03:27:38 -07:00
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