Commit Graph

103370 Commits

Author SHA1 Message Date
Henrik G. Olsson
d00f711af7 Merge pull request #84755 from hnrklssn/cherry-pick-swiftify-import-as-method-6.2
Cherry-pick [6.2] [Swiftify] Add support for free functions imported as instance methods
2025-10-10 11:00:06 -07:00
Gábor Horváth
bf2671510d Merge pull request #84768 from Xazax-hun/fix-overrelease-destroy-hoist-on-6.2
[6.2][cxx-interop] Delay lowering unowned convention until ownership elimination
2025-10-09 02:40:33 +01:00
nate-chandler
b5fed1546e Merge pull request #84763 from nate-chandler/cherrypick/release/6.2/rdar161606892_2
6.2: [VariadicGenerics] Fix memeffect of metadata accessor.
2025-10-08 15:36:36 -07:00
John McCall
d42b260497 Merge pull request #84732 from rjmccall/variadic-witness-fixes-6.2
[6.2] Fix some major SILGen bugs with pack handling:
2025-10-08 16:35:09 -04:00
Gábor Horváth
40bea13e68 [6.2][cxx-interop] Delay lowering unowned convention until ownership elimination
Explanation: Unowned result conventions do not work well with OSSA. Retain the
result right after the call when we come out of OSSA so we can treat the
returned value as if it was owned when we do optimizations.

This fix a miscompilation due to the DestroyAddrHoisting pass hoisting destroys
above copies with unowned sources. When the destroyed object was the last
reference to the pointed memory the copy is happening too late resulting in
a use after free.

Issues: rdar://160462854
Original PRs: #84612
Risk: We change where retaining of the unowned return values
happen in the optimization pipeline. It is hard to anticipate all the
possible effects but it should make the optimizer more correct.
Testing: Added a compiler test.
Reviewers: @eeckstein, @atrick
2025-10-08 18:57:54 +01:00
Alejandro Alonso
2a18def9a5 Merge pull request #84749 from Azoy/62-sext-instead-of-zext
[6.2] [IRGen] Correctly sext instead of zext for negative integer types
2025-10-08 08:03:43 -07:00
Nate Chandler
dab39bbf91 [VariadicGenerics] Fix memeffect of metadata accessor call.
Follow up to https://github.com/swiftlang/swift/pull/84635/.

The metadata accessor for a variadic generic type takes as arguments
packs of metadata records and witness tables, and each such pack is
passed in a buffer. So the call to any such accessor is not correctly
annotated memory(none).

rdar://161606892
2025-10-08 06:50:04 -07:00
Nate Chandler
9ab224212e [VariadicGenerics] Fix memeffect of metadata accessor.
The metadata accessor for a variadic generic type takes as arguments
packs of metadata records and witness tables, and each such pack is
passed in a buffer.  So any such accessor is not correctly annotated
`memory(none)`.

rdar://161606892
2025-10-08 06:50:04 -07:00
Henrik G. Olsson
6a9ac22cd2 Merge pull request #84507 from hnrklssn/swiftify-import-as-method
[Swiftify] Add support for free functions imported as instance methods

(cherry picked from commit ed4f058c01)
2025-10-07 20:12:44 -07:00
Alejandro Alonso
fbf07e7d54 Merge pull request #84655 from Azoy/negative-nancy
[IRGen] Correctly sext instead of zext for negative integer types
2025-10-07 14:27:08 -07:00
Alejandro Alonso
9c4a299cd8 Merge pull request #84625 from Azoy/fix-lifetime-serialization
[Serialization] Serialize isAddressable on param decls
2025-10-07 14:19:23 -07:00
John McCall
fd918f1a12 Fix some major SILGen bugs with pack handling:
- Calls to variadic-generic protocol requirements weren't applying
  substitutions properly, so expansion-sensitive types in the callee
  signature weren't pairing properly with their expansions in the
  caller.

- emitPackTransform had an over-destroy if the transformation function
  actually emitted into the temporary element directly.

- There were some MV ownership assertions that were wrong, which
  revealed that the corresponding code really didn't handle consuming/
  borrowing mismatches properly at all.

- We were completely mishandled consuming packs.

