Commit Graph

103252 Commits

Author SHA1 Message Date
Doug Gregor
6e419b6345 Revert "[6.2] Accept @cdecl global functions and enums, behind experimental feature flags" 2025-07-16 10:05:35 -07:00
Michael Gottesman
348720b830 Revert "[rbi] Treat a partial_apply as nonisolated(unsafe) if all of its captures are nonisolated(unsafe)."
This reverts commit 6ce93c8a37.
2025-07-16 09:58:09 -07:00
Doug Gregor
73530bf957 Merge pull request #83088 from DougGregor/se-0466-nested-no-inference-6.2
[6.2] [SE-0466] Nested types of nonisolated types don't infer main-actor isolation
2025-07-16 09:44:00 -07:00
Alexis Laferrière
ed65bb9a46 Merge pull request #82791 from xymus/cdecl-6.2
[6.2] Accept `@cdecl` global functions and enums, behind experimental feature flags
2025-07-16 09:27:04 -07:00
Gábor Horváth
ab123929f6 [6.2][cxx-interop] Types exposed from ObjC modules should be behind a macro
Explanation: We the generated reverse interop headers to be valid C++,
so every declaration coming from an Obj-C module should be behind an
ifdef. Unfortunately, we do not always have this information but we do
know that our frameworks contain Obj-C code. So this PR makes sure every
entity coming from our frameworks are behind ifdef.
Issues: rdar://152836730
Original PRs: #83002
Risk: Low, the change is narrow and straightforward.
Testing: Added a compiler test.
Reviewers: @egorzhdan
2025-07-16 11:19:55 +01:00
Doug Gregor
a4a39f2a98 [SE-0466] Nested types of nonisolated types don't infer main-actor isolation
Under discussion as part of an amendment to SE-0466, limit default main
actor inference so it doesn't apply to a nested type within a
nonisolated type.
2025-07-15 20:15:35 -07:00
Pavel Yaskevich
d7808f7804 Merge pull request #83064 from xedin/rdar-155847011-6.2
[6.2][Concurrency] Replace `nonisolated` with `nonisolated(nonsending)` when isolation is inferred
2025-07-15 17:41:06 -07:00
Michael Gottesman
182149978e [concurrency] Make optimize hop to executor more conservative for 6.2 around caller isolation inheriting functions.
Specifically for 6.2, we are making optimize hop to executor more conservative
around caller isolation inheriting functions. This means that we are:

1. No longer treating calls to caller isolation inheriting functions as having a
hop in their prologue. In terms of this pass, it means that when determining
dead hop to executors, we no longer think that a caller isolation inheriting
function means that an earlier hop to executor is not required.

2. Treating returns from caller isolation inheriting callees as requiring a
hop. The reason why we are doing this is that we can no longer assume that our
caller will hop after we return.

Post 6.2, there are three main changes we are going to make:

* Forward Dataflow

Caller isolation inheriting functions will no longer be treated as suspension
points meaning that we will be able to propagate hops over them and can assume
that we know the actor that we are on when we enter the function. Practically
this means that trees of calls that involve just nonisolated(nonsending) async
functions will avoid /all/ hop to executor calls since we will be able to
eliminate all of them since the dataflow will just propagate forward from the
entrance that we are already on the actor.

* Backwards Dataflow

A caller isolation inheriting call site will still cause preceding
hop_to_executor functions to be live. This is because we need to ensure that we
are on the caller isolation inheriting actor before we hit the call site. If we
are already on that actor, the hop will be eliminated by the forward pass. But
if the hop has not been eliminated, then the hop must be needed to return us to
the appropriate actor.

We will also keep the behavior that returns from a caller isolation inheriting
function are considered to keep hop to executors alive. If we were able to
propagate to a hop to executor before the return inst with the forward dataflow,
then we know that we are guaranteed to still be on the relevant actor. If the
hop to executor is still there, then we need it to ensure that our caller can
treat the caller isolation inheriting function as a non-suspension point.

