Commit Graph

45958 Commits

Author SHA1 Message Date
Charles Zablit
710fe1b150 [demangling] make printRoot virtual 2025-09-10 11:29:07 +01:00
Artem Chikin
174636c7c9 Merge pull request #84111 from artemcm/62_1_DepScanWorkersNoShareDiagEngine
[6.2.1 🍒][Dependency Scanning] Give each scanner worker a unique Diagnostic Engine
2025-09-08 12:14:23 -04:00
eeckstein
e35a45f7b7 Merge pull request #83965 from eeckstein/fix-simplify-alloc-stack-apply-6.2.1
[6.2.1] Optimizer: fix handling of dependent existential archetypes in `alloc_stack` and `apply` simplification
2025-09-04 17:18:22 +02:00
Artem Chikin
dbf15f9c09 [6.2][Dependency Scanning] Give each scanner worker a unique Diagnostic Engine
Otherwise, when multiple workers encounter a diagnostic simultaneously we can encounter races which lead to corrupted diagnostic data or crashes

Resolves rdar://159598539
2025-09-03 12:32:10 -07:00
Nate Chandler
5851dcb971 [MemoryLifetimeVerifier] Permit leaks in dead-ends 2025-08-28 19:08:41 -07:00
Erik Eckstein
62e4cfbea7 AST: add Type.interfaceTypeOfArchetype and some related APIs 2025-08-28 07:17:54 +02:00
Erik Eckstein
e84228baf4 Swift AST: add some Type APIs 2025-08-28 07:17:53 +02:00
Charles Zablit
6324f20318 [demangling] make printGenericSignature virtual 2025-08-21 15:09:15 +01:00
Hamish Knight
a8cea97b4b Merge pull request #82988 from hamishknight/enable-inlinearray-sugar-6.2
[6.2] Enable InlineArray type sugar
2025-08-05 22:21:05 +01:00
Adrian Prantl
95ad22e799 [ClangImporter] Prefer serialized bridging headers in LLDB.
Especially in an explicit modules project, LLDB might not know all the
search paths needed to imported the on disk header.

rdar://157063577
(cherry picked from commit a6678476d8)
2025-08-04 11:15:55 -07:00
Michael Gottesman
dcb3e5c48e [concurrency] Emit nonisolated(nonsending) async throw initializers correctly.
Specifically, we were not inserting the implicit isolated parameter and were not
setting up the actor prologue. To keep this specific to nonisolated(nonsending)
code, I only setup the actor prologue if we know that we have something that is
nonisolated(nonsending).

I also ported some async initializer tests to run with/without
nonisolated(nonsending) just to increase code coverage.

rdar://156919493
(cherry picked from commit 3871d22257)
2025-07-29 20:10:44 -07:00
Adrian Prantl
5754397c94 Merge pull request #82968 from swiftlang/dl/6.2-RemoteInspection-Add-AsyncTaskInfo.IsSuspended-based-on-HasTaskDependency
[6.2] RemoteInspection: Add AsyncTaskInfo.IsSuspended based on HasTaskDependency
2025-07-29 11:12:40 -07:00
Slava Pestov
95baef19df Merge pull request #83300 from slavapestov/update-availability-macros-26-6.0
[6.2] Update utils/availability-macros.def
2025-07-26 10:47:45 -04:00
Slava Pestov
7fabd38ed0 Update utils/availability-macros.def 2025-07-25 15:45:44 -04:00
Doug Gregor
5abbf2e4c9 [SE-0466] Under main actor default isolation, explicit nonisolated is not special
Given an explicitly-nonisolated type such as

    nonisolated struct S { }

all extensions of S were also being treated as nonisolated. This meant
that being implicitly nonisolated (i.e., when you're using nonisolated
default isolation) was different from explicitly-writing nonisolated,
which is unfortunate and confusing. Align the rules, such that an
extension of S will get default isolation:

    extension S {
      func f() { } // @MainActor if we're in main actor default isolation
    }