Fixes #81002, #80995, and #81600.
2025-10-07 16:04:14 -04:00
Alexis Laferrière
593b6c4e6a Serialization: Align conformance recovery logic across modes
Always give up early when attempting to deserialize a protocol
conformance broken by a context change. Don't attempt to replace missing
members of the conformance signature with invalid one, just mark the
whole protocol conformance as invalid.

The previous recovery logic, only for SourceKit mode and LLDB, was
inserting invalid conformances in the signature instead of dropping the
whole protocol conformance. It lead to failures later in the same
`finishNormalConformance` when accessing the invalid conformances.

rdar://98925842
2025-10-03 10:07:55 -07:00
Pavel Yaskevich
d91b4647a7 [TypeChecker] Avoid checking lazy property accessors if they haven't been synthesized yet
Ttheir availability is going to match the property itself.
This is a workaround for lazy type-checking because synthesis
of accessors for such properties requires a reference to
`self` which won't be available because pattern binding
for the variable was skipped.

Resolves: rdar://129359362
Resolves: rdar://159463230
Resolves: https://github.com/swiftlang/swift/issues/84041
(cherry picked from commit 6e7de5c1e0)
2025-10-02 23:27:35 -07:00
Yuta Saito
32846ed97b Merge pull request #84434 from kateinoigakukun/yt/cherry-pick-gh84215-release-6.2 2025-09-27 07:52:29 +09:00
Pavel Yaskevich
9ffb30354d Merge pull request #84495 from xedin/dar-157663660-6.2
[6.2][Concurrency] Prevent some extraneous function conversion sendability checking
2025-09-26 09:21:31 -07:00
Gábor Horváth
711b9dfad4 Merge pull request #84291 from Xazax-hun/handle-unowned-in-impicit-value-init-on-6.2
[6.2][cxx-interop] Handle Unowned values in implicit value ctors
2025-09-26 15:42:36 +01:00
Owen Voorhees
5904da14c3 Merge pull request #84440 from owenv/owenv/6.2-rpath
[6.2]Update OS versions requiring stdlib OS rpaths
2025-09-25 14:30:05 -07:00
Gábor Horváth
9e1b104de2 Merge pull request #84203 from Xazax-hun/handle-unowned-in-impicit-value-init
[cxx-interop] Handle Unowned values in implicit value ctors
2025-09-25 16:20:11 +01:00
Gábor Horváth
295b5c60d7 Merge pull request #84430 from Xazax-hun/unbalanced-refcount-in-pods-on-6.2
[6.2][cxx-interop] Fix over-releasing reference members of trivial C++ types
2025-09-25 16:12:02 +01:00
Egor Zhdan
14ade316f2 Merge pull request #84462 from egorzhdan/egorzhdan/6.2-retain-release-methods
🍒[cxx-interop] Allow retain/release operations to be methods
2025-09-25 15:30:48 +01:00
Pavel Yaskevich
a886c5f38a [Concurrency] Prevent extraneous sendability checking when applying nonisolated(nonsending)
`nonisolated(nonsending)` is not presented in interface types
which means that references to declarations that have this attribute
require a function conversion to apply it. Function conversion
checking should detect that and avoid sendability checking for
situations like that but there is really no conversion there.

(cherry picked from commit ce3310050b)
2025-09-24 12:06:26 -07:00
Pavel Yaskevich
18809358e1 [Concurrency] Avoid Sendable checking for conversions that strip @Sendable from nonisolated(nonsending) function type
The isolation doesn't change in this cause and making function type
non-Sendable means that it woun't be able to leave the current concurrency
domain and the compiler won't generate a thunk.

(cherry picked from commit 40c9674dfd)
2025-09-24 12:06:25 -07:00
Pavel Yaskevich
4699419dab [Concurrency] Check function conversions after their sub-expressions have been checked
Explicit closure expressions gets their isolation inferred during
actor isolation checking, if they appear as a sub-expression to
a function conversion we need to delay function checking until
the closure was processed. It shouldn't matter for other cases.