rdar://155905383
(cherry picked from commit b3942424c8)
2025-07-15 17:32:19 -07:00
Michael Gottesman
e73396bc8a [sil] Add the ability to mark a function with isolation just so we can write more concurrency tests in SIL.
Specifically, we write a string out like:

sil [isolation "$REPRESENTATION OF ISOLATION"] @function : $@convention(thin) ...

The idea is that by using a string, we avoid parsing issues of the isolation and
have flexibility. I left in the way we put isolation into the comment above
functions so I did not break any tests that rely on it. I also made it so that
we only accept this with sil tests that pass in the flag
"sil-print-function-isolation-info". I am going to for the next release put in a
full real implementation of this that allows for actor isolation to become a
true first class citizen in SIL. But for now this at least lets us write tests
in the short term.

Since this is temporary and behind a flag, I did not add support for
serialization since this is just for writing textual SIL tests.

(cherry picked from commit ee3027c2ca)

Conflicts:
	lib/SIL/Parser/ParseSIL.cpp
2025-07-15 17:12:01 -07:00
Xi Ge
6f4d55a901 Merge branch 'release/6.2' into cdecl-6.2 2025-07-15 14:50:10 -07:00
Dario Rexin
4a8ada3fb0 [IRGen] Set generic context before getting call emission in visitFullApplySite
rdar://149007227

Without the generic context, the result type can't be mapped into the current context, causing the compiler to crash.
2025-07-15 13:36:16 -07:00
Pavel Yaskevich
a7e44d422f Merge pull request #83048 from xedin/rdar-153487603-6.2
[6.2][Serialization] Move `nonisolated(nonsending)` isolation kind above g…
2025-07-15 11:20:22 -07:00
Pavel Yaskevich
84f70f3792 [Concurrency] Replace nonisolated with nonisolated(nonsending) when isolation is inferred
With `NonisolatedNonsendingByDefault` an explicit `nonisolated`
attribute in declaration context is inferred to mean `nonisolated(nonsending)`
and it should be printed as such in interface files and other places.

The inference logic that did didn't remove the original attribute
which meant that it would be printed twice i.e.
`nonisolated nonisolated(nonsending) func test() async` which is
incorrect and would fail swift interface validation.

Resolves: rdar://155847011
(cherry picked from commit b519c07428)
2025-07-15 09:20:33 -07:00
Meghana Gupta
8f00bc4fe8 Bailout from an illegal transformation in semantic arc opts
tryJoinIfDestroyConsumingUseInSameBlock replaces a copy with its operand
when there is no use of the copy's operand between the copy's forwarded consuming use
and the copy operand's destroy in the same block. It is illegal to do this transformation
when there is a non-consuming use of the copy operand after the forwarded consuming use of the copy.

The code checking this illegal case was not considerin the case where the consuming use of the copy
was in the same instruction as the non-consuming use of the copy operand.

rdar://154712867
2025-07-15 03:41:05 -07:00
Hamish Knight
234a41567f Merge pull request #83036 from hamishknight/origami-6.2
[6.2] [Sema] Avoid folding sequences multiple times for completion
2025-07-15 09:15:17 +01:00
Joe Groff
e9d2e8ac48 Merge pull request #83038 from jckarter/case-binding-addressable-scopes-6.2
[6.2] SILGen: Properly set up addressability scopes for case pattern bindings.
2025-07-14 17:58:25 -07:00
Doug Gregor
e5658e0087 Merge pull request #83020 from DougGregor/prohibit-isolated-conformance-capture-check-6.2 2025-07-14 15:37:31 -07:00
Meghana Gupta
cfe2a7030f Merge pull request #82963 from meg-gupta/disablefso2
[6.2] Disable function signature optimization on functions with lifetime dependencies
2025-07-14 15:36:46 -07:00
Pavel Yaskevich
64c8c3d5f6 [Serialization] Move nonisolated(nonsending) isolation kind above global actor one
Global actor kind also appends type offset that indicates what
global actor to use with the type. All of the isolation kinds
should be placed above it to make sure that there is never a
clash when i.e. `MainActor` is serialized as id `1`.