2025-07-25 12:21:35 -07:00
Doug Gregor
2db51c9159 Merge pull request #82923 from DougGregor/sendable-prohibits-mainactor-by-default-6.2
[6.2] [SE-0466] Enable SendableProhibitsMainActorInference by default
2025-07-23 20:04:56 -07:00
Gábor Horváth
7429124124 Merge pull request #83065 from Xazax-hun/guard-more-objc-on-6.2
[6.2][cxx-interop] Types exposed from ObjC modules should be behind a macro
2025-07-22 11:20:22 +01:00
fredriss
b8da06d64a Merge pull request #83123 from augusto2112/virtual-read-remote-addr-6.2
[NFC][RemoteInspection] Make MemoryReader::readRemoteAddress virtual
2025-07-18 15:12:35 -07:00
Gabor Horvath
f48da45438 [cxx-interop] Configure requires ObjC from frontend option
We sometimes don't have the information in the modulemaps whether a
module requires ObjC or not. This info is useful for reverse interop.
This PR introduces a frontend flag to have a comma separated list of
modules that we should import as if they had "requires ObjC" in their
modulemaps.
2025-07-18 10:35:51 +01:00
Augusto Noronha
2ec8f057ca [RemoteInspection] Make MemoryReader::readRemoteAddress virtual
Allow subclasses to override the behavior of readRemoteAddress. LLDB in
particular needs this to correctly set the address space of the result
remote address.

rdar://148361743
(cherry picked from commit 45d6d45623)
2025-07-16 21:35:07 -07:00
Augusto Noronha
ac62ffcbf8 [NFC][RemoteMirrors] Add "template" in front of calls to readRemoteAddress
(cherry picked from commit 16591e4d0e)
2025-07-16 21:35:01 -07:00
Doug Gregor
6e419b6345 Revert "[6.2] Accept @cdecl global functions and enums, behind experimental feature flags" 2025-07-16 10:05:35 -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
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
Xi Ge
6f4d55a901 Merge branch 'release/6.2' into cdecl-6.2 2025-07-15 14:50:10 -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
Evan Wilde
d438c883f9 Merge pull request #82970 from etcwilde/ewilde/6.2-skip-unused-sections
[6.2🍒]: RemoteInspection: Skip unused ELF section headers
2025-07-11 23:23:22 -07:00
Augusto Noronha
79824f56b2 [RemoteAddress] Handle comparison of addresses in different spaces
Sometimes it makes sense to compares addresses from different address
spaces.

rdar://148361743
(cherry picked from commit c97dfd6b05)
2025-07-11 16:36:40 -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
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
Hamish Knight
f807cbe30e Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-07-11 13:26:24 +01:00
Michael Gottesman
1f9e30276a [rbi] Teach SendNonSendable how to more aggressively suppress sending errors around obfuscated Sendable functions
Specifically the type checker to work around interface types not having
isolation introduces casts into the AST that enrich the AST with isolation
information. Part of that information is Sendable. This means that we can
sometimes lose due to conversions that a function is actually Sendable. To work
around this, we today suppress those errors when they are emitted (post 6.2, we
should just change their classification as being Sendable... but I don't want to
make that change now).

This change just makes the pattern matching for these conversions handle more
cases so that transfernonsendable_closureliterals_isolationinference.swift now
passes.
2025-07-10 17:25:01 -07:00
Evan Wilde
ad1a33666e RemoteInspection: Skip unused ELF section headers
ELF section headers are allowed to be left uninitialized when the
section is empty and unused. LLD is a tad more aggressive about this.
The ELF reader in the Swift runtime was a bit aggressive about
converting the section headers to names and would not skip over these
unused sections headers resulting in crashes due to operating on
uninitialized memory in the `sh_name` field.

This patch teaches the ELF reader to skip over unused section header
table entries.

(cherry picked from commit 14d2088c75)

 - Explanation: Fixes a bug where we would read uninitialized data from
                unused ELF section headers.
 - Scope: Affects ELF-based platforms and ELF file handling in tools
   like swift-reflection-dump.
 - Risk: Low -- Improves implementation according to the spec.
                Any data used from this was garbage anyway.
 - Testing: Tested on FreeBSD with LLD, which makes uses of unused
            section headers. Ensured that runtime and
            swift-reflection-dump don't crash anymore.
 - Reviewers: @compnerd, @al45tair

Cherry-Pick: https://github.com/swiftlang/swift/pull/82698
2025-07-10 14:41:54 -07:00
Dave Lee
1b93f58d0f [6.2] RemoteInspection: Add AsyncTaskInfo.IsSuspended based on HasTaskDependency 2025-07-10 13:49:23 -07: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
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
Michael Gottesman
f920aba2f9 [rbi] Use interned StringRefs for diagnostics instead of SmallString<64>.
This makes the code easier to write and also prevents any lifetime issues from a
diagnostic outliving the SmallString due to diagnostic transactions.

(cherry picked from commit 010fa39f31)
2025-07-09 12:25:06 -07:00
Michael Gottesman
85fafa5b1e [rbi] Begin tracking if a function argument is from a nonisolated(nonsending) parameter and adjust printing as appropriate.
Specifically in terms of printing, if NonisolatedNonsendingByDefault is enabled,
we print out things as nonisolated/task-isolated and @concurrent/@concurrent
task-isolated. If said feature is disabled, we print out things as
nonisolated(nonsending)/nonisolated(nonsending) task-isolated and
nonisolated/task-isolated. This ensures in the default case, diagnostics do not
change and we always print out things to match the expected meaning of
nonisolated depending on the mode.