(cherry picked from commit 61fbaa7af7)
2025-09-24 12:05:59 -07:00
Pavel Yaskevich
641cfe06be [Concurrency] Fix @Sendable closures not inferring nonisolated(nonsending)
If there are no explicit concurrency attributes, isolated parameters,
or captures associated with the closure it should infer `nonisolated(nonsending)`
for the parent conversion injected by the solver (this conversion is injected
because the solver cannot check captures to elide it).

The change pushes `isIsolationInferenceBoundaryClosure` check down
with added benefit of getting preconcurrency context from the parent.

(cherry picked from commit 3ae34e8e68)
2025-09-24 12:05:51 -07:00
Allan Shortlidge
8f61ec2c71 Sema: Don't diagnose isolated deinit availability in skipped function bodies.
As a follow-up fix for https://github.com/swiftlang/swift/pull/83545, avoid
incorrectly diagnosing isolated deinit availability during module emission
jobs, which skip type checking non-inlinable function bodies and therefore
don't build accurate availability scopes for those bodies. It's ok to skip
these diagnostics during module emission since they should still be emitted
during compilation jobs.

Resolves rdar://161178785.
2025-09-23 12:05:26 -07:00
Egor Zhdan
c5c33d6c5a [cxx-interop] Allow retain/release operations to be methods
Some foreign reference types such as IUnknown define retain/release operations as methods of the type.

Previously Swift only supported retain/release operations as standalone functions.

The syntax for member functions would be `SWIFT_SHARED_REFERENCE(.doRetain, .doRelease)`.

rdar://160696723
(cherry picked from commit e78ce6165f)
2025-09-23 14:45:41 +01:00
Yuta Saito
66902410f0 [6.2][ModuleFormat] Bump module format version 2025-09-23 00:46:00 +00:00
Owen Voorhees
8c51b8916b Update OS versions requiring stdlib OS rpaths 2025-09-22 11:46:50 -07:00
Gábor Horváth
65bf53ddf4 [6.2][cxx-interop] Fix over-releasing reference members of trival C++ types
Explanation: Large trivial types were copied via memcpy instead of doing a
field-wise copy. This is incorrect for types with reference fields where we also
need to bump the corresponding refcounts. This PR makes sure that trival
C++ types with reference members are not trivial in Swift.
Issues: rdar://160315343
Original PRs: #84321
Risk: There is a low chance of breaking source compatibility as some
types that used to be BitwiseCopyable are no longer considered as such.
However, code relying on that probably has latent memory safety bugs.
Testing: Added a compiler test.
Reviewers: @egorzhdan, @j-hui
2025-09-22 16:21:58 +01:00
Yuta Saito
da2119e315 [wasm] Fix @_expose(wasm) serialization crash
https://github.com/swiftlang/swift/pull/82616 added a new exposure kind
for the `@_expose` attribute, but did not update the serialization
format to account for the new kind. This caused a crash when
serializing a module that used `@_expose(wasm)`.
2025-09-22 14:14:19 +00:00
Joe Groff
9016636714 Merge pull request #84267 from jckarter/trivial-address-only-switch-6.2
[6.2] SILGen: Don't copy_addr [take] trivial address-only values.
2025-09-19 20:09:49 -07:00
Alexis Laferrière
e037059037 Merge pull request #84330 from xymus/spi-avail-in-ext-6.2
[6.2] Sema: Narrow fix to allow `@_spi_available` in extensions
2025-09-17 10:42:55 -07:00
Gábor Horváth
859f60d4d4 Merge pull request #84120 from Xazax-hun/no-vwt-for-anon-types-on-6.2
[6.2][cxx-interop] Basic support for anonymous structs with non-copyable fields
2025-09-17 15:38:33 +02:00
Alexis Laferrière
7a6e8f0e4d Sema: Narrow fix to allow @_spi_available in extensions
Allow referencing an `@_spi_available` decl in extensions to
`@_spi_available` types. This is a narrow fix as it should really be
handled as part of the context check but that check is currently too
permissive.

Fow now let's narrowly allow legal code. And then we should look at
revisiting the SPI availability logic, separate it from normal SPI and
treat more like availability.

Adding a test comparing the behavior of `@_spi` with `@_spi_available`
to document the current implementation.

