Commit Graph

103252 Commits

Author SHA1 Message Date
Hamish Knight
13118899cd NFC: Constify GenericTypeParamDeclGetValueTypeRequest's parameter 2025-07-02 21:19:45 +01:00
Ben Barham
075fc7de79 Merge pull request #82709 from bnbarham/6.2-dangling-reference
[6.2][ClangImporter] Fix dangling reference
2025-07-02 13:18:44 -07: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
Artem Chikin
2f07a98aec [Dependency Scanning] On cycle via overlay, fix Clang dependency path reconstruction
The code should consider *only* clang module dependencies, instead of all dependencies.
2025-07-02 12:16:06 -07: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
Zachary 'Clack' Cole
305125d8a0 Merge pull request #82694 from clackary/cherrypick/autodiff-fix-link-entity-diff-witness
[6.2 🍒][AutoDiff] Use `LinkEntity::SecondaryPointer` for diff witness
2025-07-02 11:30:48 -06:00
John McCall
8686a8beb5 Merge pull request #82710 from rjmccall/nonisolated-nonsending-thunks-6.2
[6.2] Correctly forward the implicit `nonisolated(nonsending)` parameter in thunks
2025-07-02 12:01:45 -04: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
0be39efad4 [cxx-interop] Fix generated header for Swift closures using CF_OPTIONS types
If a Swift class has a field, which has a closure type, which takes an instance of a `CF_OPTIONS`/`NS_OPTIONS` type as a parameter, the reverse interop logic would generate an invalid Objective-C++ header for such type.

This was discovered with UIKit's `UIControlState` type, which is declared with `NS_OPTIONS` in Objective-C, then renamed to `UIControl.State` with API Notes, and then re-exported to Objective-C++ via the generated header.

rdar://129622886

(cherry picked from commit e95c9ecffc)
2025-07-02 14:52:15 +01: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
John McCall
dae036ae85 Correctly forward the implicit nonisolated(nonsending) parameter in
SILGen thunks.

Also, I discovered that we don't apply nonisolated(nonsending) to
function types in the new mode. That's one for a different patch.

Fixes rdar://154401813
2025-07-02 01:54:42 -04:00
Michael Spencer
7df095f6c1 [ClangImporter] Fix dangling reference.
LookupOverloadedBinOp stores `Args` for later use, so store the
backing array on the stack instead of using a temporary.

This fixes a crash that appeared under some build configurations.

Related to rdar://154291418

(cherry picked from commit 75ac27dc3d)
2025-07-01 19:48:15 -07:00
Adrian Prantl
478d16ab5f Merge pull request #82562 from charles-zablit/charles-zablit/demangling/add-wrapper-to-6.2
🍒 [demangling] add new wrapper API
2025-07-01 16:49:16 -07:00
Nate Chandler
b730144497 [CSE] Fix combine of type_value.
The instruction has no operands but has a param type.  Hash and compare
the type and the type and the param type.