I also updated the tests as appropriate/added some more tests/added to the
SendNonSendable education notes information about this.

(cherry picked from commit 14634b6847)
2025-07-09 12:25:03 -07:00
Michael Gottesman
ca8cdc1fd7 [rbi] Thread through a SILFunction into print routines so we can access LangOpts.Features so we can change how we print based off of NonisolatedNonsendingByDefault.
We do not actually use this information yet though... This is just to ease
review.

(cherry picked from commit 4433ab8d81)
2025-07-09 12:24:17 -07:00
Michael Gottesman
0ec2527bdc [rbi] Wrap use ActorIsolation::printForDiagnostics with our own SILIsolationInfo::printActorIsolationForDiagnostics.
I am doing this so that I can change how we emit the diagnostics just for
SendNonSendable depending on if NonisolatedNonsendingByDefault is enabled
without touching the rest of the compiler.

This does not actually change any of the actual output though.

(cherry picked from commit 4ce4fc4f95)
2025-07-09 12:24:17 -07:00
Anthony Latsis
f5d547cd44 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSIL.def
(cherry picked from commit 5c190b9613)
2025-07-09 12:24:17 -07:00
Doug Gregor
457d44c624 [SE-0466] Enable SendableProhibitsMainActorInference by default
This implements the SE-0466 amendment under discussion for all code
with default main-actor isolation.

Finalizes rdar://151029300.
2025-07-09 10:49:03 -07:00
Gábor Horváth
b51b58db30 [6.2][cxx-interop] Fix unqualified name lookup failure
Explanation: C++ interop synthesizes certain forwarding functions in an
_ObjC module. This confuses MemberImportVisibility. This patch adds
logic to work this around by keeping a mapping between the synthesized
and the original function and looks up where the synthesized functions
belong to based on the original functions' parent module.
Scope: C++ forward interop when MemberImportVisibility is enabled.
Issues: rdar://154887575
Original PRs: #82840
Risk: Low, a narrow change makes getModuleContextForNameLookupForCxxDecl more
precise, and it is only used with MemberImportVisibility.
Testing: Added a compiler test.
Reviewers: @egorzhdan, @tshortli, @hnrklssn
2025-07-09 17:59:11 +01:00
Joe Groff
6f4748c5ef SILGen: Bitcast indirect returns that differ only in concurrency annotations.
A call to a `@preconcurrency` function goes through a function conversion
that removes `Sendable` from existentials among other things. Implement
support for this by bitcasting indirect return slots whose type differs
from the formal indirect return type in concurrency markings only.

Fixes rdar://154240007
2025-07-09 07:56:23 -07:00
Doug Gregor
1d86ed5f15 [Region analysis] Simplify logic for dynamic casts by making them less special
Extend and use SILIsolationInfo::getConformanceIsolation() for the dynamic
cast instructions.
2025-07-08 17:33:33 -07:00
Doug Gregor
066fa0b828 [Region isolation] Re-simplify handling of init_existential* instructions
Centralize the logic for figuring out the conformances for the various
init_existential* instructions in a SILIsolationInfo static method, and
always go through that when handling "assign" semantics. This way, we
can use CONSTANT_TRANSLATION again for these instructions, or a simpler
decision process between Assign and LookThrough.

The actually undoes a small change made earlier when we stopped looking
through `init_existential_value` instructions. Now we do when there are
no isolated conformances.
2025-07-08 17:33:33 -07:00
Doug Gregor
22ca6b98e5 [Region isolation] Factor SILIsolationInfo creation into static methods
Better match the style of SILIsolationInfo by moving the code for determining
SILIsolationInfo from conformances or dynamic casts to existentials into
static `getXYZ` methods on SILIsolationInfo.

Other than adding an assertion regarding disconnected regions, no
intended functionality change.
2025-07-08 17:33:33 -07:00
Doug Gregor
6637960bdc [SE-0470] Track the potential introduction of isolated conformances in regions
When we introduce isolation due to a (potential) isolated conformance,
keep track of the protocol to which the conformance could be
introduced. Use this information for two reasons:

1. Downgrade the error to a warning in Swift < 7, because we are newly
diagnosing these
2. Add a note indicating where the isolated conformance could be introduced.

(cherry picked from commit 02c34bb830)
2025-07-08 17:32:06 -07:00