rdar://159292698
2025-09-16 12:37:32 -07:00
Yuta Saito
d8ae0124d4 [Legacy Driver][wasm] Pass --table-base to reserve low function addresses
WebAssembly does not have a reserved address space by default, so we
need to explicitly reserve low addresses for extra inhabitants for
enum types with pointer payloads. https://github.com/swiftlang/swift/pull/39300
added `--global-base` to reserve low data addresses, but we also need
to reserve low function addresses with `--table-base` for function
pointers because WebAssembly uses a separate address space for function
pointers.
2025-09-15 07:09:09 +00:00
Yuta Saito
908b7b58c3 [NFC][wasm] Fix incorrect comment about reserved low addresses 2025-09-15 07:09:06 +00:00
John McCall
634c818a88 Merge pull request #84250 from rjmccall/isolation-fixed-6.2
[6.2] Isolation fixes for closures and defer bodies
2025-09-13 18:13:27 -04:00
Joe Groff
cc00c68cf7 SILGen: Don't copy_addr [take] trivial address-only values.
This is a new case that comes up with `InlineArray`, since an `InlineArray`
with unknown count but known trivial element type is trivial but still
address-only due to its unknown size. We are inconsistent about whether
we emit formal copies or not of these values; they should generally
be unnecessary as long as the memory location of a value is sufficiently
long-lived, but the SIL verifier still reasonably considers a `[take]` as
an invalidation of the memory, even though at runtime a take is a no-op.
Since the take is unnecessary, we can just not take when we copy out of
a trivial address location. Fixes #84141 | rdar://160007939.
2025-09-12 14:04:34 -07:00
John McCall
94fd9529a3 Merge pull request #84243 from rjmccall/complete-metadata-for-concurrency-builtins-6.2
[6.2] Fix IRGen to pass complete metadata to various concurrency builtins
2025-09-12 10:23:38 -04:00
John McCall
7e601ad247 Make sure that we capture the isolation of a defer function that
implicitly uses the isolation.
2025-09-11 21:53:22 -04:00
John McCall
59bc23f8e3 Fix the evaluation of #isolation in non-AFD contexts, most importantly
closures.

The fixes for initializers are just setting the stage for doing this
properly: we should be able to just change the isolation computation
in Sema and fix up the tests.
2025-09-11 21:53:04 -04:00
John McCall
df7cfbfbc1 Add a function for querying the isolation of an Initializer. 2025-09-11 21:52:13 -04:00
John McCall
a6c40c75c8 Fix two bugs with the isolation of defer bodies.
The first bug is that we weren't computing isolation correctly for
nested defers. This is an unlikely pattern of code, but it's good to fix.

The second bug is that getActorIsolationOfContext was looking through
defers, but getActorIsolation itself was not. This was causing defer
bodies to be emitted in SILGen without an isolation parameter, which
meant that #isolation could not possibly provide the right value. Fixing
this involves teaching SILGen that non-async functions can have
nonisolated(nonsending) isolation, but that's relatively straightforward.

This commit doesn't fix #isolation or adequately test SILGen, but that'll
be handled in a follow-up.
2025-09-11 21:52:03 -04:00
John McCall
2bd4c8c0ac At the SIL level, allow synchronous functions to be nonisolated(nonsending). 2025-09-11 21:51:44 -04:00
John McCall
6f376c2468 Fix SILGen's computation of default argument generator isolation 2025-09-11 21:51:36 -04:00
John McCall
4f6acbca63 Don't crash if there's a request cycle with DefaultArgumentExprRequest. 2025-09-11 21:51:26 -04:00
John McCall
f72fd5aa8f Merge pull request #82930 from nickolas-pohilets/mpokhylets/6.2-weak-let
[6.2] Cherry-pick SE-0481 with source-incompatible changes to closure capture semantics still wrapped into a feature
2025-09-11 20:02:39 -04:00
John McCall
81b2dae5e9 Fix IRGen to pass complete metadata to various concurrency builtins
Fixes rdar://146155888
2025-09-11 18:42:33 -04:00
Gábor Horváth
95ff51c739 Merge pull request #84199 from Xazax-hun/no-reflection-anon-types
[cxx-interop] Restrict the uses of anonymous types
2025-09-11 09:56:35 +01:00