rdar://154652254
2025-07-01 14:30:59 -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
Pavel Yaskevich
ec750efad6 Merge pull request #82674 from xedin/rdar-154695053-6.2
[6.2][Concurrency] SE-0463: `Sendable` inference on sync and async variant…
2025-07-01 13:55:08 -07:00
Pavel Yaskevich
2d06a61c49 Merge pull request #82676 from xedin/rdar-153461854-serialization-fix-6.2
[6.2][Serialization] A temporary fix for `LocatableType`
2025-07-01 10:36:28 -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
Steven Wu
7606a6982e Merge pull request #82642 from cachemeifyoucan/eng/PR-153851818-release 2025-07-01 06:23:20 -07:00
Pavel Yaskevich
9b27b45e1e [Serialization] A temporary fix for LocatableType
Gracefully handle `LocatableType` types if they show up during
serialization. This is a temporary fix until we can remove
`TransitivelyConformsTo` constraint from the solver which is
the underlying cause of the issue (see https://github.com/swiftlang/swift/pull/82541).

Resolves: rdar://153461854
(cherry picked from commit 907606ef28)
2025-07-01 00:36:46 -07:00
QuietMisdreavus
a75f94eef4 [6.2] use RespectOriginallyDefinedIn when mangling extension contexts (#82657)
- **Explanation**: USR mangling can include an extension context infix
(`AAE`) when an extended type uses `@_originallyDefinedIn` on platforms
other than the active one. This adds a check for the
`RespectOriginallyDefinedIn` flag when checking extension decls against
their extended type.
- **Scope**: Changes USR mangling in these situations so that USRs are
the same for the same code regardless of platform.
- **Issues**: rdar://152598492
- **Original PRs**: https://github.com/swiftlang/swift/pull/82348
- **Risk**: Low. The change is limited to situations where the name
mangler is already disrespecting the alternate module name, and only
additionally turns on that flag for any USR mangling.
- **Testing**: Automated tests
- **Reviewers**: @edymtt @augusto2112
2025-07-01 00:30:15 -07: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
f422085b70 [Concurrency] SE-0463: Sendable inference on sync and async variants of imported APIs should match
This is a follow-up to https://github.com/swiftlang/swift/pull/82085
which made it so async variant doesn't get `@Sendable` inferred because
the proposal specified that inference should happen only on completion
handler parameter type of a synchronous variant of an imported API.

This runs into implementation issues related to thunking in some
cases were async convention expects the type of a completion handler
to match exactly for both variants of the imported API.

Resolves: rdar://154695053
(cherry picked from commit 30f0fa8d75)
2025-07-01 00:16:36 -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
Konrad `ktoso` Malawski
9c9c8b6408 Merge pull request #82612 from ktoso/pick-wiup-cleanup-mergeconflict-potential 2025-07-01 07:25:14 +09:00
Daniil Kovalev
a86e717991 [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable`
assumes that we can safely call `LinkEntity::getType()`, which does
`reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *`
type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and
`ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are
also type kinds), we should use `SecondaryPointer` instead of `Pointer` for
storing payload here, while setting `Pointer` to `nullptr`.

(cherry picked from commit 77a3873448)
2025-06-30 15:18:55 -06: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
Joe Groff
f299c6a856 Merge pull request #82344 from jckarter/addressable-for-dependencies-vw-flag-6.2
[6.2] Add an "addressable for dependencies" flag to value witness flags.
2025-06-30 12:54:25 -07:00
Adrian Prantl
9b67659a21 Merge pull request #82591 from swiftlang/dl/IRGen-Emit-objc-type-encoding-for-ivars
[6.2] IRGen: Emit objc type encoding for ivars
2025-06-30 12:50:08 -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
Henrik G. Olsson
9de099a4b0 Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk
[Swiftify] Adjust _SwiftifyImport invocation to align with the signature

(cherry picked from commit e9ba8f8a03)
2025-06-30 12:02:55 -07:00
Henrik G. Olsson
8db1ad6222 Cherry-pick [Swiftify] Don't import counted_by with suffixed integer literals (#82469) (#82594)
Integer literal expressions with types that are not of type `int` are
printed with a suffix to indicate the type (e.g. `123U` or `456L` for
`unsigned` and `long`). This is not valid syntax for integer literals in
Swift, so until we fully translate the count expr syntax to Swift we
need to avoid importing these count expressions.

Also fixes some -Werror related stuff in test cases.

rdar://154141719
(cherry picked from commit 374658a)
2025-06-30 11:58:55 -07:00
Steven Wu
bf32a8bb14 [ScanDependencies] Fix a bug in rewrite from #81454
When improving the speed of dependency scanning when the new clang API
to speed up bridging, some unintended change was introduced. This
restore the scanner to the behavior before #81454

rdar://153851818
(cherry picked from commit cebe173ada)
2025-06-30 10:51:42 -07: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
eeckstein
8c47b59d7d Merge pull request #82560 from eeckstein/fix-closure-specializer-6.2
[6.2] ClosureSpecializer: don't specialize captures of stack-allocated Objective-C blocks
2025-06-30 18:18:10 +02: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