Resolves: rdar://153487603
(cherry picked from commit ace6f738ba)
2025-07-14 14:33:28 -07:00
Jonas Devlieghere
3d0ceb7715 Merge pull request #82997 from augusto2112/change-remote-addr-6.2-3
[NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
2025-07-14 13:24:19 -07:00
Michael Gottesman
187b1eedf7 Merge pull request #82776 from gottesmm/release/6.2-154139237
[6.2] [nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
2025-07-14 13:19:55 -07:00
Meghana Gupta
6e2065106e Merge pull request #82974 from meg-gupta/disablerrnccp
[6.2] Disable retain and release sinking when rc root values are ~Copyable
2025-07-14 12:48:27 -07:00
Hamish Knight
e653a22431 [Sema] Make change less risky for 6.2
Revert assertion changes and flip the condition to only apply when
doing completion.
2025-07-14 17:49:30 +01:00
Hamish Knight
5d93006d4c [Sema] Avoid folding sequences multiple times for completion
Completion can end up calling into pre-checking multiple times in
certain cases, make sure we don't attempt to fold a SequenceExpr
multiple times since its original AST is in a broken state
post-folding. Instead, just return the already-folded expression.

rdar://133717866
2025-07-14 17:49:23 +01:00
Joe Groff
5e021bc55a SILGen: Properly set up addressability scopes for case pattern bindings.
In order to accommodate case bodies with multiple case labels, the AST
represents the bindings in each pattern as a distinct declaration from
the matching binding in the case body, and SILGen shares the variable
representation between the two declarations. That means that the two
declarations also need to be able to share an addressable representation.
Add an "alias" state to the addressable buffer data structures so that
we can refer back to the original case label var decl when the case body
var decl is brought into scope, so that accesses through either decl
properly force the addressable representation.

Fixes rdar://154543619.
2025-07-14 09:10:35 -07:00
Doug Gregor
47bb174683 Merge pull request #83013 from DougGregor/no-mangled-name-span-metadata-6.2 2025-07-14 08:37:14 -07:00
Alastair Houghton
eefdd69c8d Merge pull request #82915 from al45tair/eng/PR-151147606-take2
[Concurrency] Remove custom global executors from 6.2.
2025-07-14 16:20:57 +01:00
Pavel Yaskevich
c4a3d31ad0 Merge pull request #82998 from xedin/rdar-155589753-6.2
[6.2][Concurrency] Don't downgrade explicit isolation attribute clashes
2025-07-13 08:22:58 -07:00
Doug Gregor
74b54fea5c Use the "prohibits isolated conformances" check for capture metatypes
When checking whether a capture of a metatype is Sendable, we had an
incomplete and incorrect check for SendableMetatype conformance.
Replace that with the proper "prohibits isolated conformances" check
on the generic signature, which matches what we do on the caller side.

Fixes issue #82905 / rdar://155399531.
2025-07-12 08:47:14 -07:00
Augusto Noronha
e2c8b761cd [NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
Add an extra opaque field to AddressSpace, which can be used by clients
of RemoteInspection to distinguish between different address spaces.

LLDB employs an optimization where it reads memory from files instead of
the running process whenever it can to speed up memory reads (these can
be slow when debugging something over a network). To do this, it needs
to keep track whether an address originated from a process or a file. It
currently distinguishes addresses by setting an unused high bit on the
address, but because of pointer authentication this is not a reliable
solution. In order to keep this optimization working, this patch adds an
extra opaque AddressSpace field to RemoteAddress, which LLDB can use on
its own implementation of MemoryReader to distinguish between addresses.

This patch is NFC for the other RemoteInspection clients, as it adds
extra information to RemoteAddress, which is entirely optional and if
unused should not change the behavior of the library.

Although this patch is quite big the changes are largely mechanical,
replacing threading StoredPointer with RemoteAddress.

rdar://148361743
(cherry picked from commit 58df5534d2)
(cherry picked from commit 8f3862b5e7)
2025-07-11 16:36:40 -07:00
Augusto Noronha
9e85b88d9d [RemoteMirrors] Fix losing the remote address on StaticMirror
The Offset field of a DynamicRelocation is either an offset or a remote
address, but was being treated only as a remote address on
getDynamicSymbol.
2025-07-11 16:36:39 -07:00
Doug Gregor
d0d1a42b7c [IRGen] Mangling of nonisolated(nonsending) function types was introduced in Swift 6.2
We can't use mangled named when back-deploying earlier.
2025-07-11 14:26:32 -07:00
Doug Gregor
81dc98b0c8 [IRGen] Don't use mangled names for metadata including Span et al when back-deploying
If back-deploying prior to the introduction of name mangling and
runtime support for invertible constraints (~Copyable, ~Escapable),
don't use mangled names to access metadata. The code already existed
for this, but had a carve-out that still used mangled names for
standard library types that have always existed but got generalized to
support non-copyable & non-escapable types.

Tweak that carve-out to not apply to types like Span that come from a
back-deployment library. Fixes crashes when using metadata for Span et
al on older platforms.

Fixes rdar://155639204.
2025-07-11 14:26:32 -07:00
Doug Gregor
4501026c94 Merge pull request #82955 from DougGregor/strict-memory-safety-spurious-warning-fixes-6.2
[6.2] Fix spurious warnings with strict memory safety
2025-07-11 10:53:18 -07:00
Adrian Prantl
bfb026cb9e [RemoteInspection] Change RemoteAbsolutePointer (NFC)
This patch changes RemoteAbsolutePointer to store both the symbol and
the resolved address. This allows us to retire some ugly workarounds
to deal with non-symbolic addresses and it fixes code paths that would
need these workarounds, but haven't implemented them yet (i.e., the
pack shape handling in the symbolicReferenceResolver in MetadatyaReader.

Addresses parts of rdar://146273066.
rdar://153687085

(cherry picked from commit 9381a54c67)
(cherry picked from commit a6eafcb311)
2025-07-11 09:43:17 -07:00
Meghana Gupta
e3f0cfb80c Merge pull request #82980 from meg-gupta/fixsilcombinecp
[6.2] Fix SILCombine of inject_enum_addr when the enum is non-trivial but payload is trivial
2025-07-11 08:51:12 -07:00
Hamish Knight
9fb2e2f6a1 Merge pull request #82967 from hamishknight/len-check-6.2
[6.2] [Refactoring] Handle argument count mismatches in `renameLabelsLenient`
2025-07-11 14:53:51 +01:00
Hamish Knight
f807cbe30e Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-07-11 13:26:24 +01:00
Hamish Knight
cbad87d977 Merge pull request #82950 from hamishknight/ident-range-6.2
[6.2] [SourceKit] Fix raw identifier handling for semantic tokens
2025-07-11 10:09:00 +01:00
Pavel Yaskevich
4e93e74898 [Concurrency] Don't downgrade explicit isolation attribute clashes
The compiler shouldn't accept mismatch in explicit isolation attributes
because it could lead to incorrect isolation selection.

Resolves: rdar://155589753

(cherry picked from commit a9373c0f3f)
2025-07-10 22:29:20 -07:00
Michael Gottesman
35c3b9e12c [concurrency] Perform some fixes so that transfernonsendable_closureliterals_isolationinference.swift now passes.
The reason why this failed is that concurrently to @xedin landing
79af04ccc4, I enabled
NonisolatedNonsendingByDefault on a bunch of other tests. That change broke the
test and so we needed to fix it.

This commit fixes a few issues that were exposed:

1. We do not propagate nonisolated(nonsending) into a closure if its inferred
context isolation is global actor isolated or if the closure captures an
isolated parameter. We previously just always inferred
nonisolated(nonsending). Unfortunately since we do not yet have capture
information in CSApply, this required us to put the isolation change into
TypeCheckConcurrency.cpp and basically have function conversions of the form:

```
(function_conversion_expr type="nonisolated(nonsending) () async -> Void"
   (closure_expr type="() async -> ()" isolated_to_caller_isolation))
```

Notice how we have a function conversion to nonisolated(nonsending) from a
closure expr that has an isolation that is isolated_to_caller.

2. With this in hand, we found that this pattern caused us to first thunk a
nonisolated(nonsending) function to an @concurrent function and then thunk that
back to nonisolated(nonsending), causing the final function to always be
concurrent. I put into SILGen a peephole that recognizes this pattern and emits
the correct code.

3. With that in hand, we found that we were emitting nonisolated(nonsending)
parameters for inheritActorContext functions. This was then fixed by @xedin in

With all this in hand, closure literal isolation and all of the other RBI tests
with nonisolated(nonsending) enabled pass.

rdar://154969621
(cherry picked from commit 648bb8fe30)
2025-07-10 17:24:48 -07:00
Meghana Gupta
212e55e055 [6.2] Fix SILCombine of inject_enum_addr when the enum is non-trivial but payload is trivial 2025-07-10 17:17:25 -07:00
Meghana Gupta
5c85c65278 Disable retain and release sinking when rc root values are ~Copyable 2025-07-10 16:13:13 -07:00
Hamish Knight
e3c1dfcc7e [Refactoring] Handle argument count mismatches in renameLabelsLenient
Make sure we bail if we don't have enough labels in the old name when
matching against a found reference.

rdar://155549979
2025-07-10 21:42:27 +01:00
Joe Groff
1dd4a993eb Merge pull request #82916 from jckarter/preconcurrency-indirect-return-6.2
[6.2] SILGen: Bitcast indirect returns that differ only in concurrency annotations.
2025-07-10 12:05:35 -07:00
Meghana Gupta
1e6f93e0e1 Disable function signature optimization on functions with lifetime dependencies
If a function has lifetime dependencies, disable FSO's dead param optimization. Dead params maybe dependency sources and we should not delete them. It is also problematic to dead code params that are not dependency sources, since lifetime dependent sources are stored as indices and deleting dead parameters will require recomputation of these indices.
2025-07-10 11:35:23 -07:00
Doug Gregor
8c34d57874 [Strict memory safety] Eliminate spurious warnings with synthesized Codable
When synthesizing code for Codable conformances involving unsafe types,
make sure to wrap the resulting expressions in "unsafe" when strict memory safety is enabled.

Tweak the warning-emission logic to suppress warnings about spurious
"unsafe" expressions when the compiler generated the "unsafe" itself,
so we don't spam the developer with warnings they can't fix. Also make
the checking for other suppression considerations safe when there are
no source locations, eliminating a potential assertion.

Fixes rdar://153665692.
2025-07-10 09:12:49 -07:00
Doug Gregor
d6deeccc81 [Strict memory safety] Fix "unsafe" checking for the for..in loop
The `$generator` variable we create for the async for..in loop is
`nonisolated(unsafe)`, so ensure that we generate an `unsafe`
expression when we use it. This uncovered some inconsistencies in how
we do `unsafe` checking for for..in loops, so fix those.

Fixes rdar://154775389.

(cherry picked from commit 35628cb503)
2025-07-10 09:12:07 -07:00
Hamish Knight
32f840631c [6.2] [SourceKit] Fix raw identifier handling for semantic tokens
The logic here was unnecessary, the SourceRange gets converted to a
CharSourceRange in the function being called, which handles raw
identifiers correctly. 6.2-only since this is already fixed on main.

rdar://152273926
2025-07-10 15:28:01 +01:00
Gábor Horváth
9f9d2651b7 Merge pull request #82917 from Xazax-hun/unqualified-name-lookup-fix-on-6.2 2025-07-10 02:37:09 +01:00