Commit Graph

28352 Commits

Author SHA1 Message Date
Alexis Laferrière
5c2efaca9a AST: Begin accepting @cdecl on enums (but not @_cdecl) 2025-07-03 14:11:27 -07:00
Alexis Laferrière
83c0667b16 Sema: Add missing range on notes about representability 2025-07-03 14:11:27 -07:00
Alexis Laferrière
3a0ba5fc1c Sema: @cdecl functions C name defaults to the Swift name 2025-07-03 14:11:27 -07:00
Alexis Laferrière
eedc7c2857 Sema: Update more diagnostics for @cdecl vs @objc 2025-07-03 14:11:27 -07:00
Alexis Laferrière
0600ddd2e9 Sema: Use ForeignLanguage directly in diagnostic definitions 2025-07-03 14:11:27 -07:00
Alexis Laferrière
e38fd7f174 Sema: Simplify tracking the foreign language of an @objc decl
Apply review comments from #80744.
2025-07-03 14:11:26 -07:00
Alexis Laferrière
41f126fde6 Sema: Basic type-checking of @cdecl on global functions
This implements basic checks on the validity of the @cdecl attribute and
ensures the parameters and result types are representable in C. Many
more diagnostics will need to be updated to verify full representability
in C.
2025-07-03 14:11:26 -07:00
Alexis Laferrière
3209730bac Parser: Intro @cdecl attribute and gate it behind feature flag CDecl 2025-07-03 13:45:33 -07:00
Alexis Laferrière
221a6f09f1 Sema: Requestify most checks on @_cdecl 2025-07-03 13:45:33 -07:00
Slava Pestov
0022c312f0 Merge pull request #82758 from slavapestov/fix-issue-60552-6.2
[6.2] Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
2025-07-03 14:05:35 -04:00
Hamish Knight
3f2d1ddcdd [CS] Downgrade an ASSERT for 6.2 2025-07-03 17:57:42 +01:00
Hamish Knight
7e537b7f00 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 17:53:23 +01:00
Pavel Yaskevich
01404bf1ae Merge pull request #82735 from xedin/rdar-154754939-6.2
[6.2][Concurency] Allow declarations with `@isolated(any)` parameters be m…
2025-07-03 09:17:34 -07:00
Pavel Yaskevich
cf5ab749eb Merge pull request #82744 from xedin/rdar-154808850-6.2
[6.2][Concurrency] SE-0461: Extend `nonisolated(nonsending)` inference to …
2025-07-03 09:17:21 -07:00
Hamish Knight
ef8e576d23 Merge pull request #82741 from hamishknight/err-val-6.2
[6.2] [AST] Use ErrorType for invalid value generic parameter
2025-07-03 14:32:44 +01:00
Hamish Knight
2e0b9d7f8a Merge pull request #82743 from hamishknight/diag-it-6.2 2025-07-03 09:24:25 +01:00
Slava Pestov
8e78de3a70 Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
- Fixes https://github.com/swiftlang/swift/issues/60552.
- Fixes rdar://problem/99699879.
2025-07-03 00:22:31 -04:00
Pavel Yaskevich
d1a1b2fb31 [Concurrency] SE-0461: Extend nonisolated(nonsending) inference to function types
Currently only declarations would get `nonisolated(nonsending)`
inferred if the upcoming flag is enabled, this changes extend
this to apply to asynchronous nonisolated function types as well.

Resolves: rdar://154808850
(cherry picked from commit bb0cd6f0a6)
2025-07-02 14:25:02 -07:00
Hamish Knight
ce273f4527 [Sema] Downgrade an ASSERT for 6.2 2025-07-02 21:30:31 +01:00
Hamish Knight
a9d72fb695 [Sema] Avoid applying diagnostic hack to caller-side expression macros
We can't assume that type-checking the expression macro in the
parameter will also fail if it fails at the call site since e.g
name lookup may differ. Make sure we only apply this logic to simple
literals.

rdar://154771596
2025-07-02 21:29:32 +01:00
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